[Cogl] [PATCH] replace public cogl_flush with _cogl_framebuffer_flush

Robert Bragg robert at sixbynine.org
Tue Nov 27 07:32:22 PST 2012


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

Ok, instead of giving the api a scary name this changes the patch to keep
_cogl_framebuffer_flush() private since actually it seems like we don't
know of a use case for this api for applications. The previously
documented use case for cogl_flush() to help applications that want to
intermix cogl and gl doesn't actually make much sense. Although all
drawing gets flushed to GL when calling the api it still leaves GL in an
undefined state so applications wouldn't realistically be able to
intermix GL drawing. If an app just needs to use GL to create objects
such as textures then they don't need to flush anything they just need
to save and restore any state they change.

-- >8 --

This removes the cogl_flush() api which depends on a global Cogl context
and provides a more specific _cogl_framebuffer_flush() instead. This
new function isn't public since we don't currently see a use for this
api for applications. (The previously documented use for cogl_flush() to
allow applications to intermix direct GL and cogl usage was missleading
and wouldn't have worked for intermixing drawing commands. Intermixing
GL to create objects such as textures doesn't require any flush api)

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              |    8 ++-
 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-private.h        |   35 ++++++++++++++++
 cogl/cogl-framebuffer.c                |   10 ++++-
 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                   |   71 --------------------------------
 doc/reference/cogl2/cogl2-sections.txt |    4 +-
 tests/conform/test-gles2-context.c     |    2 +-
 tests/conform/test-sub-texture.c       |    1 -
 22 files changed, 62 insertions(+), 106 deletions(-)
 delete mode 100644 cogl/cogl1-context.h

diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index 35f7df9..e969148 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 9953d27..f6cdeba 100644
--- a/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl-atlas-texture.c
@@ -41,10 +41,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>
 
@@ -109,6 +109,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.
@@ -116,7 +118,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,7 +371,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 e3e57fc..6aaaf7d 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 6538fb5..9db3b0e 100644
--- a/cogl/cogl-clip-stack.c
+++ b/cogl/cogl-clip-stack.c
@@ -43,7 +43,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 b7670ea..cddb388 100644
--- a/cogl/cogl-clip-state.c
+++ b/cogl/cogl-clip-state.c
@@ -38,7 +38,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 b25e627..02c187e 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-private.h b/cogl/cogl-framebuffer-private.h
index 99da66a..e6d0082 100644
--- a/cogl/cogl-framebuffer-private.h
+++ b/cogl/cogl-framebuffer-private.h
@@ -448,5 +448,40 @@ _cogl_framebuffer_get_projection_entry (CoglFramebuffer *framebuffer)
   return projection_stack->last_entry;
 }
 
+/*
+ * _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.
+ *
+ * XXX: We considered making this api public, but actually for the
+ * direct use of OpenGL usecase this api isn't really enough since
+ * it would leave GL in a completely undefined state which would
+ * basically make it inpractical for applications to use. To really
+ * support mixing raw GL with Cogl we'd probabably need to guarantee
+ * that we reset all GL state to defaults.
+ */
+void
+_cogl_framebuffer_flush (CoglFramebuffer *framebuffer);
 
 #endif /* __COGL_FRAMEBUFFER_PRIVATE_H */
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index 388d246..9d8a2ee 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -44,7 +44,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"
@@ -552,6 +551,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;
@@ -916,7 +921,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-journal.c b/cogl/cogl-journal.c
index 5db9cb4..589f2e3 100644
--- a/cogl/cogl-journal.c
+++ b/cogl/cogl-journal.c
@@ -37,7 +37,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 99a0ea0..9ae985c 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);
 
@@ -118,8 +117,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,
@@ -138,8 +137,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 9c25c31..2e49a5d 100644
--- a/cogl/cogl-path.c
+++ b/cogl/cogl-path.c
@@ -42,7 +42,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 5c1f441..feb911d 100644
--- a/cogl/cogl-pipeline.c
+++ b/cogl/cogl-pipeline.c
@@ -44,7 +44,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>
@@ -1100,10 +1100,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 c40b848..9eeac71 100644
--- a/cogl/cogl-primitives.c
+++ b/cogl/cogl-primitives.c
@@ -36,7 +36,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 6ba589b..ca508a4 100644
--- a/cogl/cogl-private.h
+++ b/cogl/cogl-private.h
@@ -78,6 +78,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 89bc465..8483715 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 30464e8..578f0b4 100644
--- a/cogl/cogl.c
+++ b/cogl/cogl.c
@@ -47,7 +47,6 @@
 #include "cogl-renderer-private.h"
 #include "cogl-config-private.h"
 #include "cogl-private.h"
-#include "cogl1-context.h"
 #include "cogl-offscreen.h"
 
 CoglBool
@@ -95,12 +94,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 7684d45..58477ff 100644
--- a/cogl/cogl.h
+++ b/cogl/cogl.h
@@ -31,7 +31,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 239c9fb..0000000
--- a/cogl/cogl1-context.h
+++ /dev/null
@@ -1,71 +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 <cogl/cogl-types.h>
-#include <cogl/cogl-texture.h>
-#include <cogl/cogl-framebuffer.h>
-
-COGL_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);
-
-COGL_END_DECLS
-
-#endif /* __COGL_1_CONTEXT_H__ */
diff --git a/doc/reference/cogl2/cogl2-sections.txt b/doc/reference/cogl2/cogl2-sections.txt
index 1849f62..a24dd05 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..fe6a893 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_finish (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 4f9448f..e81f7b1 100644
--- a/tests/conform/test-sub-texture.c
+++ b/tests/conform/test-sub-texture.c
@@ -215,7 +215,6 @@ validate_result (TestState *state)
 
   /* Sub sub texture */
   p = texture_data = g_malloc (10 * 10 * 4);
-  cogl_flush ();
   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