summaryrefslogtreecommitdiff
path: root/mozilla-1535567.patch
blob: 1cbe3fd07201d3db55ecee7199949dfd36267cf6 (plain)
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
diff -up firefox-66.0/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old firefox-66.0/media/libyuv/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium
diff -up firefox-66.0/media/webrtc/trunk/Makefile.old firefox-66.0/media/webrtc/trunk/Makefile
diff -up firefox-66.0/widget/gtk/mozcontainer.cpp.old firefox-66.0/widget/gtk/mozcontainer.cpp
--- firefox-66.0/widget/gtk/mozcontainer.cpp.old	2019-03-14 23:12:56.000000000 +0100
+++ firefox-66.0/widget/gtk/mozcontainer.cpp	2019-03-15 13:23:59.366840324 +0100
@@ -20,6 +20,20 @@
 #  include "maiRedundantObjectFactory.h"
 #endif
 
+#undef LOG
+#ifdef MOZ_LOGGING
+
+#  include "mozilla/Logging.h"
+#  include "nsTArray.h"
+#  include "Units.h"
+
+extern mozilla::LazyLogModule gWidgetLog;
+
+#  define LOG(args) MOZ_LOG(gWidgetLog, mozilla::LogLevel::Debug, args)
+#else
+#  define LOG(args)
+#endif /* MOZ_LOGGING */
+
 #ifdef MOZ_WAYLAND
 using namespace mozilla;
 using namespace mozilla::widget;
@@ -157,10 +171,14 @@ void moz_container_init(MozContainer *co
   container->subsurface = nullptr;
   container->eglwindow = nullptr;
   container->frame_callback_handler = nullptr;
+  container->frame_callback_handler_surface_id = -1;
   // We can draw to x11 window any time.
   container->ready_to_draw = GDK_IS_X11_DISPLAY(gdk_display_get_default());
   container->surface_needs_clear = true;
+  container->inital_draw_cb = nullptr;
 #endif
+
+  LOG(("moz_container_class_init() [%p]\n", (void *)container));
 }
 
 #if defined(MOZ_WAYLAND)
@@ -170,36 +188,92 @@ static wl_surface *moz_container_get_gtk
       dlsym(RTLD_DEFAULT, "gdk_wayland_window_get_wl_surface");
 
   GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(container));
-  return sGdkWaylandWindowGetWlSurface(window);
+  wl_surface *surface = sGdkWaylandWindowGetWlSurface(window);
+
+  LOG(("moz_container_get_gtk_container_surface() [%p] wl_surface %p ID %d\n",
+       (void *)container, (void *)surface,
+       surface ? wl_proxy_get_id((struct wl_proxy *)surface) : -1));
+
+  return surface;
 }
 
 static void frame_callback_handler(void *data, struct wl_callback *callback,
                                    uint32_t time) {
   MozContainer *container = MOZ_CONTAINER(data);
+
+  LOG(
+      ("moz_container_frame_callback_handler() [%p] frame_callback_handler %p "
+       "ready_to_draw %d (set to true) "
+       "inital_draw callback %d\n",
+       (void *)container, (void *)container->frame_callback_handler,
+       container->ready_to_draw, container->inital_draw_cb ? 1 : 0));
+
   g_clear_pointer(&container->frame_callback_handler, wl_callback_destroy);
+  container->frame_callback_handler_surface_id = -1;
+
+  if (!container->ready_to_draw && container->inital_draw_cb) {
+    container->inital_draw_cb();
+  }
   container->ready_to_draw = true;
 }
 
+void moz_container_set_initial_draw_callback(
+    MozContainer *container, std::function<void(void)> inital_draw_cb) {
+  container->inital_draw_cb = inital_draw_cb;
+}
+
 static const struct wl_callback_listener frame_listener = {
     frame_callback_handler};
 
