From 501d19656e7e4fba1ce43708d1312f491619dca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 20 Sep 2021 10:28:42 +0200 Subject: [PATCH] context: Make ClutterContext a GObject and move to separate file This is a step in cleaning up the Clutter context management. By making it a GObject it's easier to add e.g. properties and features that helps with introspection. For now, this means the context creation is changed to go via a "constructor" (clutter_create_context()). This is so that the global context singleton can be mantained outsid of ClutterContext, until it can be removed. Part-of: --- clutter/clutter/clutter-backend.c | 1 + clutter/clutter/clutter-context-private.h | 48 +++ clutter/clutter/clutter-context.c | 318 +++++++++++++++++++ clutter/clutter/clutter-context.h | 67 ++++ clutter/clutter/clutter-event.c | 1 + clutter/clutter/clutter-input-pointer-a11y.c | 1 + clutter/clutter/clutter-main.c | 265 +--------------- clutter/clutter/clutter-mutter.h | 23 +- clutter/clutter/clutter-private.h | 40 +-- clutter/clutter/clutter-settings.c | 1 + clutter/clutter/clutter-stage-manager.c | 3 +- clutter/clutter/clutter-stage.c | 1 + clutter/clutter/meson.build | 3 + src/backends/meta-backend.c | 9 +- 14 files changed, 469 insertions(+), 312 deletions(-) create mode 100644 clutter/clutter/clutter-context-private.h create mode 100644 clutter/clutter/clutter-context.c create mode 100644 clutter/clutter/clutter-context.h diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c index b27c6736f..ac1035231 100644 --- a/clutter/clutter/clutter-backend.c +++ b/clutter/clutter/clutter-backend.c @@ -40,6 +40,7 @@ #include "config.h" #include "clutter/clutter-backend-private.h" +#include "clutter/clutter-context-private.h" #include "clutter/clutter-debug.h" #include "clutter/clutter-event-private.h" #include "clutter/clutter-marshal.h" diff --git a/clutter/clutter/clutter-context-private.h b/clutter/clutter/clutter-context-private.h new file mode 100644 index 000000000..dc81d7f52 --- /dev/null +++ b/clutter/clutter/clutter-context-private.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006 OpenedHand + * Copyright (C) 2023 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + */ + +#pragma once + +#include "clutter/clutter-context.h" + +struct _ClutterContext +{ + GObject parent; + + ClutterBackend *backend; + ClutterStageManager *stage_manager; + + GAsyncQueue *events_queue; + + /* the event filters added via clutter_event_add_filter. these are + * ordered from least recently added to most recently added */ + GList *event_filters; + + CoglPangoFontMap *font_map; + + GSList *current_event; + + GList *repaint_funcs; + guint last_repaint_id; + + ClutterSettings *settings; + + gboolean is_initialized; + gboolean show_fps; +}; diff --git a/clutter/clutter/clutter-context.c b/clutter/clutter/clutter-context.c new file mode 100644 index 000000000..4fb4f0ff3 --- /dev/null +++ b/clutter/clutter/clutter-context.c @@ -0,0 +1,318 @@ +/* + * Copyright (C) 2006 OpenedHand + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + */ + +#include "config.h" + +#include "clutter/clutter-context-private.h" + +#include + +#include "cally/cally.h" +#include "clutter/clutter-backend-private.h" +#include "clutter/clutter-debug.h" +#include "clutter/clutter-graphene.h" +#include "clutter/clutter-main.h" +#include "clutter/clutter-paint-node-private.h" +#include "clutter/clutter-settings-private.h" + +static gboolean clutter_disable_mipmap_text = FALSE; +static gboolean clutter_show_fps = FALSE; + +#ifdef CLUTTER_ENABLE_DEBUG +static const GDebugKey clutter_debug_keys[] = { + { "misc", CLUTTER_DEBUG_MISC }, + { "actor", CLUTTER_DEBUG_ACTOR }, + { "texture", CLUTTER_DEBUG_TEXTURE }, + { "event", CLUTTER_DEBUG_EVENT }, + { "paint", CLUTTER_DEBUG_PAINT }, + { "pick", CLUTTER_DEBUG_PICK }, + { "pango", CLUTTER_DEBUG_PANGO }, + { "backend", CLUTTER_DEBUG_BACKEND }, + { "scheduler", CLUTTER_DEBUG_SCHEDULER }, + { "script", CLUTTER_DEBUG_SCRIPT }, + { "shader", CLUTTER_DEBUG_SHADER }, + { "animation", CLUTTER_DEBUG_ANIMATION }, + { "layout", CLUTTER_DEBUG_LAYOUT }, + { "clipping", CLUTTER_DEBUG_CLIPPING }, + { "oob-transforms", CLUTTER_DEBUG_OOB_TRANSFORMS }, + { "frame-timings", CLUTTER_DEBUG_FRAME_TIMINGS }, + { "detailed-trace", CLUTTER_DEBUG_DETAILED_TRACE }, + { "grabs", CLUTTER_DEBUG_GRABS }, + { "frame-clock", CLUTTER_DEBUG_FRAME_CLOCK }, +}; +#endif /* CLUTTER_ENABLE_DEBUG */ + +static const GDebugKey clutter_pick_debug_keys[] = { + { "nop-picking", CLUTTER_DEBUG_NOP_PICKING }, +}; + +static const GDebugKey clutter_paint_debug_keys[] = { + { "disable-swap-events", CLUTTER_DEBUG_DISABLE_SWAP_EVENTS }, + { "disable-clipped-redraws", CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS }, + { "redraws", CLUTTER_DEBUG_REDRAWS }, + { "paint-volumes", CLUTTER_DEBUG_PAINT_VOLUMES }, + { "disable-culling", CLUTTER_DEBUG_DISABLE_CULLING }, + { "disable-offscreen-redirect", CLUTTER_DEBUG_DISABLE_OFFSCREEN_REDIRECT }, + { "continuous-redraw", CLUTTER_DEBUG_CONTINUOUS_REDRAW }, + { "paint-deform-tiles", CLUTTER_DEBUG_PAINT_DEFORM_TILES }, + { "damage-region", CLUTTER_DEBUG_PAINT_DAMAGE_REGION }, + { "disable-dynamic-max-render-time", CLUTTER_DEBUG_DISABLE_DYNAMIC_MAX_RENDER_TIME }, + { "max-render-time", CLUTTER_DEBUG_PAINT_MAX_RENDER_TIME }, +}; + +typedef struct _ClutterContextPrivate +{ + ClutterTextDirection text_direction; +} ClutterContextPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (ClutterContext, clutter_context, G_TYPE_OBJECT) + +static void +clutter_context_dispose (GObject *object) +{ + ClutterContext *context = CLUTTER_CONTEXT (object); + + g_clear_pointer (&context->events_queue, g_async_queue_unref); + g_clear_pointer (&context->backend, clutter_backend_destroy); + + G_OBJECT_CLASS (clutter_context_parent_class)->dispose (object); +} + +static void +clutter_context_class_init (ClutterContextClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = clutter_context_dispose; + + clutter_graphene_init (); +} + +static void +clutter_context_init (ClutterContext *context) +{ + ClutterContextPrivate *priv = clutter_context_get_instance_private (context); + + priv->text_direction = CLUTTER_TEXT_DIRECTION_LTR; +} + +ClutterTextDirection +clutter_get_text_direction (void) +{ + ClutterTextDirection dir = CLUTTER_TEXT_DIRECTION_LTR; + const gchar *direction; + + direction = g_getenv ("CLUTTER_TEXT_DIRECTION"); + if (direction && *direction != '\0') + { + if (strcmp (direction, "rtl") == 0) + dir = CLUTTER_TEXT_DIRECTION_RTL; + else if (strcmp (direction, "ltr") == 0) + dir = CLUTTER_TEXT_DIRECTION_LTR; + } + else + { + PangoLanguage *language; + const PangoScript *scripts; + int n_scripts, i; + + language = pango_language_get_default (); + scripts = pango_language_get_scripts (language, &n_scripts); + + for (i = 0; i < n_scripts; i++) + { + hb_script_t script; + hb_direction_t text_dir; + + script = hb_glib_script_to_script ((GUnicodeScript) scripts[i]); + text_dir = hb_script_get_horizontal_direction (script); + + if (text_dir == HB_DIRECTION_LTR) + dir = CLUTTER_TEXT_DIRECTION_LTR; + else if (text_dir == HB_DIRECTION_RTL) + dir = CLUTTER_TEXT_DIRECTION_RTL; + else + continue; + } + } + + CLUTTER_NOTE (MISC, "Text direction: %s", + dir == CLUTTER_TEXT_DIRECTION_RTL ? "rtl" : "ltr"); + + return dir; +} + +static gboolean +clutter_context_init_real (ClutterContext *context, + ClutterContextFlags flags, + GError **error) +{ + ClutterContextPrivate *priv = clutter_context_get_instance_private (context); + + /* If we are displaying the regions that would get redrawn with clipped + * redraws enabled we actually have to disable the clipped redrawing + * because otherwise we end up with nasty trails of rectangles everywhere. + */ + if (clutter_paint_debug_flags & CLUTTER_DEBUG_REDRAWS) + clutter_paint_debug_flags |= CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS; + + /* The same is true when drawing the outlines of paint volumes... */ + if (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_VOLUMES) + { + clutter_paint_debug_flags |= + CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS | CLUTTER_DEBUG_DISABLE_CULLING; + } + + if (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_DAMAGE_REGION) + g_message ("Enabling damaged region"); + + if (!_clutter_backend_create_context (context->backend, error)) + return FALSE; + + priv->text_direction = clutter_get_text_direction (); + + context->is_initialized = TRUE; + + /* Initialize a11y */ + if (!(flags & CLUTTER_CONTEXT_FLAG_NO_A11Y)) + cally_accessibility_init (); + + /* Initialize types required for paint nodes */ + clutter_paint_node_init_types (context->backend); + + return TRUE; +} + +static void +init_clutter_debug (ClutterContext *context) +{ + const char *env_string; + +#ifdef CLUTTER_ENABLE_DEBUG + env_string = g_getenv ("CLUTTER_DEBUG"); + if (env_string != NULL) + { + clutter_debug_flags = + g_parse_debug_string (env_string, + clutter_debug_keys, + G_N_ELEMENTS (clutter_debug_keys)); + env_string = NULL; + } +#endif /* CLUTTER_ENABLE_DEBUG */ + + env_string = g_getenv ("CLUTTER_PICK"); + if (env_string != NULL) + { + clutter_pick_debug_flags = + g_parse_debug_string (env_string, + clutter_pick_debug_keys, + G_N_ELEMENTS (clutter_pick_debug_keys)); + env_string = NULL; + } + + env_string = g_getenv ("CLUTTER_PAINT"); + if (env_string != NULL) + { + clutter_paint_debug_flags = + g_parse_debug_string (env_string, + clutter_paint_debug_keys, + G_N_ELEMENTS (clutter_paint_debug_keys)); + env_string = NULL; + } + + env_string = g_getenv ("CLUTTER_SHOW_FPS"); + if (env_string) + clutter_show_fps = TRUE; + + env_string = g_getenv ("CLUTTER_DISABLE_MIPMAPPED_TEXT"); + if (env_string) + clutter_disable_mipmap_text = TRUE; +} + +ClutterContext * +clutter_context_new (ClutterContextFlags flags, + ClutterBackendConstructor backend_constructor, + gpointer user_data, + GError **error) +{ + ClutterContext *context; + + context = g_object_new (CLUTTER_TYPE_CONTEXT, NULL); + + init_clutter_debug (context); + context->show_fps = clutter_show_fps; + context->is_initialized = FALSE; + + context->backend = backend_constructor (user_data); + context->settings = clutter_settings_get_default (); + _clutter_settings_set_backend (context->settings, + context->backend); + + context->events_queue = + g_async_queue_new_full ((GDestroyNotify) clutter_event_free); + context->last_repaint_id = 1; + + if (!clutter_context_init_real (context, flags, error)) + return NULL; + + return context; +} + +void +clutter_context_destroy (ClutterContext *context) +{ + g_object_run_dispose (G_OBJECT (context)); + g_object_unref (context); +} + +ClutterBackend * +clutter_context_get_backend (ClutterContext *context) +{ + return context->backend; +} + +CoglPangoFontMap * +clutter_context_get_pango_fontmap (ClutterContext *context) +{ + CoglPangoFontMap *font_map; + gdouble resolution; + gboolean use_mipmapping; + + if (G_LIKELY (context->font_map != NULL)) + return context->font_map; + + font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new ()); + + resolution = clutter_backend_get_resolution (context->backend); + cogl_pango_font_map_set_resolution (font_map, resolution); + + use_mipmapping = !clutter_disable_mipmap_text; + cogl_pango_font_map_set_use_mipmapping (font_map, use_mipmapping); + + context->font_map = font_map; + + return context->font_map; +} + +ClutterTextDirection +clutter_context_get_text_direction (ClutterContext *context) +{ + ClutterContextPrivate *priv = clutter_context_get_instance_private (context); + + return priv->text_direction; +} diff --git a/clutter/clutter/clutter-context.h b/clutter/clutter/clutter-context.h new file mode 100644 index 000000000..8bc2aa73a --- /dev/null +++ b/clutter/clutter/clutter-context.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2006 OpenedHand + * Copyright (C) 2023 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + */ + +#pragma once + +#include "clutter-backend.h" +#include "clutter-stage-manager.h" +#include "clutter-settings.h" +#include "cogl-pango/cogl-pango.h" + +typedef enum _ClutterContextFlags +{ + CLUTTER_CONTEXT_FLAG_NONE = 0, + CLUTTER_CONTEXT_FLAG_NO_A11Y = 1 << 0, +} ClutterContextFlags; + +typedef ClutterBackend * (* ClutterBackendConstructor) (gpointer user_data); + +#define CLUTTER_TYPE_CONTEXT (clutter_context_get_type ()) +CLUTTER_EXPORT +G_DECLARE_FINAL_TYPE (ClutterContext, clutter_context, + CLUTTER, CONTEXT, GObject) + +/** + * clutter_context_new: (skip) + */ +ClutterContext * clutter_context_new (ClutterContextFlags flags, + ClutterBackendConstructor backend_constructor, + gpointer user_data, + GError **error); + +/** + * clutter_context_destroy: (skip) + */ +CLUTTER_EXPORT +void clutter_context_destroy (ClutterContext *context); + +/** + * clutter_context_get_backend: + * + * Returns: (transfer none): The %ClutterBackend + */ +CLUTTER_EXPORT +ClutterBackend * clutter_context_get_backend (ClutterContext *context); + +/** + * clutter_context_get_pango_fontmap: (skip) + */ +CoglPangoFontMap * clutter_context_get_pango_fontmap (ClutterContext *context); + +ClutterTextDirection clutter_context_get_text_direction (ClutterContext *context); diff --git a/clutter/clutter/clutter-event.c b/clutter/clutter/clutter-event.c index c6228715d..0af529c78 100644 --- a/clutter/clutter/clutter-event.c +++ b/clutter/clutter/clutter-event.c @@ -26,6 +26,7 @@ #include "config.h" #include "clutter/clutter-backend-private.h" +#include "clutter/clutter-context-private.h" #include "clutter/clutter-debug.h" #include "clutter/clutter-event-private.h" #include "clutter/clutter-keysyms.h" diff --git a/clutter/clutter/clutter-input-pointer-a11y.c b/clutter/clutter/clutter-input-pointer-a11y.c index f2098bd61..d5a27e272 100644 --- a/clutter/clutter/clutter-input-pointer-a11y.c +++ b/clutter/clutter/clutter-input-pointer-a11y.c @@ -24,6 +24,7 @@ #include "config.h" #include "clutter/clutter-backend-private.h" +#include "clutter/clutter-context-private.h" #include "clutter/clutter-enum-types.h" #include "clutter/clutter-input-device.h" #include "clutter/clutter-input-device-private.h" diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c index 94898719d..4fe341bef 100644 --- a/clutter/clutter/clutter-main.c +++ b/clutter/clutter/clutter-main.c @@ -51,10 +51,10 @@ #include #include -#include #include "clutter/clutter-actor-private.h" #include "clutter/clutter-backend-private.h" +#include "clutter/clutter-context-private.h" #include "clutter/clutter-debug.h" #include "clutter/clutter-event-private.h" #include "clutter/clutter-input-device-private.h" @@ -62,7 +62,6 @@ #include "clutter/clutter-graphene.h" #include "clutter/clutter-main.h" #include "clutter/clutter-mutter.h" -#include "clutter/clutter-paint-node-private.h" #include "clutter/clutter-private.h" #include "clutter/clutter-settings-private.h" #include "clutter/clutter-stage.h" @@ -80,12 +79,8 @@ static ClutterContext *ClutterCntx = NULL; /* command line options */ static gboolean clutter_is_initialized = FALSE; -static gboolean clutter_show_fps = FALSE; -static gboolean clutter_disable_mipmap_text = FALSE; static gboolean clutter_enable_accessibility = TRUE; -static ClutterTextDirection clutter_text_direction = CLUTTER_TEXT_DIRECTION_LTR; - /* debug flags */ guint clutter_debug_flags = 0; guint clutter_paint_debug_flags = 0; @@ -96,48 +91,6 @@ guint clutter_pick_debug_flags = 0; */ int clutter_max_render_time_constant_us = 1000; -#ifdef CLUTTER_ENABLE_DEBUG -static const GDebugKey clutter_debug_keys[] = { - { "misc", CLUTTER_DEBUG_MISC }, - { "actor", CLUTTER_DEBUG_ACTOR }, - { "texture", CLUTTER_DEBUG_TEXTURE }, - { "event", CLUTTER_DEBUG_EVENT }, - { "paint", CLUTTER_DEBUG_PAINT }, - { "pick", CLUTTER_DEBUG_PICK }, - { "pango", CLUTTER_DEBUG_PANGO }, - { "backend", CLUTTER_DEBUG_BACKEND }, - { "scheduler", CLUTTER_DEBUG_SCHEDULER }, - { "script", CLUTTER_DEBUG_SCRIPT }, - { "shader", CLUTTER_DEBUG_SHADER }, - { "animation", CLUTTER_DEBUG_ANIMATION }, - { "layout", CLUTTER_DEBUG_LAYOUT }, - { "clipping", CLUTTER_DEBUG_CLIPPING }, - { "oob-transforms", CLUTTER_DEBUG_OOB_TRANSFORMS }, - { "frame-timings", CLUTTER_DEBUG_FRAME_TIMINGS }, - { "detailed-trace", CLUTTER_DEBUG_DETAILED_TRACE }, - { "grabs", CLUTTER_DEBUG_GRABS }, - { "frame-clock", CLUTTER_DEBUG_FRAME_CLOCK }, -}; -#endif /* CLUTTER_ENABLE_DEBUG */ - -static const GDebugKey clutter_pick_debug_keys[] = { - { "nop-picking", CLUTTER_DEBUG_NOP_PICKING }, -}; - -static const GDebugKey clutter_paint_debug_keys[] = { - { "disable-swap-events", CLUTTER_DEBUG_DISABLE_SWAP_EVENTS }, - { "disable-clipped-redraws", CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS }, - { "redraws", CLUTTER_DEBUG_REDRAWS }, - { "paint-volumes", CLUTTER_DEBUG_PAINT_VOLUMES }, - { "disable-culling", CLUTTER_DEBUG_DISABLE_CULLING }, - { "disable-offscreen-redirect", CLUTTER_DEBUG_DISABLE_OFFSCREEN_REDIRECT }, - { "continuous-redraw", CLUTTER_DEBUG_CONTINUOUS_REDRAW }, - { "paint-deform-tiles", CLUTTER_DEBUG_PAINT_DEFORM_TILES }, - { "damage-region", CLUTTER_DEBUG_PAINT_DAMAGE_REGION }, - { "disable-dynamic-max-render-time", CLUTTER_DEBUG_DISABLE_DYNAMIC_MAX_RENDER_TIME }, - { "max-render-time", CLUTTER_DEBUG_PAINT_MAX_RENDER_TIME }, -}; - gboolean _clutter_context_get_show_fps (void) { @@ -182,77 +135,6 @@ clutter_disable_accessibility (void) clutter_enable_accessibility = FALSE; } -static CoglPangoFontMap * -clutter_context_get_pango_fontmap (void) -{ - ClutterContext *self; - CoglPangoFontMap *font_map; - gdouble resolution; - gboolean use_mipmapping; - - self = _clutter_context_get_default (); - if (G_LIKELY (self->font_map != NULL)) - return self->font_map; - - font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new ()); - - resolution = clutter_backend_get_resolution (self->backend); - cogl_pango_font_map_set_resolution (font_map, resolution); - - use_mipmapping = !clutter_disable_mipmap_text; - cogl_pango_font_map_set_use_mipmapping (font_map, use_mipmapping); - - self->font_map = font_map; - - return self->font_map; -} - -ClutterTextDirection -clutter_get_text_direction (void) -{ - ClutterTextDirection dir = CLUTTER_TEXT_DIRECTION_LTR; - const gchar *direction; - - direction = g_getenv ("CLUTTER_TEXT_DIRECTION"); - if (direction && *direction != '\0') - { - if (strcmp (direction, "rtl") == 0) - dir = CLUTTER_TEXT_DIRECTION_RTL; - else if (strcmp (direction, "ltr") == 0) - dir = CLUTTER_TEXT_DIRECTION_LTR; - } - else - { - PangoLanguage *language; - const PangoScript *scripts; - int n_scripts, i; - - language = pango_language_get_default (); - scripts = pango_language_get_scripts (language, &n_scripts); - - for (i = 0; i < n_scripts; i++) - { - hb_script_t script; - hb_direction_t text_dir; - - script = hb_glib_script_to_script ((GUnicodeScript) scripts[i]); - text_dir = hb_script_get_horizontal_direction (script); - - if (text_dir == HB_DIRECTION_LTR) - dir = CLUTTER_TEXT_DIRECTION_LTR; - else if (text_dir == HB_DIRECTION_RTL) - dir = CLUTTER_TEXT_DIRECTION_RTL; - else - continue; - } - } - - CLUTTER_NOTE (MISC, "Text direction: %s", - dir == CLUTTER_TEXT_DIRECTION_RTL ? "rtl" : "ltr"); - - return dir; -} - gboolean _clutter_threads_dispatch (gpointer data) { @@ -494,98 +376,12 @@ _clutter_context_get_default (void) return ClutterCntx; } -static gboolean -clutter_init_real (ClutterContext *clutter_context, - GError **error) -{ - /* If we are displaying the regions that would get redrawn with clipped - * redraws enabled we actually have to disable the clipped redrawing - * because otherwise we end up with nasty trails of rectangles everywhere. - */ - if (clutter_paint_debug_flags & CLUTTER_DEBUG_REDRAWS) - clutter_paint_debug_flags |= CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS; - - /* The same is true when drawing the outlines of paint volumes... */ - if (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_VOLUMES) - { - clutter_paint_debug_flags |= - CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS | CLUTTER_DEBUG_DISABLE_CULLING; - } - - if (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_DAMAGE_REGION) - g_message ("Enabling damaged region"); - - if (!_clutter_backend_create_context (clutter_context->backend, error)) - return FALSE; - - clutter_text_direction = clutter_get_text_direction (); - - clutter_is_initialized = TRUE; - clutter_context->is_initialized = TRUE; - - /* Initialize a11y */ - if (clutter_enable_accessibility) - cally_accessibility_init (); - - /* Initialize types required for paint nodes */ - clutter_paint_node_init_types (clutter_context->backend); - - return TRUE; -} - -static void -init_clutter_debug (ClutterContext *clutter_context) -{ - const char *env_string; - -#ifdef CLUTTER_ENABLE_DEBUG - env_string = g_getenv ("CLUTTER_DEBUG"); - if (env_string != NULL) - { - clutter_debug_flags = - g_parse_debug_string (env_string, - clutter_debug_keys, - G_N_ELEMENTS (clutter_debug_keys)); - env_string = NULL; - } -#endif /* CLUTTER_ENABLE_DEBUG */ - - env_string = g_getenv ("CLUTTER_PICK"); - if (env_string != NULL) - { - clutter_pick_debug_flags = - g_parse_debug_string (env_string, - clutter_pick_debug_keys, - G_N_ELEMENTS (clutter_pick_debug_keys)); - env_string = NULL; - } - - env_string = g_getenv ("CLUTTER_PAINT"); - if (env_string != NULL) - { - clutter_paint_debug_flags = - g_parse_debug_string (env_string, - clutter_paint_debug_keys, - G_N_ELEMENTS (clutter_paint_debug_keys)); - env_string = NULL; - } - - env_string = g_getenv ("CLUTTER_SHOW_FPS"); - if (env_string) - clutter_show_fps = TRUE; - - env_string = g_getenv ("CLUTTER_DISABLE_MIPMAPPED_TEXT"); - if (env_string) - clutter_disable_mipmap_text = TRUE; -} - ClutterContext * -clutter_context_new (ClutterBackendConstructor backend_constructor, - gpointer user_data, - GError **error) +clutter_create_context (ClutterContextFlags flags, + ClutterBackendConstructor backend_constructor, + gpointer user_data, + GError **error) { - ClutterContext *clutter_context; - if (ClutterCntx) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, @@ -593,46 +389,15 @@ clutter_context_new (ClutterBackendConstructor backend_constructor, return NULL; } - clutter_graphene_init (); + ClutterCntx = clutter_context_new (flags, + backend_constructor, user_data, + error); + if (!ClutterCntx) + return NULL; - clutter_context = g_new0 (ClutterContext, 1); - init_clutter_debug (clutter_context); - clutter_context->show_fps = clutter_show_fps; - clutter_context->is_initialized = FALSE; - - clutter_context->backend = backend_constructor (user_data); - clutter_context->settings = clutter_settings_get_default (); - _clutter_settings_set_backend (clutter_context->settings, - clutter_context->backend); - - clutter_context->events_queue = - g_async_queue_new_full ((GDestroyNotify) clutter_event_free); - clutter_context->last_repaint_id = 1; - - if (!clutter_init_real (clutter_context, error)) - { - g_free (clutter_context); - return NULL; - } - - ClutterCntx = clutter_context; - - return clutter_context; -} - -void -clutter_context_free (ClutterContext *clutter_context) -{ - g_clear_pointer (&clutter_context->events_queue, g_async_queue_unref); - g_clear_pointer (&clutter_context->backend, clutter_backend_destroy); - ClutterCntx = NULL; - g_free (clutter_context); -} - -ClutterBackend * -clutter_context_get_backend (ClutterContext *clutter_context) -{ - return clutter_context->backend; + clutter_is_initialized = TRUE; + g_object_add_weak_pointer (G_OBJECT (ClutterCntx), (gpointer *) &ClutterCntx); + return ClutterCntx; } gboolean @@ -927,7 +692,7 @@ clutter_stage_process_event (ClutterStage *stage, PangoFontMap * clutter_get_font_map (void) { - return PANGO_FONT_MAP (clutter_context_get_pango_fontmap ()); + return PANGO_FONT_MAP (clutter_context_get_pango_fontmap (ClutterCntx)); } typedef struct _ClutterRepaintFunction @@ -1165,7 +930,7 @@ _clutter_run_repaint_functions (ClutterRepaintFlags flags) ClutterTextDirection clutter_get_default_text_direction (void) { - return clutter_text_direction; + return clutter_context_get_text_direction (ClutterCntx); } /*< private > diff --git a/clutter/clutter/clutter-mutter.h b/clutter/clutter/clutter-mutter.h index 8afe0f71e..4d9c5317c 100644 --- a/clutter/clutter/clutter-mutter.h +++ b/clutter/clutter/clutter-mutter.h @@ -44,27 +44,14 @@ * various matrix calculations. */ #define CLUTTER_COORDINATE_EPSILON (1.0 / 256.0) -typedef ClutterBackend * (* ClutterBackendConstructor) (gpointer user_data); - /** - * clutter_context_new: (skip) + * clutter_create_context: (skip) */ CLUTTER_EXPORT -ClutterContext * clutter_context_new (ClutterBackendConstructor backend_constructor, - gpointer user_data, - GError **error); - -/** - * clutter_context_free: (skip) - */ -CLUTTER_EXPORT -void clutter_context_free (ClutterContext *clutter_context); - -/** - * clutter_context_get_backend: (skip) - */ -CLUTTER_EXPORT -ClutterBackend * clutter_context_get_backend (ClutterContext *clutter_context); +ClutterContext * clutter_create_context (ClutterContextFlags flags, + ClutterBackendConstructor backend_constructor, + gpointer user_data, + GError **error); CLUTTER_EXPORT GList * clutter_stage_peek_stage_views (ClutterStage *stage); diff --git a/clutter/clutter/clutter-private.h b/clutter/clutter/clutter-private.h index 6afbf5eec..de6d54a95 100644 --- a/clutter/clutter/clutter-private.h +++ b/clutter/clutter/clutter-private.h @@ -31,6 +31,7 @@ #include "cogl-pango/cogl-pango.h" #include "clutter/clutter-backend.h" +#include "clutter/clutter-context.h" #include "clutter/clutter-effect.h" #include "clutter/clutter-event.h" #include "clutter/clutter-layout-manager.h" @@ -107,45 +108,6 @@ typedef enum CLUTTER_IN_MAP_UNMAP = 1 << 8, } ClutterPrivateFlags; -/* - * ClutterContext: - * - * The shared state of Clutter - */ -struct _ClutterContext -{ - /* the main windowing system backend */ - ClutterBackend *backend; - - /* the object holding all the stage instances */ - ClutterStageManager *stage_manager; - - /* the main event queue */ - GAsyncQueue *events_queue; - - /* the event filters added via clutter_event_add_filter. these are - * ordered from least recently added to most recently added */ - GList *event_filters; - - CoglPangoFontMap *font_map; /* Global font map */ - - /* stack of #ClutterEvent */ - GSList *current_event; - - /* list of repaint functions installed through - * clutter_threads_add_repaint_func() - */ - GList *repaint_funcs; - guint last_repaint_id; - - /* main settings singleton */ - ClutterSettings *settings; - - /* boolean flags */ - guint is_initialized : 1; - guint show_fps : 1; -}; - /* shared between clutter-main.c and clutter-frame-source.c */ typedef struct { diff --git a/clutter/clutter/clutter-settings.c b/clutter/clutter/clutter-settings.c index ec0c1545f..3601cb480 100644 --- a/clutter/clutter/clutter-settings.c +++ b/clutter/clutter/clutter-settings.c @@ -25,6 +25,7 @@ #include #endif /* HAVE_PANGO_FT2 */ +#include "clutter/clutter-context-private.h" #include "clutter/clutter-debug.h" #include "clutter/clutter-settings-private.h" #include "clutter/clutter-stage-private.h" diff --git a/clutter/clutter/clutter-stage-manager.c b/clutter/clutter/clutter-stage-manager.c index bdb162929..4aaa7acfe 100644 --- a/clutter/clutter/clutter-stage-manager.c +++ b/clutter/clutter/clutter-stage-manager.c @@ -39,8 +39,9 @@ #include "clutter/clutter-stage-manager-private.h" -#include "clutter/clutter-marshal.h" +#include "clutter/clutter-context-private.h" #include "clutter/clutter-debug.h" +#include "clutter/clutter-marshal.h" #include "clutter/clutter-private.h" enum diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c index 33d387f2e..cb1890369 100644 --- a/clutter/clutter/clutter-stage.c +++ b/clutter/clutter/clutter-stage.c @@ -44,6 +44,7 @@ #include "clutter/clutter-action-private.h" #include "clutter/clutter-actor-private.h" #include "clutter/clutter-backend-private.h" +#include "clutter/clutter-context-private.h" #include "clutter/clutter-debug.h" #include "clutter/clutter-enum-types.h" #include "clutter/clutter-event-private.h" diff --git a/clutter/clutter/meson.build b/clutter/clutter/meson.build index cdb4debab..c87e7163d 100644 --- a/clutter/clutter/meson.build +++ b/clutter/clutter/meson.build @@ -25,6 +25,7 @@ clutter_headers = [ 'clutter-colorize-effect.h', 'clutter-constraint.h', 'clutter-content.h', + 'clutter-context.h', 'clutter-deform-effect.h', 'clutter-desaturate-effect.h', 'clutter-effect.h', @@ -111,6 +112,7 @@ clutter_sources = [ 'clutter-colorize-effect.c', 'clutter-constraint.c', 'clutter-content.c', + 'clutter-context.c', 'clutter-damage-history.c', 'clutter-deform-effect.c', 'clutter-desaturate-effect.c', @@ -183,6 +185,7 @@ clutter_private_headers = [ 'clutter-blur-private.h', 'clutter-constraint-private.h', 'clutter-content-private.h', + 'clutter-context-private.h', 'clutter-damage-history.h', 'clutter-debug.h', 'clutter-easing.h', diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index f925a2f69..8982d2cd8 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -251,7 +251,7 @@ meta_backend_dispose (GObject *object) g_clear_pointer (&priv->stage, clutter_actor_destroy); g_clear_pointer (&priv->idle_manager, meta_idle_manager_free); g_clear_object (&priv->renderer); - g_clear_pointer (&priv->clutter_context, clutter_context_free); + g_clear_pointer (&priv->clutter_context, clutter_context_destroy); g_clear_list (&priv->gpus, g_object_unref); G_OBJECT_CLASS (meta_backend_parent_class)->dispose (object); @@ -1181,9 +1181,10 @@ init_clutter (MetaBackend *backend, MetaBackendSource *backend_source; GSource *source; - priv->clutter_context = clutter_context_new (meta_clutter_backend_constructor, - backend, - error); + priv->clutter_context = clutter_create_context (CLUTTER_CONTEXT_FLAG_NONE, + meta_clutter_backend_constructor, + backend, + error); if (!priv->clutter_context) return FALSE;