4 * An object oriented GL/GLES Abstraction/Utility Layer
6 * Copyright (C) 2008,2009,2010,2011 Intel Corporation.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see
20 * <http://www.gnu.org/licenses/>.
25 * Robert Bragg <robert@linux.intel.com>
32 #include "cogl-context-private.h"
33 #include "cogl-pipeline-private.h"
34 #include "cogl-pipeline-layer-private.h"
35 #include "cogl-node-private.h"
48 dump_layer_cb (CoglNode *node, void *user_data)
50 CoglPipelineLayer *layer = COGL_PIPELINE_LAYER (node);
51 PrintDebugState *state = user_data;
52 int layer_id = *state->node_id_ptr;
53 PrintDebugState state_out;
54 GString *changes_label;
55 gboolean changes = FALSE;
57 if (state->parent_id >= 0)
58 g_string_append_printf (state->graph, "%*slayer%p -> layer%p;\n",
60 layer->_parent.parent,
63 g_string_append_printf (state->graph,
64 "%*slayer%p [label=\"layer=0x%p\\n"
70 COGL_OBJECT (layer)->ref_count);
72 changes_label = g_string_new ("");
73 g_string_append_printf (changes_label,
74 "%*slayer%p -> layer_state%d [weight=100];\n"
75 "%*slayer_state%d [shape=box label=\"",
82 if (layer->differences & COGL_PIPELINE_LAYER_STATE_UNIT)
85 g_string_append_printf (changes_label,
90 if (layer->differences & COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA)
93 g_string_append_printf (changes_label,
100 g_string_append_printf (changes_label, "\"];\n");
101 g_string_append (state->graph, changes_label->str);
102 g_string_free (changes_label, TRUE);
105 state_out.parent_id = layer_id;
107 state_out.node_id_ptr = state->node_id_ptr;
108 (*state_out.node_id_ptr)++;
110 state_out.graph = state->graph;
111 state_out.indent = state->indent + 2;
113 _cogl_pipeline_node_foreach_child (COGL_NODE (layer),
121 dump_layer_ref_cb (CoglPipelineLayer *layer, void *data)
123 PrintDebugState *state = data;
124 int pipeline_id = *state->node_id_ptr;
126 g_string_append_printf (state->graph,
127 "%*spipeline_state%d -> layer%p;\n",
136 dump_pipeline_cb (CoglNode *node, void *user_data)
138 CoglPipeline *pipeline = COGL_PIPELINE (node);
139 PrintDebugState *state = user_data;
140 int pipeline_id = *state->node_id_ptr;
141 PrintDebugState state_out;
142 GString *changes_label;
143 gboolean changes = FALSE;
144 gboolean layers = FALSE;
146 if (state->parent_id >= 0)
147 g_string_append_printf (state->graph, "%*spipeline%d -> pipeline%d;\n",
152 g_string_append_printf (state->graph,
153 "%*spipeline%d [label=\"pipeline=0x%p\\n"
155 "breadcrumb=\\\"%s\\\"\" color=\"red\"];\n",
159 COGL_OBJECT (pipeline)->ref_count,
160 pipeline->has_static_breadcrumb ?
161 pipeline->static_breadcrumb : "NULL");
163 changes_label = g_string_new ("");
164 g_string_append_printf (changes_label,
165 "%*spipeline%d -> pipeline_state%d [weight=100];\n"
166 "%*spipeline_state%d [shape=box label=\"",
174 if (pipeline->differences & COGL_PIPELINE_STATE_COLOR)
177 g_string_append_printf (changes_label,
178 "\\lcolor=0x%02X%02X%02X%02X\\n",
179 cogl_color_get_red_byte (&pipeline->color),
180 cogl_color_get_green_byte (&pipeline->color),
181 cogl_color_get_blue_byte (&pipeline->color),
182 cogl_color_get_alpha_byte (&pipeline->color));
185 if (pipeline->differences & COGL_PIPELINE_STATE_BLEND)
187 const char *blend_enable_name;
191 switch (pipeline->blend_enable)
193 case COGL_PIPELINE_BLEND_ENABLE_AUTOMATIC:
194 blend_enable_name = "AUTO";
196 case COGL_PIPELINE_BLEND_ENABLE_ENABLED:
197 blend_enable_name = "ENABLED";
199 case COGL_PIPELINE_BLEND_ENABLE_DISABLED:
200 blend_enable_name = "DISABLED";
203 blend_enable_name = "UNKNOWN";
205 g_string_append_printf (changes_label,
210 if (pipeline->differences & COGL_PIPELINE_STATE_LAYERS)
214 g_string_append_printf (changes_label, "\\ln_layers=%d\\n",
220 g_string_append_printf (changes_label, "\"];\n");
221 g_string_append (state->graph, changes_label->str);
222 g_string_free (changes_label, TRUE);
227 g_list_foreach (pipeline->layer_differences,
228 (GFunc)dump_layer_ref_cb,
232 state_out.parent_id = pipeline_id;
234 state_out.node_id_ptr = state->node_id_ptr;
235 (*state_out.node_id_ptr)++;
237 state_out.graph = state->graph;
238 state_out.indent = state->indent + 2;
240 _cogl_pipeline_node_foreach_child (COGL_NODE (pipeline),
247 /* This function is just here to be called from GDB so we don't really
248 want to put a declaration in a header and we just add it here to
251 _cogl_debug_dump_pipelines_dot_file (const char *filename);
254 _cogl_debug_dump_pipelines_dot_file (const char *filename)
257 PrintDebugState layer_state;
258 PrintDebugState pipeline_state;
262 _COGL_GET_CONTEXT (ctx, NO_RETVAL);
264 if (!ctx->default_pipeline)
267 graph = g_string_new ("");
268 g_string_append_printf (graph, "digraph {\n");
270 layer_state.graph = graph;
271 layer_state.parent_id = -1;
272 layer_state.node_id_ptr = &layer_id;
273 layer_state.indent = 0;
274 dump_layer_cb ((CoglNode *)ctx->default_layer_0, &layer_state);
276 pipeline_state.graph = graph;
277 pipeline_state.parent_id = -1;
278 pipeline_state.node_id_ptr = &pipeline_id;
279 pipeline_state.indent = 0;
280 dump_pipeline_cb ((CoglNode *)ctx->default_pipeline, &pipeline_state);
282 g_string_append_printf (graph, "}\n");
285 g_file_set_contents (filename, graph->str, -1, NULL);
287 g_print ("%s", graph->str);
289 g_string_free (graph, TRUE);