clutter: Attach color state information to actors

ClutterColorState, that is a GObject. each ClutterActor would own
such an object, and it'd be set via a GObject property.
It would have an API to get the colorspace, whether the actor
content is in pq or not, and things like that.
if it is NULL, it will default to color state with sRGB colorspace.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2443>
This commit is contained in:
Naveen Kumar 2022-05-20 15:47:16 +00:00 committed by Marge Bot
parent c18ce8569e
commit 12c02b3f1a
8 changed files with 347 additions and 0 deletions

View File

@ -616,6 +616,7 @@
#include "clutter-action-private.h"
#include "clutter-actor-meta-private.h"
#include "clutter-animatable.h"
#include "clutter-color-state.h"
#include "clutter-color-static.h"
#include "clutter-color.h"
#include "clutter-constraint-private.h"
@ -755,6 +756,10 @@ struct _ClutterActorPrivate
/* used when painting, to update the paint volume */
ClutterEffect *current_effect;
/* color state contains properties like colorspace for
* each clutter actor */
ClutterColorState *color_state;
/* This is used to store an effect which needs to be redrawn. A
redraw can be queued to start from a particular effect. This is
used by parametrised effects that can cache an image of the
@ -959,6 +964,8 @@ enum
PROP_MAGNIFICATION_FILTER,
PROP_CONTENT_REPEAT,
PROP_COLOR_STATE,
PROP_LAST
};
@ -5078,6 +5085,10 @@ clutter_actor_set_property (GObject *object,
clutter_actor_set_content_repeat (actor, g_value_get_flags (value));
break;
case PROP_COLOR_STATE:
clutter_actor_set_color_state (actor, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -5527,6 +5538,10 @@ clutter_actor_get_property (GObject *object,
g_value_set_flags (value, priv->content_repeat);
break;
case PROP_COLOR_STATE:
g_value_set_object (value, priv->color_state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -5574,6 +5589,7 @@ clutter_actor_dispose (GObject *object)
g_clear_object (&priv->pango_context);
g_clear_object (&priv->actions);
g_clear_object (&priv->color_state);
g_clear_object (&priv->constraints);
g_clear_object (&priv->effects);
g_clear_object (&priv->flatten_effect);
@ -7334,6 +7350,20 @@ clutter_actor_class_init (ClutterActorClass *klass)
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* ClutterActor:color-state:
*
* The #ClutterColorState contains the properties like colorspace for each
* actors.
*/
obj_props[PROP_COLOR_STATE] =
g_param_spec_object ("color-state",
P_("ColorState"),
P_("ColorState of the each actors"),
CLUTTER_TYPE_COLOR_STATE,
CLUTTER_PARAM_READWRITE |
G_PARAM_CONSTRUCT);
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
/**
@ -19044,6 +19074,65 @@ clutter_actor_get_content_repeat (ClutterActor *self)
return self->priv->content_repeat;
}
static ClutterColorState *
create_srgb_color_state (ClutterActor *self)
{
ClutterColorState *color_state;
/* create default sRGB color state */
color_state = clutter_color_state_new (CLUTTER_COLORSPACE_SRGB);
return color_state;
}
/**
* clutter_actor_set_color_state:
* @self: a #ClutterActor
* @color_state: a #ClutterColorState, or defaults to sRGB if %NULL
*
* Attaches color state properties to [class@Actor]
* default color state representing sRGB.
*/
void
clutter_actor_set_color_state (ClutterActor *self,
ClutterColorState *color_state)
{
ClutterActorPrivate *priv;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
priv = self->priv;
if (!color_state)
color_state = create_srgb_color_state (self);
else
g_object_ref (color_state);
g_set_object (&priv->color_state, color_state);
g_object_unref (color_state);
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_COLOR_STATE]);
}
/**
* clutter_actor_get_color_state:
* @self: a #ClutterActor
*
* Retrieves the color_state of a [class@Actor] set by
* [method@Actor.set_color_state].
*
* Return value: (transfer full): a pointer to the #ClutterColorState
* instance, or %NULL
*/
ClutterColorState *
clutter_actor_get_color_state (ClutterActor *self)
{
g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
return self->priv->color_state;
}
void
_clutter_actor_handle_event (ClutterActor *self,
ClutterActor *root,

View File

@ -624,6 +624,13 @@ void clutter_actor_set_content_repeat
ClutterContentRepeat repeat);
CLUTTER_EXPORT
ClutterContentRepeat clutter_actor_get_content_repeat (ClutterActor *self);
CLUTTER_EXPORT
void clutter_actor_set_color_state (ClutterActor *self,
ClutterColorState *color_state);
CLUTTER_EXPORT
ClutterColorState *clutter_actor_get_color_state (ClutterActor *self);
CLUTTER_EXPORT
void clutter_actor_get_content_box (ClutterActor *self,
ClutterActorBox *box);

View File

