[cogl] matrix-stack: Avoid referencing the default CoglContext



commit 39a7bcff67b6bd3ec8b14fa269b72e23e1f6cf82
Author: Robert Bragg <robert linux intel com>
Date:   Mon Nov 21 14:22:01 2011 +0000

    matrix-stack: Avoid referencing the default CoglContext
    
    This removes the use of _COGL_GET_CONTEXT() from cogl-matrix-stack.c
    as part of the ongoing effort to evolve cogl to get rid of the need for
    a default context.
    
    Reviewed-by: Neil Roberts <neil linux intel com>

 cogl/cogl-clip-stack.c             |   29 ++++++++++------
 cogl/cogl-journal.c                |    9 +++--
 cogl/cogl-matrix-stack.c           |   66 +++++++++++++++++-------------------
 cogl/cogl-matrix-stack.h           |   10 ++++--
 cogl/cogl-pipeline-progend-glsl.c  |   40 +++++++++++-----------
 cogl/cogl-pipeline-vertend-fixed.c |    5 ++-
 cogl/cogl-pipeline-vertend-glsl.c  |    3 +-
 7 files changed, 88 insertions(+), 74 deletions(-)
---
diff --git a/cogl/cogl-clip-stack.c b/cogl/cogl-clip-stack.c
index e3e8340..b9db676 100644
--- a/cogl/cogl-clip-stack.c
+++ b/cogl/cogl-clip-stack.c
@@ -109,7 +109,7 @@ set_clip_plane (CoglFramebuffer *framebuffer,
   _cogl_matrix_stack_translate (modelview_stack,
                                 -vertex_a[0], -vertex_a[1], -vertex_a[2]);
 
-  _cogl_matrix_stack_flush_to_gl (modelview_stack, COGL_MATRIX_MODELVIEW);
+  _cogl_matrix_stack_flush_to_gl (ctx, modelview_stack, COGL_MATRIX_MODELVIEW);
 
   planef[0] = 0;
   planef[1] = -1.0;
@@ -210,8 +210,7 @@ add_stencil_clip_rectangle (CoglFramebuffer *framebuffer,
     _cogl_framebuffer_get_modelview_stack (framebuffer);
   CoglMatrixStack *projection_stack =
     _cogl_framebuffer_get_projection_stack (framebuffer);
-
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+  CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
 
   /* temporarily swap in our special stenciling pipeline */
   _cogl_push_source (ctx->stencil_pipeline, FALSE);
@@ -219,9 +218,11 @@ add_stencil_clip_rectangle (CoglFramebuffer *framebuffer,
   /* This can be called from the journal code which doesn't flush
      the matrix stacks between calls so we need to ensure they're
      flushed now */
-  _cogl_matrix_stack_flush_to_gl (modelview_stack,
+  _cogl_matrix_stack_flush_to_gl (ctx,
+                                  modelview_stack,
                                   COGL_MATRIX_MODELVIEW);
-  _cogl_matrix_stack_flush_to_gl (projection_stack,
+  _cogl_matrix_stack_flush_to_gl (ctx,
+                                  projection_stack,
                                   COGL_MATRIX_PROJECTION);
 
   if (first)
@@ -257,9 +258,11 @@ add_stencil_clip_rectangle (CoglFramebuffer *framebuffer,
       _cogl_matrix_stack_push (modelview_stack);
       _cogl_matrix_stack_load_identity (modelview_stack);
 
-      _cogl_matrix_stack_flush_to_gl (modelview_stack,
+      _cogl_matrix_stack_flush_to_gl (ctx,
+                                      modelview_stack,
                                       COGL_MATRIX_MODELVIEW);
-      _cogl_matrix_stack_flush_to_gl (projection_stack,
+      _cogl_matrix_stack_flush_to_gl (ctx,
+                                      projection_stack,
                                       COGL_MATRIX_PROJECTION);
 
       _cogl_rectangle_immediate (-1.0, -1.0, 1.0, 1.0);
@@ -298,9 +301,11 @@ add_stencil_clip_silhouette (CoglFramebuffer *framebuffer,
   /* This can be called from the clip stack code which doesn't flush
      the matrix stacks between calls so we need to ensure they're
      flushed now */
-  _cogl_matrix_stack_flush_to_gl (modelview_stack,
+  _cogl_matrix_stack_flush_to_gl (ctx,
+                                  modelview_stack,
                                   COGL_MATRIX_MODELVIEW);
-  _cogl_matrix_stack_flush_to_gl (projection_stack,
+  _cogl_matrix_stack_flush_to_gl (ctx,
+                                  projection_stack,
                                   COGL_MATRIX_PROJECTION);
 
   /* Just setup a simple pipeline that doesn't use texturing... */
@@ -361,12 +366,14 @@ add_stencil_clip_silhouette (CoglFramebuffer *framebuffer,
 
       _cogl_matrix_stack_push (projection_stack);
       _cogl_matrix_stack_load_identity (projection_stack);
-      _cogl_matrix_stack_flush_to_gl (projection_stack,
+      _cogl_matrix_stack_flush_to_gl (ctx,
+                                      projection_stack,
                                       COGL_MATRIX_PROJECTION);
 
       _cogl_matrix_stack_push (modelview_stack);
       _cogl_matrix_stack_load_identity (modelview_stack);
-      _cogl_matrix_stack_flush_to_gl (modelview_stack,
+      _cogl_matrix_stack_flush_to_gl (ctx,
+                                      modelview_stack,
                                       COGL_MATRIX_MODELVIEW);
 
       _cogl_rectangle_immediate (-1.0, -1.0, 1.0, 1.0);
diff --git a/cogl/cogl-journal.c b/cogl/cogl-journal.c
index cd2359b..ad64675 100644
--- a/cogl/cogl-journal.c
+++ b/cogl/cogl-journal.c
@@ -292,7 +292,8 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start,
     {
       _cogl_matrix_stack_set (state->modelview_stack,
                               &batch_start->model_view);
-      _cogl_matrix_stack_flush_to_gl (state->modelview_stack,
+      _cogl_matrix_stack_flush_to_gl (ctx,
+                                      state->modelview_stack,
                                       COGL_MATRIX_MODELVIEW);
     }
 
@@ -718,14 +719,16 @@ _cogl_journal_flush_clip_stacks_and_entries (CoglJournalEntry *batch_start,
   if (G_LIKELY (!(COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM))))
     {
       _cogl_matrix_stack_load_identity (state->modelview_stack);
-      _cogl_matrix_stack_flush_to_gl (state->modelview_stack,
+      _cogl_matrix_stack_flush_to_gl (ctx,
+                                      state->modelview_stack,
                                       COGL_MATRIX_MODELVIEW);
     }
 
   /* Setting up the clip state can sometimes also flush the projection
      matrix so we should flush it again. This will be a no-op if the
      clip code didn't modify the projection */
-  _cogl_matrix_stack_flush_to_gl (state->projection_stack,
+  _cogl_matrix_stack_flush_to_gl (ctx,
+                                  state->projection_stack,
                                   COGL_MATRIX_PROJECTION);
 
   batch_and_call (batch_start,
diff --git a/cogl/cogl-matrix-stack.c b/cogl/cogl-matrix-stack.c
index 1c68654..bd6df01 100644
--- a/cogl/cogl-matrix-stack.c
+++ b/cogl/cogl-matrix-stack.c
@@ -396,23 +396,22 @@ _cogl_matrix_stack_set (CoglMatrixStack  *stack,
 #if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
 
 static void
-flush_to_fixed_api_gl (gboolean is_identity,
+flush_to_fixed_api_gl (CoglContext *context,
+                       gboolean is_identity,
                        const CoglMatrix *matrix,
                        void *user_data)
 {
   CoglMatrixStack *stack = user_data;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   if (is_identity)
     {
       if (!stack->flushed_identity)
-        GE (ctx, glLoadIdentity ());
+        GE (context, glLoadIdentity ());
       stack->flushed_identity = TRUE;
     }
   else
     {
-      GE (ctx, glLoadMatrixf (cogl_matrix_get_array (matrix)) );
+      GE (context, glLoadMatrixf (cogl_matrix_get_array (matrix)) );
       stack->flushed_identity = FALSE;
     }
 }
@@ -420,16 +419,13 @@ flush_to_fixed_api_gl (gboolean is_identity,
 #endif
 
 void
-_cogl_matrix_stack_prepare_for_flush (CoglMatrixStack *stack,
+_cogl_prepare_matrix_stack_for_flush (CoglContext *context,
+                                      CoglMatrixStack *stack,
                                       CoglMatrixMode mode,
                                       CoglMatrixStackFlushFunc callback,
                                       void *user_data)
 {
-  CoglMatrixState *state;
-
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
-  state = _cogl_matrix_stack_top (stack);
+  CoglMatrixState *state = _cogl_matrix_stack_top (stack);
 
   /* Because Cogl defines texture coordinates to have a top left origin and
    * because offscreen framebuffers may be used for rendering to textures we
@@ -440,29 +436,28 @@ _cogl_matrix_stack_prepare_for_flush (CoglMatrixStack *stack,
     {
       CoglMatrix flipped_projection;
       CoglMatrix *projection =
-        state->is_identity ? &ctx->identity_matrix : &state->matrix;
+        state->is_identity ? &context->identity_matrix : &state->matrix;
 
       cogl_matrix_multiply (&flipped_projection,
-                            &ctx->y_flip_matrix, projection);
-      callback (FALSE, &flipped_projection, user_data);
+                            &context->y_flip_matrix, projection);
+      callback (context, FALSE, &flipped_projection, user_data);
     }
   else
-    callback (state->is_identity,
-              state->is_identity ? &ctx->identity_matrix : &state->matrix,
-              user_data);
+    {
+      CoglMatrix *modelview =
+        state->is_identity ? &context->identity_matrix : &state->matrix;
+      callback (context, state->is_identity, modelview, user_data);
+    }
 }
 
 void
-_cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
-                                CoglMatrixMode   mode)
+_cogl_matrix_stack_flush_to_gl (CoglContext *context,
+                                CoglMatrixStack *stack,
+                                CoglMatrixMode mode)
 {
-  CoglMatrixState *state;
-
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
-  state = _cogl_matrix_stack_top (stack);
+  CoglMatrixState *state = _cogl_matrix_stack_top (stack);
 
-  if (ctx->driver == COGL_DRIVER_GLES2)
+  if (context->driver == COGL_DRIVER_GLES2)
     {
       /* Under GLES2 we need to flush the matrices differently because
          they are stored in uniforms attached to the program instead of
@@ -475,16 +470,16 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
         {
         case COGL_MATRIX_MODELVIEW:
           cogl_object_ref (stack);
-          if (ctx->flushed_modelview_stack)
-            cogl_object_unref (ctx->flushed_modelview_stack);
-          ctx->flushed_modelview_stack = stack;
+          if (context->flushed_modelview_stack)
+            cogl_object_unref (context->flushed_modelview_stack);
+          context->flushed_modelview_stack = stack;
           break;
 
         case COGL_MATRIX_PROJECTION:
           cogl_object_ref (stack);
-          if (ctx->flushed_projection_stack)
-            cogl_object_unref (ctx->flushed_projection_stack);
-          ctx->flushed_projection_stack = stack;
+          if (context->flushed_projection_stack)
+            cogl_object_unref (context->flushed_projection_stack);
+          context->flushed_projection_stack = stack;
           break;
 
         case COGL_MATRIX_TEXTURE:
@@ -501,7 +496,7 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
       if (stack->flushed_state == state)
         return;
 
-      if (ctx->flushed_matrix_mode != mode)
+      if (context->flushed_matrix_mode != mode)
         {
           GLenum gl_mode = 0;
 
@@ -520,11 +515,12 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
               break;
             }
 
-          GE (ctx, glMatrixMode (gl_mode));
-          ctx->flushed_matrix_mode = mode;
+          GE (context, glMatrixMode (gl_mode));
+          context->flushed_matrix_mode = mode;
         }
 
-      _cogl_matrix_stack_prepare_for_flush (stack,
+      _cogl_prepare_matrix_stack_for_flush (context,
+                                            stack,
                                             mode,
                                             flush_to_fixed_api_gl,
                                             stack);
diff --git a/cogl/cogl-matrix-stack.h b/cogl/cogl-matrix-stack.h
index 45aeaa8..0ed0f1e 100644
--- a/cogl/cogl-matrix-stack.h
+++ b/cogl/cogl-matrix-stack.h
@@ -30,6 +30,7 @@
 #define __COGL_MATRIX_STACK_H
 
 #include "cogl-matrix.h"
+#include "cogl-context.h"
 
 typedef struct _CoglMatrixStack CoglMatrixStack;
 
@@ -39,7 +40,8 @@ typedef enum {
   COGL_MATRIX_TEXTURE
 } CoglMatrixMode;
 
-typedef void (* CoglMatrixStackFlushFunc) (gboolean is_identity,
+typedef void (* CoglMatrixStackFlushFunc) (CoglContext *context,
+                                           gboolean is_identity,
                                            const CoglMatrix *matrix,
                                            void *user_data);
 
@@ -106,7 +108,8 @@ void
 _cogl_matrix_stack_set (CoglMatrixStack *stack,
                         const CoglMatrix *matrix);
 void
-_cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
+_cogl_matrix_stack_flush_to_gl (CoglContext *ctx,
+                                CoglMatrixStack *stack,
                                 CoglMatrixMode mode);
 void
 _cogl_matrix_stack_dirty (CoglMatrixStack  *stack);
@@ -122,7 +125,8 @@ gboolean
 _cogl_matrix_stack_has_identity_flag (CoglMatrixStack *stack);
 
 void
-_cogl_matrix_stack_prepare_for_flush (CoglMatrixStack *stack,
+_cogl_prepare_matrix_stack_for_flush (CoglContext *context,
+                                      CoglMatrixStack *stack,
                                       CoglMatrixMode mode,
                                       CoglMatrixStackFlushFunc callback,
                                       void *user_data);
diff --git a/cogl/cogl-pipeline-progend-glsl.c b/cogl/cogl-pipeline-progend-glsl.c
index c612d73..703cbea 100644
--- a/cogl/cogl-pipeline-progend-glsl.c
+++ b/cogl/cogl-pipeline-progend-glsl.c
@@ -994,27 +994,25 @@ _cogl_pipeline_progend_glsl_layer_pre_change_notify (
 #ifdef HAVE_COGL_GLES2
 
 static void
-flush_modelview_cb (gboolean is_identity,
+flush_modelview_cb (CoglContext *ctx,
+                    gboolean is_identity,
                     const CoglMatrix *matrix,
                     void *user_data)
 {
   CoglPipelineProgramState *program_state = user_data;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   GE( ctx, glUniformMatrix4fv (program_state->modelview_uniform, 1, FALSE,
                                cogl_matrix_get_array (matrix)) );
 }
 
 static void
-flush_projection_cb (gboolean is_identity,
-                    const CoglMatrix *matrix,
-                    void *user_data)
+flush_projection_cb (CoglContext *ctx,
+                     gboolean is_identity,
+                     const CoglMatrix *matrix,
+                     void *user_data)
 {
   CoglPipelineProgramState *program_state = user_data;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   GE( ctx, glUniformMatrix4fv (program_state->projection_uniform, 1, FALSE,
                                cogl_matrix_get_array (matrix)) );
 }
@@ -1026,15 +1024,14 @@ typedef struct
 } FlushCombinedData;
 
 static void
-flush_combined_step_two_cb (gboolean is_identity,
+flush_combined_step_two_cb (CoglContext *ctx,
+                            gboolean is_identity,
                             const CoglMatrix *matrix,
                             void *user_data)
 {
   FlushCombinedData *data = user_data;
   CoglMatrix mvp_matrix;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   /* If the modelview is the identity then we can bypass the matrix
      multiplication */
   if (is_identity)
@@ -1055,18 +1052,18 @@ flush_combined_step_two_cb (gboolean is_identity,
 }
 
 static void
-flush_combined_step_one_cb (gboolean is_identity,
+flush_combined_step_one_cb (CoglContext *ctx,
+                            gboolean is_identity,
                             const CoglMatrix *matrix,
                             void *user_data)
 {
   FlushCombinedData data;
 
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
-
   data.program_state = user_data;
   data.projection_matrix = matrix;
 
-  _cogl_matrix_stack_prepare_for_flush (ctx->flushed_modelview_stack,
+  _cogl_prepare_matrix_stack_for_flush (ctx,
+                                        ctx->flushed_modelview_stack,
                                         COGL_MATRIX_MODELVIEW,
                                         flush_combined_step_two_cb,
                                         &data);
@@ -1127,8 +1124,9 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline)
         _cogl_matrix_stack_has_identity_flag (ctx->flushed_modelview_stack);
 
       if (program_state->modelview_uniform != -1)
-        _cogl_matrix_stack_prepare_for_flush (program_state
-                                              ->flushed_modelview_stack,
+        _cogl_prepare_matrix_stack_for_flush (ctx,
+                                              program_state
+                                                ->flushed_modelview_stack,
                                               COGL_MATRIX_MODELVIEW,
                                               flush_modelview_cb,
                                               program_state);
@@ -1144,8 +1142,9 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline)
         _cogl_matrix_stack_get_age (ctx->flushed_projection_stack);
 
       if (program_state->projection_uniform != -1)
-        _cogl_matrix_stack_prepare_for_flush (program_state
-                                              ->flushed_projection_stack,
+        _cogl_prepare_matrix_stack_for_flush (ctx,
+                                              program_state
+                                                ->flushed_projection_stack,
                                               COGL_MATRIX_PROJECTION,
                                               flush_projection_cb,
                                               program_state);
@@ -1153,7 +1152,8 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline)
 
   if (program_state->mvp_uniform != -1 &&
       (modelview_changed || projection_changed))
-    _cogl_matrix_stack_prepare_for_flush (ctx->flushed_projection_stack,
+    _cogl_prepare_matrix_stack_for_flush (ctx,
+                                          ctx->flushed_projection_stack,
                                           COGL_MATRIX_PROJECTION,
                                           flush_combined_step_one_cb,
                                           program_state);
diff --git a/cogl/cogl-pipeline-vertend-fixed.c b/cogl/cogl-pipeline-vertend-fixed.c
index 477b2af..5850677 100644
--- a/cogl/cogl-pipeline-vertend-fixed.c
+++ b/cogl/cogl-pipeline-vertend-fixed.c
@@ -81,6 +81,8 @@ _cogl_pipeline_vertend_fixed_add_layer (CoglPipeline *pipeline,
   int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
   CoglTextureUnit *unit = _cogl_get_texture_unit (unit_index);
 
+  _COGL_GET_CONTEXT (ctx, FALSE);
+
   if (layers_difference & COGL_PIPELINE_LAYER_STATE_USER_MATRIX)
     {
       CoglPipelineLayerState state = COGL_PIPELINE_LAYER_STATE_USER_MATRIX;
@@ -92,7 +94,8 @@ _cogl_pipeline_vertend_fixed_add_layer (CoglPipeline *pipeline,
 
       _cogl_set_active_texture_unit (unit_index);
 
-      _cogl_matrix_stack_flush_to_gl (unit->matrix_stack, COGL_MATRIX_TEXTURE);
+      _cogl_matrix_stack_flush_to_gl (ctx, unit->matrix_stack,
+                                      COGL_MATRIX_TEXTURE);
     }
 
   return TRUE;
diff --git a/cogl/cogl-pipeline-vertend-glsl.c b/cogl/cogl-pipeline-vertend-glsl.c
index 3465573..dcd6ef5 100644
--- a/cogl/cogl-pipeline-vertend-glsl.c
+++ b/cogl/cogl-pipeline-vertend-glsl.c
@@ -306,7 +306,8 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
 
           _cogl_set_active_texture_unit (unit_index);
 
-          _cogl_matrix_stack_flush_to_gl (unit->matrix_stack,
+          _cogl_matrix_stack_flush_to_gl (ctx,
+                                          unit->matrix_stack,
                                           COGL_MATRIX_TEXTURE);
         }
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]