35
35
* mContainer size/position is known.
36
36
* It calls moz_container_wayland_surface_create_locked(), registers
37
37
* a frame callback handler
38
- * ( moz_container_wayland_frame_callback_handler() ).
38
+ * moz_container_wayland_frame_callback_handler().
39
39
*
40
40
* 2) moz_container_wayland_frame_callback_handler() is called
41
41
* when wl_surface owned by mozContainer is ready.
@@ -86,6 +86,11 @@ static void moz_container_wayland_set_scale_factor_locked(
86
86
static void moz_container_wayland_set_opaque_region_locked (
87
87
MozContainer * container );
88
88
89
+ static nsWindow * moz_container_get_nsWindow (MozContainer * container ) {
90
+ gpointer user_data = g_object_get_data (G_OBJECT (container ), "nsWindow" );
91
+ return static_cast < nsWindow * > (user_data );
92
+ }
93
+
89
94
// Imlemented in MozContainer.cpp
90
95
void moz_container_realize (GtkWidget * widget );
91
96
@@ -167,17 +172,6 @@ void moz_container_wayland_add_initial_draw_callback(
167
172
container -> wl_container .initial_draw_cbs .push_back (initial_draw_cb );
168
173
}
169
174
170
- wl_surface * moz_gtk_widget_get_wl_surface (GtkWidget * aWidget ) {
171
- GdkWindow * window = gtk_widget_get_window (aWidget );
172
- wl_surface * surface = gdk_wayland_window_get_wl_surface (window );
173
-
174
- LOGWAYLAND (("moz_gtk_widget_get_wl_surface [%p] wl_surface %p ID %d\n" ,
175
- (void * )aWidget , (void * )surface ,
176
- surface ? wl_proxy_get_id ((struct wl_proxy * )surface ) : -1 ));
177
-
178
- return surface ;
179
- }
180
-
181
175
static void moz_container_wayland_frame_callback_handler (
182
176
void * data , struct wl_callback * callback , uint32_t time ) {
183
177
MozContainerWayland * wl_container = & MOZ_CONTAINER (data )-> wl_container ;
@@ -327,13 +321,10 @@ static void moz_container_wayland_set_opaque_region(MozContainer* container) {
327
321
328
322
static void moz_container_wayland_set_scale_factor_locked (
329
323
MozContainer * container ) {
330
- gpointer user_data = g_object_get_data ( G_OBJECT ( container ), "nsWindow" );
331
- nsWindow * wnd = static_cast < nsWindow * > ( user_data ) ;
324
+ nsWindow * window = moz_container_get_nsWindow ( container );
325
+ int scale = window ? window -> GdkScaleFactor () : 1 ;
332
326
333
- int scale = 1 ;
334
- if (wnd ) {
335
- scale = wnd -> GdkScaleFactor ();
336
- }
327
+ LOGWAYLAND (("%s [%p] scale %d\n" , __FUNCTION__ , (void * )container , scale ));
337
328
wl_surface_set_buffer_scale (container -> wl_container .surface , scale );
338
329
}
339
330
@@ -348,25 +339,22 @@ static bool moz_container_wayland_surface_create_locked(
348
339
MozContainer * container ) {
349
340
MozContainerWayland * wl_container = & container -> wl_container ;
350
341
351
- LOGWAYLAND (("%s [%p] surface %p ready_to_draw %d\n" , __FUNCTION__ ,
352
- (void * )container , (void * )wl_container -> surface ,
353
- wl_container -> ready_to_draw ));
342
+ LOGWAYLAND (("%s [%p]\n" , __FUNCTION__ , (void * )container ));
354
343
355
- wl_surface * parent_surface =
356
- moz_gtk_widget_get_wl_surface ( GTK_WIDGET ( container ) );
344
+ GdkWindow * window = gtk_widget_get_window ( GTK_WIDGET ( container ));
345
+ wl_surface * parent_surface = gdk_wayland_window_get_wl_surface ( window );
357
346
if (!parent_surface ) {
358
- NS_WARNING (
359
- "moz_container_wayland_surface_create_locked(): Missing parent "
360
- "surface!" );
347
+ LOGWAYLAND ((" Failed - missing parent surface!" ));
361
348
return false;
362
349
}
350
+ LOGWAYLAND ((" gtk wl_surface %p ID %d\n" , (void * )parent_surface ,
351
+ wl_proxy_get_id ((struct wl_proxy * )parent_surface )));
363
352
364
353
// Available as of GTK 3.8+
365
354
struct wl_compositor * compositor = WaylandDisplayGet ()-> GetCompositor ();
366
355
wl_container -> surface = wl_compositor_create_surface (compositor );
367
356
if (!wl_container -> surface ) {
368
- NS_WARNING (
369
- "moz_container_wayland_surface_create_locked(): can't create surface!" );
357
+ LOGWAYLAND ((" Failed - can't create surface!" ));
370
358
return false;
371
359
}
372
360
@@ -375,13 +363,20 @@ static bool moz_container_wayland_surface_create_locked(
375
363
wl_container -> surface , parent_surface );
376
364
if (!wl_container -> subsurface ) {
377
365
g_clear_pointer (& wl_container -> surface , wl_surface_destroy );
378
- NS_WARNING (
379
- "moz_container_wayland_surface_create_locked(): can't create "
380
- "sub-surface!" );
366
+ LOGWAYLAND ((" Failed - can't create sub-surface!" ));
381
367
return false;
382
368
}
383
369
wl_subsurface_set_desync (wl_container -> subsurface );
384
370
371
+ // Try to guess subsurface offset to avoid potential flickering.
372
+ int dx , dy ;
373
+ if (moz_container_get_nsWindow (container )-> GetCSDDecorationOffset (& dx , & dy )) {
374
+ wl_container -> subsurface_dx = dx ;
375
+ wl_container -> subsurface_dy = dy ;
376
+ wl_subsurface_set_position (wl_container -> subsurface , dx , dy );
377
+ LOGWAYLAND ((" guessing subsurface position %d %d\n" , dx , dy ));
378
+ }
379
+
385
380
// Route input to parent wl_surface owned by Gtk+ so we get input
386
381
// events from Gtk+.
387
382
wl_region * region = wl_compositor_create_region (compositor );
@@ -396,12 +391,15 @@ static bool moz_container_wayland_surface_create_locked(
396
391
wl_container -> frame_callback_handler = wl_surface_frame (parent_surface );
397
392
wl_callback_add_listener (wl_container -> frame_callback_handler ,
398
393
& moz_container_frame_listener , container );
394
+ LOGWAYLAND ((
395
+ " created frame callback ID %d\n" ,
396
+ wl_proxy_get_id ((struct wl_proxy * )wl_container -> frame_callback_handler )));
399
397
400
398
wl_surface_commit (wl_container -> surface );
401
399
wl_display_flush (WaylandDisplayGet ()-> GetDisplay ());
402
400
403
- LOGWAYLAND (("%s [%p] created surface %p\n" , __FUNCTION__ , (void * )container ,
404
- ( void * )wl_container -> surface ));
401
+ LOGWAYLAND ((" created surface %p ID %p \n" , (void * )wl_container -> surface ,
402
+ wl_proxy_get_id (( struct wl_proxy * )wl_container -> surface ) ));
405
403
return true;
406
404
}
407
405
0 commit comments