clutter: Change stage view scale to be float

To support fractional scaling, change the stage view scale to be a
float instead of an int. Also change the places where it is retrieved
and used when scaling things.

https://bugzilla.gnome.org/show_bug.cgi?id=765011
This commit is contained in:
Jonas Ådahl 2017-05-25 15:54:37 +08:00
parent a3d63d0ac0
commit c2e49f1bb5
6 changed files with 36 additions and 21 deletions

View File

@ -20,6 +20,7 @@
#include "clutter/clutter-stage-view.h"
#include <cairo-gobject.h>
#include <math.h>
enum
{
@ -38,7 +39,7 @@ static GParamSpec *obj_props[PROP_LAST];
typedef struct _ClutterStageViewPrivate
{
cairo_rectangle_int_t layout;
int scale;
float scale;
CoglFramebuffer *framebuffer;
CoglOffscreen *offscreen;
@ -143,7 +144,7 @@ clutter_stage_view_blit_offscreen (ClutterStageView *view,
cogl_framebuffer_pop_matrix (priv->framebuffer);
}
int
float
clutter_stage_view_get_scale (ClutterStageView *view)
{
ClutterStageViewPrivate *priv =
@ -241,7 +242,7 @@ clutter_stage_view_get_property (GObject *object,
g_value_set_boxed (value, priv->offscreen);
break;
case PROP_SCALE:
g_value_set_int (value, priv->scale);
g_value_set_float (value, priv->scale);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -267,12 +268,26 @@ clutter_stage_view_set_property (GObject *object,
break;
case PROP_FRAMEBUFFER:
priv->framebuffer = g_value_dup_boxed (value);
#ifndef G_DISABLE_CHECKS
if (priv->framebuffer)
{
int fb_width, fb_height;
fb_width = cogl_framebuffer_get_width (priv->framebuffer);
fb_height = cogl_framebuffer_get_height (priv->framebuffer);
g_warn_if_fail (fabsf (roundf (fb_width / priv->scale) -
fb_width / priv->scale) < FLT_EPSILON);
g_warn_if_fail (fabsf (roundf (fb_height / priv->scale) -
fb_height / priv->scale) < FLT_EPSILON);
}
#endif
break;
case PROP_OFFSCREEN:
priv->offscreen = g_value_dup_boxed (value);
break;
case PROP_SCALE:
priv->scale = g_value_get_int (value);
priv->scale = g_value_get_float (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -301,7 +316,7 @@ clutter_stage_view_init (ClutterStageView *view)
priv->dirty_viewport = TRUE;
priv->dirty_projection = TRUE;
priv->scale = 1;
priv->scale = 1.0;
}
static void
@ -344,13 +359,13 @@ clutter_stage_view_class_init (ClutterStageViewClass *klass)
G_PARAM_STATIC_STRINGS);
obj_props[PROP_SCALE] =
g_param_spec_int ("scale",
"View scale",
"The view scale",
1, G_MAXINT, 1,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
g_param_spec_float ("scale",
"View scale",
"The view scale",
1.0, G_MAXFLOAT, 1.0,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
}

View File

@ -61,7 +61,7 @@ void clutter_stage_view_blit_offscreen (ClutterStageView *view,
const cairo_rectangle_int_t *clip);
CLUTTER_AVAILABLE_IN_MUTTER
int clutter_stage_view_get_scale (ClutterStageView *view);
float clutter_stage_view_get_scale (ClutterStageView *view);
gboolean clutter_stage_view_is_dirty_viewport (ClutterStageView *view);

View File

@ -1445,7 +1445,7 @@ _clutter_stage_do_pick_on_view (ClutterStage *stage,
gint read_x;
gint read_y;
float fb_width, fb_height;
int fb_scale;
float fb_scale;
int viewport_offset_x;
int viewport_offset_y;
@ -1474,8 +1474,8 @@ _clutter_stage_do_pick_on_view (ClutterStage *stage,
if (G_LIKELY (!(clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS)))
{
CLUTTER_NOTE (PICK, "Pushing pick scissor clip x: %d, y: %d, 1x1",
dirty_x * fb_scale,
dirty_y * fb_scale);
(int) dirty_x * fb_scale,
(int) dirty_y * fb_scale);
cogl_framebuffer_push_scissor_clip (fb, dirty_x * fb_scale, dirty_y * fb_scale, 1, 1);
}
@ -3622,7 +3622,7 @@ _clutter_stage_maybe_setup_viewport (ClutterStage *stage,
{
cairo_rectangle_int_t view_layout;
ClutterPerspective perspective;
int fb_scale;
float fb_scale;
int viewport_offset_x;
int viewport_offset_y;
float z_2d;

View File

@ -503,7 +503,7 @@ clutter_stage_cogl_redraw_view (ClutterStageWindow *stage_window,
cairo_rectangle_int_t swap_region;
cairo_rectangle_int_t clip_region;
gboolean clip_region_empty;
int fb_scale;
float fb_scale;
wrapper = CLUTTER_ACTOR (stage_cogl->wrapper);
@ -653,7 +653,7 @@ clutter_stage_cogl_redraw_view (ClutterStageWindow *stage_window,
int scissor_x;
int scissor_y;
scissor_x = (clip_region.x - view_rect.x) * fb_scale;;
scissor_x = (clip_region.x - view_rect.x) * fb_scale;
scissor_y = (clip_region.y - view_rect.y) * fb_scale;
cogl_framebuffer_push_scissor_clip (fb,
scissor_x,

View File

@ -1743,7 +1743,7 @@ meta_renderer_native_create_view (MetaRenderer *renderer,
view = g_object_new (META_TYPE_RENDERER_VIEW,
"layout", &logical_monitor->rect,
"scale", scale,
"scale", (float) scale,
"framebuffer", onscreen,
"offscreen", offscreen,
"logical-monitor", logical_monitor,

View File

@ -210,7 +210,7 @@ meta_renderer_x11_nested_create_view (MetaRenderer *renderer,
"framebuffer", COGL_FRAMEBUFFER (fake_onscreen),
"offscreen", COGL_FRAMEBUFFER (offscreen),
"transform", view_transform,
"scale", view_scale,
"scale", (float) view_scale,
"logical-monitor", logical_monitor,
NULL);
}