From b57f68245cc4d91229ba3ad6a3e045573c41e014 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Wed, 19 May 2010 00:36:31 +0100 Subject: [PATCH] material: Adds simple breadcrumb debugging mechanism Since it can sometimes be awkward to figure out where a particular material came from when debugging, this adds a breadcrumb mechanism that lets you associate a const string with a material that may give a clue about its origin. --- cogl/cogl-material-private.h | 14 ++++++++++++++ cogl/cogl-material.c | 23 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/cogl/cogl-material-private.h b/cogl/cogl-material-private.h index f66e3d1c3..770b60058 100644 --- a/cogl/cogl-material-private.h +++ b/cogl/cogl-material-private.h @@ -477,6 +477,11 @@ struct _CoglMaterial * be allocated dynamically when required... */ CoglMaterialBigState *big_state; + /* For debugging purposes it's possible to associate a static const + * string with a material which can be an aid when trying to trace + * where the material originates from */ + const char *static_breadcrumb; + /* Cached state... */ /* A cached, complete list of the layers this material depends @@ -519,6 +524,11 @@ struct _CoglMaterial unsigned int layers_cache_dirty:1; unsigned int deprecated_get_layers_list_dirty:1; + /* For debugging purposes it's possible to associate a static const + * string with a material which can be an aid when trying to trace + * where the material originates from */ + unsigned int has_static_breadcrumb:1; + /* There are multiple fragment processing backends for CoglMaterial, * glsl, arbfp and fixed. This identifies the backend being used for * the material and any private state the backend has associated @@ -734,5 +744,9 @@ void _cogl_material_set_blend_enabled (CoglHandle handle, CoglMaterialBlendEnable enable); +void +_cogl_material_set_static_breadcrumb (CoglHandle handle, + const char *breadcrumb); + #endif /* __COGL_MATERIAL_PRIVATE_H */ diff --git a/cogl/cogl-material.c b/cogl/cogl-material.c index 5d6523a45..bfd0b4340 100644 --- a/cogl/cogl-material.c +++ b/cogl/cogl-material.c @@ -364,6 +364,9 @@ _cogl_material_init_default_material (void) material->big_state = big_state; material->has_big_state = TRUE; + material->static_breadcrumb = "default material"; + material->has_static_breadcrumb = TRUE; + /* Use the same defaults as the GL spec... */ cogl_color_init_from_4ub (&material->color, 0xff, 0xff, 0xff, 0xff); @@ -456,15 +459,21 @@ cogl_material_copy (CoglHandle handle) material->backend = src->backend; material->backend_priv_set = FALSE; + material->has_static_breadcrumb = FALSE; + return _cogl_material_handle_new (material); } CoglHandle cogl_material_new (void) { + CoglHandle new; + _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); - return cogl_material_copy (ctx->default_material); + new = cogl_material_copy (ctx->default_material); + _cogl_material_set_static_breadcrumb (new, "new"); + return new; } static void @@ -1109,6 +1118,8 @@ _cogl_material_pre_change_notify (CoglMaterial *material, COGL_COUNTER_INC (_cogl_uprof_context, material_copy_on_write_counter); new_authority = cogl_material_copy (material->parent); + _cogl_material_set_static_breadcrumb (new_authority, + "pre_change_notify:copy-on-write"); /* We could explicitly walk the descendants, OR together the set * of differences that we determine this material is the @@ -6569,3 +6580,13 @@ _cogl_material_apply_legacy_state (CoglHandle handle) } } +void +_cogl_material_set_static_breadcrumb (CoglHandle handle, + const char *breadcrumb) +{ + CoglMaterial *material = COGL_MATERIAL (handle); + + material->has_static_breadcrumb = TRUE; + material->static_breadcrumb = breadcrumb; +} +