-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1880.patch
3245 lines (3005 loc) · 115 KB
/
1880.patch
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Author: Michel Dänzer <[email protected]>
Source: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880
Editor: Mingi Sung <[email protected]>
Commit: 05efcb4b21acc98fa5636542888c0fe2da05781b
Last Updated: 12/3/22 (Mutter 43.1+r24+g030e9b8b2-1)
---
If mutter's GPU work directly depends on unfinished client work,
mutter's work can only start once the client work has finished,
even if mutter is using a higher priority EGL context.
This is sort of like a priority inversion, which makes it impossible
for mutter's frame rate to exceed that of heavy clients.
When scanning out directly from client buffers,
unfinished client work can cause the page flip to miss the next display refresh cycle,
resulting in the previous frame being displayed again instead for another refresh cycle.
This can be noticeable as stutter if another buffer was attached
in between which would have been ready in time for the next refresh cycle.
To avoid these issues, wait for newly attached buffers to become idle before making use of them.
Sounds easy, right? :) It's rather complex in fact, because the Wayland protocol allows clients
to commit arbitrary other surface state changes together with attaching a new buffer.
mutter must ensure that all state changes committed together by the client are also applied together atomically.
(It gets even more complex than that for synchronized sub-surfaces)
To achieve this, introduce transactions consisting of state changes for one or multiple Wayland surfaces.
All Wayland surface commits (plus sub-surface state changes which aren't part of commits) are handled as transactions.
Before applying a transaction, wait for
1. all newly attached buffers it references to become idle (to avoid the issues described above)
2. all earlier committed transactions which reference any of the same surfaces to be applied first
(to ensure that state for a given surface is applied in the same order as it was committed by the client)
This fixes #1162 if the GPU & drivers support high priority contexts which can preempt lower priority contexts.
There are also fixes for various aspects related to sub-surfaces. In particular, the weston-subsurfaces demo now works
correctly when run with the -r1/-t1 command line parameters.
Nested hierarchies of synchronized sub-surfaces should now work more correctly as well.
---
diff --git a/src/compositor/meta-window-actor-wayland.c b/src/compositor/meta-window-actor-wayland.c
index 3b87f0139..78f5266d4 100644
--- a/src/compositor/meta-window-actor-wayland.c
+++ b/src/compositor/meta-window-actor-wayland.c
@@ -197,7 +197,7 @@ meta_window_actor_wayland_rebuild_surface_tree (MetaWindowActor *actor)
meta_window_actor_get_surface (actor);
MetaWaylandSurface *surface = meta_surface_actor_wayland_get_surface (
META_SURFACE_ACTOR_WAYLAND (surface_actor));
- GNode *root_node = surface->subsurface_branch_node;
+ GNode *root_node = surface->output_state.subsurface_branch_node;
g_autoptr (GList) surface_actors = NULL;
g_autoptr (GList) children = NULL;
GList *l;
diff --git a/src/meson.build b/src/meson.build
index 6790efa16..84320adbb 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -657,6 +657,8 @@ if have_wayland
'wayland/meta-wayland-text-input.h',
'wayland/meta-wayland-touch.c',
'wayland/meta-wayland-touch.h',
+ 'wayland/meta-wayland-transaction.c',
+ 'wayland/meta-wayland-transaction.h',
'wayland/meta-wayland-types.h',
'wayland/meta-wayland-versions.h',
'wayland/meta-wayland-viewporter.c',
diff --git a/src/wayland/meta-wayland-actor-surface.c b/src/wayland/meta-wayland-actor-surface.c
index 362785c89..f4ad2d0e4 100644
--- a/src/wayland/meta-wayland-actor-surface.c
+++ b/src/wayland/meta-wayland-actor-surface.c
@@ -184,16 +184,18 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
surface_actor = priv->actor;
stex = meta_surface_actor_get_texture (surface_actor);
- buffer = surface->buffer_ref->buffer;
+ buffer = meta_wayland_surface_get_buffer (surface);
if (buffer)
{
CoglSnippet *snippet;
gboolean is_y_inverted;
+ CoglTexture *texture;
snippet = meta_wayland_buffer_create_snippet (buffer);
is_y_inverted = meta_wayland_buffer_is_y_inverted (buffer);
- meta_shaped_texture_set_texture (stex, surface->texture);
+ texture = meta_wayland_surface_get_texture (surface);
+ meta_shaped_texture_set_texture (stex, texture);
meta_shaped_texture_set_snippet (stex, snippet);
meta_shaped_texture_set_is_y_inverted (stex, is_y_inverted);
meta_shaped_texture_set_buffer_scale (stex, surface->scale);
@@ -273,7 +275,8 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
meta_shaped_texture_ensure_size_valid (stex);
- META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
+ META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (&surface->output_state,
+ subsurface_surface)
{
MetaWaylandActorSurface *actor_surface;
@@ -417,7 +420,8 @@ meta_wayland_actor_surface_reset_actor (MetaWaylandActorSurface *actor_surface)
meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (actor_surface));
MetaWaylandSurface *subsurface_surface;
- META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
+ META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (&surface->output_state,
+ subsurface_surface)
{
MetaWaylandActorSurface *actor_surface;
diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c
index 7a22f824b..dea0f8e59 100644
--- a/src/wayland/meta-wayland-buffer.c
+++ b/src/wayland/meta-wayland-buffer.c
@@ -559,8 +559,6 @@ meta_wayland_buffer_attach (MetaWaylandBuffer *buffer,
CoglTexture **texture,
GError **error)
{
- g_return_val_if_fail (buffer->resource, FALSE);
-
COGL_TRACE_BEGIN_SCOPED (MetaWaylandBufferAttach, "WaylandBuffer (attach)");
if (!meta_wayland_buffer_is_realized (buffer))
@@ -621,6 +619,25 @@ meta_wayland_buffer_create_snippet (MetaWaylandBuffer *buffer)
#endif /* HAVE_WAYLAND_EGLSTREAM */
}
+void
+meta_wayland_buffer_inc_use_count (MetaWaylandBuffer *buffer)
+{
+ g_warn_if_fail (buffer->resource);
+
+ buffer->use_count++;
+}
+
+void
+meta_wayland_buffer_dec_use_count (MetaWaylandBuffer *buffer)
+{
+ g_return_if_fail (buffer->use_count > 0);
+
+ buffer->use_count--;
+
+ if (buffer->use_count == 0 && buffer->resource)
+ wl_buffer_send_release (buffer->resource);
+}
+
gboolean
meta_wayland_buffer_is_y_inverted (MetaWaylandBuffer *buffer)
{
@@ -804,6 +821,8 @@ meta_wayland_buffer_finalize (GObject *object)
{
MetaWaylandBuffer *buffer = META_WAYLAND_BUFFER (object);
+ g_warn_if_fail (buffer->use_count == 0);
+
g_clear_pointer (&buffer->egl_image.texture, cogl_object_unref);
#ifdef HAVE_WAYLAND_EGLSTREAM
g_clear_pointer (&buffer->egl_stream.texture, cogl_object_unref);
diff --git a/src/wayland/meta-wayland-buffer.h b/src/wayland/meta-wayland-buffer.h
index 0f83b67de..f0f352d71 100644
--- a/src/wayland/meta-wayland-buffer.h
+++ b/src/wayland/meta-wayland-buffer.h
@@ -54,6 +54,8 @@ struct _MetaWaylandBuffer
struct wl_resource *resource;
struct wl_listener destroy_listener;
+ unsigned int use_count;
+
gboolean is_y_inverted;
MetaWaylandBufferType type;
@@ -93,6 +95,8 @@ gboolean meta_wayland_buffer_attach (MetaWaylandBuff
CoglTexture **texture,
GError **error);
CoglSnippet * meta_wayland_buffer_create_snippet (MetaWaylandBuffer *buffer);
+void meta_wayland_buffer_inc_use_count (MetaWaylandBuffer *buffer);
+void meta_wayland_buffer_dec_use_count (MetaWaylandBuffer *buffer);
gboolean meta_wayland_buffer_is_y_inverted (MetaWaylandBuffer *buffer);
void meta_wayland_buffer_process_damage (MetaWaylandBuffer *buffer,
CoglTexture *texture,
diff --git a/src/wayland/meta-wayland-client.c b/src/wayland/meta-wayland-client.c
index 69c7b8333..5ca7c6937 100644
--- a/src/wayland/meta-wayland-client.c
+++ b/src/wayland/meta-wayland-client.c
@@ -297,7 +297,7 @@ meta_wayland_client_owns_window (MetaWaylandClient *client,
g_return_val_if_fail (client->process_running, FALSE);
surface = window->surface;
- if (surface == NULL)
+ if (surface == NULL || surface->resource == NULL)
return FALSE;
return wl_resource_get_client (surface->resource) == client->wayland_client;
diff --git a/src/wayland/meta-wayland-cursor-surface.c b/src/wayland/meta-wayland-cursor-surface.c
index 4d3b7547c..9d045c18a 100644
--- a/src/wayland/meta-wayland-cursor-surface.c
+++ b/src/wayland/meta-wayland-cursor-surface.c
@@ -139,12 +139,10 @@ meta_wayland_cursor_surface_pre_apply_state (MetaWaylandSurfaceRole *surface_ro
META_WAYLAND_CURSOR_SURFACE (surface_role);
MetaWaylandCursorSurfacePrivate *priv =
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
- MetaWaylandSurface *surface =
- meta_wayland_surface_role_get_surface (surface_role);
if (pending->newly_attached && priv->buffer)
{
- meta_wayland_surface_unref_buffer_use_count (surface);
+ meta_wayland_buffer_dec_use_count (priv->buffer);
g_clear_object (&priv->buffer);
}
}
@@ -157,15 +155,11 @@ meta_wayland_cursor_surface_apply_state (MetaWaylandSurfaceRole *surface_role,
META_WAYLAND_CURSOR_SURFACE (surface_role);
MetaWaylandCursorSurfacePrivate *priv =
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
- MetaWaylandSurface *surface =
- meta_wayland_surface_role_get_surface (surface_role);
- MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
- if (pending->newly_attached)
+ if (pending->buffer)
{
- g_set_object (&priv->buffer, buffer);
- if (priv->buffer)
- meta_wayland_surface_ref_buffer_use_count (surface);
+ priv->buffer = g_object_ref (pending->buffer);
+ meta_wayland_buffer_inc_use_count (priv->buffer);
}
wl_list_insert_list (&priv->frame_callbacks,
@@ -213,8 +207,6 @@ meta_wayland_cursor_surface_dispose (GObject *object)
META_WAYLAND_CURSOR_SURFACE (object);
MetaWaylandCursorSurfacePrivate *priv =
meta_wayland_cursor_surface_get_instance_private (cursor_surface);
- MetaWaylandSurface *surface =
- meta_wayland_surface_role_get_surface (META_WAYLAND_SURFACE_ROLE (object));
MetaWaylandFrameCallback *cb, *next;
wl_list_for_each_safe (cb, next, &priv->frame_callbacks, link)
@@ -234,7 +226,7 @@ meta_wayland_cursor_surface_dispose (GObject *object)
if (priv->buffer)
{
- meta_wayland_surface_unref_buffer_use_count (surface);
+ meta_wayland_buffer_dec_use_count (priv->buffer);
g_clear_object (&priv->buffer);
}
@@ -263,8 +255,8 @@ meta_wayland_cursor_surface_constructed (GObject *object)
if (buffer && buffer->resource)
{
- g_set_object (&priv->buffer, buffer);
- meta_wayland_surface_ref_buffer_use_count (surface);
+ priv->buffer = g_object_ref (surface->buffer);
+ meta_wayland_buffer_inc_use_count (priv->buffer);
}
priv->cursor_sprite = meta_cursor_sprite_wayland_new (surface,
diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c
index 350be1618..477d7201c 100644
--- a/src/wayland/meta-wayland-dma-buf.c
+++ b/src/wayland/meta-wayland-dma-buf.c
@@ -713,6 +713,153 @@ meta_wayland_dma_buf_from_buffer (MetaWaylandBuffer *buffer)
return NULL;
}
+typedef struct _MetaWaylandDmaBufSource
+{
+ GSource base;
+
+ MetaWaylandDmaBufSourceDispatch dispatch;
+ MetaWaylandBuffer *buffer;
+ gpointer user_data;
+
+ gpointer fd_tags[META_WAYLAND_DMA_BUF_MAX_FDS];
+} MetaWaylandDmaBufSource;
+
+static gboolean
+meta_wayland_dma_buf_fd_readable (int fd)
+{
+ GPollFD poll_fd;
+
+ poll_fd.fd = fd;
+ poll_fd.events = G_IO_IN;
+ poll_fd.revents = 0;
+
+ if (!g_poll (&poll_fd, 1, 0))
+ return FALSE;
+
+ return (poll_fd.revents & (G_IO_IN | G_IO_NVAL)) != 0;
+}
+
+static gboolean
+meta_wayland_dma_buf_source_dispatch (GSource *base,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ MetaWaylandDmaBufSource *source;
+ MetaWaylandDmaBufBuffer *dma_buf;
+ gboolean ready;
+ uint32_t i;
+
+ source = (MetaWaylandDmaBufSource *) base;
+ dma_buf = source->buffer->dma_buf.dma_buf;
+ ready = TRUE;
+
+ for (i = 0; i < META_WAYLAND_DMA_BUF_MAX_FDS; i++)
+ {
+ gpointer fd_tag = source->fd_tags[i];
+
+ if (!fd_tag)
+ continue;
+
+ if (!meta_wayland_dma_buf_fd_readable (dma_buf->fds[i]))
+ {
+ ready = FALSE;
+ continue;
+ }
+
+ g_source_remove_unix_fd (&source->base, fd_tag);
+ source->fd_tags[i] = NULL;
+ }
+
+ if (!ready)
+ return G_SOURCE_CONTINUE;
+
+ source->dispatch (source->buffer, source->user_data);
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+meta_wayland_dma_buf_source_finalize (GSource *base)
+{
+ MetaWaylandDmaBufSource *source;
+ uint32_t i;
+
+ source = (MetaWaylandDmaBufSource *) base;
+
+ for (i = 0; i < META_WAYLAND_DMA_BUF_MAX_FDS; i++)
+ {
+ gpointer fd_tag = source->fd_tags[i];
+
+ if (fd_tag)
+ {
+ g_source_remove_unix_fd (&source->base, fd_tag);
+ source->fd_tags[i] = NULL;
+ }
+ }
+
+ g_clear_object (&source->buffer);
+}
+
+static GSourceFuncs meta_wayland_dma_buf_source_funcs = {
+ .dispatch = meta_wayland_dma_buf_source_dispatch,
+ .finalize = meta_wayland_dma_buf_source_finalize
+};
+
+/**
+ * meta_wayland_dma_buf_create_source:
+ * @buffer: A #MetaWaylandBuffer object
+ * @dispatch: Callback
+ * @user_data: User data for the callback
+ *
+ * Creates a GSource which will call the specified dispatch callback when all
+ * dma-buf file descriptors for the buffer have become readable.
+ *
+ * Returns: The new GSource (or
+ * %NULL if there are no dma-buf file descriptors, or they were all readable
+ * already)
+ */
+GSource *
+meta_wayland_dma_buf_create_source (MetaWaylandBuffer *buffer,
+ MetaWaylandDmaBufSourceDispatch dispatch,
+ gpointer user_data)
+{
+ MetaWaylandDmaBufBuffer *dma_buf;
+ MetaWaylandDmaBufSource *source = NULL;
+ uint32_t i;
+
+ dma_buf = buffer->dma_buf.dma_buf;
+ if (!dma_buf)
+ return NULL;
+
+ for (i = 0; i < META_WAYLAND_DMA_BUF_MAX_FDS; i++)
+ {
+ int fd = dma_buf->fds[i];
+
+ if (fd < 0)
+ break;
+
+ if (meta_wayland_dma_buf_fd_readable (fd))
+ continue;
+
+ if (!source)
+ {
+ source =
+ (MetaWaylandDmaBufSource *) g_source_new (&meta_wayland_dma_buf_source_funcs,
+ sizeof (*source));
+ source->buffer = g_object_ref (buffer);
+ source->dispatch = dispatch;
+ source->user_data = user_data;
+ }
+
+ source->fd_tags[i] = g_source_add_unix_fd (&source->base, fd, G_IO_IN);
+ }
+
+ if (!source)
+ return NULL;
+
+ return &source->base;
+}
+
static void
buffer_params_create_common (struct wl_client *client,
struct wl_resource *params_resource,
diff --git a/src/wayland/meta-wayland-dma-buf.h b/src/wayland/meta-wayland-dma-buf.h
index dc1231560..a8b003768 100644
--- a/src/wayland/meta-wayland-dma-buf.h
+++ b/src/wayland/meta-wayland-dma-buf.h
@@ -54,6 +54,14 @@ meta_wayland_dma_buf_buffer_attach (MetaWaylandBuffer *buffer,
MetaWaylandDmaBufBuffer *
meta_wayland_dma_buf_from_buffer (MetaWaylandBuffer *buffer);
+typedef void (*MetaWaylandDmaBufSourceDispatch) (MetaWaylandBuffer *buffer,
+ gpointer user_data);
+
+GSource *
+meta_wayland_dma_buf_create_source (MetaWaylandBuffer *buffer,
+ MetaWaylandDmaBufSourceDispatch dispatch,
+ gpointer user_data);
+
CoglScanout *
meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf,
CoglOnscreen *onscreen);
diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c
index d000ccfd8..314adec27 100644
--- a/src/wayland/meta-wayland-pointer.c
+++ b/src/wayland/meta-wayland-pointer.c
@@ -1369,7 +1369,8 @@ pointer_can_grab_surface (MetaWaylandPointer *pointer,
if (pointer->focus_surface == surface)
return TRUE;
- META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface)
+ META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (&surface->output_state,
+ subsurface)
{
if (pointer_can_grab_surface (pointer, subsurface))
return TRUE;
diff --git a/src/wayland/meta-wayland-private.h b/src/wayland/meta-wayland-private.h
index dc4dba4b4..c9a236a2e 100644
--- a/src/wayland/meta-wayland-private.h
+++ b/src/wayland/meta-wayland-private.h
@@ -100,6 +100,12 @@ struct _MetaWaylandCompositor
MetaWaylandPresentationTime presentation_time;
MetaWaylandDmaBufManager *dma_buf_manager;
+
+ /*
+ * Queue of transactions which have been committed but not applied yet, in the
+ * order they were committed.
+ */
+ GQueue committed_transactions;
};
#define META_TYPE_WAYLAND_COMPOSITOR (meta_wayland_compositor_get_type ())
diff --git a/src/wayland/meta-wayland-shell-surface.c b/src/wayland/meta-wayland-shell-surface.c
index c2e8c5fc7..46a3426cf 100644
--- a/src/wayland/meta-wayland-shell-surface.c
+++ b/src/wayland/meta-wayland-shell-surface.c
@@ -59,7 +59,8 @@ meta_wayland_shell_surface_calculate_geometry (MetaWaylandShellSurface *shell_su
.height = meta_wayland_surface_get_height (surface),
};
- META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
+ META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (&surface->output_state,
+ subsurface_surface)
{
MetaWaylandSubsurface *subsurface;
@@ -214,7 +215,7 @@ meta_wayland_shell_surface_surface_pre_apply_state (MetaWaylandSurfaceRole *sur
meta_wayland_surface_role_get_surface (surface_role);
if (pending->newly_attached &&
- !surface->buffer_ref->buffer &&
+ !surface->buffer &&
priv->window)
meta_window_queue (priv->window, META_QUEUE_CALC_SHOWING);
}
diff --git a/src/wayland/meta-wayland-subsurface.c b/src/wayland/meta-wayland-subsurface.c
index 6a23c8610..63150d006 100644
--- a/src/wayland/meta-wayland-subsurface.c
+++ b/src/wayland/meta-wayland-subsurface.c
@@ -28,6 +28,7 @@
#include "wayland/meta-wayland-actor-surface.h"
#include "wayland/meta-wayland-buffer.h"
#include "wayland/meta-wayland-surface.h"
+#include "wayland/meta-wayland-transaction.h"
#include "wayland/meta-window-wayland.h"
struct _MetaWaylandSubsurface
@@ -49,7 +50,7 @@ transform_subsurface_position (MetaWaylandSurface *surface,
*x += surface->sub.x;
*y += surface->sub.y;
- surface = surface->sub.parent;
+ surface = surface->output_state.parent;
}
while (surface);
}
@@ -57,10 +58,10 @@ transform_subsurface_position (MetaWaylandSurface *surface,
static gboolean
should_show (MetaWaylandSurface *surface)
{
- if (!surface->buffer_ref->buffer)
+ if (!surface->buffer)
return FALSE;
- else if (surface->sub.parent)
- return should_show (surface->sub.parent);
+ else if (surface->output_state.parent)
+ return should_show (surface->output_state.parent);
else
return TRUE;
}
@@ -95,42 +96,15 @@ static gboolean
is_child (MetaWaylandSurface *surface,
MetaWaylandSurface *sibling)
{
- return surface->sub.parent == sibling;
+ return surface->protocol_state.parent == sibling;
}
static gboolean
is_sibling (MetaWaylandSurface *surface,
MetaWaylandSurface *sibling)
{
- return surface != sibling && surface->sub.parent == sibling->sub.parent;
-}
-
-static gboolean
-is_surface_effectively_synchronized (MetaWaylandSurface *surface)
-{
- return meta_wayland_surface_should_cache_state (surface);
-}
-
-void
-meta_wayland_subsurface_parent_state_applied (MetaWaylandSubsurface *subsurface)
-{
- MetaWaylandSurfaceRole *surface_role = META_WAYLAND_SURFACE_ROLE (subsurface);
- MetaWaylandActorSurface *actor_surface =
- META_WAYLAND_ACTOR_SURFACE (subsurface);
- MetaWaylandSurface *surface =
- meta_wayland_surface_role_get_surface (surface_role);
-
- if (surface->sub.pending_pos)
- {
- surface->sub.x = surface->sub.pending_x;
- surface->sub.y = surface->sub.pending_y;
- surface->sub.pending_pos = FALSE;
- }
-
- if (is_surface_effectively_synchronized (surface))
- meta_wayland_surface_apply_cached_state (surface);
-
- meta_wayland_actor_surface_sync_actor_state (actor_surface);
+ return surface != sibling &&
+ surface->protocol_state.parent == sibling->protocol_state.parent;
}
void
@@ -152,10 +126,11 @@ meta_wayland_subsurface_union_geometry (MetaWaylandSubsurface *subsurface,
.height = meta_wayland_surface_get_height (surface),
};
- if (surface->buffer_ref->buffer)
+ if (surface->buffer)
meta_rectangle_union (out_geometry, &geometry, out_geometry);
- META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (surface, subsurface_surface)
+ META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (&surface->output_state,
+ subsurface_surface)
{
MetaWaylandSubsurface *subsurface;
@@ -185,7 +160,7 @@ meta_wayland_subsurface_get_toplevel (MetaWaylandSurfaceRole *surface_role)
{
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
- MetaWaylandSurface *parent = surface->sub.parent;
+ MetaWaylandSurface *parent = surface->output_state.parent;
if (parent)
return meta_wayland_surface_get_toplevel (parent);
@@ -194,7 +169,7 @@ meta_wayland_subsurface_get_toplevel (MetaWaylandSurfaceRole *surface_role)
}
static gboolean
-meta_wayland_subsurface_should_cache_state (MetaWaylandSurfaceRole *surface_role)
+meta_wayland_subsurface_is_synchronized (MetaWaylandSurfaceRole *surface_role)
{
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
@@ -203,9 +178,9 @@ meta_wayland_subsurface_should_cache_state (MetaWaylandSurfaceRole *surface_role
if (surface->sub.synchronous)
return TRUE;
- parent = surface->sub.parent;
+ parent = surface->protocol_state.parent;
if (parent)
- return meta_wayland_surface_should_cache_state (parent);
+ return meta_wayland_surface_is_synchronized (parent);
return TRUE;
}
@@ -215,7 +190,7 @@ meta_wayland_subsurface_notify_subsurface_state_changed (MetaWaylandSurfaceRole
{
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
- MetaWaylandSurface *parent = surface->sub.parent;
+ MetaWaylandSurface *parent = surface->output_state.parent;
if (parent)
return meta_wayland_surface_notify_subsurface_state_changed (parent);
@@ -228,13 +203,14 @@ meta_wayland_subsurface_get_geometry_scale (MetaWaylandActorSurface *actor_surfa
META_WAYLAND_SURFACE_ROLE (actor_surface);
MetaWaylandSurface *surface =
meta_wayland_surface_role_get_surface (surface_role);
- MetaWaylandSurface *parent = surface->sub.parent;
+ MetaWaylandSurface *parent = surface->output_state.parent;
if (parent)
{
MetaWaylandActorSurface *parent_actor;
- parent_actor = META_WAYLAND_ACTOR_SURFACE (surface->sub.parent->role);
+ parent_actor =
+ META_WAYLAND_ACTOR_SURFACE (surface->output_state.parent->role);
return meta_wayland_actor_surface_get_geometry_scale (parent_actor);
}
else
@@ -276,7 +252,7 @@ meta_wayland_subsurface_class_init (MetaWaylandSubsurfaceClass *klass)
surface_role_class->assigned = meta_wayland_subsurface_assigned;
surface_role_class->get_toplevel = meta_wayland_subsurface_get_toplevel;
- surface_role_class->should_cache_state = meta_wayland_subsurface_should_cache_state;
+ surface_role_class->is_synchronized = meta_wayland_subsurface_is_synchronized;
surface_role_class->notify_subsurface_state_changed =
meta_wayland_subsurface_notify_subsurface_state_changed;
@@ -286,23 +262,6 @@ meta_wayland_subsurface_class_init (MetaWaylandSubsurfaceClass *klass)
meta_wayland_subsurface_sync_actor_state;
}
-static void
-wl_subsurface_destructor (struct wl_resource *resource)
-{
- MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
-
- g_node_unlink (surface->subsurface_branch_node);
-
- if (surface->sub.parent)
- {
- meta_wayland_surface_notify_subsurface_state_changed (surface->sub.parent);
- wl_list_remove (&surface->sub.parent_destroy_listener.link);
- surface->sub.parent = NULL;
- }
-
- surface->wl_subsurface = NULL;
-}
-
static void
wl_subsurface_destroy (struct wl_client *client,
struct wl_resource *resource)
@@ -317,10 +276,10 @@ wl_subsurface_set_position (struct wl_client *client,
int32_t y)
{
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
+ MetaWaylandTransaction *transaction;
- surface->sub.pending_x = x;
- surface->sub.pending_y = y;
- surface->sub.pending_pos = TRUE;
+ transaction = meta_wayland_surface_ensure_transaction (surface);
+ meta_wayland_transaction_add_subsurface_position (transaction, surface, x, y);
}
static gboolean
@@ -334,61 +293,57 @@ is_valid_sibling (MetaWaylandSurface *surface,
return FALSE;
}
-static void
-subsurface_handle_pending_subsurface_destroyed (struct wl_listener *listener,
- void *data)
-{
- MetaWaylandSubsurfacePlacementOp *op =
- wl_container_of (listener, op, subsurface_destroy_listener);
-
- op->surface = NULL;
- wl_list_remove (&op->subsurface_destroy_listener.link);
-}
-
-static void
-subsurface_handle_pending_sibling_destroyed (struct wl_listener *listener,
- void *data)
-{
- MetaWaylandSubsurfacePlacementOp *op =
- wl_container_of (listener, op, sibling_destroy_listener);
-
- op->sibling = NULL;
- wl_list_remove (&op->sibling_destroy_listener.link);
-}
-
-void
-meta_wayland_subsurface_placement_op_free (MetaWaylandSubsurfacePlacementOp *op)
-{
- if (op->surface)
- wl_list_remove (&op->subsurface_destroy_listener.link);
- if (op->sibling)
- wl_list_remove (&op->sibling_destroy_listener.link);
- g_free (op);
-}
-
static void
queue_subsurface_placement (MetaWaylandSurface *surface,
MetaWaylandSurface *sibling,
MetaWaylandSubsurfacePlacement placement)
{
- MetaWaylandSurface *parent = surface->sub.parent;
+ MetaWaylandSurface *parent = surface->protocol_state.parent;
+ gboolean have_synced_parent;
+ MetaWaylandTransaction *transaction;
MetaWaylandSubsurfacePlacementOp *op =
g_new0 (MetaWaylandSubsurfacePlacementOp, 1);
+ GNode *sibling_node;
+
+ have_synced_parent = sibling && meta_wayland_surface_is_synchronized (parent);
+ if (have_synced_parent)
+ transaction = meta_wayland_surface_ensure_transaction (parent);
+ else
+ transaction = meta_wayland_transaction_new (surface->compositor);
op->placement = placement;
- op->surface = surface;
op->sibling = sibling;
- op->subsurface_destroy_listener.notify =
- subsurface_handle_pending_subsurface_destroyed;
- op->sibling_destroy_listener.notify =
- subsurface_handle_pending_sibling_destroyed;
- wl_resource_add_destroy_listener (surface->wl_subsurface,
- &op->subsurface_destroy_listener);
- wl_resource_add_destroy_listener (sibling->resource,
- &op->sibling_destroy_listener);
-
- parent->pending_state->subsurface_placement_ops =
- g_slist_append (parent->pending_state->subsurface_placement_ops, op);
+ op->surface = surface;
+
+ g_node_unlink (surface->protocol_state.subsurface_branch_node);
+
+ if (!sibling)
+ goto out;
+
+ if (sibling == parent)
+ sibling_node = parent->protocol_state.subsurface_leaf_node;
+ else
+ sibling_node = sibling->protocol_state.subsurface_branch_node;
+
+ switch (placement)
+ {
+ case META_WAYLAND_SUBSURFACE_PLACEMENT_ABOVE:
+ g_node_insert_after (parent->protocol_state.subsurface_branch_node,
+ sibling_node,
+ surface->protocol_state.subsurface_branch_node);
+ break;
+ case META_WAYLAND_SUBSURFACE_PLACEMENT_BELOW:
+ g_node_insert_before (parent->protocol_state.subsurface_branch_node,
+ sibling_node,
+ surface->protocol_state.subsurface_branch_node);
+ break;
+ }
+
+out:
+ meta_wayland_transaction_add_placement_op (transaction, parent, op);
+
+ if (!have_synced_parent)
+ meta_wayland_transaction_commit (transaction);
}
static void
@@ -435,6 +390,25 @@ wl_subsurface_place_below (struct wl_client *client,
META_WAYLAND_SUBSURFACE_PLACEMENT_BELOW);
}
+static void
+wl_subsurface_destructor (struct wl_resource *resource)
+{
+ MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
+
+ if (surface->protocol_state.parent)
+ {
+ queue_subsurface_placement (surface, NULL,
+ META_WAYLAND_SUBSURFACE_PLACEMENT_BELOW);
+ surface->protocol_state.parent = NULL;
+ }
+ else
+ {
+ g_node_unlink (surface->protocol_state.subsurface_branch_node);
+ }
+
+ surface->wl_subsurface = NULL;
+}
+
static void
wl_subsurface_set_sync (struct wl_client *client,
struct wl_resource *resource)
@@ -444,23 +418,35 @@ wl_subsurface_set_sync (struct wl_client *client,
surface->sub.synchronous = TRUE;
}
+static void
+meta_wayland_subsurface_parent_desynced (MetaWaylandSurface *surface)
+{
+ MetaWaylandSurface *subsurface_surface;
+
+ if (surface->sub.synchronous)
+ return;
+
+ if (surface->sub.transaction)
+ meta_wayland_transaction_commit (g_steal_pointer (&surface->sub.transaction));
+
+ META_WAYLAND_SURFACE_FOREACH_SUBSURFACE (&surface->protocol_state,
+ subsurface_surface)
+ meta_wayland_subsurface_parent_desynced (subsurface_surface);
+}
+
static void
wl_subsurface_set_desync (struct wl_client *client,
struct wl_resource *resource)
{
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
- gboolean is_parent_effectively_synchronized;
if (!surface->sub.synchronous)
return;
- is_parent_effectively_synchronized =
- is_surface_effectively_synchronized (surface->sub.parent);
-
- if (!is_parent_effectively_synchronized)
- meta_wayland_surface_apply_cached_state (surface);
-
surface->sub.synchronous = FALSE;
+
+ if (!meta_wayland_surface_is_synchronized (surface))
+ meta_wayland_subsurface_parent_desynced (surface);
}
static const struct wl_subsurface_interface meta_wayland_wl_subsurface_interface = {
@@ -479,17 +465,12 @@ wl_subcompositor_destroy (struct wl_client *client,
wl_resource_destroy (resource);
}
-static void
-surface_handle_parent_surface_destroyed (struct wl_listener *listener,
- void *data)
+void
+meta_wayland_subsurface_parent_destroyed (MetaWaylandSurface *surface)
{
- MetaWaylandSurface *surface = wl_container_of (listener,
- surface,
- sub.parent_destroy_listener);
-
- g_node_unlink (surface->subsurface_branch_node);
- surface->sub.parent = NULL;
- wl_list_remove (&surface->sub.parent_destroy_listener.link);
+ queue_subsurface_placement (surface, NULL,
+ META_WAYLAND_SUBSURFACE_PLACEMENT_BELOW);
+ surface->protocol_state.parent = NULL;
}
static gboolean
@@ -498,8 +479,8 @@ is_same_or_ancestor (MetaWaylandSurface *surface,
{
if (surface == other_surface)
return TRUE;
- if (other_surface->sub.parent)
- return is_same_or_ancestor (surface, other_surface->sub.parent);
+ if (other_surface->protocol_state.parent)
+ return is_same_or_ancestor (surface, other_surface->protocol_state.parent);
return FALSE;
}
@@ -512,6 +493,7 @@ wl_subcompositor_get_subsurface (struct wl_client *client,
{
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
MetaWaylandSurface *parent = wl_resource_get_user_data (parent_resource);
+ MetaWaylandSurface *reference;
MetaWindow *toplevel_window;
if (surface->wl_subsurface)
@@ -558,16 +540,12 @@ wl_subcompositor_get_subsurface (struct wl_client *client,
wl_subsurface_destructor);
surface->sub.synchronous = TRUE;
- surface->sub.parent = parent;
- surface->sub.parent_destroy_listener.notify =
- surface_handle_parent_surface_destroyed;
- wl_resource_add_destroy_listener (parent->resource,
- &surface->sub.parent_destroy_listener);
+ surface->protocol_state.parent = parent;
- g_node_append (parent->subsurface_branch_node,
- surface->subsurface_branch_node);
-
- meta_wayland_surface_notify_subsurface_state_changed (parent);
+ reference =
+ g_node_last_child (parent->protocol_state.subsurface_branch_node)->data;
+ queue_subsurface_placement (surface, reference,
+ META_WAYLAND_SUBSURFACE_PLACEMENT_ABOVE);
}
static const struct wl_subcompositor_interface meta_wayland_subcompositor_interface = {
diff --git a/src/wayland/meta-wayland-subsurface.h b/src/wayland/meta-wayland-subsurface.h
index 45dbf8626..61338e921 100644
--- a/src/wayland/meta-wayland-subsurface.h
+++ b/src/wayland/meta-wayland-subsurface.h
@@ -40,18 +40,14 @@ typedef struct
MetaWaylandSubsurfacePlacement placement;
MetaWaylandSurface *surface;
MetaWaylandSurface *sibling;
- struct wl_listener subsurface_destroy_listener;
- struct wl_listener sibling_destroy_listener;
} MetaWaylandSubsurfacePlacementOp;
-void meta_wayland_subsurface_parent_state_applied (MetaWaylandSubsurface *subsurface);
-
void meta_wayland_subsurface_union_geometry (MetaWaylandSubsurface *subsurface,
int parent_x,
int parent_y,
MetaRectangle *out_geometry);
-void meta_wayland_subsurface_placement_op_free (MetaWaylandSubsurfacePlacementOp *op);
+void meta_wayland_subsurface_parent_destroyed (MetaWaylandSurface *surface);
void meta_wayland_subsurfaces_init (MetaWaylandCompositor *compositor);
diff --git a/src/wayland/meta-wayland-surface.c b/src/wayland/meta-wayland-surface.c
index 351bc589c..d5121fb6f 100644
--- a/src/wayland/meta-wayland-surface.c
+++ b/src/wayland/meta-wayland-surface.c
@@ -48,6 +48,7 @@
#include "wayland/meta-wayland-region.h"
#include "wayland/meta-wayland-seat.h"
#include "wayland/meta-wayland-subsurface.h"
+#include "wayland/meta-wayland-transaction.h"
#include "wayland/meta-wayland-viewporter.h"
#include "wayland/meta-wayland-xdg-shell.h"
#include "wayland/meta-window-wayland.h"
@@ -113,6 +114,11 @@ guint surface_signals[N_SURFACE_SIGNALS] = { 0 };
static void
meta_wayland_surface_role_assigned (MetaWaylandSurfaceRole *surface_role);
+static void
+meta_wayland_surface_role_commit_state (MetaWaylandSurfaceRole *surface_role,
+ MetaWaylandTransaction *transaction,
+ MetaWaylandSurfaceState *pending);
+
static void
meta_wayland_surface_role_pre_apply_state (MetaWaylandSurfaceRole *surface_role,
MetaWaylandSurfaceState *pending);
@@ -137,58 +143,6 @@ set_surface_is_on_output (MetaWaylandSurface *surface,
MetaWaylandOutput *wayland_output,
gboolean is_on_output);
-static MetaWaylandBufferRef *
-meta_wayland_buffer_ref_new (void)
-{
- MetaWaylandBufferRef *buffer_ref;
-
- buffer_ref = g_new0 (MetaWaylandBufferRef, 1);
- g_ref_count_init (&buffer_ref->ref_count);
-
- return buffer_ref;
-}
-
-static MetaWaylandBufferRef *
-meta_wayland_buffer_ref_ref (MetaWaylandBufferRef *buffer_ref)
-{
- g_ref_count_inc (&buffer_ref->ref_count);
- return buffer_ref;
-}
-
-static void
-meta_wayland_buffer_ref_unref (MetaWaylandBufferRef *buffer_ref)
-{
- if (g_ref_count_dec (&buffer_ref->ref_count))
- {