From 24f46448cee90178b287a1da9f0419ab946c042d Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 29 Jun 2024 14:01:50 +0200 Subject: [PATCH 01/10] cogl/pango: Take a context as a param when constructing a font map Avoids using the get_context macro Part-of: --- clutter/clutter/clutter-context.c | 6 +++++- cogl/cogl-pango/cogl-pango-fontmap.c | 4 +--- cogl/cogl-pango/cogl-pango.h | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/clutter/clutter/clutter-context.c b/clutter/clutter/clutter-context.c index 90f68ba1c5a..9a85b9aaf05 100644 --- a/clutter/clutter/clutter-context.c +++ b/clutter/clutter/clutter-context.c @@ -301,11 +301,15 @@ clutter_context_get_pango_fontmap (ClutterContext *context) CoglPangoFontMap *font_map; gdouble resolution; gboolean use_mipmapping; + ClutterBackend *backend; + CoglContext *cogl_context; if (G_LIKELY (context->font_map != NULL)) return context->font_map; - font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new ()); + backend = clutter_context_get_backend (context); + cogl_context = clutter_backend_get_cogl_context (backend); + font_map = COGL_PANGO_FONT_MAP (cogl_pango_font_map_new (cogl_context)); resolution = clutter_backend_get_resolution (context->backend); cogl_pango_font_map_set_resolution (font_map, resolution); diff --git a/cogl/cogl-pango/cogl-pango-fontmap.c b/cogl/cogl-pango/cogl-pango-fontmap.c index a3563585558..4d089c24215 100644 --- a/cogl/cogl-pango/cogl-pango-fontmap.c +++ b/cogl/cogl-pango/cogl-pango-fontmap.c @@ -57,13 +57,11 @@ free_priv (gpointer data) } PangoFontMap * -cogl_pango_font_map_new (void) +cogl_pango_font_map_new (CoglContext *context) { PangoFontMap *fm = pango_cairo_font_map_new (); g_autofree CoglPangoFontMapPriv *priv = g_new0 (CoglPangoFontMapPriv, 1); - _COGL_GET_CONTEXT (context, NULL); - priv->ctx = g_object_ref (context); /* XXX: The public pango api doesn't let us sub-class diff --git a/cogl/cogl-pango/cogl-pango.h b/cogl/cogl-pango/cogl-pango.h index 99b970db1e3..cf16ebd567c 100644 --- a/cogl/cogl-pango/cogl-pango.h +++ b/cogl/cogl-pango/cogl-pango.h @@ -73,7 +73,7 @@ typedef PangoCairoFontMap CoglPangoFontMap; * Return value: (transfer full): the newly created #PangoFontMap */ COGL_EXPORT PangoFontMap * -cogl_pango_font_map_new (void); +cogl_pango_font_map_new (CoglContext *context); /** * cogl_pango_font_map_create_context: @@ -92,9 +92,9 @@ cogl_pango_font_map_create_context (CoglPangoFontMap *font_map); * @dpi: The resolution in "dots per inch". (Physical inches aren't * actually involved; the terminology is conventional.) * - * Sets the resolution for the @font_map. - * - * This is a scale factor between points specified in a + * Sets the resolution for the @font_map. + * + * This is a scale factor between points specified in a * [struct@Pango.FontDescription] and Cogl units. * The default value is %96, meaning that a 10 point font will be 13 * units high. (10 * 96. / 72. = 13.3). -- GitLab From 3fd7cdba092c2bf36331650233f24416da471abe Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 29 Jun 2024 14:16:15 +0200 Subject: [PATCH 02/10] cogl: Pass Context where possible Avoids using the macro & global variable Part-of: --- cogl/cogl-pango/cogl-pango-glyph-cache.c | 6 +- cogl/cogl-pango/cogl-pango-glyph-cache.h | 1 + cogl/cogl-pango/cogl-pango-render.c | 1 + cogl/cogl/cogl-atlas-texture.c | 30 +--------- cogl/cogl/cogl-atlas.c | 37 ++++++------ cogl/cogl/cogl-atlas.h | 6 +- cogl/cogl/cogl-blend-string.c | 2 - cogl/cogl/cogl-pipeline-layer-state.c | 18 +++--- cogl/cogl/cogl-pipeline-state.c | 21 +------ cogl/cogl/deprecated/cogl-program-private.h | 7 ++- cogl/cogl/deprecated/cogl-program.c | 9 +-- cogl/cogl/deprecated/cogl-shader.c | 8 +-- .../driver/gl/cogl-pipeline-fragend-glsl.c | 15 ++--- .../driver/gl/cogl-pipeline-opengl-private.h | 14 +++-- cogl/cogl/driver/gl/cogl-pipeline-opengl.c | 58 +++++++++---------- .../driver/gl/cogl-pipeline-progend-glsl.c | 42 +++++--------- .../driver/gl/cogl-pipeline-vertend-glsl.c | 13 ++--- cogl/cogl/driver/gl/cogl-texture-2d-gl.c | 15 ++--- cogl/cogl/driver/gl/cogl-texture-gl.c | 4 +- .../driver/gl/gl/cogl-texture-driver-gl.c | 6 +- .../driver/gl/gles/cogl-texture-driver-gles.c | 6 +- cogl/cogl/winsys/cogl-winsys-glx.c | 2 +- 22 files changed, 127 insertions(+), 194 deletions(-) diff --git a/cogl/cogl-pango/cogl-pango-glyph-cache.c b/cogl/cogl-pango/cogl-pango-glyph-cache.c index 13ffa6b30fa..e92addac851 100644 --- a/cogl/cogl-pango/cogl-pango-glyph-cache.c +++ b/cogl/cogl-pango/cogl-pango-glyph-cache.c @@ -261,6 +261,7 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache, static gboolean cogl_pango_glyph_cache_add_to_local_atlas (CoglPangoGlyphCache *cache, + CoglContext *context, PangoFont *font, PangoGlyph glyph, CoglPangoGlyphCacheValue *value) @@ -282,7 +283,8 @@ cogl_pango_glyph_cache_add_to_local_atlas (CoglPangoGlyphCache *cache, /* If we couldn't find one then start a new atlas */ if (atlas == NULL) { - atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_A_8, + atlas = _cogl_atlas_new (context, + COGL_PIXEL_FORMAT_A_8, COGL_ATLAS_CLEAR_TEXTURE | COGL_ATLAS_DISABLE_MIGRATION, cogl_pango_glyph_cache_update_position_cb); @@ -309,6 +311,7 @@ cogl_pango_glyph_cache_add_to_local_atlas (CoglPangoGlyphCache *cache, CoglPangoGlyphCacheValue * cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache, + CoglContext *context, gboolean create, PangoFont *font, PangoGlyph glyph) @@ -350,6 +353,7 @@ cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache, value) && /* If it fails try the local atlas */ !cogl_pango_glyph_cache_add_to_local_atlas (cache, + context, font, glyph, value)) diff --git a/cogl/cogl-pango/cogl-pango-glyph-cache.h b/cogl/cogl-pango/cogl-pango-glyph-cache.h index 8739c2329de..1503c614e13 100644 --- a/cogl/cogl-pango/cogl-pango-glyph-cache.h +++ b/cogl/cogl-pango/cogl-pango-glyph-cache.h @@ -75,6 +75,7 @@ cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache); COGL_EXPORT CoglPangoGlyphCacheValue * cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache, + CoglContext *context, gboolean create, PangoFont *font, PangoGlyph glyph); diff --git a/cogl/cogl-pango/cogl-pango-render.c b/cogl/cogl-pango/cogl-pango-render.c index e88e87eecf2..03fbda8392a 100644 --- a/cogl/cogl-pango/cogl-pango-render.c +++ b/cogl/cogl-pango/cogl-pango-render.c @@ -503,6 +503,7 @@ cogl_pango_renderer_get_cached_glyph (PangoRenderer *renderer, &priv->no_mipmap_caches); return cogl_pango_glyph_cache_lookup (caches->glyph_cache, + priv->ctx, create, font, glyph); } diff --git a/cogl/cogl/cogl-atlas-texture.c b/cogl/cogl/cogl-atlas-texture.c index 7b4acfd6a75..731a0b9fe29 100644 --- a/cogl/cogl/cogl-atlas-texture.c +++ b/cogl/cogl/cogl-atlas-texture.c @@ -50,8 +50,6 @@ #include -static GQuark atlas_private_key = 0; - G_DEFINE_FINAL_TYPE (CoglAtlasTexture, cogl_atlas_texture, COGL_TYPE_TEXTURE) static void @@ -171,8 +169,6 @@ _cogl_atlas_texture_post_reorganize_cb (void *user_data) { CoglAtlas *atlas = user_data; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (atlas->map) { CoglAtlasTextureGetRectanglesData data; @@ -204,24 +200,13 @@ _cogl_atlas_texture_post_reorganize_cb (void *user_data) } /* Notify any listeners that an atlas has changed */ - g_hook_list_invoke (&ctx->atlas_reorganize_callbacks, FALSE); -} - -static void -_cogl_atlas_texture_atlas_destroyed_cb (void *user_data) -{ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - /* Remove the atlas from the global list */ - ctx->atlases = g_slist_remove (ctx->atlases, user_data); + g_hook_list_invoke (&atlas->context->atlas_reorganize_callbacks, FALSE); } static CoglAtlas * _cogl_atlas_texture_create_atlas (CoglContext *ctx) { - atlas_private_key = g_quark_from_static_string ("-cogl-atlas-texture-create-key"); - - CoglAtlas *atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888, + CoglAtlas *atlas = _cogl_atlas_new (ctx, COGL_PIXEL_FORMAT_RGBA_8888, 0, _cogl_atlas_texture_update_position_cb); @@ -231,17 +216,6 @@ _cogl_atlas_texture_create_atlas (CoglContext *ctx) atlas); ctx->atlases = g_slist_prepend (ctx->atlases, atlas); - - /* Set some data on the atlas so we can get notification when it is - destroyed in order to remove it from the list. ctx->atlases - effectively holds a weak reference. We don't need a strong - reference because the atlas textures take a reference on the - atlas so it will stay alive */ - g_object_set_qdata_full (G_OBJECT (atlas), - atlas_private_key, - atlas, - _cogl_atlas_texture_atlas_destroyed_cb); - return atlas; } diff --git a/cogl/cogl/cogl-atlas.c b/cogl/cogl/cogl-atlas.c index cb8c8a51a27..a154655bd04 100644 --- a/cogl/cogl/cogl-atlas.c +++ b/cogl/cogl/cogl-atlas.c @@ -54,8 +54,11 @@ cogl_atlas_dispose (GObject *object) COGL_NOTE (ATLAS, "%p: Atlas destroyed", atlas); - if (atlas->texture) - g_object_unref (atlas->texture); + /* Remove the atlas from the global list */ + atlas->context->atlases = g_slist_remove (atlas->context->atlases, atlas); + + g_clear_object (&atlas->texture); + g_clear_object (&atlas->context); if (atlas->map) _cogl_rectangle_map_free (atlas->map); @@ -79,7 +82,8 @@ cogl_atlas_class_init (CoglAtlasClass *class) } CoglAtlas * -_cogl_atlas_new (CoglPixelFormat texture_format, +_cogl_atlas_new (CoglContext *context, + CoglPixelFormat texture_format, CoglAtlasFlags flags, CoglAtlasUpdatePositionCallback update_position_cb) { @@ -88,6 +92,7 @@ _cogl_atlas_new (CoglPixelFormat texture_format, atlas->update_position_cb = update_position_cb; atlas->map = NULL; atlas->texture = NULL; + atlas->context = g_object_ref (context); atlas->flags = flags; atlas->texture_format = texture_format; g_hook_list_init (&atlas->pre_reorganize_callbacks, sizeof (GHook)); @@ -183,7 +188,8 @@ _cogl_atlas_get_next_size (unsigned int *map_width, } static void -_cogl_atlas_get_initial_size (CoglPixelFormat format, +_cogl_atlas_get_initial_size (CoglContext *ctx, + CoglPixelFormat format, unsigned int *map_width, unsigned int *map_height) { @@ -192,8 +198,6 @@ _cogl_atlas_get_initial_size (CoglPixelFormat format, GLenum gl_format; GLenum gl_type; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - g_return_if_fail (cogl_pixel_format_get_n_planes (format) == 1); ctx->driver_vtable->pixel_format_to_gl (ctx, @@ -228,7 +232,8 @@ _cogl_atlas_get_initial_size (CoglPixelFormat format, } static CoglRectangleMap * -_cogl_atlas_create_map (CoglPixelFormat format, +_cogl_atlas_create_map (CoglContext *ctx, + CoglPixelFormat format, unsigned int map_width, unsigned int map_height, unsigned int n_textures, @@ -238,8 +243,6 @@ _cogl_atlas_create_map (CoglPixelFormat format, GLenum gl_format; GLenum gl_type; - _COGL_GET_CONTEXT (ctx, NULL); - ctx->driver_vtable->pixel_format_to_gl (ctx, format, &gl_intformat, @@ -299,8 +302,6 @@ _cogl_atlas_create_texture (CoglAtlas *atlas, CoglTexture *tex; GError *ignore_error = NULL; - _COGL_GET_CONTEXT (ctx, NULL); - g_return_val_if_fail ( cogl_pixel_format_get_n_planes (atlas->texture_format) == 1, NULL); @@ -314,7 +315,7 @@ _cogl_atlas_create_texture (CoglAtlas *atlas, /* Create a buffer of zeroes to initially clear the texture */ clear_data = g_malloc0 (width * height * bpp); - clear_bmp = cogl_bitmap_new_for_data (ctx, + clear_bmp = cogl_bitmap_new_for_data (atlas->context, width, height, atlas->texture_format, @@ -339,7 +340,7 @@ _cogl_atlas_create_texture (CoglAtlas *atlas, } else { - tex = cogl_texture_2d_new_with_size (ctx, width, height); + tex = cogl_texture_2d_new_with_size (atlas->context, width, height); _cogl_texture_set_internal_format (tex, atlas->texture_format); @@ -469,10 +470,12 @@ _cogl_atlas_reserve_space (CoglAtlas *atlas, _cogl_atlas_get_next_size (&map_width, &map_height); } else - _cogl_atlas_get_initial_size (atlas->texture_format, + _cogl_atlas_get_initial_size (atlas->context, + atlas->texture_format, &map_width, &map_height); - new_map = _cogl_atlas_create_map (atlas->texture_format, + new_map = _cogl_atlas_create_map (atlas->context, + atlas->texture_format, map_width, map_height, data.n_textures, data.textures); @@ -623,10 +626,8 @@ _cogl_atlas_copy_rectangle (CoglAtlas *atlas, CoglBlitData blit_data; GError *ignore_error = NULL; - _COGL_GET_CONTEXT (ctx, NULL); - /* Create a new texture at the right size */ - tex = create_migration_texture (ctx, width, height, internal_format); + tex = create_migration_texture (atlas->context, width, height, internal_format); if (!cogl_texture_allocate (tex, &ignore_error)) { g_error_free (ignore_error); diff --git a/cogl/cogl/cogl-atlas.h b/cogl/cogl/cogl-atlas.h index ac5c8df102b..62172849f83 100644 --- a/cogl/cogl/cogl-atlas.h +++ b/cogl/cogl/cogl-atlas.h @@ -58,6 +58,7 @@ struct _CoglAtlas GObject parent_instance; CoglRectangleMap *map; + CoglContext *context; CoglTexture *texture; CoglPixelFormat texture_format; @@ -70,8 +71,9 @@ struct _CoglAtlas }; COGL_EXPORT CoglAtlas * -_cogl_atlas_new (CoglPixelFormat texture_format, - CoglAtlasFlags flags, +_cogl_atlas_new (CoglContext *context, + CoglPixelFormat texture_format, + CoglAtlasFlags flags, CoglAtlasUpdatePositionCallback update_position_cb); COGL_EXPORT gboolean diff --git a/cogl/cogl/cogl-blend-string.c b/cogl/cogl/cogl-blend-string.c index 50af35090b2..0f60dfbf999 100644 --- a/cogl/cogl/cogl-blend-string.c +++ b/cogl/cogl/cogl-blend-string.c @@ -214,8 +214,6 @@ validate_blend_statements (CoglBlendStringStatement *statements, const char *error_string; CoglBlendStringError detail = COGL_BLEND_STRING_ERROR_INVALID_ERROR; - _COGL_GET_CONTEXT (ctx, 0); - for (i = 0; i < n_statements; i++) for (j = 0; j < statements[i].function->argc; j++) { diff --git a/cogl/cogl/cogl-pipeline-layer-state.c b/cogl/cogl/cogl-pipeline-layer-state.c index 4d1a3e7a07d..95d44514f66 100644 --- a/cogl/cogl/cogl-pipeline-layer-state.c +++ b/cogl/cogl/cogl-pipeline-layer-state.c @@ -303,8 +303,7 @@ cogl_pipeline_set_layer_wrap_mode_s (CoglPipeline *pipeline, CoglSamplerCacheWrapMode internal_mode = public_to_internal_wrap_mode (mode); const CoglSamplerCacheEntry *sampler_state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; g_return_if_fail (COGL_IS_PIPELINE (pipeline)); @@ -343,11 +342,12 @@ cogl_pipeline_set_layer_wrap_mode_t (CoglPipeline *pipeline, CoglSamplerCacheWrapMode internal_mode = public_to_internal_wrap_mode (mode); const CoglSamplerCacheEntry *sampler_state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx; g_return_if_fail (COGL_IS_PIPELINE (pipeline)); + ctx = pipeline->context; + /* Note: this will ensure that the layer exists, creating one if it * doesn't already. * @@ -383,11 +383,11 @@ cogl_pipeline_set_layer_wrap_mode (CoglPipeline *pipeline, CoglSamplerCacheWrapMode internal_mode = public_to_internal_wrap_mode (mode); const CoglSamplerCacheEntry *sampler_state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx; g_return_if_fail (COGL_IS_PIPELINE (pipeline)); + ctx = pipeline->context; /* Note: this will ensure that the layer exists, creating one if it * doesn't already. * @@ -510,8 +510,6 @@ cogl_pipeline_set_layer_point_sprite_coords_enabled (CoglPipeline *pipeline, CoglPipelineLayer *new; CoglPipelineLayer *authority; - _COGL_GET_CONTEXT (ctx, FALSE); - g_return_val_if_fail (COGL_IS_PIPELINE (pipeline), FALSE); /* Note: this will ensure that the layer exists, creating one if it @@ -1268,14 +1266,14 @@ cogl_pipeline_set_layer_filters (CoglPipeline *pipeline, CoglPipelineLayer *layer; CoglPipelineLayer *authority; const CoglSamplerCacheEntry *sampler_state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx; g_return_if_fail (COGL_IS_PIPELINE (pipeline)); g_return_if_fail (mag_filter == COGL_PIPELINE_FILTER_NEAREST || mag_filter == COGL_PIPELINE_FILTER_LINEAR); + ctx = pipeline->context; /* Note: this will ensure that the layer exists, creating one if it * doesn't already. * diff --git a/cogl/cogl/cogl-pipeline-state.c b/cogl/cogl/cogl-pipeline-state.c index 3caf6f922f8..982b30bea8f 100644 --- a/cogl/cogl/cogl-pipeline-state.c +++ b/cogl/cogl/cogl-pipeline-state.c @@ -86,8 +86,6 @@ _cogl_pipeline_blend_state_equal (CoglPipeline *authority0, CoglPipelineBlendState *blend_state0 = &authority0->big_state->blend_state; CoglPipelineBlendState *blend_state1 = &authority1->big_state->blend_state; - _COGL_GET_CONTEXT (ctx, FALSE); - if (blend_state0->blend_equation_rgb != blend_state1->blend_equation_rgb) return FALSE; @@ -217,8 +215,7 @@ _cogl_pipeline_get_all_uniform_values (CoglPipeline *pipeline, const CoglBoxedValue **values) { GetUniformsClosure data; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; memset (values, 0, sizeof (const CoglBoxedValue *) * ctx->n_uniform_names); @@ -252,8 +249,7 @@ _cogl_pipeline_uniforms_state_equal (CoglPipeline *authority0, const CoglBoxedValue **values0, **values1; int n_longs; int i; - - _COGL_GET_CONTEXT (ctx, FALSE); + CoglContext *ctx = authority0->context; if (authority0 == authority1) return TRUE; @@ -556,8 +552,6 @@ cogl_pipeline_set_blend (CoglPipeline *pipeline, int count; CoglPipelineBlendState *blend_state; - _COGL_GET_CONTEXT (ctx, FALSE); - g_return_val_if_fail (COGL_IS_PIPELINE (pipeline), FALSE); count = @@ -633,8 +627,6 @@ cogl_pipeline_set_blend_constant (CoglPipeline *pipeline, CoglPipeline *authority; CoglPipelineBlendState *blend_state; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - g_return_if_fail (COGL_IS_PIPELINE (pipeline)); authority = _cogl_pipeline_get_authority (pipeline, state); @@ -740,8 +732,6 @@ cogl_pipeline_set_depth_state (CoglPipeline *pipeline, CoglPipeline *authority; CoglDepthState *orig_state; - _COGL_GET_CONTEXT (ctx, FALSE); - g_return_val_if_fail (COGL_IS_PIPELINE (pipeline), FALSE); g_return_val_if_fail (depth_state->magic == COGL_DEPTH_STATE_MAGIC, FALSE); @@ -949,7 +939,6 @@ cogl_pipeline_set_per_vertex_point_size (CoglPipeline *pipeline, CoglPipelineState state = COGL_PIPELINE_STATE_PER_VERTEX_POINT_SIZE; CoglPipeline *authority; - _COGL_GET_CONTEXT (ctx, FALSE); g_return_val_if_fail (COGL_IS_PIPELINE (pipeline), FALSE); authority = _cogl_pipeline_get_authority (pipeline, state); @@ -996,11 +985,9 @@ _cogl_pipeline_override_uniform (CoglPipeline *pipeline, CoglPipelineUniformsState *uniforms_state; int override_index; - _COGL_GET_CONTEXT (ctx, NULL); - g_return_val_if_fail (COGL_IS_PIPELINE (pipeline), NULL); g_return_val_if_fail (location >= 0, NULL); - g_return_val_if_fail (location < ctx->n_uniform_names, NULL); + g_return_val_if_fail (location < pipeline->context->n_uniform_names, NULL); /* - Flush journal primitives referencing the current state. * - Make sure the pipeline has no dependants so it may be modified. @@ -1271,8 +1258,6 @@ _cogl_pipeline_hash_blend_state (CoglPipeline *authority, CoglPipelineBlendState *blend_state = &authority->big_state->blend_state; unsigned int hash; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (!authority->real_blend_enable) return; diff --git a/cogl/cogl/deprecated/cogl-program-private.h b/cogl/cogl/deprecated/cogl-program-private.h index 761d8d88910..a1d43ed90be 100644 --- a/cogl/cogl/deprecated/cogl-program-private.h +++ b/cogl/cogl/deprecated/cogl-program-private.h @@ -71,9 +71,10 @@ struct _CoglProgramUniform the last time it was flushed. This will cause it to requery all of the locations and assume that all uniforms are dirty */ void -_cogl_program_flush_uniforms (CoglProgram *program, - GLuint gl_program, - gboolean gl_program_changed); +_cogl_program_flush_uniforms (CoglContext *ctx, + CoglProgram *program, + GLuint gl_program, + gboolean gl_program_changed); gboolean _cogl_program_has_fragment_shader (CoglProgram *self); diff --git a/cogl/cogl/deprecated/cogl-program.c b/cogl/cogl/deprecated/cogl-program.c index 9d257fd79cd..de824bb6d08 100644 --- a/cogl/cogl/deprecated/cogl-program.c +++ b/cogl/cogl/deprecated/cogl-program.c @@ -46,8 +46,6 @@ cogl_program_dispose (GObject *object) CoglProgram *program = COGL_PROGRAM (object); int i; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - /* Unref all of the attached shaders and destroy the list */ g_slist_free_full (program->attached_shaders, g_object_unref); @@ -105,8 +103,6 @@ void cogl_program_attach_shader (CoglProgram *program, CoglShader *shader) { - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (!COGL_IS_PROGRAM (program) || !COGL_IS_SHADER (shader)) return; @@ -247,15 +243,14 @@ cogl_program_set_uniform_matrix (CoglProgram *program, } void -_cogl_program_flush_uniforms (CoglProgram *program, +_cogl_program_flush_uniforms (CoglContext *ctx, + CoglProgram *program, GLuint gl_program, gboolean gl_program_changed) { CoglProgramUniform *uniform; int i; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - for (i = 0; i < program->custom_uniforms->len; i++) { uniform = &g_array_index (program->custom_uniforms, diff --git a/cogl/cogl/deprecated/cogl-shader.c b/cogl/cogl/deprecated/cogl-shader.c index 85d4d8ae5e1..0cc43c623ea 100644 --- a/cogl/cogl/deprecated/cogl-shader.c +++ b/cogl/cogl/deprecated/cogl-shader.c @@ -45,10 +45,10 @@ static void cogl_shader_dispose (GObject *object) { CoglShader *shader = COGL_SHADER (object); + CoglContext *ctx = shader->compilation_pipeline->context; /* Frees shader resources but its handle is not released! Do that separately before this! */ - _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (shader->gl_handle) GE (ctx, glDeleteShader (shader->gl_handle)); @@ -74,8 +74,6 @@ cogl_create_shader (CoglShaderType type) { CoglShader *shader; - _COGL_GET_CONTEXT (ctx, NULL); - switch (type) { case COGL_SHADER_TYPE_VERTEX: @@ -101,8 +99,6 @@ cogl_shader_source (CoglShader *self, { g_return_if_fail (COGL_IS_SHADER (self)); - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - self->source = g_strdup (source); } @@ -111,7 +107,5 @@ cogl_shader_get_shader_type (CoglShader *self) { g_return_val_if_fail (COGL_IS_SHADER (self), COGL_SHADER_TYPE_VERTEX); - _COGL_GET_CONTEXT (ctx, COGL_SHADER_TYPE_VERTEX); - return self->type; } diff --git a/cogl/cogl/driver/gl/cogl-pipeline-fragend-glsl.c b/cogl/cogl/driver/gl/cogl-pipeline-fragend-glsl.c index 0a16f46d355..d44ceab6086 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-fragend-glsl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-fragend-glsl.c @@ -149,8 +149,7 @@ destroy_shader_state (void *user_data) { CoglPipelineFragendShaderStateCache *cache = user_data; CoglPipelineFragendShaderState *shader_state = cache->shader_state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = cache->instance->context; if (shader_state->cache_entry && shader_state->cache_entry->pipeline != cache->instance) @@ -297,10 +296,9 @@ _cogl_pipeline_fragend_glsl_start (CoglPipeline *pipeline, CoglPipeline *authority; CoglPipelineCacheEntry *cache_entry = NULL; CoglProgram *user_program = cogl_pipeline_get_user_program (pipeline); + CoglContext *ctx = pipeline->context; int i; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - /* Now lookup our glsl backend private state */ shader_state = get_shader_state (pipeline); @@ -426,8 +424,6 @@ ensure_texture_lookup_generated (CoglPipelineFragendShaderState *shader_state, int unit_index = _cogl_pipeline_layer_get_unit_index (layer); CoglPipelineSnippetData snippet_data; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (shader_state->unit_state[unit_index].sampled) return; @@ -990,8 +986,7 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline, unsigned long pipelines_difference) { CoglPipelineFragendShaderState *shader_state = get_shader_state (pipeline); - - _COGL_GET_CONTEXT (ctx, FALSE); + CoglContext *ctx = pipeline->context; if (shader_state->source) { @@ -1092,7 +1087,7 @@ _cogl_pipeline_fragend_glsl_pre_change_notify (CoglPipeline *pipeline, CoglPipelineState change, const CoglColor *new_color) { - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; if ((change & _cogl_pipeline_get_state_for_fragment_codegen (ctx))) dirty_shader_state (pipeline); @@ -1112,7 +1107,7 @@ _cogl_pipeline_fragend_glsl_layer_pre_change_notify ( CoglPipelineLayer *layer, CoglPipelineLayerState change) { - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = owner->context; if ((change & _cogl_pipeline_get_layer_state_for_fragment_codegen (ctx))) { diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h b/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h index 187baf1a41b..03304772fe3 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h +++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl-private.h @@ -123,20 +123,24 @@ typedef struct _CoglTextureUnit } CoglTextureUnit; CoglTextureUnit * -_cogl_get_texture_unit (int index_); +_cogl_get_texture_unit (CoglContext *ctx, + int index_); void _cogl_destroy_texture_units (CoglContext *ctx); void -_cogl_set_active_texture_unit (int unit_index); +_cogl_set_active_texture_unit (CoglContext *ctx, + int unit_index); void -_cogl_bind_gl_texture_transient (GLenum gl_target, - GLuint gl_texture); +_cogl_bind_gl_texture_transient (CoglContext *ctx, + GLenum gl_target, + GLuint gl_texture); void -_cogl_delete_gl_texture (GLuint gl_texture); +_cogl_delete_gl_texture (CoglContext *ctx, + GLuint gl_texture); void _cogl_pipeline_flush_gl_state (CoglContext *context, diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c index 666d477ad0a..13180ca5cc1 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c @@ -89,9 +89,9 @@ texture_unit_free (CoglTextureUnit *unit) } CoglTextureUnit * -_cogl_get_texture_unit (int index_) +_cogl_get_texture_unit (CoglContext *ctx, + int index_) { - _COGL_GET_CONTEXT (ctx, NULL); CoglGLContext *glctx = _cogl_driver_gl_context(ctx); if (glctx->texture_units->len < (index_ + 1)) @@ -128,9 +128,9 @@ _cogl_destroy_texture_units (CoglContext *ctx) } void -_cogl_set_active_texture_unit (int unit_index) +_cogl_set_active_texture_unit (CoglContext *ctx, + int unit_index) { - _COGL_GET_CONTEXT (ctx, NO_RETVAL); CoglGLContext *glctx = _cogl_driver_gl_context(ctx); if (glctx->active_texture_unit != unit_index) @@ -161,13 +161,12 @@ _cogl_set_active_texture_unit (int unit_index) * CoglTextureUnit. */ void -_cogl_bind_gl_texture_transient (GLenum gl_target, - GLuint gl_texture) +_cogl_bind_gl_texture_transient (CoglContext *ctx, + GLenum gl_target, + GLuint gl_texture) { CoglTextureUnit *unit; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - /* We choose to always make texture unit 1 active for transient * binds so that in the common case where multitexturing isn't used * we can simply ignore the state of this texture unit. Notably we @@ -175,8 +174,8 @@ _cogl_bind_gl_texture_transient (GLenum gl_target, * in case the driver doesn't have a sparse data structure for * texture units. */ - _cogl_set_active_texture_unit (1); - unit = _cogl_get_texture_unit (1); + _cogl_set_active_texture_unit (ctx, 1); + unit = _cogl_get_texture_unit (ctx, 1); if (unit->gl_texture == gl_texture && !unit->dirty_gl_texture) return; @@ -187,11 +186,11 @@ _cogl_bind_gl_texture_transient (GLenum gl_target, } void -_cogl_delete_gl_texture (GLuint gl_texture) +_cogl_delete_gl_texture (CoglContext *ctx, + GLuint gl_texture) { int i; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); CoglGLContext *glctx = _cogl_driver_gl_context(ctx); for (i = 0; i < glctx->texture_units->len; i++) @@ -220,7 +219,7 @@ _cogl_pipeline_texture_storage_change_notify (CoglTexture *texture) { int i; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = cogl_texture_get_context (texture); CoglGLContext *glctx = _cogl_driver_gl_context(ctx); for (i = 0; i < glctx->texture_units->len; i++) @@ -306,7 +305,7 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state ( unsigned long pipelines_difference, gboolean with_color_attrib) { - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; if (pipelines_difference & COGL_PIPELINE_STATE_BLEND) { @@ -410,10 +409,8 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state ( } static int -get_max_activateable_texture_units (void) +get_max_activateable_texture_units (CoglContext *ctx) { - _COGL_GET_CONTEXT (ctx, 0); - if (G_UNLIKELY (ctx->max_activateable_texture_units == -1)) { GLint values[3]; @@ -469,17 +466,16 @@ static gboolean flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data) { CoglPipelineFlushLayerState *flush_state = user_data; - int unit_index = flush_state->i; - CoglTextureUnit *unit = _cogl_get_texture_unit (unit_index); - unsigned long layers_difference = + CoglContext *ctx = layer->owner->context; + int unit_index = flush_state->i; + CoglTextureUnit *unit = _cogl_get_texture_unit (ctx, unit_index); + unsigned long layers_difference = flush_state->layer_differences[unit_index]; - _COGL_GET_CONTEXT (ctx, FALSE); - /* There may not be enough texture units so we can bail out if * that's the case... */ - if (G_UNLIKELY (unit_index >= get_max_activateable_texture_units ())) + if (G_UNLIKELY (unit_index >= get_max_activateable_texture_units (ctx))) { static gboolean shown_warning = FALSE; @@ -505,7 +501,7 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data) &gl_texture, &gl_target); - _cogl_set_active_texture_unit (unit_index); + _cogl_set_active_texture_unit (ctx, unit_index); /* NB: There are several Cogl components and some code in * Clutter that will temporarily bind arbitrary GL textures to @@ -579,8 +575,6 @@ _cogl_pipeline_flush_common_gl_state (CoglPipeline *pipeline, { CoglPipelineFlushLayerState state; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - _cogl_pipeline_flush_color_blend_alpha_depth_state (pipeline, pipelines_difference, with_color_attrib); @@ -706,11 +700,10 @@ _cogl_sampler_gl_free (CoglContext *context, CoglSamplerCacheEntry *entry) * state. */ static void -foreach_texture_unit_update_filter_and_wrap_modes (void) +foreach_texture_unit_update_filter_and_wrap_modes (CoglContext *ctx) { int i; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); CoglGLContext *glctx = _cogl_driver_gl_context(ctx); for (i = 0; i < glctx->texture_units->len; i++) @@ -746,7 +739,8 @@ static gboolean compare_layer_differences_cb (CoglPipelineLayer *layer, void *user_data) { CoglPipelineCompareLayersState *state = user_data; - CoglTextureUnit *unit = _cogl_get_texture_unit (state->i); + CoglContext *ctx = layer->owner->context; + CoglTextureUnit *unit = _cogl_get_texture_unit (ctx, state->i); if (unit->layer == layer) state->layer_differences[state->i] = unit->layer_changes_since_flush; @@ -1137,7 +1131,7 @@ done: /* Handle the fact that OpenGL associates texture filter and wrap * modes with the texture objects not the texture units... */ if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_SAMPLER_OBJECTS)) - foreach_texture_unit_update_filter_and_wrap_modes (); + foreach_texture_unit_update_filter_and_wrap_modes (ctx); /* If this pipeline has more than one layer then we always need * to make sure we rebind the texture for unit 1. @@ -1147,10 +1141,10 @@ done: * object parameters. cogl-pipeline.c (See * _cogl_bind_gl_texture_transient) */ - unit1 = _cogl_get_texture_unit (1); + unit1 = _cogl_get_texture_unit (ctx, 1); if (cogl_pipeline_get_n_layers (pipeline) > 1 && unit1->dirty_gl_texture) { - _cogl_set_active_texture_unit (1); + _cogl_set_active_texture_unit (ctx, 1); GE (ctx, glBindTexture (unit1->gl_target, unit1->gl_texture)); unit1->dirty_gl_texture = FALSE; } diff --git a/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c b/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c index 59159d1712e..9532b604ab3 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-progend-glsl.c @@ -188,8 +188,7 @@ _cogl_pipeline_progend_glsl_get_attrib_location (CoglPipeline *pipeline, { CoglPipelineProgramState *program_state = get_program_state (pipeline); int *locations; - - _COGL_GET_CONTEXT (ctx, -1); + CoglContext *ctx = pipeline->context; g_return_val_if_fail (program_state != NULL, -1); g_return_val_if_fail (program_state->program != 0, -1); @@ -268,8 +267,7 @@ destroy_program_state (void *user_data) { CoglPipelineProgramStateCache *cache = user_data; CoglPipelineProgramState *program_state = cache->program_state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = cache->instance->context; /* If the program state was last used for this pipeline then clear it so that if same address gets used again for a new pipeline @@ -338,12 +336,11 @@ dirty_program_state (CoglPipeline *pipeline) } static void -link_program (GLint gl_program) +link_program (CoglContext *ctx, + GLint gl_program) { GLint link_status; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - GE( ctx, glLinkProgram (gl_program) ); GE( ctx, glGetProgramiv (gl_program, GL_LINK_STATUS, &link_status) ); @@ -385,8 +382,7 @@ get_uniform_cb (CoglPipeline *pipeline, CoglPipelineProgramState *program_state = state->program_state; UnitState *unit_state = &program_state->unit_state[state->unit]; GLint uniform_location; - - _COGL_GET_CONTEXT (ctx, FALSE); + CoglContext *ctx = pipeline->context; /* We can reuse the source buffer to create the uniform name because the program has now been linked */ @@ -438,8 +434,7 @@ update_constants_cb (CoglPipeline *pipeline, UpdateUniformsState *state = user_data; CoglPipelineProgramState *program_state = state->program_state; UnitState *unit_state = &program_state->unit_state[state->unit++]; - - _COGL_GET_CONTEXT (ctx, FALSE); + CoglContext *ctx = pipeline->context; if (unit_state->combine_constant_uniform != -1 && (state->update_all || unit_state->dirty_combine_constant)) @@ -569,8 +564,7 @@ _cogl_pipeline_progend_glsl_flush_uniforms (CoglPipeline *pipeline, CoglPipelineUniformsState *uniforms_state; FlushUniformsClosure data; int n_uniform_longs; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; if (pipeline->differences & COGL_PIPELINE_STATE_UNIFORMS) uniforms_state = &pipeline->big_state->uniforms_state; @@ -664,8 +658,7 @@ _cogl_shader_compile_real (CoglShader *shader, { GLenum gl_type; GLint status; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; if (shader->gl_handle) { @@ -743,8 +736,7 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline, UpdateUniformsState state; CoglProgram *user_program; CoglPipelineCacheEntry *cache_entry = NULL; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; program_state = get_program_state (pipeline); @@ -845,7 +837,7 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline, GE( ctx, glBindAttribLocation (program_state->program, 0, "cogl_position_in")); - link_program (program_state->program); + link_program (ctx, program_state->program); program_changed = TRUE; } @@ -925,7 +917,7 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline, program_changed); if (user_program) - _cogl_program_flush_uniforms (user_program, + _cogl_program_flush_uniforms (ctx, user_program, gl_program, program_changed); @@ -939,7 +931,7 @@ _cogl_pipeline_progend_glsl_pre_change_notify (CoglPipeline *pipeline, CoglPipelineState change, const CoglColor *new_color) { - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; if ((change & (_cogl_pipeline_get_state_for_vertex_codegen (ctx) | _cogl_pipeline_get_state_for_fragment_codegen (ctx)))) @@ -976,8 +968,8 @@ _cogl_pipeline_progend_glsl_layer_pre_change_notify ( CoglPipelineLayer *layer, CoglPipelineLayerState change) { - _COGL_GET_CONTEXT (ctx, NO_RETVAL); CoglTextureUnit *unit; + CoglContext *ctx = owner->context; if ((change & (_cogl_pipeline_get_layer_state_for_fragment_codegen (ctx) | COGL_PIPELINE_LAYER_STATE_AFFECTS_VERTEX_CODEGEN))) @@ -1008,7 +1000,7 @@ _cogl_pipeline_progend_glsl_layer_pre_change_notify ( * the changes so we can try to minimize redundant OpenGL calls if * the same layer is flushed again. */ - unit = _cogl_get_texture_unit (_cogl_pipeline_layer_get_unit_index (layer)); + unit = _cogl_get_texture_unit (ctx, _cogl_pipeline_layer_get_unit_index (layer)); if (unit->layer == layer) unit->layer_changes_since_flush |= change; } @@ -1026,8 +1018,7 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline, gboolean need_modelview; gboolean need_projection; graphene_matrix_t modelview, projection; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; program_state = get_program_state (pipeline); @@ -1152,8 +1143,7 @@ update_float_uniform (CoglPipeline *pipeline, { float (* float_getter_func) (CoglPipeline *) = getter_func; float value; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; value = float_getter_func (pipeline); GE( ctx, glUniform1f (uniform_location, value) ); diff --git a/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c b/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c index 9311c878f14..dd9161e5ba5 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-vertend-glsl.c @@ -108,8 +108,7 @@ destroy_shader_state (void *user_data) { CoglPipelineVertendShaderStateCache *cache = user_data; CoglPipelineVertendShaderState *shader_state = cache->shader_state; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = cache->instance->context; if (shader_state->cache_entry && shader_state->cache_entry->pipeline != cache->instance) @@ -390,8 +389,7 @@ _cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline, CoglPipelineVertendShaderState *shader_state; CoglPipelineCacheEntry *cache_entry = NULL; CoglProgram *user_program = cogl_pipeline_get_user_program (pipeline); - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; /* Now lookup our glsl backend private state (allocating if * necessary) */ @@ -513,8 +511,6 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline, CoglPipelineSnippetData snippet_data; int layer_index = layer->index; - _COGL_GET_CONTEXT (ctx, FALSE); - shader_state = get_shader_state (pipeline); if (shader_state->source == NULL) @@ -581,8 +577,7 @@ _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline, unsigned long pipelines_difference) { CoglPipelineVertendShaderState *shader_state; - - _COGL_GET_CONTEXT (ctx, FALSE); + CoglContext *ctx = pipeline->context; shader_state = get_shader_state (pipeline); @@ -728,7 +723,7 @@ _cogl_pipeline_vertend_glsl_pre_change_notify (CoglPipeline *pipeline, CoglPipelineState change, const CoglColor *new_color) { - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglContext *ctx = pipeline->context; if ((change & _cogl_pipeline_get_state_for_vertex_codegen (ctx))) dirty_shader_state (pipeline); diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c index e2bb41c78e5..dc33f0d31c4 100644 --- a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c @@ -63,7 +63,8 @@ void _cogl_texture_2d_gl_free (CoglTexture2D *tex_2d) { if (tex_2d->gl_texture) - _cogl_delete_gl_texture (tex_2d->gl_texture); + _cogl_delete_gl_texture (cogl_texture_get_context (COGL_TEXTURE (tex_2d)), + tex_2d->gl_texture); #if defined (HAVE_EGL) g_clear_pointer (&tex_2d->egl_image_external.user_data, @@ -161,7 +162,7 @@ allocate_with_size (CoglTexture2D *tex_2d, tex_2d->gl_internal_format = gl_intformat; - _cogl_bind_gl_texture_transient (GL_TEXTURE_2D, + _cogl_bind_gl_texture_transient (ctx, GL_TEXTURE_2D, gl_texture); /* Clear any GL errors */ @@ -358,7 +359,7 @@ cogl_texture_2d_gl_bind_egl_image (CoglTexture2D *tex_2d, { CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d)); - _cogl_bind_gl_texture_transient (GL_TEXTURE_2D, + _cogl_bind_gl_texture_transient (ctx, GL_TEXTURE_2D, tex_2d->gl_texture); _cogl_gl_util_clear_gl_errors (ctx); @@ -464,7 +465,7 @@ _cogl_texture_2d_gl_flush_legacy_texobj_filters (CoglTexture *tex, tex_2d->gl_legacy_texobj_mag_filter = mag_filter; /* Apply new filters to the texture */ - _cogl_bind_gl_texture_transient (GL_TEXTURE_2D, + _cogl_bind_gl_texture_transient (ctx, GL_TEXTURE_2D, tex_2d->gl_texture); GE( ctx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter) ); GE( ctx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter) ); @@ -493,7 +494,7 @@ _cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex, if (tex_2d->gl_legacy_texobj_wrap_mode_s != wrap_mode_s || tex_2d->gl_legacy_texobj_wrap_mode_t != wrap_mode_t) { - _cogl_bind_gl_texture_transient (GL_TEXTURE_2D, + _cogl_bind_gl_texture_transient (ctx, GL_TEXTURE_2D, tex_2d->gl_texture); GE( ctx, glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, @@ -530,7 +531,7 @@ _cogl_texture_2d_gl_copy_from_framebuffer (CoglTexture2D *tex_2d, (COGL_FRAMEBUFFER_STATE_ALL & ~COGL_FRAMEBUFFER_STATE_CLIP)); - _cogl_bind_gl_texture_transient (GL_TEXTURE_2D, + _cogl_bind_gl_texture_transient (ctx, GL_TEXTURE_2D, tex_2d->gl_texture); ctx->glCopyTexSubImage2D (GL_TEXTURE_2D, @@ -645,7 +646,7 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d, width, bpp); - _cogl_bind_gl_texture_transient (tex_2d->gl_target, + _cogl_bind_gl_texture_transient (ctx, tex_2d->gl_target, tex_2d->gl_texture); ctx->texture_driver->gl_get_tex_image (ctx, diff --git a/cogl/cogl/driver/gl/cogl-texture-gl.c b/cogl/cogl/driver/gl/cogl-texture-gl.c index c90835df4ae..60396b38504 100644 --- a/cogl/cogl/driver/gl/cogl-texture-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-gl.c @@ -122,7 +122,7 @@ cogl_texture_gl_set_max_level (CoglTexture *texture, cogl_texture_set_max_level_set (texture, max_level); - _cogl_bind_gl_texture_transient (gl_target, + _cogl_bind_gl_texture_transient (ctx, gl_target, gl_handle); GE( ctx, glTexParameteri (gl_target, @@ -143,7 +143,7 @@ _cogl_texture_gl_generate_mipmaps (CoglTexture *texture) cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target); - _cogl_bind_gl_texture_transient (gl_target, + _cogl_bind_gl_texture_transient (ctx, gl_target, gl_handle); GE( ctx, glGenerateMipmap (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 dd19d956bf2..c78d48e3f48 100644 --- a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c @@ -64,7 +64,7 @@ _cogl_texture_driver_gen (CoglContext *ctx, GE (ctx, glGenTextures (1, &tex)); - _cogl_bind_gl_texture_transient (gl_target, tex); + _cogl_bind_gl_texture_transient (ctx, gl_target, tex); switch (gl_target) { @@ -213,7 +213,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx, src_y, bpp); - _cogl_bind_gl_texture_transient (gl_target, gl_handle); + _cogl_bind_gl_texture_transient (ctx, gl_target, gl_handle); /* Clear any GL errors */ _cogl_gl_util_clear_gl_errors (ctx); @@ -320,7 +320,7 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx, cogl_bitmap_get_rowstride (source_bmp), 0, 0, 0, bpp); - _cogl_bind_gl_texture_transient (gl_target, gl_handle); + _cogl_bind_gl_texture_transient (ctx, gl_target, gl_handle); /* Clear any GL errors */ _cogl_gl_util_clear_gl_errors (ctx); 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 72d8155d0ef..4737ed131e0 100644 --- a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c @@ -79,7 +79,7 @@ _cogl_texture_driver_gen (CoglContext *ctx, GE (ctx, glGenTextures (1, &tex)); - _cogl_bind_gl_texture_transient (gl_target, tex); + _cogl_bind_gl_texture_transient (ctx, gl_target, tex); switch (gl_target) { @@ -267,7 +267,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx, return FALSE; } - _cogl_bind_gl_texture_transient (gl_target, gl_handle); + _cogl_bind_gl_texture_transient (ctx, gl_target, gl_handle); /* Clear any GL errors */ _cogl_gl_util_clear_gl_errors (ctx); @@ -369,7 +369,7 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx, /* Setup gl alignment to match rowstride and top-left corner */ _cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp); - _cogl_bind_gl_texture_transient (gl_target, gl_handle); + _cogl_bind_gl_texture_transient (ctx, gl_target, gl_handle); data = _cogl_bitmap_gl_bind (bmp, COGL_BUFFER_ACCESS_READ, diff --git a/cogl/cogl/winsys/cogl-winsys-glx.c b/cogl/cogl/winsys/cogl-winsys-glx.c index 67af975e45f..3799fe70c95 100644 --- a/cogl/cogl/winsys/cogl-winsys-glx.c +++ b/cogl/cogl/winsys/cogl-winsys-glx.c @@ -1329,7 +1329,7 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap, COGL_NOTE (TEXTURE_PIXMAP, "Rebinding GLXPixmap for %p", tex_pixmap); - _cogl_bind_gl_texture_transient (gl_target, gl_handle); + _cogl_bind_gl_texture_transient (ctx, gl_target, gl_handle); if (texture_info->pixmap_bound) glx_renderer->glXReleaseTexImage (xlib_renderer->xdpy, -- GitLab From 194fa80cddddf4ebdfad68e5846c1a6f86e07317 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 29 Jun 2024 15:07:44 +0200 Subject: [PATCH 03/10] cogl: Pass a Context param to winsys_has_feature Avoids using the global variable Part-of: --- cogl/cogl/cogl-context.c | 8 ++++ cogl/cogl/cogl-context.h | 4 ++ cogl/cogl/cogl-onscreen.c | 8 ++-- cogl/cogl/cogl.h | 3 -- cogl/cogl/deprecated/cogl-clutter.c | 53 -------------------------- cogl/cogl/deprecated/cogl-clutter.h | 41 -------------------- cogl/cogl/meson.build | 2 - cogl/cogl/winsys/cogl-onscreen-glx.c | 8 ++-- cogl/cogl/winsys/cogl-winsys-glx.c | 8 ++-- cogl/cogl/winsys/cogl-winsys-private.h | 3 -- cogl/cogl/winsys/cogl-winsys.c | 9 ----- src/backends/meta-stage-impl.c | 6 ++- 12 files changed, 29 insertions(+), 124 deletions(-) delete mode 100644 cogl/cogl/deprecated/cogl-clutter.c delete mode 100644 cogl/cogl/deprecated/cogl-clutter.h diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index 4a352938b37..12dbd006e41 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -567,3 +567,11 @@ cogl_context_get_gpu_time_ns (CoglContext *context) return context->driver_vtable->get_gpu_time_ns (context); } + +/* FIXME: we should distinguish renderer and context features */ +gboolean +cogl_context_has_winsys_feature (CoglContext *context, + CoglWinsysFeature feature) +{ + return COGL_FLAGS_GET (context->winsys_features, feature); +} diff --git a/cogl/cogl/cogl-context.h b/cogl/cogl/cogl-context.h index f6e383e9ad6..36ed708449e 100644 --- a/cogl/cogl/cogl-context.h +++ b/cogl/cogl/cogl-context.h @@ -342,4 +342,8 @@ cogl_context_get_gpu_time_ns (CoglContext *context); COGL_EXPORT int cogl_context_get_latest_sync_fd (CoglContext *context); +COGL_EXPORT gboolean +cogl_context_has_winsys_feature (CoglContext *context, + CoglWinsysFeature feature); + G_END_DECLS diff --git a/cogl/cogl/cogl-onscreen.c b/cogl/cogl/cogl-onscreen.c index 71a9367224d..4780c45f1fd 100644 --- a/cogl/cogl/cogl-onscreen.c +++ b/cogl/cogl/cogl-onscreen.c @@ -334,7 +334,7 @@ cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen, info, user_data); - if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) + if (!cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) { g_autoptr (CoglFrameInfo) pending_info = NULL; @@ -367,6 +367,7 @@ cogl_onscreen_swap_region (CoglOnscreen *onscreen, CoglOnscreenPrivate *priv = cogl_onscreen_get_instance_private (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglOnscreenClass *klass = COGL_ONSCREEN_GET_CLASS (onscreen); + CoglContext *context = cogl_framebuffer_get_context (framebuffer); g_return_if_fail (COGL_IS_ONSCREEN (framebuffer)); @@ -392,7 +393,7 @@ cogl_onscreen_swap_region (CoglOnscreen *onscreen, info, user_data); - if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) + if (!cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) { g_autoptr (CoglFrameInfo) pending_info = NULL; @@ -431,9 +432,10 @@ cogl_onscreen_direct_scanout (CoglOnscreen *onscreen, CoglOnscreenPrivate *priv = cogl_onscreen_get_instance_private (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglOnscreenClass *klass = COGL_ONSCREEN_GET_CLASS (onscreen); + CoglContext *context = cogl_framebuffer_get_context (framebuffer); g_warn_if_fail (COGL_IS_ONSCREEN (framebuffer)); - g_warn_if_fail (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)); + g_warn_if_fail (cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)); if (!klass->direct_scanout) { diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h index 652bc894396..983e0770aac 100644 --- a/cogl/cogl/cogl.h +++ b/cogl/cogl/cogl.h @@ -92,9 +92,6 @@ #include "cogl/cogl-trace.h" #include "cogl/cogl-scanout.h" #include "cogl/cogl-graphene.h" -/* XXX: This will definitely go away once all the Clutter winsys - * code has been migrated down into Cogl! */ -#include "cogl/deprecated/cogl-clutter.h" /* The gobject introspection scanner seems to parse public headers in * isolation which means we need to be extra careful about how we diff --git a/cogl/cogl/deprecated/cogl-clutter.c b/cogl/cogl/deprecated/cogl-clutter.c deleted file mode 100644 index f1fc685b12a..00000000000 --- a/cogl/cogl/deprecated/cogl-clutter.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Cogl - * - * A Low Level GPU Graphics and Utilities API - * - * Copyright (C) 2011 Intel Corporation. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Robert Bragg - */ - -#include "config.h" - -#include -#include - -#include "cogl/cogl-util.h" -#include "cogl/cogl-types.h" -#include "cogl/cogl-private.h" -#include "cogl/cogl-context-private.h" -#include "cogl/cogl-framebuffer-private.h" -#include "cogl/cogl-onscreen-private.h" -#ifdef HAVE_X11 -#include "cogl/cogl-xlib-renderer.h" -#endif -#include "cogl/winsys/cogl-winsys-private.h" -#include "cogl/deprecated/cogl-clutter.h" - -gboolean -cogl_clutter_winsys_has_feature (CoglWinsysFeature feature) -{ - return _cogl_winsys_has_feature (feature); -} diff --git a/cogl/cogl/deprecated/cogl-clutter.h b/cogl/cogl/deprecated/cogl-clutter.h deleted file mode 100644 index 604ad3f3a22..00000000000 --- a/cogl/cogl/deprecated/cogl-clutter.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Cogl - * - * A Low Level GPU Graphics and Utilities API - * - * Copyright (C) 2011 Intel Corporation. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION) -#error "Only can be included directly." -#endif - -G_BEGIN_DECLS - -COGL_DEPRECATED_FOR (cogl_has_feature) -COGL_EXPORT gboolean -cogl_clutter_winsys_has_feature (CoglWinsysFeature feature); - -G_END_DECLS diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build index 604a9a361f4..08431c7f1c2 100644 --- a/cogl/cogl/meson.build +++ b/cogl/cogl/meson.build @@ -16,7 +16,6 @@ endif cogl_deprecated_headers = [ 'deprecated/cogl-program.h', 'deprecated/cogl-shader.h', - 'deprecated/cogl-clutter.h', ] cogl_headers = [ @@ -283,7 +282,6 @@ cogl_sources = [ 'cogl-util.c', 'cogl-util.h', 'cogl.c', - 'deprecated/cogl-clutter.c', 'deprecated/cogl-program-private.h', 'deprecated/cogl-program.c', 'deprecated/cogl-shader-private.h', diff --git a/cogl/cogl/winsys/cogl-onscreen-glx.c b/cogl/cogl/winsys/cogl-onscreen-glx.c index acb5110064b..eb11ea06916 100644 --- a/cogl/cogl/winsys/cogl-onscreen-glx.c +++ b/cogl/cogl/winsys/cogl-onscreen-glx.c @@ -192,7 +192,7 @@ cogl_onscreen_glx_allocate (CoglFramebuffer *framebuffer, } #ifdef GLX_INTEL_swap_event - if (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) + if (cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) { GLXDrawable drawable = onscreen_glx->glxwin ? onscreen_glx->glxwin : onscreen_glx->xwin; @@ -530,7 +530,7 @@ cogl_onscreen_glx_get_buffer_age (CoglOnscreen *onscreen) GLXDrawable drawable; unsigned int age = 0; - if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_BUFFER_AGE)) + if (!cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_BUFFER_AGE)) return 0; cogl_onscreen_bind (onscreen); @@ -677,7 +677,7 @@ cogl_onscreen_glx_swap_region (CoglOnscreen *onscreen, * we only need it to throttle redraws. */ gboolean blit_sub_buffer_is_synchronized = - _cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_REGION_SYNCHRONIZED); + cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SWAP_REGION_SYNCHRONIZED); int framebuffer_width = cogl_framebuffer_get_width (framebuffer); int framebuffer_height = cogl_framebuffer_get_height (framebuffer); @@ -844,7 +844,7 @@ cogl_onscreen_glx_swap_region (CoglOnscreen *onscreen, * handling _SYNC and _COMPLETE events in the winsys then we need to * send fake events in this case. */ - if (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) + if (cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) { set_sync_pending (onscreen); set_complete_pending (onscreen); diff --git a/cogl/cogl/winsys/cogl-winsys-glx.c b/cogl/cogl/winsys/cogl-winsys-glx.c index 3799fe70c95..a6851ce5331 100644 --- a/cogl/cogl/winsys/cogl-winsys-glx.c +++ b/cogl/cogl/winsys/cogl-winsys-glx.c @@ -473,12 +473,12 @@ update_winsys_features (CoglContext *context, GError **error) /* Note: glXCopySubBuffer and glBlitFramebuffer won't be throttled * by the SwapInterval so we have to throttle swap_region requests * manually... */ - if (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_REGION) && + if (cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SWAP_REGION) && (glx_display->have_vblank_counter || glx_display->can_vblank_wait)) COGL_FLAGS_SET (context->winsys_features, COGL_WINSYS_FEATURE_SWAP_REGION_THROTTLE, TRUE); - if (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) + if (cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)) { COGL_FLAGS_SET (context->winsys_features, COGL_WINSYS_FEATURE_SWAP_BUFFERS_EVENT, TRUE); @@ -490,7 +490,7 @@ update_winsys_features (CoglContext *context, GError **error) COGL_PRIVATE_FEATURE_DIRTY_EVENTS, TRUE); - if (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_BUFFER_AGE)) + if (cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_BUFFER_AGE)) COGL_FLAGS_SET (context->features, COGL_FEATURE_ID_BUFFER_AGE, TRUE); return TRUE; @@ -1123,7 +1123,7 @@ _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap) CoglTexturePixmapGLX *glx_tex_pixmap; CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_pixmap)); - if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_TEXTURE_FROM_PIXMAP)) + if (!cogl_context_has_winsys_feature (ctx, COGL_WINSYS_FEATURE_TEXTURE_FROM_PIXMAP)) { tex_pixmap->winsys = NULL; return FALSE; diff --git a/cogl/cogl/winsys/cogl-winsys-private.h b/cogl/cogl/winsys/cogl-winsys-private.h index c7670b0f458..21ac6113eac 100644 --- a/cogl/cogl/winsys/cogl-winsys-private.h +++ b/cogl/cogl/winsys/cogl-winsys-private.h @@ -135,6 +135,3 @@ typedef struct _CoglWinsysVtable } CoglWinsysVtable; typedef const CoglWinsysVtable *(*CoglWinsysVtableGetter) (void); - -gboolean -_cogl_winsys_has_feature (CoglWinsysFeature feature); diff --git a/cogl/cogl/winsys/cogl-winsys.c b/cogl/cogl/winsys/cogl-winsys.c index 687dbd0d62a..5b29ae70326 100644 --- a/cogl/cogl/winsys/cogl-winsys.c +++ b/cogl/cogl/winsys/cogl-winsys.c @@ -39,12 +39,3 @@ _cogl_winsys_error_quark (void) { return g_quark_from_static_string ("cogl-winsys-error-quark"); } - -/* FIXME: we should distinguish renderer and context features */ -gboolean -_cogl_winsys_has_feature (CoglWinsysFeature feature) -{ - _COGL_GET_CONTEXT (ctx, FALSE); - - return COGL_FLAGS_GET (ctx->winsys_features, feature); -} diff --git a/src/backends/meta-stage-impl.c b/src/backends/meta-stage-impl.c index 552cc1637cb..a633d0b08e2 100644 --- a/src/backends/meta-stage-impl.c +++ b/src/backends/meta-stage-impl.c @@ -472,6 +472,7 @@ should_use_clipped_redraw (gboolean is_full_redraw, gboolean can_blit_sub_buffer; gboolean can_use_clipped_redraw; gboolean is_warmed_up; + CoglContext *context = cogl_framebuffer_get_context (framebuffer); if (is_full_redraw) return FALSE; @@ -490,7 +491,7 @@ should_use_clipped_redraw (gboolean is_full_redraw, } can_blit_sub_buffer = - cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_SWAP_REGION); + cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_SWAP_REGION); can_use_clipped_redraw = _clutter_stage_window_can_clip_redraws (stage_window) && (can_blit_sub_buffer || has_buffer_age); @@ -509,6 +510,7 @@ meta_stage_impl_redraw_view_primary (MetaStageImpl *stage_impl, ClutterStageWindow *stage_window = CLUTTER_STAGE_WINDOW (stage_impl); MetaStageView *view = META_STAGE_VIEW (stage_view); CoglFramebuffer *fb = clutter_stage_view_get_framebuffer (stage_view); + CoglContext *context = cogl_framebuffer_get_context (fb); CoglFramebuffer *onscreen = clutter_stage_view_get_onscreen (stage_view); MtkRectangle view_rect; gboolean is_full_redraw; @@ -536,7 +538,7 @@ meta_stage_impl_redraw_view_primary (MetaStageImpl *stage_impl, has_buffer_age = COGL_IS_ONSCREEN (onscreen) && - cogl_clutter_winsys_has_feature (COGL_WINSYS_FEATURE_BUFFER_AGE); + cogl_context_has_winsys_feature (context, COGL_WINSYS_FEATURE_BUFFER_AGE); redraw_clip = clutter_stage_view_take_accumulated_redraw_clip (stage_view); -- GitLab From b3ae93430489793283bb9e7ee7142a20a0a43f7a Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 29 Jun 2024 15:20:14 +0200 Subject: [PATCH 04/10] cogl: Pass Context to cogl_flush Avoids using the global variable & also move the function to it proper context Part-of: --- cogl/cogl/cogl-atlas-texture.c | 6 +++-- cogl/cogl/cogl-context.c | 9 ++++++++ cogl/cogl/cogl-context.h | 27 +++++++++++++++++++++++ cogl/cogl/cogl-pipeline.c | 2 +- cogl/cogl/cogl.c | 11 --------- cogl/cogl/cogl1-context.h | 26 ---------------------- src/compositor/meta-surface-actor-x11.c | 6 ++++- src/tests/cogl/conform/test-sub-texture.c | 2 +- 8 files changed, 47 insertions(+), 42 deletions(-) diff --git a/cogl/cogl/cogl-atlas-texture.c b/cogl/cogl/cogl-atlas-texture.c index 731a0b9fe29..40ceae08f8b 100644 --- a/cogl/cogl/cogl-atlas-texture.c +++ b/cogl/cogl/cogl-atlas-texture.c @@ -139,7 +139,7 @@ _cogl_atlas_texture_pre_reorganize_cb (void *data) * We are assuming that texture atlas migration never happens * during a flush so we don't have to consider recursion here. */ - cogl_flush (); + cogl_context_flush (atlas->context); if (atlas->map) _cogl_rectangle_map_foreach (atlas->map, @@ -336,11 +336,13 @@ static void _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex) { CoglTexture *standalone_tex; + CoglContext *ctx; /* Make sure this texture is not in the atlas */ if (!atlas_tex->atlas) return; + ctx = cogl_texture_get_context (COGL_TEXTURE (atlas_tex)); COGL_NOTE (ATLAS, "Migrating texture out of the atlas"); /* We don't know if any journal entries currently depend on @@ -351,7 +353,7 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex) * We are assuming that texture atlas migration never happens * during a flush so we don't have to consider recursion here. */ - cogl_flush (); + cogl_context_flush (ctx); standalone_tex = _cogl_atlas_copy_rectangle (atlas_tex->atlas, diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index 12dbd006e41..04a8ae0a6c7 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -575,3 +575,12 @@ cogl_context_has_winsys_feature (CoglContext *context, { return COGL_FLAGS_GET (context->winsys_features, feature); } + +void +cogl_context_flush (CoglContext *context) +{ + GList *l; + + for (l = context->framebuffers; l; l = l->next) + _cogl_framebuffer_flush_journal (l->data); +} diff --git a/cogl/cogl/cogl-context.h b/cogl/cogl/cogl-context.h index 36ed708449e..fcc32a16910 100644 --- a/cogl/cogl/cogl-context.h +++ b/cogl/cogl/cogl-context.h @@ -345,5 +345,32 @@ cogl_context_get_latest_sync_fd (CoglContext *context); COGL_EXPORT gboolean cogl_context_has_winsys_feature (CoglContext *context, CoglWinsysFeature feature); +/** + * cogl_context_flush: + * @context: A #CoglContext + * + * This function should only need to be called in exceptional circumstances. + * + * As an optimization Cogl drawing functions may batch up primitives + * internally, so if you are trying to use raw GL outside of Cogl you stand a + * better chance of being successful if you ask Cogl to flush any batched + * geometry before making your state changes. + * + * It only ensure that the underlying driver is issued all the commands + * necessary to draw the batched primitives. It provides no guarantees about + * when the driver will complete the rendering. + * + * This provides no guarantees about the GL state upon returning and to avoid + * confusing Cogl you should aim to restore any changes you make before + * resuming use of Cogl. + * + * If you are making state changes with the intention of affecting Cogl drawing + * primitives you are 100% on your own since you stand a good chance of + * conflicting with Cogl internals. For example clutter-gst which currently + * uses direct GL calls to bind ARBfp programs will very likely break when Cogl + * starts to use ARBfb programs itself for the material API. + */ +COGL_EXPORT void +cogl_context_flush (CoglContext *context); G_END_DECLS diff --git a/cogl/cogl/cogl-pipeline.c b/cogl/cogl/cogl-pipeline.c index 4f33c40550d..e5b9764a0f5 100644 --- a/cogl/cogl/cogl-pipeline.c +++ b/cogl/cogl/cogl-pipeline.c @@ -1084,7 +1084,7 @@ _cogl_pipeline_pre_change_notify (CoglPipeline *pipeline, /* XXX: note we use cogl_flush() not _cogl_flush_journal() so * we will flush *all* known journals that might reference the * current pipeline. */ - cogl_flush (); + cogl_context_flush (pipeline->context); } } diff --git a/cogl/cogl/cogl.c b/cogl/cogl/cogl.c index 40c85706cf0..626dae97629 100644 --- a/cogl/cogl/cogl.c +++ b/cogl/cogl/cogl.c @@ -80,17 +80,6 @@ cogl_has_feature (CoglContext *ctx, CoglFeatureID feature) return COGL_FLAGS_GET (ctx->features, feature); } -void -cogl_flush (void) -{ - GList *l; - - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - - for (l = ctx->framebuffers; l; l = l->next) - _cogl_framebuffer_flush_journal (l->data); -} - uint32_t _cogl_driver_error_quark (void) { diff --git a/cogl/cogl/cogl1-context.h b/cogl/cogl/cogl1-context.h index 9164ea7fe77..6b7996f38b5 100644 --- a/cogl/cogl/cogl1-context.h +++ b/cogl/cogl/cogl1-context.h @@ -62,31 +62,5 @@ G_BEGIN_DECLS COGL_EXPORT GCallback cogl_get_proc_address (const char *name); -/** - * cogl_flush: - * - * This function should only need to be called in exceptional circumstances. - * - * As an optimization Cogl drawing functions may batch up primitives - * internally, so if you are trying to use raw GL outside of Cogl you stand a - * better chance of being successful if you ask Cogl to flush any batched - * geometry before making your state changes. - * - * It only ensure that the underlying driver is issued all the commands - * necessary to draw the batched primitives. It provides no guarantees about - * when the driver will complete the rendering. - * - * This provides no guarantees about the GL state upon returning and to avoid - * confusing Cogl you should aim to restore any changes you make before - * resuming use of Cogl. - * - * If you are making state changes with the intention of affecting Cogl drawing - * primitives you are 100% on your own since you stand a good chance of - * conflicting with Cogl internals. For example clutter-gst which currently - * uses direct GL calls to bind ARBfp programs will very likely break when Cogl - * starts to use ARBfb programs itself for the material API. - */ -COGL_EXPORT void -cogl_flush (void); G_END_DECLS diff --git a/src/compositor/meta-surface-actor-x11.c b/src/compositor/meta-surface-actor-x11.c index 346e1c502f0..95436131615 100644 --- a/src/compositor/meta-surface-actor-x11.c +++ b/src/compositor/meta-surface-actor-x11.c @@ -88,6 +88,10 @@ detach_pixmap (MetaSurfaceActorX11 *self) { MetaDisplay *display = self->display; MetaShapedTexture *stex = meta_surface_actor_get_texture (META_SURFACE_ACTOR (self)); + MetaContext *context = meta_display_get_context (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); Display *xdisplay; if (self->pixmap == None) @@ -100,7 +104,7 @@ detach_pixmap (MetaSurfaceActorX11 *self) * pixmap, but it certainly doesn't work with current DRI/Mesa */ meta_shaped_texture_set_texture (stex, NULL); - cogl_flush (); + cogl_context_flush (cogl_context); mtk_x11_error_trap_push (xdisplay); XFreePixmap (xdisplay, self->pixmap); diff --git a/src/tests/cogl/conform/test-sub-texture.c b/src/tests/cogl/conform/test-sub-texture.c index 5f0a50ac460..7587517b370 100644 --- a/src/tests/cogl/conform/test-sub-texture.c +++ b/src/tests/cogl/conform/test-sub-texture.c @@ -211,7 +211,7 @@ validate_result (TestState *state) /* Sub sub texture */ p = texture_data = g_malloc (10 * 10 * 4); - cogl_flush (); + cogl_context_flush (cogl_framebuffer_get_context (test_fb)); cogl_framebuffer_read_pixels (test_fb, 0, SOURCE_SIZE * 2, 10, 10, COGL_PIXEL_FORMAT_RGBA_8888, -- GitLab From 9ee1a0fc342e1aaed130f985137d9c74bf7af2b4 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sat, 29 Jun 2024 16:25:22 +0200 Subject: [PATCH 05/10] cogl: Expose Renderer.get_proc_address Allows to get rid of the cogl_get_proc_address Part-of: --- cogl/cogl/cogl-atlas-texture.c | 1 - cogl/cogl/cogl-blit.c | 1 - cogl/cogl/cogl-clip-stack.c | 1 - cogl/cogl/cogl-context.c | 1 - cogl/cogl/cogl-debug.c | 1 - cogl/cogl/cogl-feature-private.c | 4 +- cogl/cogl/cogl-framebuffer.c | 1 - cogl/cogl/cogl-journal.c | 1 - cogl/cogl/cogl-onscreen.c | 1 - cogl/cogl/cogl-pipeline.c | 1 - cogl/cogl/cogl-primitives.c | 1 - cogl/cogl/cogl-renderer-private.h | 4 -- cogl/cogl/cogl-renderer.c | 2 +- cogl/cogl/cogl-renderer.h | 20 +++++++ cogl/cogl/cogl-texture.c | 1 - cogl/cogl/cogl.c | 9 --- cogl/cogl/cogl.h | 1 - cogl/cogl/cogl1-context.h | 66 --------------------- cogl/cogl/driver/gl/gl/cogl-driver-gl.c | 12 ++-- cogl/cogl/driver/gl/gles/cogl-driver-gles.c | 8 +-- cogl/cogl/meson.build | 1 - src/compositor/meta-compositor-x11.c | 15 ++++- src/compositor/meta-sync-ring.c | 41 +++++++------ src/compositor/meta-sync-ring.h | 9 ++- 24 files changed, 73 insertions(+), 130 deletions(-) delete mode 100644 cogl/cogl/cogl1-context.h diff --git a/cogl/cogl/cogl-atlas-texture.c b/cogl/cogl/cogl-atlas-texture.c index 40ceae08f8b..2e0a13b2771 100644 --- a/cogl/cogl/cogl-atlas-texture.c +++ b/cogl/cogl/cogl-atlas-texture.c @@ -44,7 +44,6 @@ #include "cogl/cogl-rectangle-map.h" #include "cogl/cogl-journal-private.h" #include "cogl/cogl-atlas.h" -#include "cogl/cogl1-context.h" #include "cogl/cogl-sub-texture.h" #include "cogl/driver/gl/cogl-texture-gl-private.h" diff --git a/cogl/cogl/cogl-blit.c b/cogl/cogl/cogl-blit.c index 0468b7f3525..817358500ed 100644 --- a/cogl/cogl/cogl-blit.c +++ b/cogl/cogl/cogl-blit.c @@ -41,7 +41,6 @@ #include "cogl/cogl-texture-private.h" #include "cogl/cogl-texture-2d-private.h" #include "cogl/cogl-private.h" -#include "cogl/cogl1-context.h" static const CoglBlitMode *_cogl_blit_default_mode = NULL; diff --git a/cogl/cogl/cogl-clip-stack.c b/cogl/cogl/cogl-clip-stack.c index fac0d02ce3c..fc3af5a0d80 100644 --- a/cogl/cogl/cogl-clip-stack.c +++ b/cogl/cogl/cogl-clip-stack.c @@ -44,7 +44,6 @@ #include "cogl/cogl-private.h" #include "cogl/cogl-attribute-private.h" #include "cogl/cogl-primitive-private.h" -#include "cogl/cogl1-context.h" #include "cogl/cogl-offscreen.h" #include "cogl/cogl-matrix-stack.h" #include "mtk/mtk.h" diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index 04a8ae0a6c7..da27c6d9b08 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -45,7 +45,6 @@ #include "cogl/cogl-framebuffer-private.h" #include "cogl/cogl-onscreen-private.h" #include "cogl/cogl-attribute-private.h" -#include "cogl/cogl1-context.h" #include "cogl/winsys/cogl-winsys-private.h" #include diff --git a/cogl/cogl/cogl-debug.c b/cogl/cogl/cogl-debug.c index 2cf0eeb3b1e..764a86176e7 100644 --- a/cogl/cogl/cogl-debug.c +++ b/cogl/cogl/cogl-debug.c @@ -35,7 +35,6 @@ #include "cogl/cogl-i18n-private.h" #include "cogl/cogl-private.h" #include "cogl/cogl-debug.h" -#include "cogl/cogl1-context.h" /* XXX: If you add a debug option, please also add an option * definition to cogl-debug-options.h. This will enable us - for diff --git a/cogl/cogl/cogl-feature-private.c b/cogl/cogl/cogl-feature-private.c index 1ef42b87ddf..1f986188efc 100644 --- a/cogl/cogl/cogl-feature-private.c +++ b/cogl/cogl/cogl-feature-private.c @@ -143,8 +143,8 @@ _cogl_feature_check (CoglRenderer *renderer, full_function_name = g_strconcat (data->functions[func_num].name, suffix, NULL); - func = _cogl_renderer_get_proc_address (renderer, - full_function_name); + func = cogl_renderer_get_proc_address (renderer, + full_function_name); g_free (full_function_name); if (func == NULL) diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c index 1df320a30b3..780c2aab842 100644 --- a/cogl/cogl/cogl-framebuffer.c +++ b/cogl/cogl/cogl-framebuffer.c @@ -46,7 +46,6 @@ #include "cogl/cogl-pipeline-state-private.h" #include "cogl/cogl-primitive-private.h" #include "cogl/cogl-offscreen.h" -#include "cogl/cogl1-context.h" #include "cogl/cogl-private.h" #include "cogl/cogl-primitives-private.h" #include "cogl/cogl-trace.h" diff --git a/cogl/cogl/cogl-journal.c b/cogl/cogl/cogl-journal.c index 4fbba687170..0e3ffa367b5 100644 --- a/cogl/cogl/cogl-journal.c +++ b/cogl/cogl/cogl-journal.c @@ -43,7 +43,6 @@ #include "cogl/cogl-point-in-poly-private.h" #include "cogl/cogl-trace.h" #include "cogl/cogl-private.h" -#include "cogl/cogl1-context.h" #include #include diff --git a/cogl/cogl/cogl-onscreen.c b/cogl/cogl/cogl-onscreen.c index 4780c45f1fd..93245267d85 100644 --- a/cogl/cogl/cogl-onscreen.c +++ b/cogl/cogl/cogl-onscreen.c @@ -38,7 +38,6 @@ #include "cogl/cogl-framebuffer-private.h" #include "cogl/cogl-onscreen-template-private.h" #include "cogl/cogl-context-private.h" -#include "cogl/cogl1-context.h" #include "cogl/cogl-closure-list-private.h" #include "cogl/cogl-poll-private.h" diff --git a/cogl/cogl/cogl-pipeline.c b/cogl/cogl/cogl-pipeline.c index e5b9764a0f5..0b47d46c304 100644 --- a/cogl/cogl/cogl-pipeline.c +++ b/cogl/cogl/cogl-pipeline.c @@ -46,7 +46,6 @@ #include "cogl/cogl-profile.h" #include "cogl/cogl-depth-state-private.h" #include "cogl/cogl-snippet-private.h" -#include "cogl/cogl1-context.h" #include #include diff --git a/cogl/cogl/cogl-primitives.c b/cogl/cogl/cogl-primitives.c index 6582c277c14..214d03416bb 100644 --- a/cogl/cogl/cogl-primitives.c +++ b/cogl/cogl/cogl-primitives.c @@ -40,7 +40,6 @@ #include "cogl/cogl-private.h" #include "cogl/cogl-meta-texture.h" #include "cogl/cogl-framebuffer-private.h" -#include "cogl/cogl1-context.h" #include "cogl/cogl-primitives-private.h" #include diff --git a/cogl/cogl/cogl-renderer-private.h b/cogl/cogl/cogl-renderer-private.h index f1dbab2b9f5..1949f5943b2 100644 --- a/cogl/cogl/cogl-renderer-private.h +++ b/cogl/cogl/cogl-renderer-private.h @@ -89,7 +89,3 @@ void _cogl_renderer_remove_native_filter (CoglRenderer *renderer, CoglNativeFilterFunc func, void *data); - -void * -_cogl_renderer_get_proc_address (CoglRenderer *renderer, - const char *name); diff --git a/cogl/cogl/cogl-renderer.c b/cogl/cogl/cogl-renderer.c index eae6f88909c..b0261001499 100644 --- a/cogl/cogl/cogl-renderer.c +++ b/cogl/cogl/cogl-renderer.c @@ -615,7 +615,7 @@ cogl_renderer_get_winsys_id (CoglRenderer *renderer) } void * -_cogl_renderer_get_proc_address (CoglRenderer *renderer, +cogl_renderer_get_proc_address (CoglRenderer *renderer, const char *name) { const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer); diff --git a/cogl/cogl/cogl-renderer.h b/cogl/cogl/cogl-renderer.h index 11557314aae..657b73ec00a 100644 --- a/cogl/cogl/cogl-renderer.h +++ b/cogl/cogl/cogl-renderer.h @@ -311,4 +311,24 @@ cogl_renderer_is_dma_buf_supported (CoglRenderer *renderer); COGL_EXPORT void cogl_renderer_bind_api (CoglRenderer *renderer); +/** + * cogl_renderer_get_proc_address: + * @renderer: A #CoglRenderer. + * @name: the name of the function. + * + * Gets a pointer to a given GL or GL ES extension function. This acts + * as a wrapper around glXGetProcAddress() or whatever is the + * appropriate function for the current backend. + * + * This function should not be used to query core opengl API + * symbols since eglGetProcAddress for example doesn't allow this and + * and may return a junk pointer if you do. + * + * Return value: a pointer to the requested function or %NULL if the + * function is not available. + */ +COGL_EXPORT void * +cogl_renderer_get_proc_address (CoglRenderer *renderer, + const char *name); + G_END_DECLS diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index 30f4c2d89a7..924960441e8 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -53,7 +53,6 @@ #include "cogl/cogl-context-private.h" #include "cogl/cogl-offscreen-private.h" #include "cogl/cogl-framebuffer-private.h" -#include "cogl/cogl1-context.h" #include "cogl/cogl-sub-texture.h" #include "cogl/cogl-primitive-texture.h" diff --git a/cogl/cogl/cogl.c b/cogl/cogl/cogl.c index 626dae97629..e11ad9dc734 100644 --- a/cogl/cogl/cogl.c +++ b/cogl/cogl/cogl.c @@ -50,18 +50,9 @@ #include "cogl/cogl-framebuffer-private.h" #include "cogl/cogl-renderer-private.h" #include "cogl/cogl-private.h" -#include "cogl/cogl1-context.h" #include "cogl/cogl-offscreen.h" #include "cogl/winsys/cogl-winsys-private.h" -GCallback -cogl_get_proc_address (const char* name) -{ - _COGL_GET_CONTEXT (ctx, NULL); - - return _cogl_renderer_get_proc_address (ctx->display->renderer, name); -} - gboolean _cogl_check_extension (const char *name, char * const *ext) { diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h index 983e0770aac..17cdc8c6215 100644 --- a/cogl/cogl/cogl.h +++ b/cogl/cogl/cogl.h @@ -45,7 +45,6 @@ #include "cogl/cogl-macros.h" -#include "cogl/cogl1-context.h" #include "cogl/cogl-bitmap.h" #include "cogl/cogl-color.h" #include "cogl/cogl-dma-buf-handle.h" diff --git a/cogl/cogl/cogl1-context.h b/cogl/cogl/cogl1-context.h deleted file mode 100644 index 6b7996f38b5..00000000000 --- a/cogl/cogl/cogl1-context.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Cogl - * - * A Low Level GPU Graphics and Utilities API - * - * Copyright (C) 2010 Intel Corporation. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Robert Bragg - * - */ - -#pragma once - -#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION) -#error "Only can be included directly." -#endif - -#include "cogl/cogl-types.h" -#include "cogl/cogl-texture.h" -#include "cogl/cogl-framebuffer.h" -#include "cogl/cogl-macros.h" - -G_BEGIN_DECLS - -/* Misc */ -/** - * cogl_get_proc_address: (skip) - * @name: the name of the function. - * - * Gets a pointer to a given GL or GL ES extension function. This acts - * as a wrapper around glXGetProcAddress() or whatever is the - * appropriate function for the current backend. - * - * This function should not be used to query core opengl API - * symbols since eglGetProcAddress for example doesn't allow this and - * and may return a junk pointer if you do. - * - * Return value: a pointer to the requested function or %NULL if the - * function is not available. - */ -COGL_EXPORT GCallback -cogl_get_proc_address (const char *name); - - -G_END_DECLS diff --git a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c index 845b1550eda..6bc944a178f 100644 --- a/cogl/cogl/driver/gl/gl/cogl-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-driver-gl.c @@ -429,14 +429,14 @@ _cogl_driver_update_features (CoglContext *ctx, functions because we need to use them to determine what functions we can expect */ ctx->glGetString = - (void *) _cogl_renderer_get_proc_address (ctx->display->renderer, - "glGetString"); + (void *) cogl_renderer_get_proc_address (ctx->display->renderer, + "glGetString"); ctx->glGetStringi = - (void *) _cogl_renderer_get_proc_address (ctx->display->renderer, - "glGetStringi"); + (void *) cogl_renderer_get_proc_address (ctx->display->renderer, + "glGetStringi"); ctx->glGetIntegerv = - (void *) _cogl_renderer_get_proc_address (ctx->display->renderer, - "glGetIntegerv"); + (void *) cogl_renderer_get_proc_address (ctx->display->renderer, + "glGetIntegerv"); gl_extensions = _cogl_context_get_gl_extensions (ctx); diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c index 1d9161bbfb6..853d1dde08b 100644 --- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c @@ -578,11 +578,11 @@ _cogl_driver_update_features (CoglContext *context, function because we need to use it to determine what functions we can expect */ context->glGetString = - (void *) _cogl_renderer_get_proc_address (context->display->renderer, - "glGetString"); + (void *) cogl_renderer_get_proc_address (context->display->renderer, + "glGetString"); context->glGetStringi = - (void *) _cogl_renderer_get_proc_address (context->display->renderer, - "glGetStringi"); + (void *) cogl_renderer_get_proc_address (context->display->renderer, + "glGetStringi"); gl_extensions = _cogl_context_get_gl_extensions (context); diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build index 08431c7f1c2..d1dd5c00f56 100644 --- a/cogl/cogl/meson.build +++ b/cogl/cogl/meson.build @@ -25,7 +25,6 @@ cogl_headers = [ 'cogl-attribute.h', 'cogl-bitmap.h', 'cogl-color.h', - 'cogl1-context.h', 'cogl-context.h', 'cogl-depth-state.h', 'cogl-display.h', diff --git a/src/compositor/meta-compositor-x11.c b/src/compositor/meta-compositor-x11.c index cbc48bcefc8..657f9bdb65c 100644 --- a/src/compositor/meta-compositor-x11.c +++ b/src/compositor/meta-compositor-x11.c @@ -133,6 +133,8 @@ meta_compositor_x11_manage (MetaCompositor *compositor, MetaDisplay *display = meta_compositor_get_display (compositor); MetaContext *context = meta_display_get_context (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); MetaX11Display *x11_display = display->x11_display; Display *xdisplay = meta_x11_display_get_xdisplay (x11_display); int composite_version; @@ -186,7 +188,7 @@ meta_compositor_x11_manage (MetaCompositor *compositor, */ XMapWindow (xdisplay, compositor_x11->output); - compositor_x11->have_x11_sync_object = meta_sync_ring_init (xdisplay); + compositor_x11->have_x11_sync_object = meta_sync_ring_init (cogl_context, xdisplay); return TRUE; } @@ -332,6 +334,9 @@ maybe_do_sync (MetaCompositor *compositor) if (compositor_x11->frame_has_updated_xsurfaces) { MetaDisplay *display = meta_compositor_get_display (compositor); + MetaBackend *backend = meta_compositor_get_backend (compositor); + ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); + CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); /* * We need to make sure that any X drawing that happens before the @@ -354,7 +359,7 @@ maybe_do_sync (MetaCompositor *compositor) * at this point is sufficient to flush the GLX buffers. */ if (compositor_x11->have_x11_sync_object) - compositor_x11->have_x11_sync_object = meta_sync_ring_insert_wait (); + compositor_x11->have_x11_sync_object = meta_sync_ring_insert_wait (cogl_context); else XSync (display->x11_display->xdisplay, False); } @@ -379,8 +384,12 @@ on_after_update (ClutterStage *stage, if (compositor_x11->frame_has_updated_xsurfaces) { + MetaBackend *backend = meta_compositor_get_backend (compositor); + ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); + CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); + if (compositor_x11->have_x11_sync_object) - compositor_x11->have_x11_sync_object = meta_sync_ring_after_frame (); + compositor_x11->have_x11_sync_object = meta_sync_ring_after_frame (cogl_context); compositor_x11->frame_has_updated_xsurfaces = FALSE; } diff --git a/src/compositor/meta-sync-ring.c b/src/compositor/meta-sync-ring.c index 1267dd4f2ca..81584128d6a 100644 --- a/src/compositor/meta-sync-ring.c +++ b/src/compositor/meta-sync-ring.c @@ -132,10 +132,11 @@ meta_sync_ring_get (void) } static gboolean -load_gl_symbol (const char *name, +load_gl_symbol (CoglContext *ctx, + const char *name, void **func) { - *func = cogl_get_proc_address (name); + *func = cogl_renderer_get_proc_address (ctx->display->renderer, name); if (!*func) { meta_verbose ("MetaSyncRing: failed to resolve required GL symbol \"%s\"", name); @@ -187,7 +188,7 @@ check_gl_extensions (void) } static gboolean -load_required_symbols (void) +load_required_symbols (CoglContext *ctx) { static gboolean success = FALSE; @@ -199,11 +200,11 @@ load_required_symbols (void) * and dynamically loaded libGL at this point. */ - if (!load_gl_symbol ("glGetString", (void **) &meta_gl_get_string)) + if (!load_gl_symbol (ctx, "glGetString", (void **) &meta_gl_get_string)) goto out; - if (!load_gl_symbol ("glGetIntegerv", (void **) &meta_gl_get_integerv)) + if (!load_gl_symbol (ctx, "glGetIntegerv", (void **) &meta_gl_get_integerv)) goto out; - if (!load_gl_symbol ("glGetStringi", (void **) &meta_gl_get_stringi)) + if (!load_gl_symbol (ctx, "glGetStringi", (void **) &meta_gl_get_stringi)) goto out; if (!check_gl_extensions ()) @@ -212,15 +213,15 @@ load_required_symbols (void) goto out; } - if (!load_gl_symbol ("glDeleteSync", (void **) &meta_gl_delete_sync)) + if (!load_gl_symbol (ctx, "glDeleteSync", (void **) &meta_gl_delete_sync)) goto out; - if (!load_gl_symbol ("glClientWaitSync", (void **) &meta_gl_client_wait_sync)) + if (!load_gl_symbol (ctx, "glClientWaitSync", (void **) &meta_gl_client_wait_sync)) goto out; - if (!load_gl_symbol ("glWaitSync", (void **) &meta_gl_wait_sync)) + if (!load_gl_symbol (ctx, "glWaitSync", (void **) &meta_gl_wait_sync)) goto out; - if (!load_gl_symbol ("glImportSyncEXT", (void **) &meta_gl_import_sync)) + if (!load_gl_symbol (ctx, "glImportSyncEXT", (void **) &meta_gl_import_sync)) goto out; - if (!load_gl_symbol ("glFenceSync", (void **) &meta_gl_fence_sync)) + if (!load_gl_symbol (ctx, "glFenceSync", (void **) &meta_gl_fence_sync)) goto out; success = TRUE; @@ -405,7 +406,8 @@ meta_sync_free (MetaSync *self) } gboolean -meta_sync_ring_init (Display *xdisplay) +meta_sync_ring_init (CoglContext *ctx, + Display *xdisplay) { gint major, minor; guint i; @@ -417,7 +419,7 @@ meta_sync_ring_init (Display *xdisplay) g_return_val_if_fail (xdisplay != NULL, FALSE); g_return_val_if_fail (ring->xdisplay == NULL, FALSE); - if (!load_required_symbols ()) + if (!load_required_symbols (ctx)) return FALSE; if (!XSyncQueryExtension (xdisplay, &ring->xsync_event_base, &ring->xsync_error_base) || @@ -477,7 +479,8 @@ meta_sync_ring_destroy (void) } static gboolean -meta_sync_ring_reboot (Display *xdisplay) +meta_sync_ring_reboot (CoglContext *ctx, + Display *xdisplay) { MetaSyncRing *ring = meta_sync_ring_get (); @@ -494,11 +497,11 @@ meta_sync_ring_reboot (Display *xdisplay) return FALSE; } - return meta_sync_ring_init (xdisplay); + return meta_sync_ring_init (ctx, xdisplay); } gboolean -meta_sync_ring_after_frame (void) +meta_sync_ring_after_frame (CoglContext *ctx) { MetaSyncRing *ring = meta_sync_ring_get (); @@ -522,7 +525,7 @@ meta_sync_ring_after_frame (void) if (status != GL_ALREADY_SIGNALED && status != GL_CONDITION_SATISFIED) { meta_warning ("MetaSyncRing: Timed out waiting for sync object."); - return meta_sync_ring_reboot (ring->xdisplay); + return meta_sync_ring_reboot (ctx, ring->xdisplay); } meta_sync_reset (sync_to_reset); @@ -541,7 +544,7 @@ meta_sync_ring_after_frame (void) } gboolean -meta_sync_ring_insert_wait (void) +meta_sync_ring_insert_wait (CoglContext *ctx) { MetaSyncRing *ring = meta_sync_ring_get (); MetaSync *sync; @@ -562,7 +565,7 @@ meta_sync_ring_insert_wait (void) else if (sync->state != META_SYNC_STATE_READY) { meta_warning ("MetaSyncRing: Sync object is not ready -- were events handled properly?"); - if (!meta_sync_ring_reboot (ring->xdisplay)) + if (!meta_sync_ring_reboot (ctx, ring->xdisplay)) return FALSE; } diff --git a/src/compositor/meta-sync-ring.h b/src/compositor/meta-sync-ring.h index 0f96f51e30e..6b82a349b06 100644 --- a/src/compositor/meta-sync-ring.h +++ b/src/compositor/meta-sync-ring.h @@ -3,8 +3,11 @@ #include #include -gboolean meta_sync_ring_init (Display *dpy); +#include "cogl/cogl.h" + +gboolean meta_sync_ring_init (CoglContext *ctx, + Display *dpy); void meta_sync_ring_destroy (void); -gboolean meta_sync_ring_after_frame (void); -gboolean meta_sync_ring_insert_wait (void); +gboolean meta_sync_ring_after_frame (CoglContext *ctx); +gboolean meta_sync_ring_insert_wait (CoglContext *ctx); void meta_sync_ring_handle_event (XEvent *event); -- GitLab From 54748b7f1f8381047220ac9274b74bba16d53549 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Mon, 15 Jul 2024 12:14:41 +0200 Subject: [PATCH 06/10] cogl: Call init when creating a context from Clutter Part-of: --- clutter/clutter/clutter-backend.c | 5 +++-- cogl/cogl/cogl-context.c | 2 -- cogl/cogl/cogl-display.c | 2 -- cogl/cogl/cogl-mutter.h | 3 +++ cogl/cogl/cogl-private.h | 3 --- cogl/cogl/cogl-renderer.c | 2 -- cogl/cogl/cogl.c | 3 ++- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c index 32ac02e3088..d97d9275dc7 100644 --- a/clutter/clutter/clutter-backend.c +++ b/clutter/clutter/clutter-backend.c @@ -26,7 +26,7 @@ /** * ClutterBackend: - * + * * Backend abstraction * * Clutter can be compiled against different backends. Each backend @@ -117,8 +117,9 @@ clutter_backend_do_real_create_context (ClutterBackend *backend, { ClutterBackendClass *klass; - klass = CLUTTER_BACKEND_GET_CLASS (backend); + cogl_init (); + klass = CLUTTER_BACKEND_GET_CLASS (backend); CLUTTER_NOTE (BACKEND, "Creating Cogl renderer"); backend->cogl_renderer = klass->get_renderer (backend, error); diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index da27c6d9b08..99c368ca408 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -188,8 +188,6 @@ cogl_context_new (CoglDisplay *display, int i; GError *local_error = NULL; - _cogl_init (); - #ifdef COGL_ENABLE_PROFILE /* We need to be absolutely sure that uprof has been initialized * before calling _cogl_uprof_init. uprof_init (NULL, NULL) diff --git a/cogl/cogl/cogl-display.c b/cogl/cogl/cogl-display.c index 16a50d05836..a5bcde08a18 100644 --- a/cogl/cogl/cogl-display.c +++ b/cogl/cogl/cogl-display.c @@ -88,8 +88,6 @@ cogl_display_new (CoglRenderer *renderer, CoglDisplay *display = g_object_new (COGL_TYPE_DISPLAY, NULL); GError *error = NULL; - _cogl_init (); - display->renderer = renderer; if (renderer) g_object_ref (renderer); diff --git a/cogl/cogl/cogl-mutter.h b/cogl/cogl/cogl-mutter.h index aadbb63eb9f..cf02b1a4928 100644 --- a/cogl/cogl/cogl-mutter.h +++ b/cogl/cogl/cogl-mutter.h @@ -55,3 +55,6 @@ void cogl_renderer_set_custom_winsys (CoglRenderer *renderer, COGL_EXPORT gboolean cogl_context_format_supports_upload (CoglContext *ctx, CoglPixelFormat format); + +COGL_EXPORT +void cogl_init (void); diff --git a/cogl/cogl/cogl-private.h b/cogl/cogl/cogl-private.h index fb18c8b9f52..636af1febe9 100644 --- a/cogl/cogl/cogl-private.h +++ b/cogl/cogl/cogl-private.h @@ -82,9 +82,6 @@ _cogl_transform_point (const graphene_matrix_t *matrix_mv, gboolean _cogl_check_extension (const char *name, char * const *ext); -void -_cogl_init (void); - #define _cogl_has_private_feature(ctx, feature) \ COGL_FLAGS_GET ((ctx)->private_features, (feature)) diff --git a/cogl/cogl/cogl-renderer.c b/cogl/cogl/cogl-renderer.c index b0261001499..2a9e3cb53e2 100644 --- a/cogl/cogl/cogl-renderer.c +++ b/cogl/cogl/cogl-renderer.c @@ -194,8 +194,6 @@ cogl_renderer_new (void) { CoglRenderer *renderer = g_object_new (COGL_TYPE_RENDERER, NULL); - _cogl_init (); - renderer->connected = FALSE; renderer->event_filters = NULL; diff --git a/cogl/cogl/cogl.c b/cogl/cogl/cogl.c index e11ad9dc734..34325fa1db7 100644 --- a/cogl/cogl/cogl.c +++ b/cogl/cogl/cogl.c @@ -52,6 +52,7 @@ #include "cogl/cogl-private.h" #include "cogl/cogl-offscreen.h" #include "cogl/winsys/cogl-winsys-private.h" +#include "cogl/cogl-mutter.h" gboolean _cogl_check_extension (const char *name, char * const *ext) @@ -124,7 +125,7 @@ _cogl_system_error_quark (void) } void -_cogl_init (void) +cogl_init (void) { static gboolean initialized = FALSE; -- GitLab From 725e826a39ef63da451438bd5f86e6a640524e42 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 3 Jul 2024 09:13:42 +0200 Subject: [PATCH 07/10] cogl: Require a Renderer/Display when initializing The whole fallbacks all over the place were only useful when Cogl was a separate library Part-of: --- cogl/cogl/cogl-context.c | 27 +++------------------------ cogl/cogl/cogl-display.c | 13 +++---------- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index 99c368ca408..37e1715aee5 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -182,6 +182,8 @@ CoglContext * cogl_context_new (CoglDisplay *display, GError **error) { + g_return_val_if_fail (display != NULL, NULL); + CoglContext *context; uint8_t white_pixel[] = { 0xff, 0xff, 0xff, 0xff }; const CoglWinsysVtable *winsys; @@ -221,30 +223,7 @@ cogl_context_new (CoglDisplay *display, memset (context->private_features, 0, sizeof (context->private_features)); memset (context->winsys_features, 0, sizeof (context->winsys_features)); - if (!display) - { - CoglRenderer *renderer = cogl_renderer_new (); - if (!cogl_renderer_connect (renderer, error)) - { - g_object_unref (renderer); - g_object_unref (context); - return NULL; - } - - display = cogl_display_new (renderer, NULL); - g_object_unref (renderer); - } - else - g_object_ref (display); - - if (!cogl_display_setup (display, error)) - { - g_object_unref (display); - g_object_unref (context); - return NULL; - } - - context->display = display; + context->display = g_object_ref (display); /* This is duplicated data, but it's much more convenient to have the driver attached to the context and the value is accessed a diff --git a/cogl/cogl/cogl-display.c b/cogl/cogl/cogl-display.c index a5bcde08a18..fca1b8e1b18 100644 --- a/cogl/cogl/cogl-display.c +++ b/cogl/cogl/cogl-display.c @@ -85,18 +85,11 @@ CoglDisplay * cogl_display_new (CoglRenderer *renderer, CoglOnscreenTemplate *onscreen_template) { - CoglDisplay *display = g_object_new (COGL_TYPE_DISPLAY, NULL); - GError *error = NULL; - - display->renderer = renderer; - if (renderer) - g_object_ref (renderer); - else - display->renderer = cogl_renderer_new (); + g_return_val_if_fail (renderer != NULL, NULL); - if (!cogl_renderer_connect (display->renderer, &error)) - g_error ("Failed to connect to renderer: %s\n", error->message); + CoglDisplay *display = g_object_new (COGL_TYPE_DISPLAY, NULL); + display->renderer = g_object_ref (renderer); display->setup = FALSE; cogl_display_set_onscreen_template (display, onscreen_template); -- GitLab From c1733e8d7c9f628309123942ce82a6e142c361a5 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 3 Jul 2024 09:24:10 +0200 Subject: [PATCH 08/10] cogl: Keep a backpointer to context/display Allows to retrieve the context from the renderer, allows to get rid of one GET_CONTEXT usages Part-of: --- cogl/cogl/cogl-context.c | 2 ++ cogl/cogl/cogl-display-private.h | 2 ++ cogl/cogl/cogl-display.c | 1 + cogl/cogl/cogl-renderer-private.h | 3 +++ cogl/cogl/winsys/cogl-winsys-glx.c | 3 +-- 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index 37e1715aee5..79e74878551 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -224,6 +224,8 @@ cogl_context_new (CoglDisplay *display, memset (context->winsys_features, 0, sizeof (context->winsys_features)); context->display = g_object_ref (display); + /* Keep a backpointer to the context */ + display->context = context; /* This is duplicated data, but it's much more convenient to have the driver attached to the context and the value is accessed a diff --git a/cogl/cogl/cogl-display-private.h b/cogl/cogl/cogl-display-private.h index d88a0847b2b..d09c994b167 100644 --- a/cogl/cogl/cogl-display-private.h +++ b/cogl/cogl/cogl-display-private.h @@ -38,6 +38,8 @@ struct _CoglDisplay { GObjectClass parnet_class; + CoglContext *context; + gboolean setup; CoglRenderer *renderer; CoglOnscreenTemplate *onscreen_template; diff --git a/cogl/cogl/cogl-display.c b/cogl/cogl/cogl-display.c index fca1b8e1b18..796031db800 100644 --- a/cogl/cogl/cogl-display.c +++ b/cogl/cogl/cogl-display.c @@ -90,6 +90,7 @@ cogl_display_new (CoglRenderer *renderer, CoglDisplay *display = g_object_new (COGL_TYPE_DISPLAY, NULL); display->renderer = g_object_ref (renderer); + renderer->display = display; display->setup = FALSE; cogl_display_set_onscreen_template (display, onscreen_template); diff --git a/cogl/cogl/cogl-renderer-private.h b/cogl/cogl/cogl-renderer-private.h index 1949f5943b2..d5e832e551b 100644 --- a/cogl/cogl/cogl-renderer-private.h +++ b/cogl/cogl/cogl-renderer-private.h @@ -43,6 +43,9 @@ typedef const CoglWinsysVtable *(*CoglCustomWinsysVtableGetter) (CoglRenderer *r struct _CoglRenderer { GObject parent_instance; + + CoglDisplay *display; + gboolean connected; CoglDriver driver_override; const CoglDriverVtable *driver_vtable; diff --git a/cogl/cogl/winsys/cogl-winsys-glx.c b/cogl/cogl/winsys/cogl-winsys-glx.c index a6851ce5331..bed116eff37 100644 --- a/cogl/cogl/winsys/cogl-winsys-glx.c +++ b/cogl/cogl/winsys/cogl-winsys-glx.c @@ -261,8 +261,7 @@ static gboolean update_all_outputs (CoglRenderer *renderer) { GList *l; - - _COGL_GET_CONTEXT (context, FALSE); + CoglContext *context = renderer->display->context; if (context->display == NULL) /* during connection */ return FALSE; -- GitLab From c23bc80ba4e2a06fe71b9e2ca4c0a009684330bf Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 3 Jul 2024 09:27:39 +0200 Subject: [PATCH 09/10] cogl/debug: Take a context param This will make the usage through gdb not as useful as it was but it is the last remaining usage of a gross hack, so let us get rid of it Part-of: --- cogl/cogl/cogl-pipeline-debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cogl/cogl/cogl-pipeline-debug.c b/cogl/cogl/cogl-pipeline-debug.c index 455ffaec8cb..2e4ff70743c 100644 --- a/cogl/cogl/cogl-pipeline-debug.c +++ b/cogl/cogl/cogl-pipeline-debug.c @@ -241,10 +241,12 @@ dump_pipeline_cb (CoglNode *node, void *user_data) want to put a declaration in a header and we just add it here to avoid a warning */ void -_cogl_debug_dump_pipelines_dot_file (const char *filename); +_cogl_debug_dump_pipelines_dot_file (const char *filename, + CoglContext *ctx); void -_cogl_debug_dump_pipelines_dot_file (const char *filename) +_cogl_debug_dump_pipelines_dot_file (const char *filename, + CoglContext *ctx) { GString *graph; PrintDebugState layer_state; @@ -252,8 +254,6 @@ _cogl_debug_dump_pipelines_dot_file (const char *filename) int layer_id = 0; int pipeline_id = 0; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (!ctx->default_pipeline) return; -- GitLab From 1d465461a723007d3f97f9663d8cb2d541eec3ba Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 3 Jul 2024 09:32:35 +0200 Subject: [PATCH 10/10] cogl: Remove default context gross hack As nothing uses it anymore Part-of: --- cogl/cogl/cogl-context-private.h | 10 ---------- cogl/cogl/cogl-context.c | 30 ------------------------------ 2 files changed, 40 deletions(-) diff --git a/cogl/cogl/cogl-context-private.h b/cogl/cogl/cogl-context-private.h index 70d101a13ec..09931a85bb9 100644 --- a/cogl/cogl/cogl-context-private.h +++ b/cogl/cogl/cogl-context-private.h @@ -276,9 +276,6 @@ struct _CoglContext #undef COGL_EXT_END }; -COGL_EXPORT CoglContext * -_cogl_context_get_default (void); - const CoglWinsysVtable * _cogl_context_get_winsys (CoglContext *context); @@ -292,13 +289,6 @@ gboolean _cogl_context_update_features (CoglContext *context, GError **error); -/* Obtains the context and returns retval if NULL */ -#define _COGL_GET_CONTEXT(ctxvar, retval) \ -CoglContext *ctxvar = _cogl_context_get_default (); \ -if (ctxvar == NULL) return retval; - -#define NO_RETVAL - void _cogl_context_set_current_projection_entry (CoglContext *context, CoglMatrixEntry *entry); diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index 79e74878551..2c22b70ce8c 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -160,8 +160,6 @@ cogl_context_class_init (CoglContextClass *class) extern void _cogl_create_context_driver (CoglContext *context); -static CoglContext *_cogl_context = NULL; - static void _cogl_init_feature_overrides (CoglContext *ctx) { @@ -209,15 +207,6 @@ cogl_context_new (CoglDisplay *display, /* Allocate context memory */ context = g_object_new (COGL_TYPE_CONTEXT, NULL); - /* XXX: Gross hack! - * Currently everything in Cogl just assumes there is a default - * context which it can access via _COGL_GET_CONTEXT() including - * code used to construct a CoglContext. Until all of that code - * has been updated to take an explicit context argument we have - * to immediately make our pointer the default context. - */ - _cogl_context = context; - /* Init default values */ memset (context->features, 0, sizeof (context->features)); memset (context->private_features, 0, sizeof (context->private_features)); @@ -386,25 +375,6 @@ cogl_context_new (CoglDisplay *display, return context; } -CoglContext * -_cogl_context_get_default (void) -{ - GError *error = NULL; - /* Create if doesn't exist yet */ - if (_cogl_context == NULL) - { - _cogl_context = cogl_context_new (NULL, &error); - if (!_cogl_context) - { - g_warning ("Failed to create default context: %s", - error->message); - g_error_free (error); - } - } - - return _cogl_context; -} - CoglDisplay * cogl_context_get_display (CoglContext *context) { -- GitLab