diff --git a/libweston/backend.h b/libweston/backend.h index 8e91746b..b9afb2c0 100644 --- a/libweston/backend.h +++ b/libweston/backend.h @@ -170,6 +170,10 @@ weston_output_transform_coordinate(struct weston_output *output, double device_x, double device_y, double *x, double *y); +void +weston_output_region_from_global(struct weston_output *output, + pixman_region32_t *region); + /* weston_seat */ void diff --git a/libweston/compositor.c b/libweston/compositor.c index 89fa7c48..22a3a897 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -5844,6 +5844,36 @@ weston_compositor_reflow_outputs(struct weston_compositor *compositor, } } +/** Transform a region in-place from global to output coordinates + * + * \param output The output that defines the transformation. + * \param region The region to be transformed in-place. + * + * This takes a region in the global coordinate system, and takes into account + * output position, transform and scale, and the zoom, and converts the region + * into output pixel coordinates in the framebuffer. + * + * Uses floating-point operations if zoom is active, which may round to expand + * the region. + * + * \internal + * \ingroup output + */ +WL_EXPORT void +weston_output_region_from_global(struct weston_output *output, + pixman_region32_t *region) +{ + if (output->zoom.active) { + weston_matrix_transform_region(region, &output->matrix, region); + } else { + pixman_region32_translate(region, -output->x, -output->y); + weston_transformed_region(output->width, output->height, + output->transform, + output->current_scale, + region, region); + } +} + static void weston_output_update_matrix(struct weston_output *output) { diff --git a/libweston/pixman-renderer.c b/libweston/pixman-renderer.c index 59b1f0ff..8cd650ca 100644 --- a/libweston/pixman-renderer.c +++ b/libweston/pixman-renderer.c @@ -125,20 +125,6 @@ pixman_renderer_read_pixels(struct weston_output *output, return 0; } -static void -region_global_to_output(struct weston_output *output, pixman_region32_t *region) -{ - if (output->zoom.active) { - weston_matrix_transform_region(region, &output->matrix, region); - } else { - pixman_region32_translate(region, -output->x, -output->y); - weston_transformed_region(output->width, output->height, - output->transform, - output->current_scale, - region, region); - } -} - #define D2F(v) pixman_double_to_fixed((double)v) static void @@ -426,7 +412,8 @@ draw_view_translated(struct weston_view *view, struct weston_output *output, repaint_global, &surface->opaque, view); - region_global_to_output(output, &repaint_output); + weston_output_region_from_global(output, + &repaint_output); repaint_region(view, output, &repaint_output, NULL, PIXMAN_OP_SRC); @@ -437,7 +424,7 @@ draw_view_translated(struct weston_view *view, struct weston_output *output, region_intersect_only_translation(&repaint_output, repaint_global, &surface_blend, view); - region_global_to_output(output, &repaint_output); + weston_output_region_from_global(output, &repaint_output); repaint_region(view, output, &repaint_output, NULL, PIXMAN_OP_OVER); @@ -473,7 +460,7 @@ draw_view_source_clipped(struct weston_view *view, pixman_region32_init(&repaint_output); pixman_region32_copy(&repaint_output, repaint_global); - region_global_to_output(output, &repaint_output); + weston_output_region_from_global(output, &repaint_output); repaint_region(view, output, &repaint_output, &buffer_region, PIXMAN_OP_OVER); @@ -546,7 +533,7 @@ copy_to_hw_buffer(struct weston_output *output, pixman_region32_t *region) pixman_region32_init(&output_region); pixman_region32_copy(&output_region, region); - region_global_to_output(output, &output_region); + weston_output_region_from_global(output, &output_region); pixman_image_set_clip_region32 (po->hw_buffer, &output_region); pixman_region32_fini(&output_region);