[gtk] csstransform: Create a GtkTransform
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] csstransform: Create a GtkTransform
- Date: Thu, 21 Feb 2019 18:53:32 +0000 (UTC)
commit ad58dd5cf5670a6a39e1771a0452e9dad1276e7b
Author: Benjamin Otte <otte redhat com>
Date: Thu Feb 21 06:27:30 2019 +0100
csstransform: Create a GtkTransform
Stop creating graphene_matrix_t's.
gtk/gtkcsstransformvalue.c | 100 +++++++++++++++++++-------------------
gtk/gtkcsstransformvalueprivate.h | 3 +-
gtk/gtkrendericon.c | 23 +++++----
3 files changed, 63 insertions(+), 63 deletions(-)
---
diff --git a/gtk/gtkcsstransformvalue.c b/gtk/gtkcsstransformvalue.c
index fcddf6d2ac..5868627025 100644
--- a/gtk/gtkcsstransformvalue.c
+++ b/gtk/gtkcsstransformvalue.c
@@ -17,13 +17,13 @@
#include "config.h"
-#include "gtkcssbgsizevalueprivate.h"
+#include "gtkcsstransformvalueprivate.h"
#include <math.h>
#include <string.h>
-#include "gtkcsstransformvalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
+#include "gtktransform.h"
typedef union _GtkCssTransform GtkCssTransform;
@@ -161,64 +161,62 @@ gtk_css_transform_init_identity (GtkCssTransform *transform,
transform->type = type;
}
-static void
+static GtkTransform *
gtk_css_transform_apply (const GtkCssTransform *transform,
- graphene_matrix_t *matrix)
+ GtkTransform *next)
{
- graphene_matrix_t skew, tmp;
+ graphene_matrix_t skew;
switch (transform->type)
{
case GTK_CSS_TRANSFORM_MATRIX:
- graphene_matrix_multiply (matrix, &transform->matrix.matrix, &tmp);
- graphene_matrix_init_from_matrix (matrix, &tmp);
- break;
+ return gtk_transform_matrix (next, &transform->matrix.matrix);
+
case GTK_CSS_TRANSFORM_TRANSLATE:
- graphene_matrix_translate (matrix, &GRAPHENE_POINT3D_INIT(
- _gtk_css_number_value_get (transform->translate.x, 100),
- _gtk_css_number_value_get (transform->translate.y, 100),
- _gtk_css_number_value_get (transform->translate.z, 100)));
- break;
+ return gtk_transform_translate_3d (next,
+ &GRAPHENE_POINT3D_INIT (
+ _gtk_css_number_value_get (transform->translate.x, 100),
+ _gtk_css_number_value_get (transform->translate.y, 100),
+ _gtk_css_number_value_get (transform->translate.z, 100)
+ ));
+
case GTK_CSS_TRANSFORM_ROTATE:
{
- graphene_vec3_t vec;
+ graphene_vec3_t axis;
- graphene_vec3_init (&vec,
+ graphene_vec3_init (&axis,
_gtk_css_number_value_get (transform->rotate.x, 1),
_gtk_css_number_value_get (transform->rotate.y, 1),
_gtk_css_number_value_get (transform->rotate.z, 1));
- graphene_matrix_rotate (matrix,
- _gtk_css_number_value_get (transform->rotate.angle, 100),
- &vec);
+ return gtk_transform_rotate_3d (next,
+ _gtk_css_number_value_get (transform->rotate.angle, 100),
+ &axis);
}
- break;
+
case GTK_CSS_TRANSFORM_SCALE:
- graphene_matrix_scale (matrix,
- _gtk_css_number_value_get (transform->scale.x, 1),
- _gtk_css_number_value_get (transform->scale.y, 1),
- _gtk_css_number_value_get (transform->scale.z, 1));
+ return gtk_transform_scale_3d (next,
+ _gtk_css_number_value_get (transform->scale.x, 1),
+ _gtk_css_number_value_get (transform->scale.y, 1),
+ _gtk_css_number_value_get (transform->scale.z, 1));
break;
case GTK_CSS_TRANSFORM_SKEW:
graphene_matrix_init_skew (&skew,
_gtk_css_number_value_get (transform->skew.x, 100) / 180.0f * G_PI,
- _gtk_css_number_value_get (transform->skew.y, 100) /180.0f * G_PI);
- graphene_matrix_multiply (matrix, &skew, &tmp);
- graphene_matrix_init_from_matrix (matrix, &tmp);
- break;
+ _gtk_css_number_value_get (transform->skew.y, 100) / 180.0f * G_PI);
+ return gtk_transform_matrix (next, &skew);
+
case GTK_CSS_TRANSFORM_SKEW_X:
graphene_matrix_init_skew (&skew,
_gtk_css_number_value_get (transform->skew_x.skew, 100) / 180.0f * G_PI,
0);
- graphene_matrix_multiply (matrix, &skew, &tmp);
- graphene_matrix_init_from_matrix (matrix, &tmp);
- break;
+ return gtk_transform_matrix (next, &skew);
+
case GTK_CSS_TRANSFORM_SKEW_Y:
graphene_matrix_init_skew (&skew,
0,
_gtk_css_number_value_get (transform->skew_y.skew, 100) / 180.0f * G_PI);
- graphene_matrix_multiply (matrix, &skew, &tmp);
- graphene_matrix_init_from_matrix (matrix, &tmp);
- break;
+ return gtk_transform_matrix (next, &skew);
+
case GTK_CSS_TRANSFORM_NONE:
default:
g_assert_not_reached ();
@@ -227,18 +225,20 @@ gtk_css_transform_apply (const GtkCssTransform *transform,
}
/* NB: The returned matrix may be invalid */
-static void
-gtk_css_transform_value_compute_matrix (const GtkCssValue *value,
- graphene_matrix_t *matrix)
+static GtkTransform *
+gtk_css_transform_value_compute_transform (const GtkCssValue *value)
{
+ GtkTransform *transform;
guint i;
- graphene_matrix_init_identity (matrix);
+ transform = NULL;
for (i = 0; i < value->n_transforms; i++)
{
- gtk_css_transform_apply (&value->transforms[i], matrix);
+ transform = gtk_css_transform_apply (&value->transforms[i], transform);
}
+
+ return transform;
}
static void
@@ -512,12 +512,16 @@ gtk_css_value_transform_transition (GtkCssValue *start,
{
if (start->transforms[i].type != end->transforms[i].type)
{
+ GtkTransform *transform;
graphene_matrix_t start_matrix, end_matrix;
- graphene_matrix_init_identity (&start_matrix);
- gtk_css_transform_value_compute_matrix (start, &start_matrix);
- graphene_matrix_init_identity (&end_matrix);
- gtk_css_transform_value_compute_matrix (end, &end_matrix);
+ transform = gtk_css_transform_value_compute_transform (start);
+ gtk_transform_to_matrix (transform, &start_matrix);
+ gtk_transform_unref (transform);
+
+ transform = gtk_css_transform_value_compute_transform (end);
+ gtk_transform_to_matrix (transform, &end_matrix);
+ gtk_transform_unref (transform);
result = gtk_css_transform_value_alloc (1);
result->transforms[0].type = GTK_CSS_TRANSFORM_MATRIX;
@@ -1094,17 +1098,11 @@ _gtk_css_transform_value_parse (GtkCssParser *parser)
return value;
}
-gboolean
-gtk_css_transform_value_get_matrix (const GtkCssValue *transform,
- graphene_matrix_t *matrix)
+GtkTransform *
+gtk_css_transform_value_get_transform (const GtkCssValue *transform)
{
- graphene_matrix_t invert;
-
g_return_val_if_fail (transform->class == >K_CSS_VALUE_TRANSFORM, FALSE);
- g_return_val_if_fail (matrix != NULL, FALSE);
- gtk_css_transform_value_compute_matrix (transform, matrix);
-
- return graphene_matrix_inverse (matrix, &invert);
+ return gtk_css_transform_value_compute_transform (transform);
}
diff --git a/gtk/gtkcsstransformvalueprivate.h b/gtk/gtkcsstransformvalueprivate.h
index 00a8f8563e..77114cd6b4 100644
--- a/gtk/gtkcsstransformvalueprivate.h
+++ b/gtk/gtkcsstransformvalueprivate.h
@@ -28,8 +28,7 @@ G_BEGIN_DECLS
GtkCssValue * _gtk_css_transform_value_new_none (void);
GtkCssValue * _gtk_css_transform_value_parse (GtkCssParser *parser);
-gboolean gtk_css_transform_value_get_matrix (const GtkCssValue *transform,
- graphene_matrix_t *matrix);
+GtkTransform * gtk_css_transform_value_get_transform (const GtkCssValue *transform);
G_END_DECLS
diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c
index f79862fa73..df855a853c 100644
--- a/gtk/gtkrendericon.c
+++ b/gtk/gtkrendericon.c
@@ -29,6 +29,7 @@
#include "gtkcsstransformvalueprivate.h"
#include "gtkiconthemeprivate.h"
#include "gtksnapshot.h"
+#include "gtktransform.h"
#include <math.h>
@@ -40,7 +41,7 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
GtkCssImageBuiltinType builtin_type)
{
const GtkCssValue *shadows_value, *transform_value, *filter_value;
- graphene_matrix_t transform_matrix;
+ GtkTransform *transform;
GtkCssImage *image;
gboolean has_shadow;
@@ -58,8 +59,7 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
transform_value = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM);
filter_value = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_FILTER);
- if (!gtk_css_transform_value_get_matrix (transform_value, &transform_matrix))
- return;
+ transform = gtk_css_transform_value_get_transform (transform_value);
gtk_snapshot_push_debug (snapshot, "CSS Icon @ %gx%g", width, height);
@@ -67,7 +67,7 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
has_shadow = gtk_css_shadows_value_push_snapshot (shadows_value, snapshot);
- if (graphene_matrix_is_identity (&transform_matrix))
+ if (transform == NULL)
{
gtk_css_image_builtin_snapshot (image, snapshot, width, height, builtin_type);
}
@@ -77,7 +77,7 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
/* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2.0, height / 2.0));
- gtk_snapshot_transform_matrix (snapshot, &transform_matrix);
+ gtk_snapshot_transform (snapshot, transform);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- width / 2.0, - height / 2.0));
gtk_css_image_builtin_snapshot (image, snapshot, width, height, builtin_type);
@@ -91,6 +91,8 @@ gtk_css_style_snapshot_icon (GtkCssStyle *style,
gtk_css_filter_value_pop_snapshot (filter_value, snapshot);
gtk_snapshot_pop (snapshot);
+
+ gtk_transform_unref (transform);
}
void
@@ -102,7 +104,7 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
gboolean recolor)
{
const GtkCssValue *shadows_value, *transform_value, *filter_value;
- graphene_matrix_t transform_matrix;
+ GtkTransform *transform;
gboolean has_shadow;
g_return_if_fail (GTK_IS_CSS_STYLE (style));
@@ -115,8 +117,7 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
transform_value = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM);
filter_value = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_FILTER);
- if (!gtk_css_transform_value_get_matrix (transform_value, &transform_matrix))
- return;
+ transform = gtk_css_transform_value_get_transform (transform_value);
gtk_css_filter_value_push_snapshot (filter_value, snapshot);
@@ -144,7 +145,7 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
gtk_snapshot_push_color_matrix (snapshot, &color_matrix, &color_offset);
}
- if (graphene_matrix_is_identity (&transform_matrix))
+ if (transform == NULL)
{
gdk_paintable_snapshot (paintable, snapshot, width, height);
}
@@ -154,7 +155,7 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
/* XXX: Implement -gtk-icon-transform-origin instead of hardcoding "50% 50%" here */
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (width / 2.0, height / 2.0));
- gtk_snapshot_transform_matrix (snapshot, &transform_matrix);
+ gtk_snapshot_transform (snapshot, transform);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- width / 2.0, - height / 2.0));
gdk_paintable_snapshot (paintable, snapshot, width, height);
@@ -170,4 +171,6 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle *style,
transparent:
gtk_css_filter_value_pop_snapshot (filter_value, snapshot);
+
+ gtk_transform_unref (transform);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]