1
0
Fork 0

compositor: Require a context when creating a texture mipmap

avoids going through globals

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3989>
This commit is contained in:
Bilal Elmoussaoui 2024-08-24 09:39:32 +02:00 committed by Jonas Ådahl
parent 0c7019a092
commit ea902ac928
3 changed files with 21 additions and 7 deletions

View file

@ -175,6 +175,20 @@ meta_shaped_texture_get_property (GObject *object,
}
}
static void
meta_shaped_texture_constructed (GObject *object)
{
MetaShapedTexture *stex = META_SHAPED_TEXTURE (object);
ClutterBackend *clutter_backend =
clutter_context_get_backend (stex->clutter_context);
CoglContext *cogl_context =
clutter_backend_get_cogl_context (clutter_backend);
G_OBJECT_CLASS (meta_shaped_texture_parent_class)->constructed (object);
stex->texture_mipmap = meta_texture_mipmap_new (cogl_context);
}
static void
meta_shaped_texture_class_init (MetaShapedTextureClass *klass)
{
@ -183,6 +197,7 @@ meta_shaped_texture_class_init (MetaShapedTextureClass *klass)
object_class->dispose = meta_shaped_texture_dispose;
object_class->set_property = meta_shaped_texture_set_property;
object_class->get_property = meta_shaped_texture_get_property;
object_class->constructed = meta_shaped_texture_constructed;
signals[SIZE_CHANGED] = g_signal_new ("size-changed",
G_TYPE_FROM_CLASS (klass),
@ -215,7 +230,6 @@ invalidate_size (MetaShapedTexture *stex)
static void
meta_shaped_texture_init (MetaShapedTexture *stex)
{
stex->texture_mipmap = meta_texture_mipmap_new ();
stex->buffer_scale = 1;
stex->texture = NULL;
stex->mask_texture = NULL;

View file

@ -36,6 +36,7 @@ struct _MetaTextureMipmap
MetaMultiTexture *mipmap_texture;
CoglPipeline *pipeline;
CoglFramebuffer *fb;
CoglContext *cogl_context;
gboolean invalid;
};
@ -48,11 +49,12 @@ struct _MetaTextureMipmap
* Return value: the new texture mipmap handler. Free with meta_texture_mipmap_free()
*/
MetaTextureMipmap *
meta_texture_mipmap_new (void)
meta_texture_mipmap_new (CoglContext *cogl_context)
{
MetaTextureMipmap *mipmap;
mipmap = g_new0 (MetaTextureMipmap, 1);
mipmap->cogl_context = cogl_context;
return mipmap;
}
@ -132,8 +134,6 @@ meta_texture_mipmap_clear (MetaTextureMipmap *mipmap)
static void
ensure_mipmap_texture (MetaTextureMipmap *mipmap)
{
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
int width, height;
/* Let's avoid spending any texture memory copying the base level texture
@ -172,7 +172,7 @@ ensure_mipmap_texture (MetaTextureMipmap *mipmap)
free_mipmaps (mipmap);
tex = cogl_texture_2d_new_with_size (ctx, width, height);
tex = cogl_texture_2d_new_with_size (mipmap->cogl_context, width, height);
if (!tex)
return;
@ -212,7 +212,7 @@ ensure_mipmap_texture (MetaTextureMipmap *mipmap)
CoglSnippet *fragment_globals_snippet;
CoglSnippet *fragment_snippet;
mipmap->pipeline = cogl_pipeline_new (ctx);
mipmap->pipeline = cogl_pipeline_new (mipmap->cogl_context);
cogl_pipeline_set_blend (mipmap->pipeline,
"RGBA = ADD (SRC_COLOR, 0)",
NULL);

View file

@ -37,7 +37,7 @@ G_BEGIN_DECLS
typedef struct _MetaTextureMipmap MetaTextureMipmap;
MetaTextureMipmap *meta_texture_mipmap_new (void);
MetaTextureMipmap *meta_texture_mipmap_new (CoglContext *cogl_context);
void meta_texture_mipmap_free (MetaTextureMipmap *mipmap);