Skip to content

Commit

Permalink
wl: Set opaque region if possible also when windowed
Browse files Browse the repository at this point in the history
Configure an opaque region for the Wayland surface also when not
fullscreened, as long as the web view background color is set to be
opaque. This should slightly improve performance in compositors which
take the opaque region hint into account also for non fullscreen
surfaces.
  • Loading branch information
aperezdc committed Sep 25, 2023
1 parent 1d27133 commit 6a59736
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,8 @@ static const struct wl_buffer_listener dmabuf_buffer_listener = {
static void
on_export_wl_egl_image(void *data, struct wpe_fdo_egl_exported_image *image)
{
CogWlPlatform *self = data;

const uint32_t surface_pixel_width = wl_data.current_output->scale * win_data.width;
const uint32_t surface_pixel_height = wl_data.current_output->scale * win_data.height;

Expand All @@ -1623,14 +1625,17 @@ on_export_wl_egl_image(void *data, struct wpe_fdo_egl_exported_image *image)

if (wpe_view_data.should_update_opaque_region) {
wpe_view_data.should_update_opaque_region = false;
if (win_data.is_fullscreen) {
struct wl_region *region =
wl_compositor_create_region (wl_data.compositor);
wl_region_add (region, 0, 0, win_data.width, win_data.height);
wl_surface_set_opaque_region (win_data.wl_surface, region);
wl_region_destroy (region);

WebKitColor bg_color;
webkit_web_view_get_background_color(self->web_view, &bg_color);

if (win_data.is_fullscreen || bg_color.alpha >= 1.0) {
struct wl_region *region = wl_compositor_create_region(wl_data.compositor);
wl_region_add(region, 0, 0, win_data.width, win_data.height);
wl_surface_set_opaque_region(win_data.wl_surface, region);
wl_region_destroy(region);
} else {
wl_surface_set_opaque_region (win_data.wl_surface, NULL);
wl_surface_set_opaque_region(win_data.wl_surface, NULL);
}
}

Expand Down Expand Up @@ -2513,7 +2518,7 @@ cog_wl_platform_get_view_backend(CogPlatform *platform, WebKitWebView *related_v
};

wpe_host_data.exportable =
wpe_view_backend_exportable_fdo_egl_create(&exportable_egl_client, NULL, win_data.width, win_data.height);
wpe_view_backend_exportable_fdo_egl_create(&exportable_egl_client, platform, win_data.width, win_data.height);
g_assert(wpe_host_data.exportable);

/* init WPE view backend */
Expand Down

0 comments on commit 6a59736

Please sign in to comment.