-static gboolean moz_container_map_wayland(GtkWidget *widget,
-                                          GdkEventAny *event) {
-  MozContainer *container = MOZ_CONTAINER(widget);
-
-  if (container->ready_to_draw || container->frame_callback_handler) {
-    return FALSE;
-  }
-
+static void moz_container_request_parent_frame_callback(
+    MozContainer *container) {
   wl_surface *gtk_container_surface =
       moz_container_get_gtk_container_surface(container);
+  int gtk_container_surface_id =
+      gtk_container_surface
+          ? wl_proxy_get_id((struct wl_proxy *)gtk_container_surface)
+          : -1;
+
+  LOG(
+      ("moz_container_request_parent_frame_callback() [%p] "
+       "container->frame_callback_handler %p "
+       "container->frame_callback_handler_surface_id %d\n",
+       (void *)container, container->frame_callback_handler,
+       container->frame_callback_handler_surface_id));
+
+  if (container->frame_callback_handler &&
+      container->frame_callback_handler_surface_id ==
+          gtk_container_surface_id) {
+    return;
+  }
+
+  // If there's pending frame callback, delete it.
+  if (container->frame_callback_handler) {
+    g_clear_pointer(&container->frame_callback_handler, wl_callback_destroy);
+  }
 
   if (gtk_container_surface) {
+    container->frame_callback_handler_surface_id = gtk_container_surface_id;
     container->frame_callback_handler = wl_surface_frame(gtk_container_surface);
     wl_callback_add_listener(container->frame_callback_handler, &frame_listener,
                              container);
+  } else {
+    container->frame_callback_handler_surface_id = -1;
   }
+}
 
+static gboolean moz_container_map_wayland(GtkWidget *widget,
+                                          GdkEventAny *event) {
+  MozContainer *container = MOZ_CONTAINER(widget);
+
+  LOG(("moz_container_map_wayland() begin [%p] ready_to_draw %d\n",
+       (void *)container, container->ready_to_draw));
+
+  if (container->ready_to_draw) {
+    return FALSE;
+  }
+
+  moz_container_request_parent_frame_callback(MOZ_CONTAINER(widget));
   return FALSE;
 }
 
@@ -208,9 +282,12 @@ static void moz_container_unmap_wayland(
   g_clear_pointer(&container->subsurface, wl_subsurface_destroy);
   g_clear_pointer(&container->surface, wl_surface_destroy);
   g_clear_pointer(&container->frame_callback_handler, wl_callback_destroy);
+  container->frame_callback_handler_surface_id = -1;
 
   container->surface_needs_clear = true;
   container->ready_to_draw = false;
+
+  LOG(("moz_container_unmap_wayland() [%p]\n", (void *)container));
 }
 
 static gint moz_container_get_scale(MozContainer *container) {
@@ -227,6 +304,10 @@ static gint moz_container_get_scale(MozC
 
 void moz_container_scale_changed(MozContainer *container,
                                  GtkAllocation *aAllocation) {
+  LOG(("moz_container_scale_changed() [%p] surface %p eglwindow %p\n",
+       (void *)container, (void *)container->surface,
+       (void *)container->eglwindow));
+
   if (!container->surface) {
     return;
   }
@@ -320,6 +401,10 @@ void moz_container_realize(GtkWidget *wi
             : gtk_widget_get_visual(widget);
 
     window = gdk_window_new(parent, &attributes, attributes_mask);
+
+    LOG(("moz_container_realize() [%p] GdkWindow %p\n", (void *)container,
+         (void *)window));
+
     gdk_window_set_user_data(window, widget);
   } else {
     window = parent;
@@ -336,12 +421,8 @@ void moz_container_size_allocate(GtkWidg
 
   g_return_if_fail(IS_MOZ_CONTAINER(widget));
 
-  /*  printf("moz_container_size_allocate %p %d %d %d %d\n",
-      (void *)widget,
-      allocation->x,
-      allocation->y,
-      allocation->width,
-      allocation->height); */
+  LOG(("moz_container_size_allocate() [%p] %d %d %d %d\n", (void *)widget,
+       allocation->x, allocation->y, allocation->width, allocation->height));
 
   /* short circuit if you can */
   container = MOZ_CONTAINER(widget);
@@ -487,8 +568,13 @@ static void moz_container_add(GtkContain
 
 #ifdef MOZ_WAYLAND
 struct wl_surface *moz_container_get_wl_surface(MozContainer *container) {
+  LOG(("moz_container_get_wl_surface() [%p] surface %p ready_to_draw %d\n",
+       (void *)container, (void *)container->surface,
+       container->ready_to_draw));
+
   if (!container->surface) {
     if (!container->ready_to_draw) {
+      moz_container_request_parent_frame_callback(container);
       return nullptr;
     }
     GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(container));
@@ -526,10 +612,16 @@ struct wl_surface *moz_container_get_wl_
     WaylandDisplayRelease(waylandDisplay);
   }
 
+  LOG(("moz_container_get_wl_surface() [%p] created surface %p\n",
+       (void *)container, (void *)container->surface));
+
   return container->surface;
 }
 
 struct wl_egl_window *moz_container_get_wl_egl_window(MozContainer *container) {
+  LOG(("moz_container_get_wl_egl_window() [%p] eglwindow %p\n",
+       (void *)container, (void *)container->eglwindow));
+
   if (!container->eglwindow) {
     wl_surface *surface = moz_container_get_wl_surface(container);
     if (!surface) {
@@ -543,6 +635,10 @@ struct wl_egl_window *moz_container_get_
                              gdk_window_get_height(window) * scale);
     wl_surface_set_buffer_scale(surface, scale);
   }
+
+  LOG(("moz_container_get_wl_egl_window() [%p] created eglwindow %p\n",
+       (void *)container, (void *)container->eglwindow));
+
   return container->eglwindow;
 }
 
diff -up firefox-66.0/widget/gtk/mozcontainer.h.old firefox-66.0/widget/gtk/mozcontainer.h
--- firefox-66.0/widget/gtk/mozcontainer.h.old	2019-03-14 23:13:02.000000000 +0100
+++ firefox-66.0/widget/gtk/mozcontainer.h	2019-03-15 13:23:59.366840324 +0100
@@ -9,6 +9,7 @@
 #define __MOZ_CONTAINER_H__
 
 #include <gtk/gtk.h>
+#include <functional>
 
 /*
  * MozContainer
@@ -76,8 +77,10 @@ struct _MozContainer {
   struct wl_subsurface *subsurface;
   struct wl_egl_window *eglwindow;
   struct wl_callback *frame_callback_handler;
+  int frame_callback_handler_surface_id;
   gboolean surface_needs_clear;
   gboolean ready_to_draw;
+  std::function<void(void)> inital_draw_cb;
 #endif
   gboolean force_default_visual;
 };
@@ -100,6 +103,8 @@ gboolean moz_container_has_wl_egl_window
 gboolean moz_container_surface_needs_clear(MozContainer *container);
 void moz_container_scale_changed(MozContainer *container,
                                  GtkAllocation *aAllocation);
+void moz_container_set_initial_draw_callback(
+    MozContainer *container, std::function<void(void)> inital_draw_cb);
 #endif
 
 #endif /* __MOZ_CONTAINER_H__ */
bgstack15