1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
/*
* Copyright (C) 2012,2013 Intel Corporation
* Copyright (C) 2013-2017 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
*/
#include "config.h"
#include "wayland/meta-wayland-actor-surface.h"
#include "backends/meta-backend-private.h"
#include "backends/meta-logical-monitor.h"
#include "compositor/meta-surface-actor-wayland.h"
#include "compositor/region-utils.h"
#include "wayland/meta-wayland-surface.h"
#include "wayland/meta-window-wayland.h"
typedef struct _MetaWaylandActorSurfacePrivate MetaWaylandActorSurfacePrivate;
struct _MetaWaylandActorSurfacePrivate
{
MetaSurfaceActor *actor;
};
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaWaylandActorSurface,
meta_wayland_actor_surface,
META_TYPE_WAYLAND_SURFACE_ROLE)
static void
meta_wayland_actor_surface_constructed (GObject *object)
{
G_OBJECT_CLASS (meta_wayland_actor_surface_parent_class)->constructed (object);
meta_wayland_actor_surface_reset_actor (META_WAYLAND_ACTOR_SURFACE (object));
}
static void
meta_wayland_actor_surface_dispose (GObject *object)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (object));
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object));
if (priv->actor)
{
g_signal_handlers_disconnect_by_func (priv->actor,
meta_wayland_surface_notify_geometry_changed,
surface);
clutter_actor_set_reactive (CLUTTER_ACTOR (priv->actor), FALSE);
g_clear_object (&priv->actor);
}
G_OBJECT_CLASS (meta_wayland_actor_surface_parent_class)->dispose (object);
}
static void
meta_wayland_actor_surface_assigned (MetaWaylandSurfaceRole *surface_role)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (surface_role));
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
GList *l;
meta_surface_actor_wayland_add_frame_callbacks (META_SURFACE_ACTOR_WAYLAND (priv->actor),
&surface->pending_frame_callback_list);
wl_list_init (&surface->pending_frame_callback_list);
for (l = surface->subsurfaces; l; l = l->next)
{
ClutterActor *subsurface_actor =
CLUTTER_ACTOR (meta_wayland_surface_get_actor (l->data));
clutter_actor_add_child (CLUTTER_ACTOR (priv->actor), subsurface_actor);
}
}
void
meta_wayland_actor_surface_queue_frame_callbacks (MetaWaylandActorSurface *actor_surface,
MetaWaylandPendingState *pending)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (actor_surface);
MetaSurfaceActorWayland *surface_actor_wayland =
META_SURFACE_ACTOR_WAYLAND (priv->actor);
meta_surface_actor_wayland_add_frame_callbacks (surface_actor_wayland,
&pending->frame_callback_list);
wl_list_init (&pending->frame_callback_list);
}
double
meta_wayland_actor_surface_get_geometry_scale (MetaWaylandActorSurface *actor_surface)
{
MetaWaylandSurfaceRole *surface_role =
META_WAYLAND_SURFACE_ROLE (actor_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaWindow *toplevel_window;
toplevel_window = meta_wayland_surface_get_toplevel_window (surface);
if (meta_is_stage_views_scaled ())
{
return 1;
}
else
{
if (!toplevel_window ||
toplevel_window->client_type == META_WINDOW_CLIENT_TYPE_X11)
return 1;
else
return meta_window_wayland_get_geometry_scale (toplevel_window);
}
}
static void
meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor_surface)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (actor_surface);
MetaWaylandSurfaceRole *surface_role =
META_WAYLAND_SURFACE_ROLE (actor_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
MetaSurfaceActor *surface_actor;
MetaShapedTexture *stex;
GList *l;
cairo_rectangle_int_t surface_rect;
int geometry_scale;
surface_actor = priv->actor;
stex = meta_surface_actor_get_texture (surface_actor);
meta_shaped_texture_set_buffer_scale (stex, surface->scale);
/* Wayland surface coordinate space -> stage coordinate space */
geometry_scale = meta_wayland_actor_surface_get_geometry_scale (actor_surface);
clutter_actor_set_scale (CLUTTER_ACTOR (surface_actor),
geometry_scale,
geometry_scale);
surface_rect = (cairo_rectangle_int_t) {
.width = meta_wayland_surface_get_width (surface) * geometry_scale,
.height = meta_wayland_surface_get_height (surface) * geometry_scale,
};
if (surface->input_region)
{
cairo_region_t *input_region;
input_region = cairo_region_copy (surface->input_region);
cairo_region_intersect_rectangle (input_region, &surface_rect);
meta_surface_actor_set_input_region (surface_actor, input_region);
cairo_region_destroy (input_region);
}
else
{
meta_surface_actor_set_input_region (surface_actor, NULL);
}
if (surface->opaque_region)
{
cairo_region_t *opaque_region;
opaque_region = cairo_region_copy (surface->opaque_region);
cairo_region_intersect_rectangle (opaque_region, &surface_rect);
meta_surface_actor_set_opaque_region (surface_actor, opaque_region);
cairo_region_destroy (opaque_region);
}
else
{
meta_surface_actor_set_opaque_region (surface_actor, NULL);
}
meta_surface_actor_set_transform (surface_actor, surface->buffer_transform);
if (surface->viewport.has_src_rect)
{
meta_surface_actor_set_viewport_src_rect (surface_actor,
&surface->viewport.src_rect);
}
else
{
meta_surface_actor_reset_viewport_src_rect (surface_actor);
}
if (surface->viewport.has_dst_size)
{
meta_surface_actor_set_viewport_dst_size (surface_actor,
surface->viewport.dst_width,
surface->viewport.dst_height);
}
else
{
meta_surface_actor_reset_viewport_dst_size (surface_actor);
}
for (l = surface->subsurfaces; l; l = l->next)
{
MetaWaylandSurface *subsurface_surface = l->data;
MetaWaylandActorSurface *subsurface_actor_surface =
META_WAYLAND_ACTOR_SURFACE (subsurface_surface->role);
meta_wayland_actor_surface_sync_actor_state (subsurface_actor_surface);
}
}
void
meta_wayland_actor_surface_sync_actor_state (MetaWaylandActorSurface *actor_surface)
{
MetaWaylandActorSurfaceClass *actor_surface_class =
META_WAYLAND_ACTOR_SURFACE_GET_CLASS (actor_surface);
actor_surface_class->sync_actor_state (actor_surface);
}
static void
meta_wayland_actor_surface_commit (MetaWaylandSurfaceRole *surface_role,
MetaWaylandPendingState *pending)
{
MetaWaylandActorSurface *actor_surface =
META_WAYLAND_ACTOR_SURFACE (surface_role);
meta_wayland_actor_surface_queue_frame_callbacks (actor_surface, pending);
meta_wayland_actor_surface_sync_actor_state (actor_surface);
}
static gboolean
meta_wayland_actor_surface_is_on_logical_monitor (MetaWaylandSurfaceRole *surface_role,
MetaLogicalMonitor *logical_monitor)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (META_WAYLAND_ACTOR_SURFACE (surface_role));
ClutterActor *actor = CLUTTER_ACTOR (priv->actor);
float x, y, width, height;
cairo_rectangle_int_t actor_rect;
cairo_region_t *region;
MetaRectangle logical_monitor_layout;
gboolean is_on_monitor;
clutter_actor_get_transformed_position (actor, &x, &y);
clutter_actor_get_transformed_size (actor, &width, &height);
actor_rect.x = (int) roundf (x);
actor_rect.y = (int) roundf (y);
actor_rect.width = (int) roundf (x + width) - actor_rect.x;
actor_rect.height = (int) roundf (y + height) - actor_rect.y;
/* Calculate the scaled surface actor region. */
region = cairo_region_create_rectangle (&actor_rect);
logical_monitor_layout = meta_logical_monitor_get_layout (logical_monitor);
cairo_region_intersect_rectangle (region,
&((cairo_rectangle_int_t) {
.x = logical_monitor_layout.x,
.y = logical_monitor_layout.y,
.width = logical_monitor_layout.width,
.height = logical_monitor_layout.height,
}));
is_on_monitor = !cairo_region_is_empty (region);
cairo_region_destroy (region);
return is_on_monitor;
}
static void
meta_wayland_actor_surface_init (MetaWaylandActorSurface *role)
{
}
static void
meta_wayland_actor_surface_class_init (MetaWaylandActorSurfaceClass *klass)
{
MetaWaylandSurfaceRoleClass *surface_role_class =
META_WAYLAND_SURFACE_ROLE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = meta_wayland_actor_surface_constructed;
object_class->dispose = meta_wayland_actor_surface_dispose;
surface_role_class->assigned = meta_wayland_actor_surface_assigned;
surface_role_class->commit = meta_wayland_actor_surface_commit;
surface_role_class->is_on_logical_monitor =
meta_wayland_actor_surface_is_on_logical_monitor;
klass->sync_actor_state = meta_wayland_actor_surface_real_sync_actor_state;
}
MetaSurfaceActor *
meta_wayland_actor_surface_get_actor (MetaWaylandActorSurface *actor_surface)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (actor_surface);
return priv->actor;
}
void
meta_wayland_actor_surface_reset_actor (MetaWaylandActorSurface *actor_surface)
{
MetaWaylandActorSurfacePrivate *priv =
meta_wayland_actor_surface_get_instance_private (actor_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (actor_surface));
if (priv->actor)
{
g_signal_handlers_disconnect_by_func (priv->actor,
meta_wayland_surface_notify_geometry_changed,
surface);
g_object_unref (priv->actor);
}
priv->actor = g_object_ref_sink (meta_surface_actor_wayland_new (surface));
g_signal_connect_swapped (priv->actor, "notify::allocation",
G_CALLBACK (meta_wayland_surface_notify_geometry_changed),
surface);
g_signal_connect_swapped (priv->actor, "notify::position",
G_CALLBACK (meta_wayland_surface_notify_geometry_changed),
surface);
g_signal_connect_swapped (priv->actor, "notify::mapped",
G_CALLBACK (meta_wayland_surface_notify_geometry_changed),
surface);
}
|