cogl: Compensate for window scaling

The common stage window code that we share on Cogl-based backends should
also use the scaling factor.

https://bugzilla.gnome.org/show_bug.cgi?id=705915
This commit is contained in:
Emmanuele Bassi 2013-08-14 11:27:48 +01:00
parent 75f81fee70
commit a26690a73d

View File

@ -160,10 +160,10 @@ clutter_stage_cogl_realize (ClutterStageWindow *stage_window)
* updated to this size. */ * updated to this size. */
stage_cogl->frame_closure = stage_cogl->frame_closure =
cogl_onscreen_add_frame_callback (stage_cogl->onscreen, cogl_onscreen_add_frame_callback (stage_cogl->onscreen,
frame_cb, frame_cb,
stage_cogl, stage_cogl,
NULL); NULL);
return TRUE; return TRUE;
} }
@ -260,8 +260,11 @@ clutter_stage_cogl_get_geometry (ClutterStageWindow *stage_window,
cairo_rectangle_int_t *geometry) cairo_rectangle_int_t *geometry)
{ {
ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window);
int window_scale;
if (geometry) window_scale = _clutter_stage_window_get_scale_factor (stage_window);
if (geometry != NULL)
{ {
if (stage_cogl->onscreen) if (stage_cogl->onscreen)
{ {
@ -270,8 +273,8 @@ clutter_stage_cogl_get_geometry (ClutterStageWindow *stage_window,
geometry->x = geometry->y = 0; geometry->x = geometry->y = 0;
geometry->width = cogl_framebuffer_get_width (framebuffer); geometry->width = cogl_framebuffer_get_width (framebuffer) / window_scale;
geometry->height = cogl_framebuffer_get_height (framebuffer); geometry->height = cogl_framebuffer_get_height (framebuffer) / window_scale;
} }
else else
{ {
@ -284,8 +287,8 @@ clutter_stage_cogl_get_geometry (ClutterStageWindow *stage_window,
static void static void
clutter_stage_cogl_resize (ClutterStageWindow *stage_window, clutter_stage_cogl_resize (ClutterStageWindow *stage_window,
gint width, gint width,
gint height) gint height)
{ {
} }
@ -402,6 +405,7 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
ClutterActor *wrapper; ClutterActor *wrapper;
cairo_rectangle_int_t *clip_region; cairo_rectangle_int_t *clip_region;
gboolean force_swap; gboolean force_swap;
int window_scale;
CLUTTER_STATIC_TIMER (painting_timer, CLUTTER_STATIC_TIMER (painting_timer,
"Redrawing", /* parent */ "Redrawing", /* parent */
@ -445,14 +449,15 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
} }
if (may_use_clipped_redraw && if (may_use_clipped_redraw &&
G_LIKELY (!(clutter_paint_debug_flags & G_LIKELY (!(clutter_paint_debug_flags & CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS)))
CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS)))
use_clipped_redraw = TRUE; use_clipped_redraw = TRUE;
else else
use_clipped_redraw = FALSE; use_clipped_redraw = FALSE;
force_swap = FALSE; force_swap = FALSE;
window_scale = _clutter_stage_window_get_scale_factor (stage_window);
if (use_clipped_redraw) if (use_clipped_redraw)
{ {
if (has_buffer_age) if (has_buffer_age)
@ -461,10 +466,10 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
cairo_rectangle_int_t *current_damage; cairo_rectangle_int_t *current_damage;
current_damage = g_new0 (cairo_rectangle_int_t, 1); current_damage = g_new0 (cairo_rectangle_int_t, 1);
current_damage->x = clip_region->x; current_damage->x = clip_region->x * window_scale;
current_damage->y = clip_region->y; current_damage->y = clip_region->y * window_scale;
current_damage->width = clip_region->width; current_damage->width = clip_region->width * window_scale;
current_damage->height = clip_region->height; current_damage->height = clip_region->height * window_scale;
stage_cogl->damage_history = g_slist_prepend (stage_cogl->damage_history, current_damage); stage_cogl->damage_history = g_slist_prepend (stage_cogl->damage_history, current_damage);
@ -486,10 +491,10 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
force_swap = TRUE; force_swap = TRUE;
CLUTTER_NOTE (CLIPPING, "Reusing back buffer - repairing region: x=%d, y=%d, width=%d, height=%d\n", CLUTTER_NOTE (CLIPPING, "Reusing back buffer - repairing region: x=%d, y=%d, width=%d, height=%d\n",
clip_region->x, clip_region->x,
clip_region->y, clip_region->y,
clip_region->width, clip_region->width,
clip_region->height); clip_region->height);
} }
else if (age == 0 || stage_cogl->dirty_backbuffer) else if (age == 0 || stage_cogl->dirty_backbuffer)
@ -522,12 +527,11 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
stage_cogl->using_clipped_redraw = TRUE; stage_cogl->using_clipped_redraw = TRUE;
cogl_clip_push_window_rectangle (clip_region->x, cogl_clip_push_window_rectangle (clip_region->x * window_scale,
clip_region->y, clip_region->y * window_scale,
clip_region->width, clip_region->width * window_scale,
clip_region->height); clip_region->height * window_scale);
_clutter_stage_do_paint (CLUTTER_STAGE (wrapper), _clutter_stage_do_paint (CLUTTER_STAGE (wrapper), clip_region);
clip_region);
cogl_clip_pop (); cogl_clip_pop ();
stage_cogl->using_clipped_redraw = FALSE; stage_cogl->using_clipped_redraw = FALSE;
@ -538,8 +542,7 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
/* If we are trying to debug redraw issues then we want to pass /* If we are trying to debug redraw issues then we want to pass
* the bounding_redraw_clip so it can be visualized */ * the bounding_redraw_clip so it can be visualized */
if (G_UNLIKELY (clutter_paint_debug_flags & if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS) &&
CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS) &&
may_use_clipped_redraw) may_use_clipped_redraw)
{ {
_clutter_stage_do_paint (CLUTTER_STAGE (wrapper), _clutter_stage_do_paint (CLUTTER_STAGE (wrapper),
@ -557,10 +560,10 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
static CoglPipeline *outline = NULL; static CoglPipeline *outline = NULL;
cairo_rectangle_int_t *clip = &stage_cogl->bounding_redraw_clip; cairo_rectangle_int_t *clip = &stage_cogl->bounding_redraw_clip;
ClutterActor *actor = CLUTTER_ACTOR (wrapper); ClutterActor *actor = CLUTTER_ACTOR (wrapper);
float x_1 = clip->x; float x_1 = clip->x * window_scale;
float x_2 = clip->x + clip->width; float x_2 = clip->x + clip->width * window_scale;
float y_1 = clip->y; float y_1 = clip->y * window_scale;
float y_2 = clip->y + clip->height; float y_2 = clip->y + clip->height * window_scale;
CoglVertexP2 quad[4] = { CoglVertexP2 quad[4] = {
{ x_1, y_1 }, { x_1, y_1 },
{ x_2, y_1 }, { x_2, y_1 },
@ -609,10 +612,10 @@ clutter_stage_cogl_redraw (ClutterStageWindow *stage_window)
* artefacts. * artefacts.
*/ */
copy_area[0] = clip->x; copy_area[0] = clip->x * window_scale;
copy_area[1] = clip->y; copy_area[1] = clip->y * window_scale;
copy_area[2] = clip->width; copy_area[2] = clip->width * window_scale;
copy_area[3] = clip->height; copy_area[3] = clip->height * window_scale;
CLUTTER_NOTE (BACKEND, CLUTTER_NOTE (BACKEND,
"cogl_onscreen_swap_region (onscreen: %p, " "cogl_onscreen_swap_region (onscreen: %p, "
@ -671,22 +674,24 @@ clutter_stage_cogl_dirty_back_buffer (ClutterStageWindow *stage_window)
static void static void
clutter_stage_cogl_get_dirty_pixel (ClutterStageWindow *stage_window, clutter_stage_cogl_get_dirty_pixel (ClutterStageWindow *stage_window,
int *x, int *y) int *x,
int *y)
{ {
ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window); ClutterStageCogl *stage_cogl = CLUTTER_STAGE_COGL (stage_window);
gboolean has_buffer_age = cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_BUFFER_AGE); gboolean has_buffer_age = cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_BUFFER_AGE);
if ((stage_cogl->damage_history == NULL && has_buffer_age) || !has_buffer_age)
{ if ((stage_cogl->damage_history == NULL && has_buffer_age) || !has_buffer_age)
*x = 0; {
*y = 0; *x = 0;
} *y = 0;
else }
{ else
cairo_rectangle_int_t *rect; {
rect = (cairo_rectangle_int_t *) (stage_cogl->damage_history->data); cairo_rectangle_int_t *rect;
*x = rect->x; rect = (cairo_rectangle_int_t *) (stage_cogl->damage_history->data);
*y = rect->y; *x = rect->x;
} *y = rect->y;
}
} }
static void static void