cogl: Pass Context to cogl_flush

Avoids using the global variable & also move the function to
it proper context

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3857>
This commit is contained in:
Bilal Elmoussaoui 2024-06-29 15:20:14 +02:00 committed by Marge Bot
parent 194fa80cdd
commit b3ae934304
8 changed files with 47 additions and 42 deletions

View File

@ -139,7 +139,7 @@ _cogl_atlas_texture_pre_reorganize_cb (void *data)
* We are assuming that texture atlas migration never happens * We are assuming that texture atlas migration never happens
* during a flush so we don't have to consider recursion here. * during a flush so we don't have to consider recursion here.
*/ */
cogl_flush (); cogl_context_flush (atlas->context);
if (atlas->map) if (atlas->map)
_cogl_rectangle_map_foreach (atlas->map, _cogl_rectangle_map_foreach (atlas->map,
@ -336,11 +336,13 @@ static void
_cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex) _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
{ {
CoglTexture *standalone_tex; CoglTexture *standalone_tex;
CoglContext *ctx;
/* Make sure this texture is not in the atlas */ /* Make sure this texture is not in the atlas */
if (!atlas_tex->atlas) if (!atlas_tex->atlas)
return; return;
ctx = cogl_texture_get_context (COGL_TEXTURE (atlas_tex));
COGL_NOTE (ATLAS, "Migrating texture out of the atlas"); COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
/* We don't know if any journal entries currently depend on /* 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 * We are assuming that texture atlas migration never happens
* during a flush so we don't have to consider recursion here. * during a flush so we don't have to consider recursion here.
*/ */
cogl_flush (); cogl_context_flush (ctx);
standalone_tex = standalone_tex =
_cogl_atlas_copy_rectangle (atlas_tex->atlas, _cogl_atlas_copy_rectangle (atlas_tex->atlas,

View File

@ -575,3 +575,12 @@ cogl_context_has_winsys_feature (CoglContext *context,
{ {
return COGL_FLAGS_GET (context->winsys_features, feature); 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);
}

View File

@ -345,5 +345,32 @@ cogl_context_get_latest_sync_fd (CoglContext *context);
COGL_EXPORT gboolean COGL_EXPORT gboolean
cogl_context_has_winsys_feature (CoglContext *context, cogl_context_has_winsys_feature (CoglContext *context,
CoglWinsysFeature feature); 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 G_END_DECLS

View File

@ -1084,7 +1084,7 @@ _cogl_pipeline_pre_change_notify (CoglPipeline *pipeline,
/* XXX: note we use cogl_flush() not _cogl_flush_journal() so /* XXX: note we use cogl_flush() not _cogl_flush_journal() so
* we will flush *all* known journals that might reference the * we will flush *all* known journals that might reference the
* current pipeline. */ * current pipeline. */
cogl_flush (); cogl_context_flush (pipeline->context);
} }
} }

View File

@ -80,17 +80,6 @@ cogl_has_feature (CoglContext *ctx, CoglFeatureID feature)
return COGL_FLAGS_GET (ctx->features, 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 uint32_t
_cogl_driver_error_quark (void) _cogl_driver_error_quark (void)
{ {

View File

@ -62,31 +62,5 @@ G_BEGIN_DECLS
COGL_EXPORT GCallback COGL_EXPORT GCallback
cogl_get_proc_address (const char *name); 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 G_END_DECLS

View File

@ -88,6 +88,10 @@ detach_pixmap (MetaSurfaceActorX11 *self)
{ {
MetaDisplay *display = self->display; MetaDisplay *display = self->display;
MetaShapedTexture *stex = meta_surface_actor_get_texture (META_SURFACE_ACTOR (self)); 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; Display *xdisplay;
if (self->pixmap == None) if (self->pixmap == None)
@ -100,7 +104,7 @@ detach_pixmap (MetaSurfaceActorX11 *self)
* pixmap, but it certainly doesn't work with current DRI/Mesa * pixmap, but it certainly doesn't work with current DRI/Mesa
*/ */
meta_shaped_texture_set_texture (stex, NULL); meta_shaped_texture_set_texture (stex, NULL);
cogl_flush (); cogl_context_flush (cogl_context);
mtk_x11_error_trap_push (xdisplay); mtk_x11_error_trap_push (xdisplay);
XFreePixmap (xdisplay, self->pixmap); XFreePixmap (xdisplay, self->pixmap);

View File

@ -211,7 +211,7 @@ validate_result (TestState *state)
/* Sub sub texture */ /* Sub sub texture */
p = texture_data = g_malloc (10 * 10 * 4); 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, cogl_framebuffer_read_pixels (test_fb,
0, SOURCE_SIZE * 2, 10, 10, 0, SOURCE_SIZE * 2, 10, 10,
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,