diff --git a/src/tests/cursor-tests.c b/src/tests/cursor-tests.c index a90525adc..7a8be1ced 100644 --- a/src/tests/cursor-tests.c +++ b/src/tests/cursor-tests.c @@ -35,6 +35,7 @@ #define CURSOR_SCALE_METHOD_BUFFER_SCALE "buffer-scale" #define CURSOR_SCALE_METHOD_VIEWPORT "viewport" +#define CURSOR_SCALE_METHOD_VIEWPORT_CROPPED "viewport-cropped" struct _MetaCrossOverlay { @@ -471,11 +472,88 @@ meta_test_native_cursor_scaling (void) 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 init_tests (void) { g_test_add_func ("/backends/native/cursor/scaling", meta_test_native_cursor_scaling); + g_test_add_func ("/backends/native/cursor/cropping", + meta_test_native_cursor_cropping); } static void diff --git a/src/tests/ref-tests/backends_native_cursor_cropping_0_0.ref.png b/src/tests/ref-tests/backends_native_cursor_cropping_0_0.ref.png new file mode 100644 index 000000000..9a9d93739 Binary files /dev/null and b/src/tests/ref-tests/backends_native_cursor_cropping_0_0.ref.png differ diff --git a/src/tests/ref-tests/backends_native_cursor_cropping_1_0.ref.png b/src/tests/ref-tests/backends_native_cursor_cropping_1_0.ref.png new file mode 100644 index 000000000..9a9d93739 Binary files /dev/null and b/src/tests/ref-tests/backends_native_cursor_cropping_1_0.ref.png differ diff --git a/src/tests/ref-tests/backends_native_cursor_cropping_2_0.ref.png b/src/tests/ref-tests/backends_native_cursor_cropping_2_0.ref.png new file mode 100644 index 000000000..259c74b3b Binary files /dev/null and b/src/tests/ref-tests/backends_native_cursor_cropping_2_0.ref.png differ diff --git a/src/tests/ref-tests/backends_native_cursor_cropping_3_0.ref.png b/src/tests/ref-tests/backends_native_cursor_cropping_3_0.ref.png new file mode 100644 index 000000000..255134d83 Binary files /dev/null and b/src/tests/ref-tests/backends_native_cursor_cropping_3_0.ref.png differ diff --git a/src/tests/ref-tests/backends_native_cursor_cropping_4_0.ref.png b/src/tests/ref-tests/backends_native_cursor_cropping_4_0.ref.png new file mode 100644 index 000000000..ea1b05060 Binary files /dev/null and b/src/tests/ref-tests/backends_native_cursor_cropping_4_0.ref.png differ diff --git a/src/tests/ref-tests/backends_native_cursor_cropping_5_0.ref.png b/src/tests/ref-tests/backends_native_cursor_cropping_5_0.ref.png new file mode 100644 index 000000000..bdc9034f2 Binary files /dev/null and b/src/tests/ref-tests/backends_native_cursor_cropping_5_0.ref.png differ diff --git a/src/tests/wayland-test-clients/cursor-tests-client.c b/src/tests/wayland-test-clients/cursor-tests-client.c index 7655a58ba..6a79b8c49 100644 --- a/src/tests/wayland-test-clients/cursor-tests-client.c +++ b/src/tests/wayland-test-clients/cursor-tests-client.c @@ -26,6 +26,7 @@ typedef enum _CursorScaleMethod { CURSOR_SCALE_METHOD_BUFFER_SCALE, CURSOR_SCALE_METHOD_VIEWPORT, + CURSOR_SCALE_METHOD_VIEWPORT_CROPPED, } CursorScaleMethod; static CursorScaleMethod scale_method; @@ -62,6 +63,7 @@ on_pointer_enter (WaylandSurface *surface, g_clear_pointer (&cursor_viewport, wp_viewport_destroy); break; case CURSOR_SCALE_METHOD_VIEWPORT: + case CURSOR_SCALE_METHOD_VIEWPORT_CROPPED: if (!cursor_viewport) { 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)); break; case CURSOR_SCALE_METHOD_VIEWPORT: + case CURSOR_SCALE_METHOD_VIEWPORT_CROPPED: effective_theme_size = (int) (theme_size * ceilf (scale)); break; } @@ -110,6 +113,12 @@ on_pointer_enter (WaylandSurface *surface, hotspot_x = (int) roundf (image->hotspot_x / image_scale); hotspot_y = (int) roundf (image->hotspot_y / image_scale); 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, @@ -130,6 +139,16 @@ on_pointer_enter (WaylandSurface *surface, (int) roundf (image->width / image_scale), (int) roundf (image->height / image_scale)); 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); @@ -150,6 +169,8 @@ main (int argc, scale_method = CURSOR_SCALE_METHOD_BUFFER_SCALE; else if (g_strcmp0 (argv[1], "viewport") == 0) scale_method = CURSOR_SCALE_METHOD_VIEWPORT; + else if (g_strcmp0 (argv[1], "viewport-cropped") == 0) + scale_method = CURSOR_SCALE_METHOD_VIEWPORT_CROPPED; else g_error ("Missing scale method");