tests/cursors: Test viewport based cropping
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3859>
This commit is contained in:
parent
a9a4923c03
commit
5e4821d9fc
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#define CURSOR_SCALE_METHOD_BUFFER_SCALE "buffer-scale"
|
#define CURSOR_SCALE_METHOD_BUFFER_SCALE "buffer-scale"
|
||||||
#define CURSOR_SCALE_METHOD_VIEWPORT "viewport"
|
#define CURSOR_SCALE_METHOD_VIEWPORT "viewport"
|
||||||
|
#define CURSOR_SCALE_METHOD_VIEWPORT_CROPPED "viewport-cropped"
|
||||||
|
|
||||||
struct _MetaCrossOverlay
|
struct _MetaCrossOverlay
|
||||||
{
|
{
|
||||||
@ -471,11 +472,88 @@ meta_test_native_cursor_scaling (void)
|
|||||||
clutter_actor_destroy (overlay_actor);
|
clutter_actor_destroy (overlay_actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
meta_test_native_cursor_cropping (void)
|
||||||
|
{
|
||||||
|
MetaBackend *backend = meta_context_get_backend (test_context);
|
||||||
|
MetaDisplay *display = meta_context_get_display (test_context);
|
||||||
|
ClutterSeat *seat = meta_backend_get_default_seat (backend);
|
||||||
|
g_autoptr (ClutterVirtualInputDevice) virtual_pointer = NULL;
|
||||||
|
ClutterActor *overlay_actor;
|
||||||
|
ClutterStageView *view;
|
||||||
|
struct {
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
float scale;
|
||||||
|
MetaLogicalMonitorLayoutMode layout_mode;
|
||||||
|
} test_cases[] = {
|
||||||
|
{
|
||||||
|
.width = 1920, .height = 1080, .scale = 1.0,
|
||||||
|
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.width = 1920, .height = 1080, .scale = 1.0,
|
||||||
|
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.width = 1920, .height = 1080, .scale = 2.0,
|
||||||
|
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.width = 1920, .height = 1080, .scale = 2.0,
|
||||||
|
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.width = 1440, .height = 900, .scale = 1.5,
|
||||||
|
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.width = 1440, .height = 900, .scale = 2.25,
|
||||||
|
.layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
|
||||||
|
meta_display_set_cursor (display, META_CURSOR_DEFAULT);
|
||||||
|
virtual_pointer = clutter_seat_create_virtual_device (seat,
|
||||||
|
CLUTTER_POINTER_DEVICE);
|
||||||
|
overlay_actor = create_overlay_actor ();
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (test_cases); i++)
|
||||||
|
{
|
||||||
|
g_autofree char *ref_test_name = NULL;
|
||||||
|
|
||||||
|
g_debug ("Testing monitor resolution %dx%d with scale %f and "
|
||||||
|
"%s layout mode",
|
||||||
|
test_cases[i].width, test_cases[i].height, test_cases[i].scale,
|
||||||
|
layout_mode_to_string (test_cases[i].layout_mode));
|
||||||
|
|
||||||
|
wait_for_no_windows ();
|
||||||
|
|
||||||
|
ref_test_name = g_strdup_printf ("%s/%d", g_test_get_path (), i);
|
||||||
|
|
||||||
|
view = setup_test_case (test_cases[i].width, test_cases[i].height,
|
||||||
|
test_cases[i].scale,
|
||||||
|
test_cases[i].layout_mode,
|
||||||
|
virtual_pointer);
|
||||||
|
|
||||||
|
test_client_cursor (view,
|
||||||
|
CURSOR_SCALE_METHOD_VIEWPORT_CROPPED,
|
||||||
|
META_CURSOR_MOVE_OR_RESIZE_WINDOW,
|
||||||
|
ref_test_name, 0,
|
||||||
|
meta_ref_test_determine_ref_test_flag ());
|
||||||
|
}
|
||||||
|
|
||||||
|
clutter_actor_destroy (overlay_actor);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_tests (void)
|
init_tests (void)
|
||||||
{
|
{
|
||||||
g_test_add_func ("/backends/native/cursor/scaling",
|
g_test_add_func ("/backends/native/cursor/scaling",
|
||||||
meta_test_native_cursor_scaling);
|
meta_test_native_cursor_scaling);
|
||||||
|
g_test_add_func ("/backends/native/cursor/cropping",
|
||||||
|
meta_test_native_cursor_cropping);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
BIN
src/tests/ref-tests/backends_native_cursor_cropping_0_0.ref.png
Normal file
BIN
src/tests/ref-tests/backends_native_cursor_cropping_0_0.ref.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
BIN
src/tests/ref-tests/backends_native_cursor_cropping_1_0.ref.png
Normal file
BIN
src/tests/ref-tests/backends_native_cursor_cropping_1_0.ref.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
BIN
src/tests/ref-tests/backends_native_cursor_cropping_2_0.ref.png
Normal file
BIN
src/tests/ref-tests/backends_native_cursor_cropping_2_0.ref.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
BIN
src/tests/ref-tests/backends_native_cursor_cropping_3_0.ref.png
Normal file
BIN
src/tests/ref-tests/backends_native_cursor_cropping_3_0.ref.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
BIN
src/tests/ref-tests/backends_native_cursor_cropping_4_0.ref.png
Normal file
BIN
src/tests/ref-tests/backends_native_cursor_cropping_4_0.ref.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
BIN
src/tests/ref-tests/backends_native_cursor_cropping_5_0.ref.png
Normal file
BIN
src/tests/ref-tests/backends_native_cursor_cropping_5_0.ref.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
@ -26,6 +26,7 @@ typedef enum _CursorScaleMethod
|
|||||||
{
|
{
|
||||||
CURSOR_SCALE_METHOD_BUFFER_SCALE,
|
CURSOR_SCALE_METHOD_BUFFER_SCALE,
|
||||||
CURSOR_SCALE_METHOD_VIEWPORT,
|
CURSOR_SCALE_METHOD_VIEWPORT,
|
||||||
|
CURSOR_SCALE_METHOD_VIEWPORT_CROPPED,
|
||||||
} CursorScaleMethod;
|
} CursorScaleMethod;
|
||||||
|
|
||||||
static CursorScaleMethod scale_method;
|
static CursorScaleMethod scale_method;
|
||||||
@ -62,6 +63,7 @@ on_pointer_enter (WaylandSurface *surface,
|
|||||||
g_clear_pointer (&cursor_viewport, wp_viewport_destroy);
|
g_clear_pointer (&cursor_viewport, wp_viewport_destroy);
|
||||||
break;
|
break;
|
||||||
case CURSOR_SCALE_METHOD_VIEWPORT:
|
case CURSOR_SCALE_METHOD_VIEWPORT:
|
||||||
|
case CURSOR_SCALE_METHOD_VIEWPORT_CROPPED:
|
||||||
if (!cursor_viewport)
|
if (!cursor_viewport)
|
||||||
{
|
{
|
||||||
cursor_viewport = wp_viewporter_get_viewport (display->viewporter,
|
cursor_viewport = wp_viewporter_get_viewport (display->viewporter,
|
||||||
@ -82,6 +84,7 @@ on_pointer_enter (WaylandSurface *surface,
|
|||||||
effective_theme_size = (int) (theme_size * ceilf (scale));
|
effective_theme_size = (int) (theme_size * ceilf (scale));
|
||||||
break;
|
break;
|
||||||
case CURSOR_SCALE_METHOD_VIEWPORT:
|
case CURSOR_SCALE_METHOD_VIEWPORT:
|
||||||
|
case CURSOR_SCALE_METHOD_VIEWPORT_CROPPED:
|
||||||
effective_theme_size = (int) (theme_size * ceilf (scale));
|
effective_theme_size = (int) (theme_size * ceilf (scale));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -110,6 +113,12 @@ on_pointer_enter (WaylandSurface *surface,
|
|||||||
hotspot_x = (int) roundf (image->hotspot_x / image_scale);
|
hotspot_x = (int) roundf (image->hotspot_x / image_scale);
|
||||||
hotspot_y = (int) roundf (image->hotspot_y / image_scale);
|
hotspot_y = (int) roundf (image->hotspot_y / image_scale);
|
||||||
break;
|
break;
|
||||||
|
case CURSOR_SCALE_METHOD_VIEWPORT_CROPPED:
|
||||||
|
hotspot_x = (int) roundf ((image->hotspot_x -
|
||||||
|
(image->width / 4)) / image_scale);
|
||||||
|
hotspot_y = (int) roundf ((image->hotspot_y -
|
||||||
|
(image->height / 4)) / image_scale);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_pointer_set_cursor (pointer, serial,
|
wl_pointer_set_cursor (pointer, serial,
|
||||||
@ -130,6 +139,16 @@ on_pointer_enter (WaylandSurface *surface,
|
|||||||
(int) roundf (image->width / image_scale),
|
(int) roundf (image->width / image_scale),
|
||||||
(int) roundf (image->height / image_scale));
|
(int) roundf (image->height / image_scale));
|
||||||
break;
|
break;
|
||||||
|
case CURSOR_SCALE_METHOD_VIEWPORT_CROPPED:
|
||||||
|
wp_viewport_set_source (cursor_viewport,
|
||||||
|
wl_fixed_from_int (image->width / 4),
|
||||||
|
wl_fixed_from_int (image->height / 4),
|
||||||
|
wl_fixed_from_int (image->width / 2),
|
||||||
|
wl_fixed_from_int (image->height / 2));
|
||||||
|
wp_viewport_set_destination (cursor_viewport,
|
||||||
|
(int) roundf (image->width / 2 / image_scale),
|
||||||
|
(int) roundf (image->height / 2 / image_scale));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_surface_commit (cursor_surface);
|
wl_surface_commit (cursor_surface);
|
||||||
@ -150,6 +169,8 @@ main (int argc,
|
|||||||
scale_method = CURSOR_SCALE_METHOD_BUFFER_SCALE;
|
scale_method = CURSOR_SCALE_METHOD_BUFFER_SCALE;
|
||||||
else if (g_strcmp0 (argv[1], "viewport") == 0)
|
else if (g_strcmp0 (argv[1], "viewport") == 0)
|
||||||
scale_method = CURSOR_SCALE_METHOD_VIEWPORT;
|
scale_method = CURSOR_SCALE_METHOD_VIEWPORT;
|
||||||
|
else if (g_strcmp0 (argv[1], "viewport-cropped") == 0)
|
||||||
|
scale_method = CURSOR_SCALE_METHOD_VIEWPORT_CROPPED;
|
||||||
else
|
else
|
||||||
g_error ("Missing scale method");
|
g_error ("Missing scale method");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user