compositor: Pass CoglContext to create_texture helper

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3989>
This commit is contained in:
Bilal Elmoussaoui 2024-08-23 23:52:50 +02:00 committed by Jonas Ådahl
parent b83385e911
commit 770fbb71f3
5 changed files with 27 additions and 19 deletions

View File

@ -28,6 +28,7 @@
/** /**
* meta_create_texture_pipeline: * meta_create_texture_pipeline:
* @cogl_context: A #CoglContext
* @src_texture: (nullable): texture to use initially for the layer * @src_texture: (nullable): texture to use initially for the layer
* *
* Creates a pipeline with a single layer. Using a common template * Creates a pipeline with a single layer. Using a common template
@ -37,7 +38,8 @@
* Return value: (transfer full): a newly created #CoglPipeline * Return value: (transfer full): a newly created #CoglPipeline
*/ */
CoglPipeline * CoglPipeline *
meta_create_texture_pipeline (CoglTexture *src_texture) meta_create_texture_pipeline (CoglContext *cogl_context,
CoglTexture *src_texture)
{ {
static CoglPipeline *texture_pipeline_template = NULL; static CoglPipeline *texture_pipeline_template = NULL;
CoglPipeline *pipeline; CoglPipeline *pipeline;
@ -50,10 +52,7 @@ meta_create_texture_pipeline (CoglTexture *src_texture)
pipeline ancestry instead of resorting to the shader cache. */ pipeline ancestry instead of resorting to the shader cache. */
if (G_UNLIKELY (texture_pipeline_template == NULL)) if (G_UNLIKELY (texture_pipeline_template == NULL))
{ {
CoglContext *ctx = texture_pipeline_template = cogl_pipeline_new (cogl_context);
clutter_backend_get_cogl_context (clutter_get_default_backend ());
texture_pipeline_template = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_null_texture (texture_pipeline_template, 0); cogl_pipeline_set_layer_null_texture (texture_pipeline_template, 0);
} }

View File

@ -22,7 +22,8 @@
#include "cogl/cogl.h" #include "cogl/cogl.h"
CoglPipeline * meta_create_texture_pipeline (CoglTexture *texture); CoglPipeline * meta_create_texture_pipeline (CoglContext *cogl_context,
CoglTexture *texture);
typedef enum typedef enum
{ {

View File

@ -306,7 +306,8 @@ on_background_changed (MetaBackground *background,
} }
static CoglPipeline * static CoglPipeline *
make_pipeline (PipelineFlags pipeline_flags) make_pipeline (CoglContext *cogl_context,
PipelineFlags pipeline_flags)
{ {
static CoglPipeline *templates[PIPELINE_ALL + 1]; static CoglPipeline *templates[PIPELINE_ALL + 1];
CoglPipeline **templatep; CoglPipeline **templatep;
@ -320,7 +321,7 @@ make_pipeline (PipelineFlags pipeline_flags)
* so we need to prevent identical pipelines from getting cached * so we need to prevent identical pipelines from getting cached
* separately, by reusing the same shader snippets. * separately, by reusing the same shader snippets.
*/ */
*templatep = COGL_PIPELINE (meta_create_texture_pipeline (NULL)); *templatep = COGL_PIPELINE (meta_create_texture_pipeline (cogl_context, NULL));
if ((pipeline_flags & PIPELINE_VIGNETTE) != 0) if ((pipeline_flags & PIPELINE_VIGNETTE) != 0)
{ {
@ -393,6 +394,8 @@ setup_pipeline (MetaBackgroundContent *self,
{ {
MetaContext *context = meta_display_get_context (self->display); MetaContext *context = meta_display_get_context (self->display);
MetaBackend *backend = meta_context_get_backend (context); MetaBackend *backend = meta_context_get_backend (context);
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
PipelineFlags pipeline_flags = 0; PipelineFlags pipeline_flags = 0;
guint8 opacity; guint8 opacity;
float color_component; float color_component;
@ -416,7 +419,7 @@ setup_pipeline (MetaBackgroundContent *self,
if (self->pipeline == NULL) if (self->pipeline == NULL)
{ {
self->pipeline_flags = pipeline_flags; self->pipeline_flags = pipeline_flags;
self->pipeline = make_pipeline (pipeline_flags); self->pipeline = make_pipeline (cogl_context, pipeline_flags);
self->changed = CHANGED_ALL; self->changed = CHANGED_ALL;
} }

View File

@ -611,7 +611,8 @@ typedef enum
} PipelineType; } PipelineType;
static CoglPipeline * static CoglPipeline *
create_pipeline (PipelineType type) create_pipeline (CoglContext *cogl_context,
PipelineType type)
{ {
const char * const blend_strings[3] = { const char * const blend_strings[3] = {
[PIPELINE_REPLACE] = "RGBA = ADD (SRC_COLOR, 0)", [PIPELINE_REPLACE] = "RGBA = ADD (SRC_COLOR, 0)",
@ -622,7 +623,7 @@ create_pipeline (PipelineType type)
if (templates[type] == NULL) if (templates[type] == NULL)
{ {
templates[type] = meta_create_texture_pipeline (NULL); templates[type] = meta_create_texture_pipeline (cogl_context, NULL);
cogl_pipeline_set_blend (templates[type], blend_strings[type], NULL); cogl_pipeline_set_blend (templates[type], blend_strings[type], NULL);
} }
@ -663,6 +664,8 @@ ensure_wallpaper_texture (MetaBackground *self,
{ {
int width = cogl_texture_get_width (texture); int width = cogl_texture_get_width (texture);
int height = cogl_texture_get_height (texture); int height = cogl_texture_get_height (texture);
CoglContext *cogl_context =
cogl_texture_get_context (texture);
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *fbo; CoglFramebuffer *fbo;
GError *catch_error = NULL; GError *catch_error = NULL;
@ -692,7 +695,7 @@ ensure_wallpaper_texture (MetaBackground *self,
cogl_framebuffer_orthographic (fbo, 0, 0, cogl_framebuffer_orthographic (fbo, 0, 0,
width, height, -1., 1.); width, height, -1., 1.);
pipeline = create_pipeline (PIPELINE_REPLACE); pipeline = create_pipeline (cogl_context, PIPELINE_REPLACE);
cogl_pipeline_set_layer_texture (pipeline, 0, texture); cogl_pipeline_set_layer_texture (pipeline, 0, texture);
cogl_framebuffer_draw_textured_rectangle (fbo, pipeline, 0, 0, width, height, cogl_framebuffer_draw_textured_rectangle (fbo, pipeline, 0, 0, width, height,
0., 0., 1., 1.); 0., 0., 1., 1.);
@ -702,7 +705,7 @@ ensure_wallpaper_texture (MetaBackground *self,
{ {
ensure_color_texture (self); ensure_color_texture (self);
pipeline = create_pipeline (PIPELINE_OVER_REVERSE); pipeline = create_pipeline (cogl_context, PIPELINE_OVER_REVERSE);
cogl_pipeline_set_layer_texture (pipeline, 0, self->color_texture); cogl_pipeline_set_layer_texture (pipeline, 0, self->color_texture);
cogl_framebuffer_draw_rectangle (fbo, pipeline, 0, 0, width, height); cogl_framebuffer_draw_rectangle (fbo, pipeline, 0, 0, width, height);
g_object_unref (pipeline); g_object_unref (pipeline);
@ -762,6 +765,10 @@ meta_background_get_texture (MetaBackground *self,
MtkRectangle monitor_area; MtkRectangle monitor_area;
CoglTexture *texture1, *texture2; CoglTexture *texture1, *texture2;
float monitor_scale; float monitor_scale;
MetaContext *context = meta_display_get_context (self->display);
MetaBackend *backend = meta_context_get_backend (context);
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend);
g_return_val_if_fail (META_IS_BACKGROUND (self), NULL); g_return_val_if_fail (META_IS_BACKGROUND (self), NULL);
g_return_val_if_fail (monitor_index >= 0 && monitor_index < self->n_monitors, NULL); g_return_val_if_fail (monitor_index >= 0 && monitor_index < self->n_monitors, NULL);
@ -802,8 +809,6 @@ meta_background_get_texture (MetaBackground *self,
if (monitor->dirty) if (monitor->dirty)
{ {
MetaContext *context = meta_display_get_context (self->display);
MetaBackend *backend = meta_context_get_backend (context);
GError *catch_error = NULL; GError *catch_error = NULL;
gboolean bare_region_visible = FALSE; gboolean bare_region_visible = FALSE;
int texture_width, texture_height; int texture_width, texture_height;
@ -860,7 +865,7 @@ meta_background_get_texture (MetaBackground *self,
if (texture2 != NULL && self->blend_factor != 0.0f) if (texture2 != NULL && self->blend_factor != 0.0f)
{ {
CoglPipeline *pipeline = create_pipeline (PIPELINE_REPLACE); CoglPipeline *pipeline = create_pipeline (cogl_context, PIPELINE_REPLACE);
int mipmap_level; int mipmap_level;
CoglColor color; CoglColor color;
@ -892,7 +897,7 @@ meta_background_get_texture (MetaBackground *self,
if (texture1 != NULL && self->blend_factor != 1.0) if (texture1 != NULL && self->blend_factor != 1.0)
{ {
CoglPipeline *pipeline = create_pipeline (PIPELINE_ADD); CoglPipeline *pipeline = create_pipeline (cogl_context, PIPELINE_ADD);
int mipmap_level; int mipmap_level;
CoglColor color; CoglColor color;
@ -918,7 +923,7 @@ meta_background_get_texture (MetaBackground *self,
if (bare_region_visible) if (bare_region_visible)
{ {
CoglPipeline *pipeline = create_pipeline (PIPELINE_OVER_REVERSE); CoglPipeline *pipeline = create_pipeline (cogl_context, PIPELINE_OVER_REVERSE);
ensure_color_texture (self); ensure_color_texture (self);
cogl_pipeline_set_layer_texture (pipeline, 0, self->color_texture); cogl_pipeline_set_layer_texture (pipeline, 0, self->color_texture);

View File

@ -931,7 +931,7 @@ make_shadow (MetaShadow *shadow,
g_free (buffer); g_free (buffer);
shadow->pipeline = meta_create_texture_pipeline (shadow->texture); shadow->pipeline = meta_create_texture_pipeline (ctx, shadow->texture);
cogl_pipeline_set_static_name (shadow->pipeline, "MetaShadowFactory"); cogl_pipeline_set_static_name (shadow->pipeline, "MetaShadowFactory");
} }