@ -0,0 +1,182 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2022 Intel Corporation.
*
* 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 <http://www.gnu.org/licenses/>.
*
* Author:
* Naveen Kumar <naveen1.kumar@intel.com>
*/
/**
* ClutterColorState:
*
* Color state of each ClutterActor
*
* The #ClutterColorState class contains the colorspace of each color
* states (e.g. sRGB colorspace).
*
* Each [class@Actor] would own such an object.
*
* A single #ClutterColorState object can be shared by multiple [class@Actor]
* or maybe a separate color state for each [class@Actor] (depending on whether
* #ClutterColorState would be statefull or stateless).
*
* #ClutterColorState, if not set during construction, it will default to sRGB
* color state
*
* The #ClutterColorState would have API to get the colorspace, whether the
* actor content is in pq or not, and things like that
*/
#include "clutter-build-config.h"
#include "clutter-color-state.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-private.h"
enum
{
PROP_0,
PROP_COLORSPACE,
N_PROPS
};
static GParamSpec *obj_props[N_PROPS];
typedef struct _ClutterColorStatePrivate ClutterColorStatePrivate;
struct _ClutterColorState
{
GObject parent_instance;
};
struct _ClutterColorStatePrivate
{
ClutterColorspace colorspace;
};
G_DEFINE_TYPE_WITH_PRIVATE (ClutterColorState,
clutter_color_state,
G_TYPE_OBJECT)
ClutterColorspace
clutter_color_state_get_colorspace (ClutterColorState *color_state)
{
ClutterColorStatePrivate *priv;
g_return_val_if_fail (CLUTTER_IS_COLOR_STATE (color_state),
CLUTTER_COLORSPACE_UNKNOWN);
priv = clutter_color_state_get_instance_private (color_state);
return priv->colorspace;
}
static void
clutter_color_state_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ClutterColorState *color_state = CLUTTER_COLOR_STATE (object);
ClutterColorStatePrivate *priv;
priv = clutter_color_state_get_instance_private (color_state);
switch (prop_id)
{
case PROP_COLORSPACE:
priv->colorspace = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
clutter_color_state_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ClutterColorState *color_state = CLUTTER_COLOR_STATE (object);
switch (prop_id)
{
case PROP_COLORSPACE:
g_value_set_enum (value,
clutter_color_state_get_colorspace (color_state));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
clutter_color_state_class_init (ClutterColorStateClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = clutter_color_state_set_property;
gobject_class->get_property = clutter_color_state_get_property;
/**
* ClutterColorState:colorspace:
*
* Colorspace information of the each color state,
* defaults to sRGB colorspace
*/
obj_props[PROP_COLORSPACE] =
g_param_spec_enum ("colorspace",
P_("Colorspace"),
P_("Colorspace information of the color state"),
CLUTTER_TYPE_COLORSPACE,
CLUTTER_COLORSPACE_SRGB,
CLUTTER_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (gobject_class, N_PROPS, obj_props);
}
static void
clutter_color_state_init (ClutterColorState *color_state)
{
}
/**
* clutter_color_state_new:
*
* Create a new ClutterColorState object.
*
* Return value: A new ClutterColorState object.
**/
ClutterColorState*
clutter_color_state_new (ClutterColorspace colorspace)
{
return g_object_new (CLUTTER_TYPE_COLOR_STATE,
"colorspace", colorspace,
NULL);
}

View File

@ -0,0 +1,50 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2022 Intel Corporation.
*
* 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 <http://www.gnu.org/licenses/>.
*
* Author:
* Naveen Kumar <naveen1.kumar@intel.com>
*/
#ifndef CLUTTER_COLOR_STATE_H
#define CLUTTER_COLOR_STATE_H
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <clutter/clutter.h> can be included directly."
#endif
#include <clutter/clutter-types.h>
G_BEGIN_DECLS
#define CLUTTER_TYPE_COLOR_STATE (clutter_color_state_get_type ())
CLUTTER_EXPORT
G_DECLARE_FINAL_TYPE (ClutterColorState, clutter_color_state,
CLUTTER, COLOR_STATE,
GObject)
CLUTTER_EXPORT
ClutterColorState * clutter_color_state_new (ClutterColorspace colorspace);
CLUTTER_EXPORT
ClutterColorspace clutter_color_state_get_colorspace (ClutterColorState *color_state);
G_END_DECLS
#endif /* CLUTTER_COLOR_STATE_H */

View File

@ -1424,6 +1424,21 @@ typedef enum
CLUTTER_REPEAT_BOTH = CLUTTER_REPEAT_X_AXIS | CLUTTER_REPEAT_Y_AXIS
} ClutterContentRepeat;
/**
* ClutterColorspace:
* @CLUTTER_COLORSPACE_UNKNOWN: Unknown colorspace
* @CLUTTER_COLORSPACE_SRGB: Default sRGB colorspace
* @CLUTTER_COLORSPACE_BT2020: BT2020 colorspace
*
* Colorspace informations.
*/
typedef enum
{
CLUTTER_COLORSPACE_UNKNOWN,
CLUTTER_COLORSPACE_SRGB,
CLUTTER_COLORSPACE_BT2020
} ClutterColorspace;
/**
* ClutterStepMode:
* @CLUTTER_STEP_MODE_START: The change in the value of a

View File

@ -76,6 +76,7 @@ typedef struct _ClutterPathNode ClutterPathNode;
typedef struct _ClutterActorBox ClutterActorBox;
typedef struct _ClutterColor ClutterColor;
typedef struct _ClutterColorState ClutterColorState;
typedef struct _ClutterKnot ClutterKnot;
typedef struct _ClutterMargin ClutterMargin;
typedef struct _ClutterPerspective ClutterPerspective;

View File

@ -48,6 +48,7 @@
#include "clutter-click-action.h"
#include "clutter-clone.h"
#include "clutter-color.h"
#include "clutter-color-state.h"
#include "clutter-color-static.h"
#include "clutter-colorize-effect.h"
#include "clutter-constraint.h"

View File

@ -21,6 +21,7 @@ clutter_headers = [
'clutter-child-meta.h',
'clutter-click-action.h',
'clutter-clone.h',
'clutter-color-state.h',
'clutter-color-static.h',
'clutter-color.h',
'clutter-colorize-effect.h',
@ -113,6 +114,7 @@ clutter_sources = [
'clutter-click-action.c',
'clutter-clone.c',
'clutter-color.c',
'clutter-color-state.c',
'clutter-colorize-effect.c',
'clutter-constraint.c',
'clutter-container.c',