mirror of
https://github.com/brl/mutter.git
synced 2024-12-25 04:22:05 +00:00
material: Adds experimental cogl_material_foreach_layer API
This adds a way to iterate the layer indices of the given material since cogl_material_get_layers has been deprecated. The user provides a callback to be called once for each layer. Because modification of layers in the callback may potentially invalidate any number of the internal CoglMaterialLayer structures and invalidate the material's layer cache this should be more robust than cogl_material_get_layers() which used to return a const GList * pointing directly to internal state.
This commit is contained in:
parent
7eff623b96
commit
16c64054b9
@ -226,7 +226,7 @@ find_arbfp_authority (CoglMaterial *material, CoglHandle user_program)
|
|||||||
g_alloca (sizeof (CoglMaterialLayer *) * n_layers);
|
g_alloca (sizeof (CoglMaterialLayer *) * n_layers);
|
||||||
state.i = 0;
|
state.i = 0;
|
||||||
state.layers = authority0_layers;
|
state.layers = authority0_layers;
|
||||||
_cogl_material_foreach_layer (authority0,
|
_cogl_material_foreach_layer_internal (authority0,
|
||||||
add_layer_to_array_cb,
|
add_layer_to_array_cb,
|
||||||
&state);
|
&state);
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ find_arbfp_authority (CoglMaterial *material, CoglHandle user_program)
|
|||||||
g_alloca (sizeof (CoglMaterialLayer *) * n_layers);
|
g_alloca (sizeof (CoglMaterialLayer *) * n_layers);
|
||||||
state.i = 0;
|
state.i = 0;
|
||||||
state.layers = authority1_layers;
|
state.layers = authority1_layers;
|
||||||
_cogl_material_foreach_layer (authority1,
|
_cogl_material_foreach_layer_internal (authority1,
|
||||||
add_layer_to_array_cb,
|
add_layer_to_array_cb,
|
||||||
&state);
|
&state);
|
||||||
|
|
||||||
|
@ -833,7 +833,7 @@ _cogl_material_flush_common_gl_state (CoglMaterial *material,
|
|||||||
|
|
||||||
state.i = 0;
|
state.i = 0;
|
||||||
state.layer_differences = layer_differences;
|
state.layer_differences = layer_differences;
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
flush_layers_common_gl_state_cb,
|
flush_layers_common_gl_state_cb,
|
||||||
&state);
|
&state);
|
||||||
|
|
||||||
@ -1115,7 +1115,7 @@ _cogl_material_flush_gl_state (CoglMaterial *material,
|
|||||||
memset (layer_differences, 0, sizeof (layer_differences));
|
memset (layer_differences, 0, sizeof (layer_differences));
|
||||||
state.i = 0;
|
state.i = 0;
|
||||||
state.layer_differences = layer_differences;
|
state.layer_differences = layer_differences;
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
compare_layer_differences_cb,
|
compare_layer_differences_cb,
|
||||||
&state);
|
&state);
|
||||||
}
|
}
|
||||||
@ -1178,7 +1178,7 @@ _cogl_material_flush_gl_state (CoglMaterial *material,
|
|||||||
state.layer_differences = layer_differences;
|
state.layer_differences = layer_differences;
|
||||||
state.error_adding_layer = FALSE;
|
state.error_adding_layer = FALSE;
|
||||||
state.added_layer = FALSE;
|
state.added_layer = FALSE;
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
backend_add_layer_cb,
|
backend_add_layer_cb,
|
||||||
&state);
|
&state);
|
||||||
|
|
||||||
|
@ -903,12 +903,12 @@ _cogl_material_layer_get_authority (CoglMaterialLayer *layer,
|
|||||||
CoglHandle
|
CoglHandle
|
||||||
_cogl_material_layer_get_texture (CoglMaterialLayer *layer);
|
_cogl_material_layer_get_texture (CoglMaterialLayer *layer);
|
||||||
|
|
||||||
typedef gboolean (*CoglMaterialLayerCallback) (CoglMaterialLayer *layer,
|
typedef gboolean (*CoglMaterialInternalLayerCallback) (CoglMaterialLayer *layer,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_material_foreach_layer (CoglMaterial *material,
|
_cogl_material_foreach_layer_internal (CoglMaterial *material,
|
||||||
CoglMaterialLayerCallback callback,
|
CoglMaterialInternalLayerCallback callback,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -676,13 +676,11 @@ _cogl_material_update_layers_cache (CoglMaterial *material)
|
|||||||
g_warn_if_reached ();
|
g_warn_if_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: add public cogl_material_foreach_layer but instead of passing
|
/* XXX: Be carefull when using this API that the callback given doesn't result
|
||||||
* a CoglMaterialLayer pointer to the callback we should pass a
|
* in the layer cache being invalidated during the iteration! */
|
||||||
* layer_index instead. */
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_material_foreach_layer (CoglMaterial *material,
|
_cogl_material_foreach_layer_internal (CoglMaterial *material,
|
||||||
CoglMaterialLayerCallback callback,
|
CoglMaterialInternalLayerCallback callback,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
CoglMaterial *authority =
|
CoglMaterial *authority =
|
||||||
@ -698,8 +696,54 @@ _cogl_material_foreach_layer (CoglMaterial *material,
|
|||||||
_cogl_material_update_layers_cache (authority);
|
_cogl_material_update_layers_cache (authority);
|
||||||
|
|
||||||
for (i = 0, cont = TRUE; i < n_layers && cont == TRUE; i++)
|
for (i = 0, cont = TRUE; i < n_layers && cont == TRUE; i++)
|
||||||
|
{
|
||||||
|
g_return_if_fail (authority->layers_cache_dirty == FALSE);
|
||||||
cont = callback (authority->layers_cache[i], user_data);
|
cont = callback (authority->layers_cache[i], user_data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int *indices;
|
||||||
|
} AppendLayerIndexState;
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
append_layer_index_cb (CoglMaterialLayer *layer,
|
||||||
|
void *user_data)
|
||||||
|
{
|
||||||
|
AppendLayerIndexState *state = user_data;
|
||||||
|
state->indices[state->i++] = layer->index;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cogl_material_foreach_layer (CoglMaterial *material,
|
||||||
|
CoglMaterialLayerCallback callback,
|
||||||
|
void *user_data)
|
||||||
|
{
|
||||||
|
CoglMaterial *authority =
|
||||||
|
_cogl_material_get_authority (material, COGL_MATERIAL_STATE_LAYERS);
|
||||||
|
AppendLayerIndexState state;
|
||||||
|
gboolean cont;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* XXX: We don't know what the user is going to want to do to the layers
|
||||||
|
* but any modification of layers can result in the layer graph changing
|
||||||
|
* which could confuse _cogl_material_foreach_layer_internal(). We first
|
||||||
|
* get a list of layer indices which will remain valid so long as the
|
||||||
|
* user doesn't remove layers. */
|
||||||
|
|
||||||
|
state.i = 0;
|
||||||
|
state.indices = g_alloca (authority->n_layers * sizeof (int));
|
||||||
|
|
||||||
|
_cogl_material_foreach_layer_internal (material,
|
||||||
|
append_layer_index_cb,
|
||||||
|
&state);
|
||||||
|
|
||||||
|
for (i = 0, cont = TRUE; i < authority->n_layers && cont; i++)
|
||||||
|
cont = callback (material, state.indices[i], user_data);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
layer_has_alpha_cb (CoglMaterialLayer *layer, void *data)
|
layer_has_alpha_cb (CoglMaterialLayer *layer, void *data)
|
||||||
@ -872,7 +916,7 @@ _cogl_material_needs_blending_enabled (CoglMaterial *material,
|
|||||||
* To start with that's defined by the material color which
|
* To start with that's defined by the material color which
|
||||||
* must be fully opaque if we got this far. */
|
* must be fully opaque if we got this far. */
|
||||||
gboolean has_alpha = FALSE;
|
gboolean has_alpha = FALSE;
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
layer_has_alpha_cb,
|
layer_has_alpha_cb,
|
||||||
&has_alpha);
|
&has_alpha);
|
||||||
if (has_alpha)
|
if (has_alpha)
|
||||||
@ -1393,7 +1437,7 @@ _cogl_material_prune_to_n_layers (CoglMaterial *material, int n)
|
|||||||
state.keep_n = n;
|
state.keep_n = n;
|
||||||
state.current_pos = 0;
|
state.current_pos = 0;
|
||||||
state.needs_pruning = FALSE;
|
state.needs_pruning = FALSE;
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
update_prune_layers_info_cb,
|
update_prune_layers_info_cb,
|
||||||
&state);
|
&state);
|
||||||
|
|
||||||
@ -1814,7 +1858,7 @@ _cogl_material_get_layer_info (CoglMaterial *material,
|
|||||||
int n_layers = material->n_layers;
|
int n_layers = material->n_layers;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* FIXME: _cogl_material_foreach_layer now calls
|
/* FIXME: _cogl_material_foreach_layer_internal now calls
|
||||||
* _cogl_material_update_layers_cache anyway so this codepath is
|
* _cogl_material_update_layers_cache anyway so this codepath is
|
||||||
* pointless! */
|
* pointless! */
|
||||||
if (layer_info->ignore_shift_layers_if_found &&
|
if (layer_info->ignore_shift_layers_if_found &&
|
||||||
@ -1827,7 +1871,7 @@ _cogl_material_get_layer_info (CoglMaterial *material,
|
|||||||
* necessarily have to iterate all the layers of the material we
|
* necessarily have to iterate all the layers of the material we
|
||||||
* use a foreach_layer callback instead of updating the cache
|
* use a foreach_layer callback instead of updating the cache
|
||||||
* and iterating that as below. */
|
* and iterating that as below. */
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
update_layer_info_cb,
|
update_layer_info_cb,
|
||||||
layer_info);
|
layer_info);
|
||||||
return;
|
return;
|
||||||
@ -2743,7 +2787,7 @@ _cogl_material_apply_overrides (CoglMaterial *material,
|
|||||||
state.material = material;
|
state.material = material;
|
||||||
state.fallback_layers = options->fallback_layers;
|
state.fallback_layers = options->fallback_layers;
|
||||||
|
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
fallback_layer_cb,
|
fallback_layer_cb,
|
||||||
&state);
|
&state);
|
||||||
}
|
}
|
||||||
@ -2756,11 +2800,11 @@ _cogl_material_apply_overrides (CoglMaterial *material,
|
|||||||
|
|
||||||
/* NB: we are overriding the first layer, but we don't know
|
/* NB: we are overriding the first layer, but we don't know
|
||||||
* the user's given layer_index, which is why we use
|
* the user's given layer_index, which is why we use
|
||||||
* _cogl_material_foreach_layer() here even though we know
|
* _cogl_material_foreach_layer_internal() here even though we know
|
||||||
* there's only one layer. */
|
* there's only one layer. */
|
||||||
state.material = material;
|
state.material = material;
|
||||||
state.gl_texture = options->layer0_override_texture;
|
state.gl_texture = options->layer0_override_texture;
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
override_layer_texture_cb,
|
override_layer_texture_cb,
|
||||||
&state);
|
&state);
|
||||||
}
|
}
|
||||||
@ -2772,7 +2816,7 @@ _cogl_material_apply_overrides (CoglMaterial *material,
|
|||||||
state.material = material;
|
state.material = material;
|
||||||
state.wrap_mode_overrides = &options->wrap_mode_overrides;
|
state.wrap_mode_overrides = &options->wrap_mode_overrides;
|
||||||
state.i = 0;
|
state.i = 0;
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
apply_wrap_mode_overrides_cb,
|
apply_wrap_mode_overrides_cb,
|
||||||
&state);
|
&state);
|
||||||
}
|
}
|
||||||
@ -5074,7 +5118,7 @@ cogl_material_get_layers (CoglMaterial *material)
|
|||||||
|
|
||||||
material->deprecated_get_layers_list = NULL;
|
material->deprecated_get_layers_list = NULL;
|
||||||
|
|
||||||
_cogl_material_foreach_layer (material,
|
_cogl_material_foreach_layer_internal (material,
|
||||||
prepend_layer_to_list_cb,
|
prepend_layer_to_list_cb,
|
||||||
&material->deprecated_get_layers_list);
|
&material->deprecated_get_layers_list);
|
||||||
material->deprecated_get_layers_list =
|
material->deprecated_get_layers_list =
|
||||||
@ -5550,7 +5594,7 @@ dump_material_cb (CoglMaterialNode *node, void *user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (layers)
|
if (layers)
|
||||||
_cogl_material_foreach_layer (material, dump_layer_ref_cb, state);
|
_cogl_material_foreach_layer_internal (material, dump_layer_ref_cb, state);
|
||||||
|
|
||||||
state_out.parent_id = material_id;
|
state_out.parent_id = material_id;
|
||||||
|
|
||||||
|
@ -1348,6 +1348,39 @@ cogl_material_get_depth_range (CoglMaterial *material,
|
|||||||
float *near_val,
|
float *near_val,
|
||||||
float *far_val);
|
float *far_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CoglMaterialLayerCallback:
|
||||||
|
* @material: The #CoglMaterial whos layers are being iterated
|
||||||
|
* @layer_index: The current layer index
|
||||||
|
* @user_data: The private data passed to cogl_material_foreach_layer()
|
||||||
|
*
|
||||||
|
* The callback prototype used with cogl_material_foreach_layer() for
|
||||||
|
* iterating all the layers of a @material.
|
||||||
|
*
|
||||||
|
* Since: 1.4
|
||||||
|
* Stability: Unstable
|
||||||
|
*/
|
||||||
|
typedef gboolean (*CoglMaterialLayerCallback) (CoglMaterial *material,
|
||||||
|
int layer_index,
|
||||||
|
void *user_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cogl_material_foreach_layer:
|
||||||
|
* @material: A #CoglMaterial object
|
||||||
|
* @callback: A #CoglMaterialLayerCallback to be called for each layer
|
||||||
|
* index
|
||||||
|
* @user_data: Private data that will be passed to the callback
|
||||||
|
*
|
||||||
|
* Iterates all the layer indices of the given @material.
|
||||||
|
*
|
||||||
|
* Since: 1.4
|
||||||
|
* Stability: Unstable
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
cogl_material_foreach_layer (CoglMaterial *material,
|
||||||
|
CoglMaterialLayerCallback callback,
|
||||||
|
void *user_data);
|
||||||
|
|
||||||
#endif /* COGL_ENABLE_EXPERIMENTAL_API */
|
#endif /* COGL_ENABLE_EXPERIMENTAL_API */
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
Loading…
Reference in New Issue
Block a user