Allow lazy texture storage allocation

Consistent with how we lazily allocate framebuffers this patch allows us
to instantiate textures but still specify constraints and requirements
before allocating storage so that we can be sure to allocate the most
appropriate/efficient storage.

This adds a cogl_texture_allocate() function that is analogous to
cogl_framebuffer_allocate() which can optionally be called to explicitly
allocate storage and catch any errors. If this function isn't used
explicitly then Cogl will implicitly ensure textures are allocated
before the storage is needed.

It is generally recommended to rely on lazy storage allocation or at
least perform explicit allocation as late as possible so Cogl can be
fully informed about the best way to allocate storage.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 1fa7c0f10a8a03043e3c75cb079a49625df098b7)

Note: This reverts the cogl_texture_rectangle_new_with_size API change
that dropped the CoglError argument and keeps the semantics of
allocating the texture immediately. This is because Mutter currently
uses this API so we will probably look at updating this later once
we have a corresponding Mutter patch prepared. The other API changes
were kept since they only affected experimental api.
This commit is contained in:
Robert Bragg
2012-11-22 23:01:08 +00:00
parent 5a814e386a
commit 73e8a6d7ce
37 changed files with 713 additions and 419 deletions

View File

@ -112,7 +112,14 @@ uint32_t cogl_texture_error_quark (void);
*
* Creates a new #CoglTexture with the specified dimensions and pixel format.
*
* Return value: A newly created #CoglTexture or %NULL on failure
* The storage for the texture is not necesarily created before this
* function returns. The storage can be explicitly allocated using
* cogl_texture_allocate() or preferably you can let Cogl
* automatically allocate the storage lazily when uploading data when
* Cogl may know more about how the texture will be used and can
* optimize how it is allocated.
*
* Return value: A newly created #CoglTexture
*
* Since: 0.8
*/
@ -517,6 +524,28 @@ cogl_texture_unref (void *texture) G_GNUC_DEPRECATED;
#endif /* COGL_DISABLE_DEPRECATED */
/**
* cogl_texture_allocate:
* @texture: A #CoglTexture
* @error: A #CoglError to return exceptional errors or %NULL
*
* Explicitly allocates the storage for the given @texture which
* allows you to be sure that there is enough memory for the
* texture and if not then the error can be handled gracefully.
*
* <note>Normally applications don't need to use this api directly
* since the texture will be implicitly allocated when data is set on
* the texture, or if the texture is attached to a #CoglOffscreen
* framebuffer and rendered too.</note>
*
* Return value: %TRUE if the texture was successfully allocated,
* otherwise %FALSE and @error will be updated if it
* wasn't %NULL.
*/
CoglBool
cogl_texture_allocate (CoglTexture *texture,
CoglError **error);
COGL_END_DECLS
#endif /* __COGL_TEXTURE_H__ */