[mutter] clutter: Change stage view scale to be float



commit c2e49f1bb51a304e2d09617fd209ff4d5aa68275
Author: Jonas Ådahl <jadahl gmail com>
Date:   Thu May 25 15:54:37 2017 +0800

    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

 clutter/clutter/clutter-stage-view.c               |   39 ++++++++++++++------
 clutter/clutter/clutter-stage-view.h               |    2 +-
 clutter/clutter/clutter-stage.c                    |    8 ++--
 clutter/clutter/cogl/clutter-stage-cogl.c          |    4 +-
 src/backends/native/meta-renderer-native.c         |    2 +-
 src/backends/x11/nested/meta-renderer-x11-nested.c |    2 +-
 6 files changed, 36 insertions(+), 21 deletions(-)
---
diff --git a/clutter/clutter/clutter-stage-view.c b/clutter/clutter/clutter-stage-view.c
index c784759..7efb9e2 100644
--- a/clutter/clutter/clutter-stage-view.c
+++ b/clutter/clutter/clutter-stage-view.c
@@ -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);
 }
diff --git a/clutter/clutter/clutter-stage-view.h b/clutter/clutter/clutter-stage-view.h
index a358d4d..a737090 100644
--- a/clutter/clutter/clutter-stage-view.h
+++ b/clutter/clutter/clutter-stage-view.h
@@ -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);
 
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index d1dfdd2..b7e7cd3 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -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;
diff --git a/clutter/clutter/cogl/clutter-stage-cogl.c b/clutter/clutter/cogl/clutter-stage-cogl.c
index 02a0955..436494a 100644
--- a/clutter/clutter/cogl/clutter-stage-cogl.c
+++ b/clutter/clutter/cogl/clutter-stage-cogl.c
@@ -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,
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 05ed09e..fdcf2da 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -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,
diff --git a/src/backends/x11/nested/meta-renderer-x11-nested.c 
b/src/backends/x11/nested/meta-renderer-x11-nested.c
index 8843252..6880b45 100644
--- a/src/backends/x11/nested/meta-renderer-x11-nested.c
+++ b/src/backends/x11/nested/meta-renderer-x11-nested.c
@@ -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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]