diff options
author | Robert Bragg <robert@linux.intel.com> | 2013-10-12 14:21:31 +0100 |
---|---|---|
committer | Robert Bragg <robert@linux.intel.com> | 2013-10-12 14:39:49 +0100 |
commit | a18410042dc549b1f1c9bdc3f271c06555941484 (patch) | |
tree | 2df0bda61de9200852b1ab749a25f02447c33526 | |
parent | ac413ad1ee5a1c1fb04386339d06e05bc01a9636 (diff) | |
download | cogl-a18410042dc549b1f1c9bdc3f271c06555941484.tar.gz |
auto-texture: revert _new_with_size semanticswip/cogl-1.14-fixes
This reverts the change in semantics for cogl_texture_new_with_size so
that it goes back to allocating textures synchronously and returning
NULL if there was a failure to allocate. Only the new/2.0 texture apis
will have the lazy allocation behaviour so we avoid breaking existing
code. This also fixes a potential crasher by removing a code path that
was passing NULL to cogl_texture_allocate() that would have caused and
abort if there were an error.
-rw-r--r-- | cogl/cogl-auto-texture.c | 39 | ||||
-rw-r--r-- | cogl/cogl-texture.h | 9 |
2 files changed, 33 insertions, 15 deletions
diff --git a/cogl/cogl-auto-texture.c b/cogl/cogl-auto-texture.c index 9a5819d9..5bb5319d 100644 --- a/cogl/cogl-auto-texture.c +++ b/cogl/cogl-auto-texture.c @@ -46,6 +46,16 @@ #include "cogl-sub-texture.h" #include "cogl-texture-2d-gl.h" +static void +set_auto_mipmap_cb (CoglTexture *sub_texture, + const float *sub_texture_coords, + const float *meta_coords, + void *user_data) +{ + cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (sub_texture), + FALSE); +} + CoglTexture * cogl_texture_new_with_size (unsigned int width, unsigned int height, @@ -80,13 +90,7 @@ cogl_texture_new_with_size (unsigned int width, else tex = NULL; - if (tex) - { - CoglBool auto_mipmap = !(flags & COGL_TEXTURE_NO_AUTO_MIPMAP); - cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex), - auto_mipmap); - } - else + if (!tex) { /* If it fails resort to sliced textures */ int max_waste = flags & COGL_TEXTURE_NO_SLICING ? -1 : COGL_TEXTURE_MAX_WASTE; @@ -97,6 +101,27 @@ cogl_texture_new_with_size (unsigned int width, internal_format)); } + /* NB: This api existed before Cogl introduced lazy allocation of + * textures and so we maintain its original synchronous allocation + * semantics and return NULL if allocation fails... */ + if (!cogl_texture_allocate (tex, &skip_error)) + { + cogl_error_free (skip_error); + cogl_object_unref (tex); + return NULL; + } + + if (tex && + flags & COGL_TEXTURE_NO_AUTO_MIPMAP) + { + cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (tex), + 0, 0, 1, 1, + COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, + COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, + set_auto_mipmap_cb, + NULL); + } + return tex; } diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h index a0261da5..8f6c201d 100644 --- a/cogl/cogl-texture.h +++ b/cogl/cogl-texture.h @@ -112,14 +112,7 @@ uint32_t cogl_texture_error_quark (void); * * Creates a new #CoglTexture with the specified dimensions and pixel format. * - * 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 + * Return value: A newly created #CoglTexture or %NULL on failure * * Since: 0.8 */ |