ui::testing::OffscreenCapture¶
Header: winui/testing/OffscreenCapture.hpp.
Renders a laid-out Window to a Bitmap with the same renderer an on-screen window uses, with no native window and no GPU. The pixel golden tests capture through it.
Draws into a software bitmap with grayscale text anti-aliasing, so output is stable run to run and independent of the monitor. Lay the window out with measurer() first so text metrics match what capture() paints. On a platform the library has no renderer for, ok() is false and every capture is an empty bitmap. Not copyable.
Example:
ui::testing::OffscreenCapture d2d;
REQUIRE(d2d.ok());
ui::Window window;
window.set_content(ui::Button{.text = "Hello"});
const ui::Size client{200, 60};
window.layout(client, d2d.measurer());
const ui::Bitmap image = d2d.capture(window, client, ui::Theme::light().colors().background);
REQUIRE(image.width() == 200);
OffscreenCapture¶
Sets up the renderer; check ok() afterwards.
~OffscreenCapture¶
Releases the renderer's resources.
OffscreenCapture¶
Not copyable: owns renderer resources.
operator=¶
Not copyable: owns renderer resources.
ok¶
True if the renderer was set up and capture() can draw.
measurer¶
The text measurer the renderer uses. Lay the window out with it so text metrics match what capture() paints. Owned by this object; valid for its lifetime.
capture¶
Renders an already laid-out window at client pixels (1 DIP == 1 px) to an RGBA image, over background. Pass the theme's window background, since Fluent fills are translucent. Returns an empty image if the renderer is not ok().
capture_changes¶
capture() the way a window repaints. Over what the last capture of the same size left, only the areas Window::take_damage() reports are cleared and drawn again, and the whole image the first time. A test of the partial repaint checks that the result matches a full capture().