[mutter] clutter: Add clutter_stage_paint_to_content ()
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] clutter: Add clutter_stage_paint_to_content ()
- Date: Sun, 22 Aug 2021 13:10:03 +0000 (UTC)
commit 13a2a33257da9f73079b1934d2e41584dcf32679
Author: Ivan Molodetskikh <yalterz gmail com>
Date: Wed Jun 16 21:45:02 2021 +0300
clutter: Add clutter_stage_paint_to_content ()
Used in the new screenshot UI.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1899>
clutter/clutter/clutter-stage.c | 55 +++++++++++++++++++++++++++++++++++++++++
clutter/clutter/clutter-stage.h | 7 ++++++
2 files changed, 62 insertions(+)
---
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index fc170107f2..658a3156a5 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -3269,6 +3269,61 @@ clutter_stage_paint_to_buffer (ClutterStage *stage,
return TRUE;
}
+/**
+ * clutter_stage_paint_to_content:
+ * @stage: a #ClutterStage actor
+ * @rect: a #cairo_rectangle_int_t
+ * @scale: the scale
+ * @paint_flags: the #ClutterPaintFlag
+ * @error: the error
+ *
+ * Take a snapshot of the stage to a #ClutterContent.
+ *
+ * Returns: (transfer full): the #ClutterContent or %NULL on error.
+ */
+ClutterContent *
+clutter_stage_paint_to_content (ClutterStage *stage,
+ const cairo_rectangle_int_t *rect,
+ float scale,
+ ClutterPaintFlag paint_flags,
+ GError **error)
+{
+ ClutterBackend *clutter_backend = clutter_get_default_backend ();
+ CoglContext *cogl_context =
+ clutter_backend_get_cogl_context (clutter_backend);
+ int texture_width, texture_height;
+ CoglTexture2D *texture;
+ CoglOffscreen *offscreen;
+ g_autoptr (CoglFramebuffer) framebuffer = NULL;
+
+ texture_width = (int) roundf (rect->width * scale);
+ texture_height = (int) roundf (rect->height * scale);
+ texture = cogl_texture_2d_new_with_size (cogl_context,
+ texture_width,
+ texture_height);
+ if (!texture)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Failed to create %dx%d texture",
+ texture_width, texture_height);
+ return NULL;
+ }
+
+ offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture));
+ framebuffer = COGL_FRAMEBUFFER (offscreen);
+
+ cogl_object_unref (texture);
+
+ if (!cogl_framebuffer_allocate (framebuffer, error))
+ return NULL;
+
+ clutter_stage_paint_to_framebuffer (stage, framebuffer,
+ rect, scale, paint_flags);
+
+ return clutter_texture_content_new_from_texture (cogl_offscreen_get_texture (offscreen),
+ NULL);
+}
+
void
clutter_stage_capture_view_into (ClutterStage *stage,
ClutterStageView *view,
diff --git a/clutter/clutter/clutter-stage.h b/clutter/clutter/clutter-stage.h
index 69ab1d6eba..efb788e70a 100644
--- a/clutter/clutter/clutter-stage.h
+++ b/clutter/clutter/clutter-stage.h
@@ -252,6 +252,13 @@ gboolean clutter_stage_paint_to_buffer (ClutterStage *stage,
ClutterPaintFlag paint_flags,
GError **error);
+CLUTTER_EXPORT
+ClutterContent * clutter_stage_paint_to_content (ClutterStage *stage,
+ const cairo_rectangle_int_t *rect,
+ float scale,
+ ClutterPaintFlag paint_flags,
+ GError **error);
+
CLUTTER_EXPORT
ClutterStageView * clutter_stage_get_view_at (ClutterStage *stage,
float x,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]