[mutter/gbsneto/content: 29/29] shaped-texture: Move scale to MetaSurfaceActor
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/gbsneto/content: 29/29] shaped-texture: Move scale to MetaSurfaceActor
- Date: Tue, 23 Apr 2019 13:52:07 +0000 (UTC)
commit cbc5690e34a8038fa8df3293120abff8d6cba018
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Apr 19 17:49:39 2019 -0300
shaped-texture: Move scale to MetaSurfaceActor
The scale property is a surface-specific property. Theoretically,
MetaShapedTexture is "dumb" and doesn't really know nor care about
the scale; its contents are always in pixel sizes, and whoever is
displaying the texture is the actual responsible for handling the
scale.
In this case, the responsible one is MetaSurfaceActor.
Make MetaSurefaceActor handle scale. This is implemented by applying
a scale transformation to the actors transform matrix. Additionally,
it needs to set the reverse scale to child surfaces - that's because
scales are applied independently on each surface.
Everything that is passed to MetaShapedTexture is now scaled in
advance.
Notice that the wp_viewporter values are now converted to buffer
coordinates before being passed to MetaShapedTexture. That's because
wp_viewporter values are on surface coordinates after applying
rotation and scale [1].
[1] https://github.com/wayland-project/wayland-protocols/blob/master/stable/viewporter/viewporter.xml#L98
src/compositor/meta-shaped-texture-private.h | 4 --
src/compositor/meta-shaped-texture.c | 84 ++++++----------------
src/compositor/meta-surface-actor.c | 103 ++++++++++++++++++++++++---
src/compositor/meta-surface-actor.h | 3 +
src/compositor/meta-window-actor.c | 8 +--
src/wayland/meta-wayland-actor-surface.c | 4 +-
src/wayland/meta-wayland-surface.c | 7 +-
7 files changed, 124 insertions(+), 89 deletions(-)
---
diff --git a/src/compositor/meta-shaped-texture-private.h b/src/compositor/meta-shaped-texture-private.h
index 6e6739e6b..e87443451 100644
--- a/src/compositor/meta-shaped-texture-private.h
+++ b/src/compositor/meta-shaped-texture-private.h
@@ -50,10 +50,6 @@ void meta_shaped_texture_set_viewport_dst_size (MetaShapedTexture *stex,
int dst_width,
int dst_height);
void meta_shaped_texture_reset_viewport_dst_size (MetaShapedTexture *stex);
-void meta_shaped_texture_set_scale (MetaShapedTexture *stex,
- double scale);
-double meta_shaped_texture_get_scale (MetaShapedTexture *stex);
-
gboolean meta_shaped_texture_update_area (MetaShapedTexture *stex,
int x,
int y,
diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c
index e1c04fdf3..8071c5558 100644
--- a/src/compositor/meta-shaped-texture.c
+++ b/src/compositor/meta-shaped-texture.c
@@ -38,7 +38,6 @@
#include "compositor/clutter-utils.h"
#include "compositor/meta-cullable.h"
#include "compositor/meta-texture-tower.h"
-#include "compositor/region-utils.h"
#include "core/boxes-private.h"
#include "meta/meta-shaped-texture.h"
@@ -105,8 +104,6 @@ struct _MetaShapedTexture
guint remipmap_timeout_id;
gint64 earliest_remipmap;
- double scale;
-
guint create_mipmaps : 1;
};
@@ -140,7 +137,6 @@ meta_shaped_texture_init (MetaShapedTexture *stex)
{
stex->paint_tower = meta_texture_tower_new ();
- stex->scale = 1.0;
stex->texture = NULL;
stex->mask_texture = NULL;
stex->create_mipmaps = TRUE;
@@ -156,13 +152,13 @@ update_size (MetaShapedTexture *stex)
if (stex->has_viewport_dst_size)
{
- dst_width = ceil (stex->viewport_dst_width / stex->scale);
- dst_height = ceil (stex->viewport_dst_height / stex->scale);
+ dst_width = ceil (stex->viewport_dst_width);
+ dst_height = ceil (stex->viewport_dst_height);
}
else if (stex->has_viewport_src_rect)
{
- dst_width = ceil (stex->viewport_src_rect.size.width / stex->scale);
- dst_height = ceil (stex->viewport_src_rect.size.height / stex->scale);
+ dst_width = ceil (stex->viewport_src_rect.size.width);
+ dst_height = ceil (stex->viewport_src_rect.size.height);
}
else
{
@@ -313,25 +309,20 @@ get_base_pipeline (MetaShapedTexture *stex,
if (stex->has_viewport_src_rect)
{
+ double scale_x, scale_y;
+
if (meta_monitor_transform_is_rotated (stex->transform))
{
- cogl_matrix_scale (&matrix,
- stex->viewport_src_rect.size.width /
- (stex->tex_height * stex->scale),
- stex->viewport_src_rect.size.height /
- (stex->tex_width * stex->scale),
- 1);
+ scale_x = stex->viewport_src_rect.size.width / (double) stex->tex_height;
+ scale_y = stex->viewport_src_rect.size.height / (double) stex->tex_width;
}
else
{
- cogl_matrix_scale (&matrix,
- stex->viewport_src_rect.size.width /
- (stex->tex_width * stex->scale),
- stex->viewport_src_rect.size.height /
- (stex->tex_height * stex->scale),
- 1);
+ scale_x = stex->viewport_src_rect.size.width / (double) stex->tex_width;
+ scale_y = stex->viewport_src_rect.size.height / (double) stex->tex_height;
}
+ cogl_matrix_scale (&matrix, scale_x, scale_y, 1);
cogl_matrix_translate (&matrix,
stex->viewport_src_rect.origin.x /
stex->viewport_src_rect.size.width,
@@ -547,10 +538,7 @@ do_paint_content (MetaShapedTexture *stex,
if (stex->opaque_region && opacity == 255)
{
- opaque_tex_region =
- meta_region_scale_double (stex->opaque_region,
- 1.0 / stex->scale,
- META_ROUNDING_STRATEGY_SHRINK);
+ opaque_tex_region = cairo_region_reference (stex->opaque_region);
use_opaque_region = TRUE;
}
else
@@ -769,10 +757,10 @@ meta_shaped_texture_get_preferred_size (ClutterContent *content,
ensure_size_valid (stex);
if (width)
- *width = stex->dst_width * stex->scale;
+ *width = stex->dst_width;
if (height)
- *height = stex->dst_height * stex->scale;
+ *height = stex->dst_height;
return TRUE;
}
@@ -852,17 +840,12 @@ meta_shaped_texture_update_area (MetaShapedTexture *stex,
.height = height
};
- meta_rectangle_scale_double (clip,
- stex->scale,
- META_ROUNDING_STRATEGY_GROW,
- clip);
-
inverted_transform = meta_monitor_transform_invert (stex->transform);
ensure_size_valid (stex);
meta_rectangle_transform (clip,
inverted_transform,
- stex->dst_width * stex->scale,
- stex->dst_height * stex->scale,
+ stex->dst_width,
+ stex->dst_height,
clip);
if (stex->has_viewport_src_rect || stex->has_viewport_dst_size)
@@ -883,8 +866,8 @@ meta_shaped_texture_update_area (MetaShapedTexture *stex,
viewport = (ClutterRect) {
.origin.x = 0,
.origin.y = 0,
- .size.width = stex->tex_width * stex->scale,
- .size.height = stex->tex_height * stex->scale
+ .size.width = stex->tex_width,
+ .size.height = stex->tex_height
};
}
@@ -895,8 +878,8 @@ meta_shaped_texture_update_area (MetaShapedTexture *stex,
}
else
{
- dst_width = (float) stex->tex_width * stex->scale;
- dst_height = (float) stex->tex_height * stex->scale;
+ dst_width = (float) stex->tex_width;
+ dst_height = (float) stex->tex_height;
}
inverted_viewport = (ClutterRect) {
@@ -1250,10 +1233,7 @@ meta_shaped_texture_get_image (MetaShapedTexture *stex,
cairo_rectangle_int_t dst_rect;
transformed_clip = alloca (sizeof (cairo_rectangle_int_t));
-
- meta_rectangle_scale_double (clip, 1.0 / stex->scale,
- META_ROUNDING_STRATEGY_GROW,
- transformed_clip);
+ *transformed_clip = *clip;
dst_rect = (cairo_rectangle_int_t) {
.width = stex->dst_width,
@@ -1343,25 +1323,3 @@ meta_shaped_texture_new (void)
{
return g_object_new (META_TYPE_SHAPED_TEXTURE, NULL);
}
-
-void
-meta_shaped_texture_set_scale (MetaShapedTexture *stex,
- double scale)
-{
- g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
-
- if (scale == stex->scale)
- return;
-
- stex->scale = scale;
-
- invalidate_size (stex);
-}
-
-double
-meta_shaped_texture_get_scale (MetaShapedTexture *stex)
-{
- g_return_val_if_fail (META_IS_SHAPED_TEXTURE (stex), 1.0);
-
- return stex->scale;
-}
diff --git a/src/compositor/meta-surface-actor.c b/src/compositor/meta-surface-actor.c
index 14b95d92a..15ea1489f 100644
--- a/src/compositor/meta-surface-actor.c
+++ b/src/compositor/meta-surface-actor.c
@@ -22,12 +22,15 @@
#include "clutter/clutter.h"
#include "compositor/meta-cullable.h"
#include "compositor/meta-shaped-texture-private.h"
+#include "compositor/region-utils.h"
#include "meta/meta-shaped-texture.h"
typedef struct _MetaSurfaceActorPrivate
{
MetaShapedTexture *texture;
+ double geometry_scale;
+
cairo_region_t *input_region;
/* MetaCullable regions, see that documentation for more details */
@@ -110,6 +113,21 @@ set_clip_region (MetaSurfaceActor *surface_actor,
priv->clip_region = cairo_region_copy (clip_region);
}
+static void
+meta_surface_actor_apply_transform (ClutterActor *actor,
+ CoglMatrix *matrix)
+{
+ ClutterActorClass *parent_class =
+ CLUTTER_ACTOR_CLASS (meta_surface_actor_parent_class);
+ MetaSurfaceActor *surface_actor = META_SURFACE_ACTOR (actor);
+ MetaSurfaceActorPrivate *priv =
+ meta_surface_actor_get_instance_private (surface_actor);
+
+ parent_class->apply_transform (actor, matrix);
+
+ cogl_matrix_scale (matrix, priv->geometry_scale, priv->geometry_scale, 1);
+}
+
static void
meta_surface_actor_paint (ClutterActor *actor)
{
@@ -211,6 +229,7 @@ meta_surface_actor_class_init (MetaSurfaceActorClass *klass)
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
object_class->dispose = meta_surface_actor_dispose;
+ actor_class->apply_transform = meta_surface_actor_apply_transform;
actor_class->paint = meta_surface_actor_paint;
actor_class->pick = meta_surface_actor_pick;
actor_class->get_paint_volume = meta_surface_actor_get_paint_volume;
@@ -288,6 +307,7 @@ meta_surface_actor_init (MetaSurfaceActor *self)
MetaSurfaceActorPrivate *priv =
meta_surface_actor_get_instance_private (self);
+ priv->geometry_scale = 1.0;
priv->texture = META_SHAPED_TEXTURE (meta_shaped_texture_new ());
g_signal_connect_object (priv->texture, "size-changed",
G_CALLBACK (texture_size_changed), self, 0);
@@ -302,6 +322,11 @@ meta_surface_actor_get_image (MetaSurfaceActor *self,
MetaSurfaceActorPrivate *priv =
meta_surface_actor_get_instance_private (self);
+ meta_rectangle_scale_double (clip,
+ 1.0 / priv->geometry_scale,
+ META_ROUNDING_STRATEGY_GROW,
+ clip);
+
return meta_shaped_texture_get_image (priv->texture, clip);
}
@@ -374,6 +399,21 @@ meta_surface_actor_is_obscured (MetaSurfaceActor *self)
return FALSE;
}
+static cairo_region_t *
+apply_scale_to_region (MetaSurfaceActor *surface_actor,
+ cairo_region_t *region)
+{
+ MetaSurfaceActorPrivate *priv =
+ meta_surface_actor_get_instance_private (surface_actor);
+
+ if (!region)
+ return NULL;
+
+ return meta_region_scale_double (region,
+ 1.0 / priv->geometry_scale,
+ META_ROUNDING_STRATEGY_SHRINK);
+}
+
void
meta_surface_actor_set_input_region (MetaSurfaceActor *self,
cairo_region_t *region)
@@ -384,10 +424,7 @@ meta_surface_actor_set_input_region (MetaSurfaceActor *self,
if (priv->input_region)
cairo_region_destroy (priv->input_region);
- if (region)
- priv->input_region = cairo_region_reference (region);
- else
- priv->input_region = NULL;
+ priv->input_region = apply_scale_to_region (self, region);
}
void
@@ -396,8 +433,12 @@ meta_surface_actor_set_opaque_region (MetaSurfaceActor *self,
{
MetaSurfaceActorPrivate *priv =
meta_surface_actor_get_instance_private (self);
+ cairo_region_t *scaled_region;
+
+ scaled_region = apply_scale_to_region (self, region);
+ meta_shaped_texture_set_opaque_region (priv->texture, scaled_region);
- meta_shaped_texture_set_opaque_region (priv->texture, region);
+ g_clear_pointer (&scaled_region, cairo_region_destroy);
}
cairo_region_t *
@@ -567,8 +608,13 @@ meta_surface_actor_set_viewport_src_rect (MetaSurfaceActor *self,
{
MetaSurfaceActorPrivate *priv =
meta_surface_actor_get_instance_private (self);
+ ClutterRect scaled_rect = *src_rect;
- meta_shaped_texture_set_viewport_src_rect (priv->texture, src_rect);
+ clutter_rect_scale (&scaled_rect,
+ 1.0 / priv->geometry_scale,
+ 1.0 / priv->geometry_scale);
+
+ meta_shaped_texture_set_viewport_src_rect (priv->texture, &scaled_rect);
}
void
@@ -589,8 +635,8 @@ meta_surface_actor_set_viewport_dst_size (MetaSurfaceActor *self,
meta_surface_actor_get_instance_private (self);
meta_shaped_texture_set_viewport_dst_size (priv->texture,
- dst_width,
- dst_height);
+ dst_width / priv->geometry_scale,
+ dst_height / priv->geometry_scale);
}
void
@@ -601,3 +647,44 @@ meta_surface_actor_reset_viewport_dst_size (MetaSurfaceActor *self)
meta_shaped_texture_reset_viewport_dst_size (priv->texture);
}
+
+double
+meta_surface_actor_get_geometry_scale (MetaSurfaceActor *surface_actor)
+{
+ MetaSurfaceActorPrivate *priv =
+ meta_surface_actor_get_instance_private (surface_actor);
+
+ return priv->geometry_scale;
+}
+
+void
+meta_surface_actor_set_geometry_scale (MetaSurfaceActor *surface_actor,
+ double geometry_scale)
+{
+ MetaSurfaceActorPrivate *priv =
+ meta_surface_actor_get_instance_private (surface_actor);
+ ClutterActor *actor = CLUTTER_ACTOR (surface_actor);
+ CoglMatrix child_transform;
+
+ if (priv->geometry_scale == geometry_scale)
+ return;
+
+ priv->geometry_scale = geometry_scale;
+
+ if (geometry_scale != 1.0)
+ {
+ cogl_matrix_init_identity (&child_transform);
+ cogl_matrix_scale (&child_transform,
+ 1.0 / geometry_scale,
+ 1.0 / geometry_scale,
+ 1.0);
+
+ clutter_actor_set_child_transform (actor, &child_transform);
+ }
+ else
+ {
+ clutter_actor_set_child_transform (actor, NULL);
+ }
+
+ clutter_actor_queue_relayout (actor);
+}
diff --git a/src/compositor/meta-surface-actor.h b/src/compositor/meta-surface-actor.h
index 1cffcf99c..da3e81144 100644
--- a/src/compositor/meta-surface-actor.h
+++ b/src/compositor/meta-surface-actor.h
@@ -72,6 +72,9 @@ void meta_surface_actor_set_viewport_dst_size (MetaSurfaceActor *self,
int dst_width,
int dst_height);
void meta_surface_actor_reset_viewport_dst_size (MetaSurfaceActor *self);
+double meta_surface_actor_get_geometry_scale (MetaSurfaceActor *surface_actor);
+void meta_surface_actor_set_geometry_scale (MetaSurfaceActor *surface_actor,
+ double geometry_scale);
G_END_DECLS
#endif /* META_SURFACE_ACTOR_PRIVATE_H */
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index 71667e226..08d192151 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -1842,13 +1842,11 @@ meta_window_actor_get_frame_bounds (MetaScreenCastWindow *screen_cast_window,
MetaWindowActorPrivate *priv =
meta_window_actor_get_instance_private (window_actor);
MetaWindow *window;
- MetaShapedTexture *stex;
MetaRectangle buffer_rect;
MetaRectangle frame_rect;
double scale;
- stex = meta_surface_actor_get_texture (priv->surface);
- scale = meta_shaped_texture_get_scale (stex);
+ scale = meta_surface_actor_get_geometry_scale (priv->surface);
window = priv->window;
meta_window_get_buffer_rect (window, &buffer_rect);
@@ -1911,12 +1909,10 @@ meta_window_actor_transform_cursor_position (MetaScreenCastWindow *screen_cast_w
meta_cursor_sprite_get_cogl_texture (cursor_sprite) &&
out_cursor_scale)
{
- MetaShapedTexture *stex;
double texture_scale;
float cursor_texture_scale;
- stex = meta_surface_actor_get_texture (priv->surface);
- texture_scale = meta_shaped_texture_get_scale (stex);
+ texture_scale = meta_surface_actor_get_geometry_scale (priv->surface);
cursor_texture_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
*out_cursor_scale = texture_scale / cursor_texture_scale;
diff --git a/src/wayland/meta-wayland-actor-surface.c b/src/wayland/meta-wayland-actor-surface.c
index 2dc495be5..e278421ed 100644
--- a/src/wayland/meta-wayland-actor-surface.c
+++ b/src/wayland/meta-wayland-actor-surface.c
@@ -153,17 +153,15 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaSurfaceActor *surface_actor;
- MetaShapedTexture *stex;
double actor_scale;
GList *l;
cairo_rectangle_int_t surface_rect;
int geometry_scale;
surface_actor = priv->actor;
- stex = meta_surface_actor_get_texture (surface_actor);
actor_scale = meta_wayland_actor_surface_calculate_scale (actor_surface);
- meta_shaped_texture_set_scale (stex, actor_scale);
+ meta_surface_actor_set_geometry_scale (surface_actor, actor_scale);
/* Wayland surface coordinate space -> stage coordinate space */
geometry_scale = meta_wayland_actor_surface_get_geometry_scale (actor_surface);
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index f04758e9e..5755264c6 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -1572,14 +1572,11 @@ meta_wayland_surface_get_relative_coordinates (MetaWaylandSurface *surface,
{
MetaSurfaceActor *surface_actor =
meta_wayland_surface_get_actor (surface);
- MetaShapedTexture *stex =
- meta_surface_actor_get_texture (surface_actor);
ClutterActor *actor = CLUTTER_ACTOR (surface_actor);
- double scale = meta_shaped_texture_get_scale (stex);
clutter_actor_transform_stage_point (actor, abs_x, abs_y, sx, sy);
- *sx /= surface->scale * scale;
- *sy /= surface->scale * scale;
+ *sx /= surface->scale;
+ *sy /= surface->scale;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]