[Cogl] [PATCH] replace public cogl_flush with cogl_framebuffer_flush

Robert Bragg robert at sixbynine.org
Mon Nov 19 08:54:49 PST 2012


From: Robert Bragg <robert at linux.intel.com>

This removes the cogl_flush() api which depends on a global Cogl context
and provides a more specific cogl_framebuffer_flush() instead.

Since there are a few places internally where we do actually need to
flush *all* framebuffer journals we keep an equivalent to cogl_flush()
renamed to _cogl_flush() which now takes a CoglContext pointer.

cogl1-context.h has now been removed since there was nothing left in it.
---
 cogl/Makefile.am                       |    1 -
 cogl/cogl-atlas-texture.c              |   10 +++-
 cogl/cogl-blit.c                       |    1 -
 cogl/cogl-clip-stack.c                 |    1 -
 cogl/cogl-clip-state.c                 |    1 -
 cogl/cogl-context.c                    |    1 -
 cogl/cogl-debug.c                      |    1 -
 cogl/cogl-framebuffer.c                |   10 ++++-
 cogl/cogl-framebuffer.h                |   29 +++++++++++++
 cogl/cogl-journal.c                    |    1 -
 cogl/cogl-onscreen.c                   |    8 +--
 cogl/cogl-path.c                       |    1 -
 cogl/cogl-pipeline.c                   |   10 ++--
 cogl/cogl-primitives.c                 |    1 -
 cogl/cogl-private.h                    |    3 +
 cogl/cogl-texture.c                    |    1 -
 cogl/cogl.c                            |    5 +--
 cogl/cogl.h                            |    1 -
 cogl/cogl1-context.h                   |   73 --------------------------------
 doc/reference/cogl2/cogl2-sections.txt |    4 +-
 tests/conform/test-gles2-context.c     |    2 +-
 tests/conform/test-sub-texture.c       |    2 +-
 22 files changed, 59 insertions(+), 108 deletions(-)
 delete mode 100644 cogl/cogl1-context.h

diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index a026e91..a9f128b 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -106,7 +106,6 @@ cogl_public_h = \
 	$(srcdir)/cogl-vector.h 		\
 	$(srcdir)/cogl-version.h		\
 	$(srcdir)/cogl.h			\
-	$(srcdir)/cogl1-context.h 		\
 	$(NULL)
 
 # experimental api headers
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index 77e52f9..93fe2fe 100644
--- a/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl-atlas-texture.c
@@ -42,10 +42,10 @@
 #include "cogl-journal-private.h"
 #include "cogl-pipeline-opengl-private.h"
 #include "cogl-atlas.h"
-#include "cogl1-context.h"
 #include "cogl-sub-texture.h"
 #include "cogl-error-private.h"
 #include "cogl-texture-gl-private.h"
+#include "cogl-private.h"
 
 #include <stdlib.h>
 
