From c11f72fd6d226037a20aba14caae3bd4d3b30858 Mon Sep 17 00:00:00 2001
From: Neil Roberts <neil@linux.intel.com>
Date: Fri, 10 Dec 2010 16:06:16 +0000
Subject: [PATCH] cogl-matrix-stack: Convert to be a CoglObject

We will want to use ref-counting on the CoglMatrixStack so it might as
well be a CoglObject.
---
 cogl/cogl-framebuffer.c     |  4 ++--
 cogl/cogl-matrix-stack.c    | 13 ++++++++++---
 cogl/cogl-matrix-stack.h    |  3 ---
 cogl/cogl-pipeline-opengl.c |  2 +-
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index b65dae730..eab9a0746 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -166,10 +166,10 @@ _cogl_framebuffer_free (CoglFramebuffer *framebuffer)
 {
   _cogl_clip_state_destroy (&framebuffer->clip_state);
 
-  _cogl_matrix_stack_destroy (framebuffer->modelview_stack);
+  cogl_object_unref (framebuffer->modelview_stack);
   framebuffer->modelview_stack = NULL;
 
-  _cogl_matrix_stack_destroy (framebuffer->projection_stack);
+  cogl_object_unref (framebuffer->projection_stack);
   framebuffer->projection_stack = NULL;
 }
 
diff --git a/cogl/cogl-matrix-stack.c b/cogl/cogl-matrix-stack.c
index dec1fc555..7b4ad69f8 100644
--- a/cogl/cogl-matrix-stack.c
+++ b/cogl/cogl-matrix-stack.c
@@ -34,6 +34,7 @@
 #include "cogl-internal.h"
 #include "cogl-matrix-stack.h"
 #include "cogl-framebuffer-private.h"
+#include "cogl-object-private.h"
 
 typedef struct {
   CoglMatrix matrix;
@@ -53,6 +54,8 @@ typedef struct {
  */
 struct _CoglMatrixStack
 {
+  CoglObject _parent;
+
   GArray *stack;
 
   /* which state does GL have, NULL if unknown */
@@ -62,6 +65,10 @@ struct _CoglMatrixStack
   unsigned int age;
 };
 
+static void _cogl_matrix_stack_free (CoglMatrixStack *stack);
+
+COGL_OBJECT_INTERNAL_DEFINE (MatrixStack, matrix_stack);
+
 /* XXX: this doesn't initialize the matrix! */
 static void
 _cogl_matrix_state_init (CoglMatrixState *state)
@@ -142,11 +149,11 @@ _cogl_matrix_stack_new (void)
 
   stack->age = 0;
 
-  return stack;
+  return _cogl_matrix_stack_object_new (stack);
 }
 
-void
-_cogl_matrix_stack_destroy (CoglMatrixStack *stack)
+static void
+_cogl_matrix_stack_free (CoglMatrixStack *stack)
 {
   g_array_free (stack->stack, TRUE);
   g_slice_free (CoglMatrixStack, stack);
diff --git a/cogl/cogl-matrix-stack.h b/cogl/cogl-matrix-stack.h
index 7024f99a5..8efca3fed 100644
--- a/cogl/cogl-matrix-stack.h
+++ b/cogl/cogl-matrix-stack.h
@@ -42,9 +42,6 @@ typedef enum {
 CoglMatrixStack *
 _cogl_matrix_stack_new (void);
 
-void
-_cogl_matrix_stack_destroy (CoglMatrixStack *stack);
-
 void
 _cogl_matrix_stack_push (CoglMatrixStack *stack);
 
diff --git a/cogl/cogl-pipeline-opengl.c b/cogl/cogl-pipeline-opengl.c
index 84ca8a51c..1700dc887 100644
--- a/cogl/cogl-pipeline-opengl.c
+++ b/cogl/cogl-pipeline-opengl.c
@@ -102,7 +102,7 @@ texture_unit_free (CoglTextureUnit *unit)
 {
   if (unit->layer)
     cogl_object_unref (unit->layer);
-  _cogl_matrix_stack_destroy (unit->matrix_stack);
+  cogl_object_unref (unit->matrix_stack);
 }
 
 CoglTextureUnit *