utils: Pass a CoglContext to meta_create_texture

Moves the global backend access from the function to the only
place where we don't have a way to get CoglContext in background
loading.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4201>
This commit is contained in:
Bilal Elmoussaoui 2024-12-30 18:24:30 +01:00 committed by Marge Bot
parent 5a2ef3ca4b
commit 98e887df48
4 changed files with 17 additions and 13 deletions

View File

@ -68,7 +68,8 @@ meta_create_texture_pipeline (CoglContext *cogl_context,
* meta_create_texture:
* @width: width of the texture to create
* @height: height of the texture to create
* @components; components to store in the texture (color or alpha)
* @ctx: A #CoglContext
* @components: components to store in the texture (color or alpha)
* @flags: flags that affect the allocation behavior
*
* Creates a texture of the given size with the specified components
@ -82,13 +83,12 @@ meta_create_texture_pipeline (CoglContext *cogl_context,
* be as small as 2048x2048 on reasonably current systems.
*/
CoglTexture *
meta_create_texture (int width,
int height,
CoglTextureComponents components,
MetaTextureFlags flags)
meta_create_texture (int width,
int height,
CoglContext *ctx,
CoglTextureComponents components,
MetaTextureFlags flags)
{
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
CoglTexture *texture;
texture = cogl_texture_2d_new_with_size (ctx, width, height);

View File

@ -31,8 +31,9 @@ typedef enum
META_TEXTURE_ALLOW_SLICING = 1 << 1
} MetaTextureFlags;
CoglTexture *meta_create_texture (int width,
int height,
CoglTextureComponents components,
MetaTextureFlags flags);
CoglTexture * meta_create_texture (int width,
int height,
CoglContext *cogl_context,
CoglTextureComponents components,
MetaTextureFlags flags);

View File

@ -157,6 +157,8 @@ file_loaded (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
ClutterBackend *backend = clutter_get_default_backend ();
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
MetaBackgroundImage *image = META_BACKGROUND_IMAGE (source_object);
g_autoptr (GError) error = NULL;
g_autoptr (GError) local_error = NULL;
@ -192,7 +194,7 @@ file_loaded (GObject *source_object,
pixels = gdk_pixbuf_get_pixels (pixbuf);
has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
texture = meta_create_texture (width, height,
texture = meta_create_texture (width, height, ctx,
has_alpha ? COGL_TEXTURE_COMPONENTS_RGBA : COGL_TEXTURE_COMPONENTS_RGB,
META_TEXTURE_ALLOW_SLICING);

View File

@ -671,7 +671,7 @@ ensure_wallpaper_texture (MetaBackground *self,
GError *catch_error = NULL;
CoglPipeline *pipeline;
self->wallpaper_texture = meta_create_texture (width, height,
self->wallpaper_texture = meta_create_texture (width, height, cogl_context,
COGL_TEXTURE_COMPONENTS_RGBA,
META_TEXTURE_FLAGS_NONE);
offscreen = cogl_offscreen_new_with_texture (self->wallpaper_texture);
@ -830,6 +830,7 @@ meta_background_get_texture (MetaBackground *self,
monitor->texture = meta_create_texture (texture_width,
texture_height,
cogl_context,
COGL_TEXTURE_COMPONENTS_RGBA,
META_TEXTURE_FLAGS_NONE);
offscreen = cogl_offscreen_new_with_texture (monitor->texture);