@@ -110,6 +110,8 @@ _cogl_atlas_texture_pre_reorganize_cb (void *data)
 {
   CoglAtlas *atlas = data;
 
+  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
   /* We don't know if any journal entries currently depend on OpenGL
    * texture coordinates that would be invalidated by reorganizing
    * this atlas so we flush all journals before migrating.
@@ -117,7 +119,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_flush (ctx);
 
   if (atlas->map)
     _cogl_rectangle_map_foreach (atlas->map,
@@ -369,6 +371,8 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
     {
       CoglTexture *standalone_tex;
 
+      _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+
       COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
 
       /* We don't know if any journal entries currently depend on
@@ -379,7 +383,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_flush (ctx);
 
       standalone_tex =
         _cogl_atlas_copy_rectangle (atlas_tex->atlas,
diff --git a/cogl/cogl-blit.c b/cogl/cogl-blit.c
index d74356d..3e738a1 100644
--- a/cogl/cogl-blit.c
+++ b/cogl/cogl-blit.c
@@ -37,7 +37,6 @@
 #include "cogl-texture-private.h"
 #include "cogl-texture-2d-private.h"
 #include "cogl-private.h"
-#include "cogl1-context.h"
 
 static const CoglBlitMode *_cogl_blit_default_mode = NULL;
 
diff --git a/cogl/cogl-clip-stack.c b/cogl/cogl-clip-stack.c
index a25a9db..da881eb 100644
--- a/cogl/cogl-clip-stack.c
+++ b/cogl/cogl-clip-stack.c
@@ -44,7 +44,6 @@
 #include "cogl-pipeline-opengl-private.h"
 #include "cogl-attribute-private.h"
 #include "cogl-primitive-private.h"
-#include "cogl1-context.h"
 #include "cogl-offscreen.h"
 #include "cogl-matrix-stack.h"
 
diff --git a/cogl/cogl-clip-state.c b/cogl/cogl-clip-state.c
index 8325e96..464bc61 100644
--- a/cogl/cogl-clip-state.c
+++ b/cogl/cogl-clip-state.c
@@ -39,7 +39,6 @@
 #include "cogl-util.h"
 #include "cogl-matrix-private.h"
 #include "cogl-clip-state.h"
-#include "cogl1-context.h"
 
 void
 _cogl_clip_state_init (CoglClipState *clip_state)
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index 6788da5..85eccd7 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -46,7 +46,6 @@
 #include "cogl-onscreen-private.h"
 #include "cogl-path.h"
 #include "cogl-attribute-private.h"
-#include "cogl1-context.h"
 #include "cogl-gpu-info-private.h"
 #include "cogl-config-private.h"
 #include "cogl-error-private.h"
diff --git a/cogl/cogl-debug.c b/cogl/cogl-debug.c
index 1a7e7e6..01af450 100644
--- a/cogl/cogl-debug.c
+++ b/cogl/cogl-debug.c
@@ -30,7 +30,6 @@
 
 #include "cogl-private.h"
 #include "cogl-debug.h"
-#include "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-framebuffer.c b/cogl/cogl-framebuffer.c
index b9a3b29..3ba4b80 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -45,7 +45,6 @@
 #include "cogl-matrix-private.h"
 #include "cogl-primitive-private.h"
 #include "cogl-offscreen.h"
-#include "cogl1-context.h"
 #include "cogl-private.h"
 #include "cogl-primitives-private.h"
 #include "cogl-path-private.h"
@@ -546,6 +545,12 @@ _cogl_framebuffer_flush_journal (CoglFramebuffer *framebuffer)
 }
 
 void
+cogl_framebuffer_flush (CoglFramebuffer *framebuffer)
+{
+  _cogl_framebuffer_flush_journal (framebuffer);
+}
+
+void
 _cogl_framebuffer_flush_dependency_journals (CoglFramebuffer *framebuffer)
 {
   GList *l;
@@ -913,7 +918,8 @@ cogl_framebuffer_set_dither_enabled (CoglFramebuffer *framebuffer,
   if (framebuffer->dither_enabled == dither_enabled)
     return;
 
-  cogl_flush (); /* Currently dithering changes aren't tracked in the journal */
+  _cogl_framebuffer_flush_journal (framebuffer);
+
   framebuffer->dither_enabled = dither_enabled;
 
   if (framebuffer->context->current_draw_buffer == framebuffer)
diff --git a/cogl/cogl-framebuffer.h b/cogl/cogl-framebuffer.h
index 540702b..e6bbd15 100644
--- a/cogl/cogl-framebuffer.h
+++ b/cogl/cogl-framebuffer.h
@@ -1636,6 +1636,35 @@ cogl_framebuffer_discard_buffers (CoglFramebuffer *framebuffer,
                                   CoglBufferBit buffers);
 
 /**
+ * cogl_framebuffer_flush:
+ * @framebuffer: A #CoglFramebuffer
+ *
+ * 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 native drawing apis
+ * directly to a Cogl onscreen framebuffer or raw OpenGL outside of
+ * Cogl you stand a better chance of being successful if you ask Cogl
+ * to flush any batched drawing before issuing your own drawing
+ * commands.
+ *
+ * This api 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 native graphics state or OpenGL
+ * state upon returning and to avoid confusing Cogl you should aim to
+ * save and restore any changes you make before resuming use of Cogl.
+ *
+ * Note: If you make OpenGL state changes with the intention of
+ * affecting Cogl drawing primitives you stand a high chance of
+ * conflicting with Cogl internals which can change so this is not
+ * supported.
+ */
+void
+cogl_framebuffer_flush (CoglFramebuffer *framebuffer);
+
+/**
  * cogl_framebuffer_finish:
  * @framebuffer: A #CoglFramebuffer pointer
  *
diff --git a/cogl/cogl-journal.c b/cogl/cogl-journal.c
index 0e00546..0b1a0cc 100644
--- a/cogl/cogl-journal.c
+++ b/cogl/cogl-journal.c
@@ -38,7 +38,6 @@
 #include "cogl-attribute-private.h"
 #include "cogl-point-in-poly-private.h"
 #include "cogl-private.h"
-#include "cogl1-context.h"
 
 #include <string.h>
 #include <gmodule.h>
diff --git a/cogl/cogl-onscreen.c b/cogl/cogl-onscreen.c
index 234f8bf..09a0140 100644
--- a/cogl/cogl-onscreen.c
+++ b/cogl/cogl-onscreen.c
@@ -31,7 +31,6 @@
 #include "cogl-onscreen-template-private.h"
 #include "cogl-context-private.h"
 #include "cogl-object-private.h"
-#include "cogl1-context.h"
 
 static void _cogl_onscreen_free (CoglOnscreen *onscreen);
 
@@ -146,8 +145,8 @@ cogl_onscreen_swap_buffers (CoglOnscreen *onscreen)
 
   _COGL_RETURN_IF_FAIL  (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN);
 
-  /* FIXME: we shouldn't need to flush *all* journals here! */
-  cogl_flush ();
+  _cogl_framebuffer_flush_journal (framebuffer);
+
   winsys = _cogl_framebuffer_get_winsys (framebuffer);
   winsys->onscreen_swap_buffers (COGL_ONSCREEN (framebuffer));
   cogl_framebuffer_discard_buffers (framebuffer,
@@ -166,8 +165,7 @@ cogl_onscreen_swap_region (CoglOnscreen *onscreen,
 
   _COGL_RETURN_IF_FAIL  (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN);
 
-  /* FIXME: we shouldn't need to flush *all* journals here! */
-  cogl_flush ();
+  _cogl_framebuffer_flush_journal (framebuffer);
 
   winsys = _cogl_framebuffer_get_winsys (framebuffer);
 
diff --git a/cogl/cogl-path.c b/cogl/cogl-path.c
index af82950..f02d5b3 100644
--- a/cogl/cogl-path.c
+++ b/cogl/cogl-path.c
@@ -43,7 +43,6 @@
 #include "cogl-primitives-private.h"
 #include "cogl-private.h"
 #include "cogl-attribute-private.h"
-#include "cogl1-context.h"
 #include "tesselator/tesselator.h"
 
 #include <string.h>
diff --git a/cogl/cogl-pipeline.c b/cogl/cogl-pipeline.c
index 85264ab..53d984b 100644
--- a/cogl/cogl-pipeline.c
+++ b/cogl/cogl-pipeline.c
@@ -45,7 +45,7 @@
 #include "cogl-util.h"
 #include "cogl-profile.h"
 #include "cogl-depth-state-private.h"
-#include "cogl1-context.h"
+#include "cogl-private.h"
 
 #include <glib.h>
 #include <glib/gprintf.h>
@@ -1101,10 +1101,10 @@ _cogl_pipeline_pre_change_notify (CoglPipeline     *pipeline,
 
       if (!skip_journal_flush)
         {
-          /* 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 ();
+          /* XXX: note we need to use _cogl_flush() so we will flush
+           * *all* journals that might reference the current pipeline.
+           */
+          _cogl_flush (ctx);
         }
     }
 
diff --git a/cogl/cogl-primitives.c b/cogl/cogl-primitives.c
index 87ca8bc..ff36c0c 100644
--- a/cogl/cogl-primitives.c
+++ b/cogl/cogl-primitives.c
@@ -37,7 +37,6 @@
 #include "cogl-private.h"
 #include "cogl-meta-texture.h"
 #include "cogl-framebuffer-private.h"
-#include "cogl1-context.h"
 #include "cogl-primitives-private.h"
 
 #include <string.h>
diff --git a/cogl/cogl-private.h b/cogl/cogl-private.h
index a78435b..9eb2b84 100644
--- a/cogl/cogl-private.h
+++ b/cogl/cogl-private.h
@@ -34,6 +34,9 @@ CoglBool
 _cogl_check_extension (const char *name, char * const *ext);
 
 void
+_cogl_flush (CoglContext *ctx);
+
+void
 _cogl_clear (const CoglColor *color, unsigned long buffers);
 
 void
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index cf69304..761f916 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -51,7 +51,6 @@
 #include "cogl-object-private.h"
 #include "cogl-object-private.h"
 #include "cogl-framebuffer-private.h"
-#include "cogl1-context.h"
 #include "cogl-sub-texture.h"
 #include "cogl-primitive-texture.h"
 #include "cogl-error-private.h"
diff --git a/cogl/cogl.c b/cogl/cogl.c
index 62d511e..256c337 100644
--- a/cogl/cogl.c
+++ b/cogl/cogl.c
@@ -48,7 +48,6 @@
 #include "cogl-renderer-private.h"
 #include "cogl-config-private.h"
 #include "cogl-private.h"
-#include "cogl1-context.h"
 #include "cogl-offscreen.h"
 
 #ifdef COGL_GL_DEBUG
@@ -134,12 +133,10 @@ cogl_foreach_feature (CoglContext *ctx,
 }
 
 void
-cogl_flush (void)
+_cogl_flush (CoglContext *ctx)
 {
   GList *l;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   for (l = ctx->framebuffers; l; l = l->next)
     _cogl_framebuffer_flush_journal (l->data);
 }
diff --git a/cogl/cogl.h b/cogl/cogl.h
index 875f32a..1350dce 100644
--- a/cogl/cogl.h
+++ b/cogl/cogl.h
@@ -37,7 +37,6 @@
 #include <cogl/cogl-error.h>
 
 #include <cogl/cogl-object.h>
-#include <cogl/cogl1-context.h>
 #include <cogl/cogl-bitmap.h>
 #include <cogl/cogl-color.h>
 #include <cogl/cogl-matrix.h>
diff --git a/cogl/cogl1-context.h b/cogl/cogl1-context.h
deleted file mode 100644
index f702ae6..0000000
--- a/cogl/cogl1-context.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Cogl
- *
- * An object oriented GL/GLES Abstraction/Utility Layer
- *
- * Copyright (C) 2010 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * Authors:
- *  Robert Bragg <robert at linux.intel.com>
- *
- */
-
-#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
-#error "Only <cogl/cogl.h> can be included directly."
-#endif
-
-#ifndef __COGL_1_CONTEXT_H__
-#define __COGL_1_CONTEXT_H__
-
-#include <glib.h>
-
-#include <cogl/cogl-types.h>
-#include <cogl/cogl-texture.h>
-#include <cogl/cogl-framebuffer.h>
-
-G_BEGIN_DECLS
-
-/**
- * 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.
- *
- * Since: 1.0
- */
-void
-cogl_flush (void);
-
-G_END_DECLS
-
-#endif /* __COGL_1_CONTEXT_H__ */
diff --git a/doc/reference/cogl2/cogl2-sections.txt b/doc/reference/cogl2/cogl2-sections.txt
index c006b89..e7875b8 100644
--- a/doc/reference/cogl2/cogl2-sections.txt
+++ b/doc/reference/cogl2/cogl2-sections.txt
@@ -100,9 +100,6 @@ COGL_TYPE_BUFFER_BIT
 <SUBSECTION>
 CoglReadPixelsFlags
 
-<SUBSECTION>
-cogl_flush
-
 <SUBSECTION Standard>
 COGL_TYPE_ATTRIBUTE_TYPE
 COGL_TYPE_BLEND_STRING_ERROR
@@ -390,6 +387,7 @@ cogl_framebuffer_swap_buffers
 cogl_framebuffer_swap_region
 cogl_framebuffer_add_swap_buffers_callback
 cogl_framebuffer_remove_swap_buffers_callback
+cogl_framebuffer_flush
 cogl_framebuffer_finish
 
 <SUBSECTION>
diff --git a/tests/conform/test-gles2-context.c b/tests/conform/test-gles2-context.c
index 9a3c8b6..5670c44 100644
--- a/tests/conform/test-gles2-context.c
+++ b/tests/conform/test-gles2-context.c
@@ -87,7 +87,7 @@ test_push_pop_single_context (void)
    * of textures and so we explicitly flush the drawn rectangle to the
    * framebuffer now otherwise it may be batched until after the
    * offscreen texture has been modified again. */
-  cogl_flush ();
+  cogl_framebuffer_flush (test_fb);
 
   /* Clear the offscreen framebuffer to blue using GLES2 before
    * reading back from the onscreen framebuffer in case we mistakenly
diff --git a/tests/conform/test-sub-texture.c b/tests/conform/test-sub-texture.c
index 0291afb..318e694 100644
--- a/tests/conform/test-sub-texture.c
+++ b/tests/conform/test-sub-texture.c
@@ -215,7 +215,7 @@ validate_result (TestState *state)
 
   /* Sub sub texture */
   p = texture_data = g_malloc (10 * 10 * 4);
-  cogl_flush ();
+  cogl_framebuffer_flush (test_fb);
   cogl_framebuffer_read_pixels (test_fb,
                                 0, SOURCE_SIZE * 2, 10, 10,
                                 COGL_PIXEL_FORMAT_RGBA_8888,
-- 
1.7.7.6



More information about the Cogl mailing list