mirror of
https://github.com/brl/mutter.git
synced 2024-12-24 12:02:04 +00:00
cogl-atlas-texture: Make copying a texture out more robust
Previously when _cogl_atlas_texture_migrate_out_of_atlas is called it would unreference the atlas texture's sub-texture before calling _cogl_atlas_copy_rectangle. This would leave the atlas texture in an inconsistent state during the copy. This doesn't normally matter but if the copy ends up doing a render then the atlas texture may end up being referenced. In particular it would cause problems if the texture is left in a texture unit because then Cogl may try to call get_gl_texture even though the texture isn't actually being used for rendering. To fix this the sub texture is now unrefed after the copy call instead.
This commit is contained in:
parent
a067e7a16b
commit
50babfbc7a
@ -292,6 +292,8 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
|
||||
/* Make sure this texture is not in the atlas */
|
||||
if (atlas_tex->atlas)
|
||||
{
|
||||
CoglHandle sub_texture;
|
||||
|
||||
COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
|
||||
|
||||
/* We don't know if any journal entries currently depend on
|
||||
@ -304,14 +306,7 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
|
||||
*/
|
||||
cogl_flush ();
|
||||
|
||||
/* Notify cogl-pipeline.c that the texture's underlying GL texture
|
||||
* storage is changing so it knows it may need to bind a new texture
|
||||
* if the CoglTexture is reused with the same texture unit. */
|
||||
_cogl_pipeline_texture_storage_change_notify (atlas_tex);
|
||||
|
||||
cogl_handle_unref (atlas_tex->sub_texture);
|
||||
|
||||
atlas_tex->sub_texture =
|
||||
sub_texture =
|
||||
_cogl_atlas_copy_rectangle (atlas_tex->atlas,
|
||||
atlas_tex->rectangle.x + 1,
|
||||
atlas_tex->rectangle.y + 1,
|
||||
@ -320,6 +315,18 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
|
||||
COGL_TEXTURE_NO_ATLAS,
|
||||
atlas_tex->format);
|
||||
|
||||
/* Notify cogl-pipeline.c that the texture's underlying GL texture
|
||||
* storage is changing so it knows it may need to bind a new texture
|
||||
* if the CoglTexture is reused with the same texture unit. */
|
||||
_cogl_pipeline_texture_storage_change_notify (atlas_tex);
|
||||
|
||||
/* We need to unref the sub texture after doing the copy because
|
||||
the copy can involve rendering which might cause the texture
|
||||
to be used if it is used from a layer that is left in a
|
||||
texture unit */
|
||||
cogl_handle_unref (atlas_tex->sub_texture);
|
||||
atlas_tex->sub_texture = sub_texture;
|
||||
|
||||
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user