Changelog: C++: Add slint::Window::take_snapshot()

Corresponds to the Rust API.
This commit is contained in:
Simon Hausmann 2024-11-13 11:22:23 +01:00 committed by Simon Hausmann
parent 8fdbfc5ee5
commit a7a3b3f9ee
5 changed files with 39 additions and 2 deletions

View file

@ -573,6 +573,7 @@ fn gen_corelib(
"slint_windowrc_is_fullscreen",
"slint_windowrc_is_minimized",
"slint_windowrc_is_maximized",
"slint_windowrc_take_snapshot",
"slint_new_path_elements",
"slint_new_path_events",
"slint_color_brighter",

View file

@ -64,6 +64,7 @@ struct SharedPixelBuffer
private:
friend struct Image;
friend class Window;
uint32_t m_width;
uint32_t m_height;
SharedVector<Pixel> m_data;

View file

@ -602,6 +602,21 @@ public:
return cbindgen_private::slint_windowrc_has_active_animations(&inner.handle());
}
/// Takes a snapshot of the window contents and returns it as RGBA8 encoded pixel buffer.
///
/// Note that this function may be slow to call. Reading from the framebuffer previously
/// rendered, too, may take a long time.
std::optional<SharedPixelBuffer<Rgba8Pixel>> take_snapshot() const
{
SharedPixelBuffer<Rgba8Pixel> result;
if (cbindgen_private::slint_windowrc_take_snapshot(&inner.handle(), &result.m_data,
&result.m_width, &result.m_height)) {
return result;
} else {
return {};
}
}
/// \private
private_api::WindowAdapterRc &window_handle() { return inner; }
/// \private