mirror of
https://github.com/brl/mutter.git
synced 2025-02-15 04:44:11 +00:00
backend: Remove unnecessary private data structure
The whole of ClutterBackend is a final/protected type, so having a bunch of instance fields and an instance private data structure is redundant at best, and less efficient at worst.
This commit is contained in:
parent
19fbbcd358
commit
938eea175f
@ -48,7 +48,14 @@ struct _ClutterBackend
|
|||||||
|
|
||||||
ClutterDeviceManager *device_manager;
|
ClutterDeviceManager *device_manager;
|
||||||
|
|
||||||
ClutterBackendPrivate *priv;
|
cairo_font_options_t *font_options;
|
||||||
|
|
||||||
|
gchar *font_name;
|
||||||
|
|
||||||
|
gfloat units_per_em;
|
||||||
|
gint32 units_serial;
|
||||||
|
|
||||||
|
GList *event_translators;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _ClutterBackendClass
|
struct _ClutterBackendClass
|
||||||
|
@ -103,18 +103,6 @@
|
|||||||
|
|
||||||
#define DEFAULT_FONT_NAME "Sans 10"
|
#define DEFAULT_FONT_NAME "Sans 10"
|
||||||
|
|
||||||
struct _ClutterBackendPrivate
|
|
||||||
{
|
|
||||||
cairo_font_options_t *font_options;
|
|
||||||
|
|
||||||
gchar *font_name;
|
|
||||||
|
|
||||||
gfloat units_per_em;
|
|
||||||
gint32 units_serial;
|
|
||||||
|
|
||||||
GList *event_translators;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
RESOLUTION_CHANGED,
|
RESOLUTION_CHANGED,
|
||||||
@ -124,7 +112,7 @@ enum
|
|||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ClutterBackend, clutter_backend, G_TYPE_OBJECT)
|
G_DEFINE_ABSTRACT_TYPE (ClutterBackend, clutter_backend, G_TYPE_OBJECT)
|
||||||
|
|
||||||
static guint backend_signals[LAST_SIGNAL] = { 0, };
|
static guint backend_signals[LAST_SIGNAL] = { 0, };
|
||||||
|
|
||||||
@ -139,17 +127,13 @@ static const char *allowed_backend;
|
|||||||
static void
|
static void
|
||||||
clutter_backend_dispose (GObject *gobject)
|
clutter_backend_dispose (GObject *gobject)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv = CLUTTER_BACKEND (gobject)->priv;
|
ClutterBackend *backend = CLUTTER_BACKEND (gobject);
|
||||||
|
|
||||||
/* clear the events still in the queue of the main context */
|
/* clear the events still in the queue of the main context */
|
||||||
_clutter_clear_events_queue ();
|
_clutter_clear_events_queue ();
|
||||||
|
|
||||||
/* remove all event translators */
|
/* remove all event translators */
|
||||||
if (priv->event_translators != NULL)
|
g_clear_pointer (&backend->event_translators, g_list_free);
|
||||||
{
|
|
||||||
g_list_free (priv->event_translators);
|
|
||||||
priv->event_translators = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
|
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
|
||||||
}
|
}
|
||||||
@ -161,7 +145,7 @@ clutter_backend_finalize (GObject *gobject)
|
|||||||
|
|
||||||
g_source_destroy (backend->cogl_source);
|
g_source_destroy (backend->cogl_source);
|
||||||
|
|
||||||
g_free (backend->priv->font_name);
|
g_free (backend->font_name);
|
||||||
clutter_backend_set_font_options (backend, NULL);
|
clutter_backend_set_font_options (backend, NULL);
|
||||||
|
|
||||||
G_OBJECT_CLASS (clutter_backend_parent_class)->finalize (gobject);
|
G_OBJECT_CLASS (clutter_backend_parent_class)->finalize (gobject);
|
||||||
@ -226,7 +210,6 @@ get_units_per_em (ClutterBackend *backend,
|
|||||||
static void
|
static void
|
||||||
clutter_backend_real_resolution_changed (ClutterBackend *backend)
|
clutter_backend_real_resolution_changed (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv = backend->priv;
|
|
||||||
ClutterMainContext *context;
|
ClutterMainContext *context;
|
||||||
ClutterSettings *settings;
|
ClutterSettings *settings;
|
||||||
gdouble resolution;
|
gdouble resolution;
|
||||||
@ -244,21 +227,19 @@ clutter_backend_real_resolution_changed (ClutterBackend *backend)
|
|||||||
if (context->font_map != NULL)
|
if (context->font_map != NULL)
|
||||||
cogl_pango_font_map_set_resolution (context->font_map, resolution);
|
cogl_pango_font_map_set_resolution (context->font_map, resolution);
|
||||||
|
|
||||||
priv->units_per_em = get_units_per_em (backend, NULL);
|
backend->units_per_em = get_units_per_em (backend, NULL);
|
||||||
priv->units_serial += 1;
|
backend->units_serial += 1;
|
||||||
|
|
||||||
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", priv->units_per_em);
|
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->units_per_em);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_backend_real_font_changed (ClutterBackend *backend)
|
clutter_backend_real_font_changed (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv = backend->priv;
|
backend->units_per_em = get_units_per_em (backend, NULL);
|
||||||
|
backend->units_serial += 1;
|
||||||
|
|
||||||
priv->units_per_em = get_units_per_em (backend, NULL);
|
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->units_per_em);
|
||||||
priv->units_serial += 1;
|
|
||||||
|
|
||||||
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", priv->units_per_em);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -634,10 +615,9 @@ clutter_backend_real_translate_event (ClutterBackend *backend,
|
|||||||
gpointer native,
|
gpointer native,
|
||||||
ClutterEvent *event)
|
ClutterEvent *event)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv = backend->priv;
|
|
||||||
GList *l;
|
GList *l;
|
||||||
|
|
||||||
for (l = priv->event_translators;
|
for (l = backend->event_translators;
|
||||||
l != NULL;
|
l != NULL;
|
||||||
l = l->next)
|
l = l->next)
|
||||||
{
|
{
|
||||||
@ -737,9 +717,8 @@ clutter_backend_class_init (ClutterBackendClass *klass)
|
|||||||
static void
|
static void
|
||||||
clutter_backend_init (ClutterBackend *self)
|
clutter_backend_init (ClutterBackend *self)
|
||||||
{
|
{
|
||||||
self->priv = clutter_backend_get_instance_private (self);
|
self->units_per_em = -1.0;
|
||||||
self->priv->units_per_em = -1.0;
|
self->units_serial = 1;
|
||||||
self->priv->units_serial = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -956,18 +935,14 @@ gfloat
|
|||||||
_clutter_backend_get_units_per_em (ClutterBackend *backend,
|
_clutter_backend_get_units_per_em (ClutterBackend *backend,
|
||||||
PangoFontDescription *font_desc)
|
PangoFontDescription *font_desc)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv;
|
|
||||||
|
|
||||||
priv = backend->priv;
|
|
||||||
|
|
||||||
/* recompute for the font description, but do not cache the result */
|
/* recompute for the font description, but do not cache the result */
|
||||||
if (font_desc != NULL)
|
if (font_desc != NULL)
|
||||||
return get_units_per_em (backend, font_desc);
|
return get_units_per_em (backend, font_desc);
|
||||||
|
|
||||||
if (priv->units_per_em < 0)
|
if (backend->units_per_em < 0)
|
||||||
priv->units_per_em = get_units_per_em (backend, NULL);
|
backend->units_per_em = get_units_per_em (backend, NULL);
|
||||||
|
|
||||||
return priv->units_per_em;
|
return backend->units_per_em;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1196,21 +1171,17 @@ void
|
|||||||
clutter_backend_set_font_options (ClutterBackend *backend,
|
clutter_backend_set_font_options (ClutterBackend *backend,
|
||||||
const cairo_font_options_t *options)
|
const cairo_font_options_t *options)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv;
|
|
||||||
|
|
||||||
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
||||||
|
|
||||||
priv = backend->priv;
|
if (backend->font_options != options)
|
||||||
|
|
||||||
if (priv->font_options != options)
|
|
||||||
{
|
{
|
||||||
if (priv->font_options)
|
if (backend->font_options)
|
||||||
cairo_font_options_destroy (priv->font_options);
|
cairo_font_options_destroy (backend->font_options);
|
||||||
|
|
||||||
if (options)
|
if (options)
|
||||||
priv->font_options = cairo_font_options_copy (options);
|
backend->font_options = cairo_font_options_copy (options);
|
||||||
else
|
else
|
||||||
priv->font_options = NULL;
|
backend->font_options = NULL;
|
||||||
|
|
||||||
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
|
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
|
||||||
}
|
}
|
||||||
@ -1231,27 +1202,20 @@ clutter_backend_set_font_options (ClutterBackend *backend,
|
|||||||
const cairo_font_options_t *
|
const cairo_font_options_t *
|
||||||
clutter_backend_get_font_options (ClutterBackend *backend)
|
clutter_backend_get_font_options (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv;
|
|
||||||
|
|
||||||
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
|
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
|
||||||
|
|
||||||
priv = backend->priv;
|
if (G_LIKELY (backend->font_options))
|
||||||
|
return backend->font_options;
|
||||||
|
|
||||||
if (G_LIKELY (priv->font_options))
|
backend->font_options = cairo_font_options_create ();
|
||||||
return priv->font_options;
|
|
||||||
|
|
||||||
priv->font_options = cairo_font_options_create ();
|
cairo_font_options_set_hint_style (backend->font_options, CAIRO_HINT_STYLE_NONE);
|
||||||
|
cairo_font_options_set_subpixel_order (backend->font_options, CAIRO_SUBPIXEL_ORDER_DEFAULT);
|
||||||
cairo_font_options_set_hint_style (priv->font_options,
|
cairo_font_options_set_antialias (backend->font_options, CAIRO_ANTIALIAS_DEFAULT);
|
||||||
CAIRO_HINT_STYLE_NONE);
|
|
||||||
cairo_font_options_set_subpixel_order (priv->font_options,
|
|
||||||
CAIRO_SUBPIXEL_ORDER_DEFAULT);
|
|
||||||
cairo_font_options_set_antialias (priv->font_options,
|
|
||||||
CAIRO_ANTIALIAS_DEFAULT);
|
|
||||||
|
|
||||||
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
|
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
|
||||||
|
|
||||||
return priv->font_options;
|
return backend->font_options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1294,28 +1258,25 @@ clutter_backend_set_font_name (ClutterBackend *backend,
|
|||||||
const gchar *
|
const gchar *
|
||||||
clutter_backend_get_font_name (ClutterBackend *backend)
|
clutter_backend_get_font_name (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv;
|
|
||||||
ClutterSettings *settings;
|
ClutterSettings *settings;
|
||||||
|
|
||||||
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
|
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
|
||||||
|
|
||||||
priv = backend->priv;
|
|
||||||
|
|
||||||
settings = clutter_settings_get_default ();
|
settings = clutter_settings_get_default ();
|
||||||
|
|
||||||
/* XXX yuck. but we return a const pointer, so we need to
|
/* XXX yuck. but we return a const pointer, so we need to
|
||||||
* store it in the backend
|
* store it in the backend
|
||||||
*/
|
*/
|
||||||
g_free (priv->font_name);
|
g_free (backend->font_name);
|
||||||
g_object_get (settings, "font-name", &priv->font_name, NULL);
|
g_object_get (settings, "font-name", &backend->font_name, NULL);
|
||||||
|
|
||||||
return priv->font_name;
|
return backend->font_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint32
|
gint32
|
||||||
_clutter_backend_get_units_serial (ClutterBackend *backend)
|
_clutter_backend_get_units_serial (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
return backend->priv->units_serial;
|
return backend->units_serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -1332,26 +1293,22 @@ void
|
|||||||
_clutter_backend_add_event_translator (ClutterBackend *backend,
|
_clutter_backend_add_event_translator (ClutterBackend *backend,
|
||||||
ClutterEventTranslator *translator)
|
ClutterEventTranslator *translator)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv = backend->priv;
|
if (g_list_find (backend->event_translators, translator) != NULL)
|
||||||
|
|
||||||
if (g_list_find (priv->event_translators, translator) != NULL)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
priv->event_translators =
|
backend->event_translators =
|
||||||
g_list_prepend (priv->event_translators, translator);
|
g_list_prepend (backend->event_translators, translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_clutter_backend_remove_event_translator (ClutterBackend *backend,
|
_clutter_backend_remove_event_translator (ClutterBackend *backend,
|
||||||
ClutterEventTranslator *translator)
|
ClutterEventTranslator *translator)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv = backend->priv;
|
if (g_list_find (backend->event_translators, translator) == NULL)
|
||||||
|
|
||||||
if (g_list_find (priv->event_translators, translator) == NULL)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
priv->event_translators =
|
backend->event_translators =
|
||||||
g_list_remove (priv->event_translators, translator);
|
g_list_remove (backend->event_translators, translator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user