From f4301b77faf570252f65f9a77d2144ca222b8056 Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Thu, 16 Apr 2020 17:18:46 +0800 Subject: [PATCH] cogl: Generalize `maybe_update_max_level()` into `set_max_level()` This way the caller can choose their own precondition. https://gitlab.gnome.org/GNOME/mutter/merge_requests/1003 --- cogl/cogl/cogl-texture-private.h | 2 +- cogl/cogl/cogl-texture.c | 2 +- cogl/cogl/driver/gl/cogl-texture-2d-gl.c | 3 ++- cogl/cogl/driver/gl/cogl-texture-gl-private.h | 4 ++-- cogl/cogl/driver/gl/cogl-texture-gl.c | 14 +++++++------- cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c | 2 +- .../cogl/driver/gl/gles/cogl-texture-driver-gles.c | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cogl/cogl/cogl-texture-private.h b/cogl/cogl/cogl-texture-private.h index 69d7ebd4a..c6a00ca0e 100644 --- a/cogl/cogl/cogl-texture-private.h +++ b/cogl/cogl/cogl-texture-private.h @@ -204,7 +204,7 @@ struct _CoglTexture CoglContext *context; CoglTextureLoader *loader; GList *framebuffers; - int max_level; + int max_level_set; int width; int height; gboolean allocated; diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index 587088c97..5c9848d68 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -115,7 +115,7 @@ _cogl_texture_init (CoglTexture *texture, const CoglTextureVtable *vtable) { texture->context = context; - texture->max_level = 0; + texture->max_level_set = 0; texture->width = width; texture->height = height; texture->allocated = FALSE; diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c index 749c9941f..d602de2c8 100644 --- a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c @@ -567,7 +567,8 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d, &gl_format, &gl_type); - _cogl_texture_gl_maybe_update_max_level (tex, level); + if (tex->max_level_set < level) + cogl_texture_gl_set_max_level (tex, level); status = ctx->texture_driver->upload_subregion_to_gl (ctx, tex, diff --git a/cogl/cogl/driver/gl/cogl-texture-gl-private.h b/cogl/cogl/driver/gl/cogl-texture-gl-private.h index 70e79998d..a8fbd2866 100644 --- a/cogl/cogl/driver/gl/cogl-texture-gl-private.h +++ b/cogl/cogl/driver/gl/cogl-texture-gl-private.h @@ -53,8 +53,8 @@ _cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture, unsigned int mag_filter); void -_cogl_texture_gl_maybe_update_max_level (CoglTexture *texture, - int max_level); +cogl_texture_gl_set_max_level (CoglTexture *texture, + int max_level); void _cogl_texture_gl_generate_mipmaps (CoglTexture *texture); diff --git a/cogl/cogl/driver/gl/cogl-texture-gl.c b/cogl/cogl/driver/gl/cogl-texture-gl.c index f365fc90b..25a8537c9 100644 --- a/cogl/cogl/driver/gl/cogl-texture-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-gl.c @@ -107,26 +107,25 @@ _cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture, #endif void -_cogl_texture_gl_maybe_update_max_level (CoglTexture *texture, - int max_level) +cogl_texture_gl_set_max_level (CoglTexture *texture, + int max_level) { CoglContext *ctx = texture->context; - if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_TEXTURE_MAX_LEVEL) && - texture->max_level < max_level) + if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_TEXTURE_MAX_LEVEL)) { GLuint gl_handle; GLenum gl_target; cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target); - texture->max_level = max_level; + texture->max_level_set = max_level; _cogl_bind_gl_texture_transient (gl_target, gl_handle); GE( ctx, glTexParameteri (gl_target, - GL_TEXTURE_MAX_LEVEL, texture->max_level)); + GL_TEXTURE_MAX_LEVEL, texture->max_level_set)); } } @@ -138,7 +137,8 @@ _cogl_texture_gl_generate_mipmaps (CoglTexture *texture) GLuint gl_handle; GLenum gl_target; - _cogl_texture_gl_maybe_update_max_level (texture, n_levels - 1); + if (texture->max_level_set < n_levels - 1) + cogl_texture_gl_set_max_level (texture, n_levels - 1); cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target); diff --git a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c index 5b33a0a25..35c10c2d6 100644 --- a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c @@ -255,7 +255,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx, * glTexImage2D first to assert that the storage for this * level exists. */ - if (texture->max_level < level) + if (texture->max_level_set < level) { ctx->glTexImage2D (gl_target, level, diff --git a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c index 01653bc87..f3cf3831e 100644 --- a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c @@ -303,7 +303,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx, * glTexImage2D first to assert that the storage for this * level exists. */ - if (texture->max_level < level) + if (texture->max_level_set < level) { ctx->glTexImage2D (gl_target, level,