cogl/pipeline-layer: Inherit from GObject directly
Instead of inheriting from CoglNode, inherit from GObject and manually manage children. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4155>
This commit is contained in:
parent
b0219f0697
commit
a88f0b72aa
@ -49,10 +49,10 @@ typedef struct
|
|||||||
int indent;
|
int indent;
|
||||||
} PrintDebugState;
|
} PrintDebugState;
|
||||||
|
|
||||||
static gboolean
|
static void
|
||||||
dump_layer_cb (CoglNode *node, void *user_data)
|
dump_layer_cb (CoglPipelineLayer *layer,
|
||||||
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
CoglPipelineLayer *layer = COGL_PIPELINE_LAYER (node);
|
|
||||||
PrintDebugState *state = user_data;
|
PrintDebugState *state = user_data;
|
||||||
int layer_id = *state->node_id_ptr;
|
int layer_id = *state->node_id_ptr;
|
||||||
PrintDebugState state_out;
|
PrintDebugState state_out;
|
||||||
@ -62,7 +62,7 @@ dump_layer_cb (CoglNode *node, void *user_data)
|
|||||||
if (state->parent_id >= 0)
|
if (state->parent_id >= 0)
|
||||||
g_string_append_printf (state->graph, "%*slayer%p -> layer%p;\n",
|
g_string_append_printf (state->graph, "%*slayer%p -> layer%p;\n",
|
||||||
state->indent, "",
|
state->indent, "",
|
||||||
layer->parent_instance.parent,
|
layer->parent,
|
||||||
layer);
|
layer);
|
||||||
|
|
||||||
g_string_append_printf (state->graph,
|
g_string_append_printf (state->graph,
|
||||||
@ -116,11 +116,12 @@ dump_layer_cb (CoglNode *node, void *user_data)
|
|||||||
state_out.graph = state->graph;
|
state_out.graph = state->graph;
|
||||||
state_out.indent = state->indent + 2;
|
state_out.indent = state->indent + 2;
|
||||||
|
|
||||||
_cogl_pipeline_node_foreach_child (COGL_NODE (layer),
|
for (CoglPipelineLayer *child = layer->first_child;
|
||||||
dump_layer_cb,
|
child != NULL;
|
||||||
&state_out);
|
child = child->next_sibling)
|
||||||
|
{
|
||||||
return TRUE;
|
dump_layer_cb (child, &state_out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -264,7 +265,7 @@ _cogl_debug_dump_pipelines_dot_file (const char *filename,
|
|||||||
layer_state.parent_id = -1;
|
layer_state.parent_id = -1;
|
||||||
layer_state.node_id_ptr = &layer_id;
|
layer_state.node_id_ptr = &layer_id;
|
||||||
layer_state.indent = 0;
|
layer_state.indent = 0;
|
||||||
dump_layer_cb ((CoglNode *)ctx->default_layer_0, &layer_state);
|
dump_layer_cb (ctx->default_layer_0, &layer_state);
|
||||||
|
|
||||||
pipeline_state.graph = graph;
|
pipeline_state.graph = graph;
|
||||||
pipeline_state.parent_id = -1;
|
pipeline_state.parent_id = -1;
|
||||||
|
@ -35,7 +35,6 @@
|
|||||||
|
|
||||||
#include "cogl/cogl-private.h"
|
#include "cogl/cogl-private.h"
|
||||||
#include "cogl/cogl-pipeline.h"
|
#include "cogl/cogl-pipeline.h"
|
||||||
#include "cogl/cogl-node-private.h"
|
|
||||||
#include "cogl/cogl-texture.h"
|
#include "cogl/cogl-texture.h"
|
||||||
#include "cogl/cogl-pipeline-layer-state.h"
|
#include "cogl/cogl-pipeline-layer-state.h"
|
||||||
#include "cogl/cogl-pipeline-snippet-private.h"
|
#include "cogl/cogl-pipeline-snippet-private.h"
|
||||||
@ -218,7 +217,13 @@ struct _CoglPipelineLayer
|
|||||||
* the state relating to a given pipeline or layer may actually be
|
* the state relating to a given pipeline or layer may actually be
|
||||||
* owned by one if is ancestors in the tree. We have a common data
|
* owned by one if is ancestors in the tree. We have a common data
|
||||||
* type to track the tree hierarchy so we can share code... */
|
* type to track the tree hierarchy so we can share code... */
|
||||||
CoglNode parent_instance;
|
GObject parent_instance;
|
||||||
|
|
||||||
|
CoglPipelineLayer *parent;
|
||||||
|
CoglPipelineLayer *prev_sibling;
|
||||||
|
CoglPipelineLayer *next_sibling;
|
||||||
|
CoglPipelineLayer *first_child;
|
||||||
|
CoglPipelineLayer *last_child;
|
||||||
|
|
||||||
/* Some layers have a pipeline owner, which is to say that the layer
|
/* Some layers have a pipeline owner, which is to say that the layer
|
||||||
* is referenced in that pipelines->layer_differences list. A layer
|
* is referenced in that pipelines->layer_differences list. A layer
|
||||||
@ -264,7 +269,7 @@ struct _CoglPipelineLayer
|
|||||||
|
|
||||||
struct _CoglPipelineLayerClass
|
struct _CoglPipelineLayerClass
|
||||||
{
|
{
|
||||||
CoglNodeClass parent_class;
|
GObjectClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -280,8 +285,7 @@ _cogl_pipeline_init_default_layers (CoglContext *ctx);
|
|||||||
static inline CoglPipelineLayer *
|
static inline CoglPipelineLayer *
|
||||||
_cogl_pipeline_layer_get_parent (CoglPipelineLayer *layer)
|
_cogl_pipeline_layer_get_parent (CoglPipelineLayer *layer)
|
||||||
{
|
{
|
||||||
CoglNode *parent_node = COGL_NODE (layer)->parent;
|
return layer->parent;
|
||||||
return COGL_PIPELINE_LAYER (parent_node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CoglPipelineLayer *
|
CoglPipelineLayer *
|
||||||
|
@ -41,20 +41,42 @@
|
|||||||
#include "cogl/cogl-pipeline-layer-private.h"
|
#include "cogl/cogl-pipeline-layer-private.h"
|
||||||
#include "cogl/cogl-pipeline-layer-state-private.h"
|
#include "cogl/cogl-pipeline-layer-state-private.h"
|
||||||
#include "cogl/cogl-pipeline-layer-state.h"
|
#include "cogl/cogl-pipeline-layer-state.h"
|
||||||
#include "cogl/cogl-node-private.h"
|
|
||||||
#include "cogl/cogl-context-private.h"
|
#include "cogl/cogl-context-private.h"
|
||||||
#include "cogl/cogl-texture-private.h"
|
#include "cogl/cogl-texture-private.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
G_DEFINE_FINAL_TYPE (CoglPipelineLayer, cogl_pipeline_layer, COGL_TYPE_NODE)
|
G_DEFINE_FINAL_TYPE (CoglPipelineLayer, cogl_pipeline_layer, G_TYPE_OBJECT)
|
||||||
|
|
||||||
|
static void
|
||||||
|
cogl_pipeline_layer_unparent (CoglPipelineLayer *layer)
|
||||||
|
{
|
||||||
|
g_autoptr (CoglPipelineLayer) parent = g_steal_pointer (&layer->parent);
|
||||||
|
|
||||||
|
if (parent)
|
||||||
|
{
|
||||||
|
if (parent->first_child == layer)
|
||||||
|
parent->first_child = layer->next_sibling;
|
||||||
|
|
||||||
|
if (parent->last_child == layer)
|
||||||
|
parent->last_child = layer->prev_sibling;
|
||||||
|
|
||||||
|
if (layer->prev_sibling)
|
||||||
|
layer->prev_sibling->next_sibling = layer->next_sibling;
|
||||||
|
if (layer->next_sibling)
|
||||||
|
layer->next_sibling->prev_sibling = layer->prev_sibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
layer->prev_sibling = NULL;
|
||||||
|
layer->next_sibling = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cogl_pipeline_layer_dispose (GObject *object)
|
cogl_pipeline_layer_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
CoglPipelineLayer *layer = COGL_PIPELINE_LAYER (object);
|
CoglPipelineLayer *layer = COGL_PIPELINE_LAYER (object);
|
||||||
|
|
||||||
_cogl_pipeline_node_unparent (COGL_NODE (layer));
|
cogl_pipeline_layer_unparent (layer);
|
||||||
|
|
||||||
if (layer->differences & COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA &&
|
if (layer->differences & COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA &&
|
||||||
layer->texture != NULL)
|
layer->texture != NULL)
|
||||||
@ -371,8 +393,7 @@ _cogl_pipeline_layer_pre_change_notify (CoglPipeline *required_owner,
|
|||||||
{
|
{
|
||||||
/* Identify the case where the layer is new with no owner or
|
/* Identify the case where the layer is new with no owner or
|
||||||
* dependants and so we don't need to do anything. */
|
* dependants and so we don't need to do anything. */
|
||||||
if (_cogl_list_empty (&COGL_NODE (layer)->children) &&
|
if (layer->first_child == NULL && layer->owner == NULL)
|
||||||
layer->owner == NULL)
|
|
||||||
goto init_layer_state;
|
goto init_layer_state;
|
||||||
|
|
||||||
/* We only allow a NULL required_owner for new layers */
|
/* We only allow a NULL required_owner for new layers */
|
||||||
@ -393,8 +414,7 @@ _cogl_pipeline_layer_pre_change_notify (CoglPipeline *required_owner,
|
|||||||
* they have dependants - either direct children, or another
|
* they have dependants - either direct children, or another
|
||||||
* pipeline as an owner.
|
* pipeline as an owner.
|
||||||
*/
|
*/
|
||||||
if (!_cogl_list_empty (&COGL_NODE (layer)->children) ||
|
if (layer->first_child != NULL || layer->owner != required_owner)
|
||||||
layer->owner != required_owner)
|
|
||||||
{
|
{
|
||||||
CoglPipelineLayer *new = _cogl_pipeline_layer_copy (layer);
|
CoglPipelineLayer *new = _cogl_pipeline_layer_copy (layer);
|
||||||
if (layer->owner == required_owner)
|
if (layer->owner == required_owner)
|
||||||
@ -468,10 +488,32 @@ static void
|
|||||||
_cogl_pipeline_layer_set_parent (CoglPipelineLayer *layer,
|
_cogl_pipeline_layer_set_parent (CoglPipelineLayer *layer,
|
||||||
CoglPipelineLayer *parent)
|
CoglPipelineLayer *parent)
|
||||||
{
|
{
|
||||||
/* Chain up */
|
g_autoptr (CoglPipelineLayer) owned_parent = NULL;
|
||||||
_cogl_pipeline_node_set_parent (COGL_NODE (layer),
|
|
||||||
COGL_NODE (parent),
|
g_assert (COGL_IS_PIPELINE_LAYER (layer));
|
||||||
TRUE);
|
g_assert (COGL_IS_PIPELINE_LAYER (parent));
|
||||||
|
|
||||||
|
if (layer->parent == parent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (layer->parent)
|
||||||
|
{
|
||||||
|
owned_parent = g_object_ref (layer->parent);
|
||||||
|
cogl_pipeline_layer_unparent (layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
layer->parent = g_object_ref (parent);
|
||||||
|
|
||||||
|
if (parent->first_child)
|
||||||
|
{
|
||||||
|
parent->first_child->prev_sibling = layer;
|
||||||
|
layer->next_sibling = parent->first_child;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parent->last_child = layer;
|
||||||
|
}
|
||||||
|
parent->first_child = layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoglPipelineLayer *
|
CoglPipelineLayer *
|
||||||
|
@ -2558,7 +2558,7 @@ deep_copy_layer_cb (CoglPipelineLayer *src_layer,
|
|||||||
differences ^= to_copy;
|
differences ^= to_copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
src_layer = COGL_PIPELINE_LAYER (COGL_NODE (src_layer)->parent);
|
src_layer = src_layer->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user