gdouble resolution;
gfloat units_per_em;
+ gint32 units_serial;
cairo_font_options_t *font_options;
static void
clutter_backend_real_resolution_changed (ClutterBackend *backend)
{
- backend->priv->units_per_em = get_units_per_em (backend, NULL);
+ ClutterBackendPrivate *priv = backend->priv;
+
+ priv->units_per_em = get_units_per_em (backend, NULL);
+ priv->units_serial += 1;
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->priv->units_per_em);
}
static void
clutter_backend_real_font_changed (ClutterBackend *backend)
{
- backend->priv->units_per_em = get_units_per_em (backend, NULL);
+ ClutterBackendPrivate *priv = backend->priv;
+
+ priv->units_per_em = get_units_per_em (backend, NULL);
+ priv->units_serial += 1;
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->priv->units_per_em);
}
priv = backend->priv = CLUTTER_BACKEND_GET_PRIVATE (backend);
priv->resolution = -1.0;
+
priv->units_per_em = -1.0;
+ priv->units_serial = 1;
}
void
return priv->font_name;
}
+
+gint32
+_clutter_backend_get_units_serial (ClutterBackend *backend)
+{
+ g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0);
+
+ return backend->priv->units_serial;
+}
clutter_units_from_mm (ClutterUnits *units,
gfloat mm)
{
+ ClutterBackend *backend;
+
g_return_if_fail (units != NULL);
+ backend = clutter_get_default_backend ();
+
units->unit_type = CLUTTER_UNIT_MM;
units->value = mm;
units->pixels = units_mm_to_pixels (mm);
units->pixels_set = TRUE;
+ units->serial = _clutter_backend_get_units_serial (backend);
}
/**
clutter_units_from_cm (ClutterUnits *units,
gfloat cm)
{
+ ClutterBackend *backend;
+
g_return_if_fail (units != NULL);
+ backend = clutter_get_default_backend ();
+
units->unit_type = CLUTTER_UNIT_CM;
units->value = cm;
units->pixels = units_cm_to_pixels (cm);
units->pixels_set = TRUE;
+ units->serial = _clutter_backend_get_units_serial (backend);
}
/**
clutter_units_from_pt (ClutterUnits *units,
gfloat pt)
{
+ ClutterBackend *backend;
+
g_return_if_fail (units != NULL);
+ backend = clutter_get_default_backend ();
+
units->unit_type = CLUTTER_UNIT_POINT;
units->value = pt;
units->pixels = units_pt_to_pixels (pt);
units->pixels_set = TRUE;
+ units->serial = _clutter_backend_get_units_serial (backend);
}
/**
clutter_units_from_em (ClutterUnits *units,
gfloat em)
{
+ ClutterBackend *backend;
+
g_return_if_fail (units != NULL);
+ backend = clutter_get_default_backend ();
+
units->unit_type = CLUTTER_UNIT_EM;
units->value = em;
units->pixels = units_em_to_pixels (NULL, em);
units->pixels_set = TRUE;
+ units->serial = _clutter_backend_get_units_serial (backend);
}
/**
const gchar *font_name,
gfloat em)
{
+ ClutterBackend *backend;
+
g_return_if_fail (units != NULL);
+ backend = clutter_get_default_backend ();
+
units->unit_type = CLUTTER_UNIT_EM;
units->value = em;
units->pixels = units_em_to_pixels (font_name, em);
units->pixels_set = TRUE;
+ units->serial = _clutter_backend_get_units_serial (backend);
}
/**
clutter_units_from_pixels (ClutterUnits *units,
gint px)
{
+ ClutterBackend *backend;
+
g_return_if_fail (units != NULL);
+ backend = clutter_get_default_backend ();
+
units->unit_type = CLUTTER_UNIT_PIXEL;
units->value = px;
units->pixels = px;
units->pixels_set = TRUE;
+ units->serial = _clutter_backend_get_units_serial (backend);
}
/**
gfloat
clutter_units_to_pixels (ClutterUnits *units)
{
+ ClutterBackend *backend;
+
g_return_val_if_fail (units != NULL, 0.0);
+ /* if the backend settings changed we evict the cached value */
+ backend = clutter_get_default_backend ();
+ if (units->serial != _clutter_backend_get_units_serial (backend))
+ units->pixels_set = FALSE;
+
+ if (units->pixels_set)
+ return units->pixels;
+
switch (units->unit_type)
{
case CLUTTER_UNIT_MM:
}
units->pixels_set = TRUE;
+ units->serial = _clutter_backend_get_units_serial (backend);
return units->pixels;
}
clutter_units_from_string (ClutterUnits *units,
const gchar *str)
{
+ ClutterBackend *backend;
ClutterUnitType unit_type;
gfloat value;
if (*str != '\0')
return FALSE;
+ backend = clutter_get_default_backend ();
+
units->unit_type = unit_type;
units->value = value;
units->pixels_set = FALSE;
+ units->serial = _clutter_backend_get_units_serial (backend);
return TRUE;
}
#include "test-conform-common.h"
void
+test_units_cache (TestConformSimpleFixture *fixture,
+ gconstpointer data)
+{
+ ClutterUnits units;
+ ClutterBackend *backend;
+ gfloat pixels;
+ gdouble dpi;
+
+ backend = clutter_get_default_backend ();
+
+ dpi = clutter_backend_get_resolution (backend);
+
+ clutter_units_from_em (&units, 1.0);
+ pixels = clutter_units_to_pixels (&units);
+
+ clutter_backend_set_resolution (backend, dpi + 10);
+ g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, pixels);
+
+ clutter_backend_set_resolution (backend, dpi);
+ g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, pixels);
+}
+
+void
test_units_constructors (TestConformSimpleFixture *fixture,
gconstpointer data)
{