monitor-transform: Invert the behaviour of transform_point

Previously it transformed a physical CRTC coordinate to a logical desktop
coordinate. But current and future users of the function all require
conversion from logical coordinates to physical coordinates. We would have
had to always invert the transform parameter which is a waste of time when
we can instead just invert the function behaviour.

We also simplify the parameters to show both the point coordinate and the
area dimensions are potentially transformed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3180>
This commit is contained in:
Daniel van Vugt 2023-08-16 18:26:05 +08:00 committed by Marge Bot
parent 7a4c98438a
commit 5a05b1a901
3 changed files with 55 additions and 30 deletions

View File

@ -110,48 +110,76 @@ meta_monitor_transform_transform (MetaMonitorTransform transform,
void void
meta_monitor_transform_transform_point (MetaMonitorTransform transform, meta_monitor_transform_transform_point (MetaMonitorTransform transform,
int area_width, int *area_width,
int area_height, int *area_height,
int x, int *point_x,
int y, int *point_y)
int *out_x,
int *out_y)
{ {
int old_x = *point_x;
int old_y = *point_y;
int old_width = *area_width;
int old_height = *area_height;
int new_x = 0;
int new_y = 0;
int new_width = 0;
int new_height = 0;
switch (transform) switch (transform)
{ {
case META_MONITOR_TRANSFORM_NORMAL: case META_MONITOR_TRANSFORM_NORMAL:
*out_x = x; new_x = old_x;
*out_y = y; new_y = old_y;
new_width = old_width;
new_height = old_height;
break; break;
case META_MONITOR_TRANSFORM_90: case META_MONITOR_TRANSFORM_90:
*out_x = area_width - y; new_x = old_y;
*out_y = x; new_y = old_width - old_x;
new_width = old_height;
new_height = old_width;
break; break;
case META_MONITOR_TRANSFORM_180: case META_MONITOR_TRANSFORM_180:
*out_x = area_width - x; new_x = old_width - old_x;
*out_y = area_height - y; new_y = old_height - old_y;
new_width = old_width;
new_height = old_height;
break; break;
case META_MONITOR_TRANSFORM_270: case META_MONITOR_TRANSFORM_270:
*out_x = y, new_x = old_height - old_y;
*out_y = area_height - x; new_y = old_x;
new_width = old_height;
new_height = old_width;
break; break;
case META_MONITOR_TRANSFORM_FLIPPED: case META_MONITOR_TRANSFORM_FLIPPED:
*out_x = area_width - x; new_x = old_width - old_x;
*out_y = y; new_y = old_y;
new_width = old_width;
new_height = old_height;
break; break;
case META_MONITOR_TRANSFORM_FLIPPED_90: case META_MONITOR_TRANSFORM_FLIPPED_90:
*out_x = area_width - y; new_x = old_y;
*out_y = area_height - x; new_y = old_x;
new_width = old_height;
new_height = old_width;
break; break;
case META_MONITOR_TRANSFORM_FLIPPED_180: case META_MONITOR_TRANSFORM_FLIPPED_180:
*out_x = x; new_x = old_x;
*out_y = area_height - y; new_y = old_height - old_y;
new_width = old_width;
new_height = old_height;
break; break;
case META_MONITOR_TRANSFORM_FLIPPED_270: case META_MONITOR_TRANSFORM_FLIPPED_270:
*out_x = y; new_x = old_height - old_y;
*out_y = x; new_y = old_width - old_x;
new_width = old_height;
new_height = old_width;
break; break;
} }
*point_x = new_x;
*point_y = new_y;
*area_width = new_width;
*area_height = new_height;
} }
void void

View File

@ -64,12 +64,10 @@ MetaMonitorTransform meta_monitor_transform_transform (MetaMonitorTransform tran
MetaMonitorTransform other); MetaMonitorTransform other);
void meta_monitor_transform_transform_point (MetaMonitorTransform transform, void meta_monitor_transform_transform_point (MetaMonitorTransform transform,
int area_width, int *area_width,
int area_height, int *area_height,
int x, int *point_x,
int y, int *point_y);
int *out_x,
int *out_y);
void meta_monitor_transform_transform_matrix (MetaMonitorTransform transform, void meta_monitor_transform_transform_matrix (MetaMonitorTransform transform,
graphene_matrix_t *matrix); graphene_matrix_t *matrix);

View File

@ -575,8 +575,7 @@ calculate_crtc_cursor_hotspot (MetaCursorSprite *cursor_sprite,
width = meta_cursor_sprite_get_width (cursor_sprite); width = meta_cursor_sprite_get_width (cursor_sprite);
height = meta_cursor_sprite_get_height (cursor_sprite); height = meta_cursor_sprite_get_height (cursor_sprite);
meta_monitor_transform_transform_point (transform, meta_monitor_transform_transform_point (transform,
width, height, &width, &height,
hot_x, hot_y,
&hot_x, &hot_y); &hot_x, &hot_y);
*hotspot = GRAPHENE_POINT_INIT (hot_x * scale, hot_y * scale); *hotspot = GRAPHENE_POINT_INIT (hot_x * scale, hot_y * scale);
} }