1
0
Fork 0

clutter/color-manager: Add a method to get the default color state

This avoids re-creating new color states objects to the default state.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3897>
This commit is contained in:
Sebastian Wick 2024-07-18 13:48:00 +02:00 committed by Marge Bot
parent b1370a483e
commit 2693cac83a
5 changed files with 41 additions and 16 deletions

View file

@ -17845,13 +17845,13 @@ clutter_actor_get_content_repeat (ClutterActor *self)
}
static ClutterColorState *
create_default_color_state (ClutterActor *self)
get_default_color_state (ClutterActor *self)
{
ClutterColorState *color_state;
color_state = clutter_color_state_new (clutter_actor_get_context (self),
CLUTTER_COLORSPACE_DEFAULT,
CLUTTER_TRANSFER_FUNCTION_DEFAULT);
ClutterContext *context = clutter_actor_get_context (self);
ClutterColorManager *color_manager =
clutter_context_get_color_manager (context);
ClutterColorState *color_state =
clutter_color_manager_get_default_color_state (color_manager);
return color_state;
}
@ -17875,11 +17875,11 @@ clutter_actor_set_color_state_internal (ClutterActor *self,
void
clutter_actor_unset_color_state (ClutterActor *self)
{
g_autoptr (ClutterColorState) default_color_state = NULL;
ClutterColorState *default_color_state;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
default_color_state = create_default_color_state (self);
default_color_state = get_default_color_state (self);
clutter_actor_set_color_state_internal (self, default_color_state);
}

View file

@ -46,6 +46,7 @@ struct _ClutterColorManager
GHashTable *snippet_cache;
unsigned int id_counter;
ClutterColorState *default_color_state;
};
G_DEFINE_FINAL_TYPE (ClutterColorManager, clutter_color_manager, G_TYPE_OBJECT)
@ -140,6 +141,20 @@ clutter_color_manager_get_next_id (ClutterColorManager *color_manager)
return ++color_manager->id_counter;
}
ClutterColorState *
clutter_color_manager_get_default_color_state (ClutterColorManager *color_manager)
{
if (!color_manager->default_color_state)
{
color_manager->default_color_state =
clutter_color_state_new (color_manager->context,
CLUTTER_COLORSPACE_DEFAULT,
CLUTTER_TRANSFER_FUNCTION_DEFAULT);
}
return color_manager->default_color_state;
}
CoglSnippet *
clutter_color_manager_lookup_snippet (ClutterColorManager *color_manager,
const ClutterColorTransformKey *key)

View file

@ -32,3 +32,9 @@
CLUTTER_EXPORT
G_DECLARE_FINAL_TYPE (ClutterColorManager, clutter_color_manager,
CLUTTER, COLOR_MANAGER, GObject)
/**
* clutter_color_manager_get_default_color_state: (skip)
*/
CLUTTER_EXPORT
ClutterColorState * clutter_color_manager_get_default_color_state (ClutterColorManager *color_manager);

View file

@ -383,13 +383,15 @@ ensure_xcursor_color_state (MetaCursorTracker *cursor_tracker)
meta_cursor_tracker_get_backend (cursor_tracker);
ClutterContext *clutter_context =
meta_backend_get_clutter_context (backend);
ClutterColorManager *color_manager =
clutter_context_get_color_manager (clutter_context);
color_state = clutter_color_manager_get_default_color_state (color_manager);
color_state = clutter_color_state_new (clutter_context,
CLUTTER_COLORSPACE_DEFAULT,
CLUTTER_TRANSFER_FUNCTION_DEFAULT);
g_object_set_qdata_full (G_OBJECT (cursor_tracker),
GPOINTER_TO_INT (quark_once.retval),
color_state, g_object_unref);
g_object_ref (color_state),
g_object_unref);
}
return color_state;

View file

@ -82,13 +82,15 @@ ensure_default_color_state (MetaCursorTracker *cursor_tracker)
meta_cursor_tracker_get_backend (cursor_tracker);
ClutterContext *clutter_context =
meta_backend_get_clutter_context (backend);
ClutterColorManager *color_manager =
clutter_context_get_color_manager (clutter_context);
color_state = clutter_color_manager_get_default_color_state (color_manager);
color_state = clutter_color_state_new (clutter_context,
CLUTTER_COLORSPACE_DEFAULT,
CLUTTER_TRANSFER_FUNCTION_DEFAULT);
g_object_set_qdata_full (G_OBJECT (cursor_tracker),
GPOINTER_TO_INT (quark_once.retval),
color_state, g_object_unref);
g_object_ref (color_state),
g_object_unref);
}
return color_state;