From cd2bf776b19502dd4b54a72ba130e9e6a1aed5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 11 Jul 2024 22:44:08 +0200 Subject: [PATCH] clutter: Add color manager type This type is intended to carry color related state that is "global", without having to add more and more things to ClutterContext. Part-of: --- clutter/clutter/clutter-color-manager.c | 115 ++++++++++++++++++++++++ clutter/clutter/clutter-color-manager.h | 34 +++++++ clutter/clutter/clutter-context.c | 6 ++ clutter/clutter/clutter-types.h | 1 + clutter/clutter/clutter.h | 1 + clutter/clutter/meson.build | 2 + 6 files changed, 159 insertions(+) create mode 100644 clutter/clutter/clutter-color-manager.c create mode 100644 clutter/clutter/clutter-color-manager.h diff --git a/clutter/clutter/clutter-color-manager.c b/clutter/clutter/clutter-color-manager.c new file mode 100644 index 000000000..77be36da2 --- /dev/null +++ b/clutter/clutter/clutter-color-manager.c @@ -0,0 +1,115 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2024 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 . + * + */ + +#include "config.h" + +#include "clutter/clutter-color-manager.h" + +#include "clutter/clutter-context.h" + +enum +{ + PROP_0, + + PROP_CONTEXT, + + N_PROPS +}; + +static GParamSpec *obj_props[N_PROPS]; + +struct _ClutterColorManager +{ + GObject parent; + + ClutterContext *context; +}; + +G_DEFINE_FINAL_TYPE (ClutterColorManager, clutter_color_manager, G_TYPE_OBJECT) + +static void +clutter_color_manager_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + ClutterColorManager *color_manager = CLUTTER_COLOR_MANAGER (object); + + switch (prop_id) + { + case PROP_CONTEXT: + color_manager->context = g_value_get_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +clutter_color_manager_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + ClutterColorManager *color_manager = CLUTTER_COLOR_MANAGER (object); + + switch (prop_id) + { + case PROP_CONTEXT: + g_value_set_object (value, color_manager->context); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +clutter_color_manager_class_init (ClutterColorManagerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->set_property = clutter_color_manager_set_property; + object_class->get_property = clutter_color_manager_get_property; + + /** + * ClutterColorManager:context: + * + * The associated ClutterContext. + */ + obj_props[PROP_CONTEXT] = + g_param_spec_object ("context", NULL, NULL, + CLUTTER_TYPE_CONTEXT, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS | + G_PARAM_CONSTRUCT_ONLY); + + g_object_class_install_properties (object_class, N_PROPS, obj_props); +} + +static void +clutter_color_manager_init (ClutterColorManager *color_manager) +{ +} diff --git a/clutter/clutter/clutter-color-manager.h b/clutter/clutter/clutter-color-manager.h new file mode 100644 index 000000000..9ad47bf19 --- /dev/null +++ b/clutter/clutter/clutter-color-manager.h @@ -0,0 +1,34 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2024 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 + +#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) +#error "Only can be included directly." +#endif + +#include "clutter/clutter-types.h" + +#define CLUTTER_TYPE_COLOR_MANAGER (clutter_color_manager_get_type ()) +CLUTTER_EXPORT +G_DECLARE_FINAL_TYPE (ClutterColorManager, clutter_color_manager, + CLUTTER, COLOR_MANAGER, GObject) diff --git a/clutter/clutter/clutter-context.c b/clutter/clutter/clutter-context.c index 9a85b9aaf..0f2e46505 100644 --- a/clutter/clutter/clutter-context.c +++ b/clutter/clutter/clutter-context.c @@ -24,6 +24,7 @@ #include "cally/cally.h" #include "clutter/clutter-backend-private.h" +#include "clutter/clutter-color-manager.h" #include "clutter/clutter-debug.h" #include "clutter/clutter-main.h" #include "clutter/clutter-private.h" @@ -80,6 +81,7 @@ typedef struct _ClutterContextPrivate { ClutterTextDirection text_direction; + ClutterColorManager *color_manager; ClutterPipelineCache *pipeline_cache; } ClutterContextPrivate; @@ -92,6 +94,7 @@ clutter_context_dispose (GObject *object) ClutterContextPrivate *priv = clutter_context_get_instance_private (context); g_clear_object (&priv->pipeline_cache); + g_clear_object (&priv->color_manager); g_clear_pointer (&context->events_queue, g_async_queue_unref); g_clear_pointer (&context->backend, clutter_backend_destroy); @@ -274,6 +277,9 @@ clutter_context_new (ClutterContextFlags flags, g_async_queue_new_full ((GDestroyNotify) clutter_event_free); context->last_repaint_id = 1; + priv->color_manager = g_object_new (CLUTTER_TYPE_COLOR_MANAGER, + "context", context, + NULL); priv->pipeline_cache = g_object_new (CLUTTER_TYPE_PIPELINE_CACHE, NULL); if (!clutter_context_init_real (context, flags, error)) diff --git a/clutter/clutter/clutter-types.h b/clutter/clutter/clutter-types.h index 7408d0d30..539e1442a 100644 --- a/clutter/clutter/clutter-types.h +++ b/clutter/clutter/clutter-types.h @@ -48,6 +48,7 @@ typedef struct _ClutterFrame ClutterFrame; typedef struct _ClutterFrameInfo ClutterFrameInfo; typedef struct _ClutterLayoutMeta ClutterLayoutMeta; typedef struct _ClutterActorMeta ClutterActorMeta; +typedef struct _ClutterColorManager ClutterColorManager; typedef struct _ClutterLayoutManager ClutterLayoutManager; typedef struct _ClutterActorIter ClutterActorIter; typedef struct _ClutterPaintContext ClutterPaintContext; diff --git a/clutter/clutter/clutter.h b/clutter/clutter/clutter.h index 109358540..010c1f4b7 100644 --- a/clutter/clutter/clutter.h +++ b/clutter/clutter/clutter.h @@ -43,6 +43,7 @@ #include "clutter/clutter-brightness-contrast-effect.h" #include "clutter/clutter-click-action.h" #include "clutter/clutter-clone.h" +#include "clutter/clutter-color-manager.h" #include "clutter/clutter-color-state.h" #include "clutter/clutter-colorize-effect.h" #include "clutter/clutter-constraint.h" diff --git a/clutter/clutter/meson.build b/clutter/clutter/meson.build index 22af0b2b1..0875c6973 100644 --- a/clutter/clutter/meson.build +++ b/clutter/clutter/meson.build @@ -17,6 +17,7 @@ clutter_headers = [ 'clutter-brightness-contrast-effect.h', 'clutter-click-action.h', 'clutter-clone.h', + 'clutter-color-manager.h', 'clutter-color-state.h', 'clutter-colorize-effect.h', 'clutter-constraint.h', @@ -101,6 +102,7 @@ clutter_sources = [ 'clutter-brightness-contrast-effect.c', 'clutter-click-action.c', 'clutter-clone.c', + 'clutter-color-manager.c', 'clutter-color-state.c', 'clutter-colorize-effect.c', 'clutter-constraint.c',