summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Mader <robert.mader@posteo.de>2021-08-22 13:46:52 +0200
committerMarge Bot <marge-bot@gnome.org>2021-09-04 09:17:44 +0000
commit2239e7ad29781b7ed8c2171759e5befca2239a71 (patch)
tree822d0696d8a05207bd2a37d46430f1db7ead33ec
parentb1c8510a95dfe7c4bdf7835cdccd25ac2c11b491 (diff)
downloadmutter-2239e7ad29781b7ed8c2171759e5befca2239a71.tar.gz
shaped-texture: Remove get_image_via_offscreen()
It duplicates functionality in `meta_window_actor_get_image()`, its only user. Instead, make `should_get_via_offscreen()` public and use it in the former. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1893>
-rw-r--r--src/compositor/meta-shaped-texture-private.h2
-rw-r--r--src/compositor/meta-shaped-texture.c118
-rw-r--r--src/compositor/meta-window-actor.c7
3 files changed, 11 insertions, 116 deletions
diff --git a/src/compositor/meta-shaped-texture-private.h b/src/compositor/meta-shaped-texture-private.h
index 2fe1b8ea4..bfe3039a9 100644
--- a/src/compositor/meta-shaped-texture-private.h
+++ b/src/compositor/meta-shaped-texture-private.h
@@ -73,4 +73,6 @@ void meta_shaped_texture_set_opaque_region (MetaShapedTexture *stex,
void meta_shaped_texture_ensure_size_valid (MetaShapedTexture *stex);
+gboolean meta_shaped_texture_should_get_via_offscreen (MetaShapedTexture *stex);
+
#endif
diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c
index f237d82dd..9d811ea07 100644
--- a/src/compositor/meta-shaped-texture.c
+++ b/src/compositor/meta-shaped-texture.c
@@ -1343,8 +1343,8 @@ meta_shaped_texture_reset_viewport_dst_size (MetaShapedTexture *stex)
invalidate_size (stex);
}
-static gboolean
-should_get_via_offscreen (MetaShapedTexture *stex)
+gboolean
+meta_shaped_texture_should_get_via_offscreen (MetaShapedTexture *stex)
{
if (!cogl_texture_is_get_data_supported (stex->texture))
return TRUE;
@@ -1369,104 +1369,6 @@ should_get_via_offscreen (MetaShapedTexture *stex)
return FALSE;
}
-static cairo_surface_t *
-get_image_via_offscreen (MetaShapedTexture *stex,
- cairo_rectangle_int_t *clip,
- int image_width,
- int image_height)
-{
- g_autoptr (ClutterPaintNode) root_node = NULL;
- ClutterBackend *clutter_backend = clutter_get_default_backend ();
- CoglContext *cogl_context =
- clutter_backend_get_cogl_context (clutter_backend);
- CoglTexture *image_texture;
- GError *error = NULL;
- CoglOffscreen *offscreen;
- CoglFramebuffer *fb;
- graphene_matrix_t projection_matrix;
- cairo_rectangle_int_t fallback_clip;
- ClutterColor clear_color;
- ClutterPaintContext *paint_context;
- cairo_surface_t *surface;
-
- if (!clip)
- {
- fallback_clip = (cairo_rectangle_int_t) {
- .width = image_width,
- .height = image_height,
- };
- clip = &fallback_clip;
- }
-
- image_texture =
- COGL_TEXTURE (cogl_texture_2d_new_with_size (cogl_context,
- image_width,
- image_height));
- cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (image_texture),
- FALSE);
- if (!cogl_texture_allocate (COGL_TEXTURE (image_texture), &error))
- {
- g_error_free (error);
- cogl_object_unref (image_texture);
- return FALSE;
- }
-
- offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (image_texture));
- fb = COGL_FRAMEBUFFER (offscreen);
- cogl_object_unref (image_texture);
- if (!cogl_framebuffer_allocate (fb, &error))
- {
- g_error_free (error);
- g_object_unref (fb);
- return FALSE;
- }
-
- cogl_framebuffer_push_matrix (fb);
- graphene_matrix_init_translate (&projection_matrix,
- &GRAPHENE_POINT3D_INIT (-(image_width / 2.0),
- -(image_height / 2.0),
- 0));
- graphene_matrix_scale (&projection_matrix,
- 1.0 / (image_width / 2.0),
- -1.0 / (image_height / 2.0), 0);
-
- cogl_framebuffer_set_projection_matrix (fb, &projection_matrix);
-
- clear_color = (ClutterColor) { 0, 0, 0, 0 };
-
- root_node = clutter_root_node_new (fb, &clear_color, COGL_BUFFER_BIT_COLOR);
- clutter_paint_node_set_static_name (root_node, "MetaShapedTexture.offscreen");
-
- paint_context =
- clutter_paint_context_new_for_framebuffer (fb, NULL,
- CLUTTER_PAINT_FLAG_NONE);
-
- do_paint_content (stex, root_node, paint_context,
- stex->texture,
- &(ClutterActorBox) {
- 0, 0,
- image_width,
- image_height,
- },
- 255);
-
- clutter_paint_node_paint (root_node, paint_context);
- clutter_paint_context_destroy (paint_context);
-
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- clip->width, clip->height);
- cogl_framebuffer_read_pixels (fb,
- clip->x, clip->y,
- clip->width, clip->height,
- CLUTTER_CAIRO_FORMAT_ARGB32,
- cairo_image_surface_get_data (surface));
- g_object_unref (fb);
-
- cairo_surface_mark_dirty (surface);
-
- return surface;
-}
-
/**
* meta_shaped_texture_get_image:
* @stex: A #MetaShapedTexture
@@ -1496,6 +1398,9 @@ meta_shaped_texture_get_image (MetaShapedTexture *stex,
if (texture == NULL)
return NULL;
+ if (meta_shaped_texture_should_get_via_offscreen (stex))
+ return NULL;
+
meta_shaped_texture_ensure_size_valid (stex);
if (stex->dst_width == 0 || stex->dst_height == 0)
@@ -1523,19 +1428,6 @@ meta_shaped_texture_get_image (MetaShapedTexture *stex,
};
}
- if (should_get_via_offscreen (stex))
- {
- int image_width;
- int image_height;
-
- image_width = stex->dst_width * stex->buffer_scale;
- image_height = stex->dst_height * stex->buffer_scale;
- return get_image_via_offscreen (stex,
- image_clip,
- image_width,
- image_height);
- }
-
if (image_clip)
texture = cogl_texture_new_from_sub_texture (texture,
image_clip->x,
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index cbc0c96a8..b32df2010 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -1484,6 +1484,7 @@ meta_window_actor_get_image (MetaWindowActor *self,
{
MetaWindowActorPrivate *priv = meta_window_actor_get_instance_private (self);
ClutterActor *actor = CLUTTER_ACTOR (self);
+ MetaShapedTexture *stex;
cairo_surface_t *surface = NULL;
CoglFramebuffer *framebuffer;
MetaRectangle framebuffer_clip;
@@ -1495,9 +1496,10 @@ meta_window_actor_get_image (MetaWindowActor *self,
clutter_actor_inhibit_culling (actor);
- if (clutter_actor_get_n_children (actor) == 1)
+ stex = meta_surface_actor_get_texture (priv->surface);
+ if (!meta_shaped_texture_should_get_via_offscreen (stex) &&
+ clutter_actor_get_n_children (actor) == 1)
{
- MetaShapedTexture *stex;
MetaRectangle *surface_clip = NULL;
if (clip)
@@ -1514,7 +1516,6 @@ meta_window_actor_get_image (MetaWindowActor *self,
surface_clip->height = clip->height / geometry_scale;
}
- stex = meta_surface_actor_get_texture (priv->surface);
surface = meta_shaped_texture_get_image (stex, surface_clip);
goto out;
}