material: pass material owner for layer pre changes

When notifying a backend about a layer being modified we now pass the
layers current owner for reference. NB: Although a layer can indirectly
be referenced by multiple layers, a layer is considered immutable once
it has dependants, so there is only ever one material associated with a
layer being modified. Passing the material pointer to the backends
layer_pre_change callback can be useful for backends that associate
their private state with materials and may need to update that state in
response to layer changes.
This commit is contained in:
Robert Bragg 2010-09-13 23:05:49 +01:00
parent d9a32f979c
commit a114843f74
3 changed files with 16 additions and 5 deletions

View File

@ -1073,10 +1073,19 @@ _cogl_material_backend_arbfp_material_set_parent_notify (
NULL); NULL);
} }
/* NB: layers are considered immutable once they have any dependants
* so although multiple materials can end up depending on a single
* static layer, we can guarantee that if a layer is being *changed*
* then it can only have one material depending on it.
*
* XXX: Don't forget this is *pre* change, we can't read the new value
* yet!
*/
static void static void
_cogl_material_backend_arbfp_layer_pre_change_notify ( _cogl_material_backend_arbfp_layer_pre_change_notify (
CoglMaterial *owner,
CoglMaterialLayer *layer, CoglMaterialLayer *layer,
CoglMaterialLayerState changes) CoglMaterialLayerState change)
{ {
/* TODO: we could be saving snippets of texture combine code along /* TODO: we could be saving snippets of texture combine code along
* with each layer and then when a layer changes we would just free * with each layer and then when a layer changes we would just free

View File

@ -557,7 +557,8 @@ typedef struct _CoglMaterialBackend
CoglMaterialState change, CoglMaterialState change,
const CoglColor *new_color); const CoglColor *new_color);
void (*material_set_parent_notify) (CoglMaterial *material); void (*material_set_parent_notify) (CoglMaterial *material);
void (*layer_pre_change_notify) (CoglMaterialLayer *layer, void (*layer_pre_change_notify) (CoglMaterial *owner,
CoglMaterialLayer *layer,
CoglMaterialLayerState change); CoglMaterialLayerState change);
void (*free_priv) (CoglMaterial *material); void (*free_priv) (CoglMaterial *material);

View File

@ -1418,7 +1418,8 @@ _cogl_material_prune_to_n_layers (CoglMaterial *material, int n)
} }
static void static void
_cogl_material_backend_layer_change_notify (CoglMaterialLayer *layer, _cogl_material_backend_layer_change_notify (CoglMaterial *owner,
CoglMaterialLayer *layer,
CoglMaterialLayerState change) CoglMaterialLayerState change)
{ {
int i; int i;
@ -1433,7 +1434,7 @@ _cogl_material_backend_layer_change_notify (CoglMaterialLayer *layer,
_cogl_material_backends[i]->layer_pre_change_notify) _cogl_material_backends[i]->layer_pre_change_notify)
{ {
const CoglMaterialBackend *backend = _cogl_material_backends[i]; const CoglMaterialBackend *backend = _cogl_material_backends[i];
backend->layer_pre_change_notify (layer, change); backend->layer_pre_change_notify (owner, layer, change);
} }
} }
} }
@ -1594,7 +1595,7 @@ _cogl_material_layer_pre_change_notify (CoglMaterial *required_owner,
* this layer (required_owner), and there are no other layers * this layer (required_owner), and there are no other layers
* dependant on this layer so it's ok to modify it. */ * dependant on this layer so it's ok to modify it. */
_cogl_material_backend_layer_change_notify (layer, change); _cogl_material_backend_layer_change_notify (required_owner, layer, change);
/* If the layer being changed is the same as the last layer we /* If the layer being changed is the same as the last layer we
* flushed to the corresponding texture unit then we keep a track of * flushed to the corresponding texture unit then we keep a track of