wayland/surface: Export get_buffer_[width|height] to tests

It will be used in fractional scale tests.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2394>
This commit is contained in:
Robert Mader 2023-03-03 16:48:31 +01:00
parent 305931e2dd
commit c64a04678a
2 changed files with 55 additions and 44 deletions

View File

@ -261,28 +261,6 @@ meta_wayland_surface_assign_role (MetaWaylandSurface *surface,
} }
} }
static int
get_buffer_width (MetaWaylandSurface *surface)
{
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
if (buffer)
return cogl_texture_get_width (surface->output_state.texture);
else
return 0;
}
static int
get_buffer_height (MetaWaylandSurface *surface)
{
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
if (buffer)
return cogl_texture_get_height (surface->output_state.texture);
else
return 0;
}
static void static void
surface_process_damage (MetaWaylandSurface *surface, surface_process_damage (MetaWaylandSurface *surface,
cairo_region_t *surface_region, cairo_region_t *surface_region,
@ -300,8 +278,8 @@ surface_process_damage (MetaWaylandSurface *surface,
return; return;
buffer_rect = (cairo_rectangle_int_t) { buffer_rect = (cairo_rectangle_int_t) {
.width = get_buffer_width (surface), .width = meta_wayland_surface_get_buffer_width (surface),
.height = get_buffer_height (surface), .height = meta_wayland_surface_get_buffer_height (surface),
}; };
if (!cairo_region_is_empty (surface_region)) if (!cairo_region_is_empty (surface_region))
@ -338,13 +316,13 @@ surface_process_damage (MetaWaylandSurface *surface,
if (meta_monitor_transform_is_rotated (surface->buffer_transform)) if (meta_monitor_transform_is_rotated (surface->buffer_transform))
{ {
width = get_buffer_height (surface); width = meta_wayland_surface_get_buffer_height (surface);
height = get_buffer_width (surface); height = meta_wayland_surface_get_buffer_width (surface);
} }
else else
{ {
width = get_buffer_width (surface); width = meta_wayland_surface_get_buffer_width (surface);
height = get_buffer_height (surface); height = meta_wayland_surface_get_buffer_height (surface);
} }
src_rect = (graphene_rect_t) { src_rect = (graphene_rect_t) {
@ -770,16 +748,17 @@ meta_wayland_surface_apply_state (MetaWaylandSurface *surface,
if (state->scale > 0) if (state->scale > 0)
surface->scale = state->scale; surface->scale = state->scale;
if ((get_buffer_width (surface) % surface->scale != 0) || if ((meta_wayland_surface_get_buffer_width (surface) % surface->scale != 0) ||
(get_buffer_height (surface) % surface->scale != 0)) (meta_wayland_surface_get_buffer_height (surface) % surface->scale != 0))
{ {
if (surface->role && !META_IS_WAYLAND_CURSOR_SURFACE (surface->role)) if (surface->role && !META_IS_WAYLAND_CURSOR_SURFACE (surface->role))
{ {
wl_resource_post_error (surface->resource, WL_SURFACE_ERROR_INVALID_SIZE, wl_resource_post_error (surface->resource, WL_SURFACE_ERROR_INVALID_SIZE,
"Buffer size (%dx%d) must be an integer multiple " "Buffer size (%dx%d) must be an integer multiple "
"of the buffer_scale (%d).", "of the buffer_scale (%d).",
get_buffer_width (surface), meta_wayland_surface_get_buffer_width (surface),
get_buffer_height (surface), surface->scale); meta_wayland_surface_get_buffer_height (surface),
surface->scale);
} }
else else
{ {
@ -791,8 +770,10 @@ meta_wayland_surface_apply_state (MetaWaylandSurface *surface,
g_warning ("Bug in client with pid %ld: Cursor buffer size (%dx%d) is " g_warning ("Bug in client with pid %ld: Cursor buffer size (%dx%d) is "
"not an integer multiple of the buffer_scale (%d).", "not an integer multiple of the buffer_scale (%d).",
(long) pid, get_buffer_width (surface), (long) pid,
get_buffer_height (surface), surface->scale); meta_wayland_surface_get_buffer_width (surface),
meta_wayland_surface_get_buffer_height (surface),
surface->scale);
} }
} }
@ -2171,9 +2152,9 @@ meta_wayland_surface_get_width (MetaWaylandSurface *surface)
int width; int width;
if (meta_monitor_transform_is_rotated (surface->buffer_transform)) if (meta_monitor_transform_is_rotated (surface->buffer_transform))
width = get_buffer_height (surface); width = meta_wayland_surface_get_buffer_height (surface);
else else
width = get_buffer_width (surface); width = meta_wayland_surface_get_buffer_width (surface);
return width / surface->scale; return width / surface->scale;
} }
@ -2195,14 +2176,36 @@ meta_wayland_surface_get_height (MetaWaylandSurface *surface)
int height; int height;
if (meta_monitor_transform_is_rotated (surface->buffer_transform)) if (meta_monitor_transform_is_rotated (surface->buffer_transform))
height = get_buffer_width (surface); height = meta_wayland_surface_get_buffer_width (surface);
else else
height = get_buffer_height (surface); height = meta_wayland_surface_get_buffer_height (surface);
return height / surface->scale; return height / surface->scale;
} }
} }
int
meta_wayland_surface_get_buffer_width (MetaWaylandSurface *surface)
{
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
if (buffer)
return cogl_texture_get_width (surface->output_state.texture);
else
return 0;
}
int
meta_wayland_surface_get_buffer_height (MetaWaylandSurface *surface)
{
MetaWaylandBuffer *buffer = meta_wayland_surface_get_buffer (surface);
if (buffer)
return cogl_texture_get_height (surface->output_state.texture);
else
return 0;
}
static void static void
scanout_destroyed (gpointer data, scanout_destroyed (gpointer data,
GObject *where_the_object_was) GObject *where_the_object_was)
@ -2293,10 +2296,10 @@ meta_wayland_surface_can_scanout_untransformed (MetaWaylandSurface *surface,
if (view_layout.width != surface->viewport.dst_width || if (view_layout.width != surface->viewport.dst_width ||
view_layout.height != surface->viewport.dst_height || view_layout.height != surface->viewport.dst_height ||
!G_APPROX_VALUE (untransformed_layout_width, !G_APPROX_VALUE (untransformed_layout_width,
get_buffer_width (surface), meta_wayland_surface_get_buffer_width (surface),
FLT_EPSILON) || FLT_EPSILON) ||
!G_APPROX_VALUE (untransformed_layout_height, !G_APPROX_VALUE (untransformed_layout_height,
get_buffer_height (surface), meta_wayland_surface_get_buffer_height (surface),
FLT_EPSILON)) FLT_EPSILON))
{ {
meta_topic (META_DEBUG_RENDER, meta_topic (META_DEBUG_RENDER,
@ -2305,8 +2308,10 @@ meta_wayland_surface_can_scanout_untransformed (MetaWaylandSurface *surface,
"layout. (%d != %d || %d != %d || %f != %d %f != %d)", "layout. (%d != %d || %d != %d || %f != %d %f != %d)",
view_layout.width, surface->viewport.dst_width, view_layout.width, surface->viewport.dst_width,
view_layout.height, surface->viewport.dst_height, view_layout.height, surface->viewport.dst_height,
untransformed_layout_width, get_buffer_width (surface), untransformed_layout_width,
untransformed_layout_height, get_buffer_height (surface)); meta_wayland_surface_get_buffer_width (surface),
untransformed_layout_height,
meta_wayland_surface_get_buffer_height (surface));
return FALSE; return FALSE;
} }
} }
@ -2349,11 +2354,11 @@ meta_wayland_surface_can_scanout_untransformed (MetaWaylandSurface *surface,
FLT_EPSILON) || FLT_EPSILON) ||
!G_APPROX_VALUE (surface->viewport.src_rect.size.width * !G_APPROX_VALUE (surface->viewport.src_rect.size.width *
surface->scale, surface->scale,
get_buffer_width (surface), meta_wayland_surface_get_buffer_width (surface),
FLT_EPSILON) || FLT_EPSILON) ||
!G_APPROX_VALUE (surface->viewport.src_rect.size.height * !G_APPROX_VALUE (surface->viewport.src_rect.size.height *
surface->scale, surface->scale,
get_buffer_height (surface), meta_wayland_surface_get_buffer_height (surface),
FLT_EPSILON)) FLT_EPSILON))
{ {
meta_topic (META_DEBUG_RENDER, meta_topic (META_DEBUG_RENDER,

View File

@ -388,6 +388,12 @@ int meta_wayland_surface_get_width (MetaWaylandSurface *surface)
META_EXPORT_TEST META_EXPORT_TEST
int meta_wayland_surface_get_height (MetaWaylandSurface *surface); int meta_wayland_surface_get_height (MetaWaylandSurface *surface);
META_EXPORT_TEST
int meta_wayland_surface_get_buffer_width (MetaWaylandSurface *surface);
META_EXPORT_TEST
int meta_wayland_surface_get_buffer_height (MetaWaylandSurface *surface);
CoglScanout * meta_wayland_surface_try_acquire_scanout (MetaWaylandSurface *surface, CoglScanout * meta_wayland_surface_try_acquire_scanout (MetaWaylandSurface *surface,
CoglOnscreen *onscreen); CoglOnscreen *onscreen);