[cogl/wip/rib/master-next: 38/44] texture: Make CoglSubTexture experimental public api



commit 3d70990b031db2bb36fff35f2f30f849bc173f11
Author: Robert Bragg <robert linux intel com>
Date:   Fri Oct 21 11:36:25 2011 +0100

    texture: Make CoglSubTexture experimental public api
    
    This exposes cogl_sub_texture_new() and cogl_is_sub_texture() as
    experimental public API. Previously sub-textures were only exposed via
    cogl_texture_new_from_sub_texture() so there wasn't a corresponding
    CoglSubTexture type. A CoglSubTexture is a high-level texture defined as
    a sub-region of some other parent texture. CoglSubTextures are high
    level textures that implement the CoglMetaTexture interface which can
    be used to manually handle texture repeating.

 cogl/cogl-atlas-texture.c                          |   12 ++++---
 cogl/cogl-sub-texture-private.h                    |   24 ++++---------
 cogl/cogl-sub-texture.c                            |   38 +++++++++----------
 cogl/cogl-texture.c                                |   11 ++++--
 cogl/cogl.h                                        |    1 +
 .../cogl-2.0-experimental-sections.txt             |    7 ++++
 6 files changed, 47 insertions(+), 46 deletions(-)
---
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index bb10c98..e3ecf80 100644
--- a/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl-atlas-texture.c
@@ -58,11 +58,13 @@ _cogl_atlas_texture_create_sub_texture (CoglHandle full_texture,
 {
   /* Create a subtexture for the given rectangle not including the
      1-pixel border */
-  return _cogl_sub_texture_new (full_texture,
-                                rectangle->x + 1,
-                                rectangle->y + 1,
-                                rectangle->width - 2,
-                                rectangle->height - 2);
+  _COGL_GET_CONTEXT (ctx, NULL);
+  return cogl_sub_texture_new (ctx,
+                               full_texture,
+                               rectangle->x + 1,
+                               rectangle->y + 1,
+                               rectangle->width - 2,
+                               rectangle->height - 2);
 }
 
 static void
diff --git a/cogl/cogl-sub-texture-private.h b/cogl/cogl-sub-texture-private.h
index 0cc3c91..b3fb761 100644
--- a/cogl/cogl-sub-texture-private.h
+++ b/cogl/cogl-sub-texture-private.h
@@ -21,15 +21,12 @@
  *
  */
 
-#ifndef __COGL_SUB_TEXTURE_H
-#define __COGL_SUB_TEXTURE_H
+#ifndef __COGL_SUB_TEXTURE_PRIVATE_H
+#define __COGL_SUB_TEXTURE_PRIVATE_H
 
-#include "cogl-handle.h"
 #include "cogl-texture-private.h"
 
-#define COGL_SUB_TEXTURE(tex) ((CoglSubTexture *) tex)
-
-typedef struct _CoglSubTexture CoglSubTexture;
+#include <glib.h>
 
 struct _CoglSubTexture
 {
@@ -40,12 +37,12 @@ struct _CoglSubTexture
      use the full texture from that to render instead of making a
      chain. However we want to preserve the next texture in case the
      user is expecting us to keep a reference and also so that we can
-     later add a cogl_sub_texture_get_full_texture() function. */
-  CoglHandle  next_texture;
+     later add a cogl_sub_texture_get_parent_texture() function. */
+  CoglTexture *next_texture;
   /* This is the texture that will actually be used to draw. It will
      point to the end of the chain if a sub texture of a sub texture
      is created */
-  CoglHandle  full_texture;
+  CoglTexture *full_texture;
 
   /* The region represented by this sub-texture. This is the region of
      full_texture which won't necessarily be the same as the region
@@ -60,11 +57,4 @@ struct _CoglSubTexture
 GQuark
 _cogl_handle_sub_texture_get_type (void);
 
-CoglHandle
-_cogl_sub_texture_new (CoglHandle next_texture,
-                       int sub_x,
-                       int sub_y,
-                       int sub_width,
-                       int sub_height);
-
-#endif /* __COGL_SUB_TEXTURE_H */
+#endif /* __COGL_SUB_TEXTURE_PRIVATE_H */
diff --git a/cogl/cogl-sub-texture.c b/cogl/cogl-sub-texture.c
index 0739782..5af4d02 100644
--- a/cogl/cogl-sub-texture.c
+++ b/cogl/cogl-sub-texture.c
@@ -3,7 +3,7 @@
  *
  * An object oriented GL/GLES Abstraction/Utility Layer
  *
- * Copyright (C) 2009,2010 Intel Corporation.
+ * Copyright (C) 2009,2010,2011 Intel Corporation.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -34,7 +34,7 @@
 #include "cogl-texture-private.h"
 #include "cogl-sub-texture-private.h"
 #include "cogl-context-private.h"
-#include "cogl-handle.h"
+#include "cogl-object.h"
 #include "cogl-texture-driver.h"
 #include "cogl-texture-rectangle-private.h"
 
@@ -43,7 +43,7 @@
 
 static void _cogl_sub_texture_free (CoglSubTexture *sub_tex);
 
-COGL_TEXTURE_INTERNAL_DEFINE (SubTexture, sub_texture);
+COGL_TEXTURE_DEFINE (SubTexture, sub_texture);
 
 static const CoglTextureVtable cogl_sub_texture_vtable;
 
@@ -196,19 +196,20 @@ _cogl_sub_texture_set_wrap_mode_parameters (CoglTexture *tex,
 static void
 _cogl_sub_texture_free (CoglSubTexture *sub_tex)
 {
-  cogl_handle_unref (sub_tex->next_texture);
-  cogl_handle_unref (sub_tex->full_texture);
+  cogl_object_unref (sub_tex->next_texture);
+  cogl_object_unref (sub_tex->full_texture);
 
   /* Chain up */
   _cogl_texture_free (COGL_TEXTURE (sub_tex));
 }
 
-CoglHandle
-_cogl_sub_texture_new (CoglHandle next_texture,
-                       int sub_x, int sub_y,
-                       int sub_width, int sub_height)
+CoglSubTexture *
+cogl_sub_texture_new (CoglContext *ctx,
+                      CoglTexture *next_texture,
+                      int sub_x, int sub_y,
+                      int sub_width, int sub_height)
 {
-  CoglHandle      full_texture;
+  CoglTexture    *full_texture;
   CoglSubTexture *sub_tex;
   CoglTexture    *tex;
   unsigned int    next_width, next_height;
@@ -217,13 +218,10 @@ _cogl_sub_texture_new (CoglHandle next_texture,
   next_height = cogl_texture_get_height (next_texture);
 
   /* The region must specify a non-zero subset of the full texture */
-  _COGL_RETURN_VAL_IF_FAIL (sub_x >= 0 && sub_y >= 0, COGL_INVALID_HANDLE);
-  _COGL_RETURN_VAL_IF_FAIL (sub_width > 0 && sub_height > 0,
-                            COGL_INVALID_HANDLE);
-  _COGL_RETURN_VAL_IF_FAIL (sub_x + sub_width <= next_width,
-                            COGL_INVALID_HANDLE);
-  _COGL_RETURN_VAL_IF_FAIL (sub_y + sub_height <= next_height,
-                            COGL_INVALID_HANDLE);
+  _COGL_RETURN_VAL_IF_FAIL (sub_x >= 0 && sub_y >= 0, NULL);
+  _COGL_RETURN_VAL_IF_FAIL (sub_width > 0 && sub_height > 0, NULL);
+  _COGL_RETURN_VAL_IF_FAIL (sub_x + sub_width <= next_width, NULL);
+  _COGL_RETURN_VAL_IF_FAIL (sub_y + sub_height <= next_height, NULL);
 
   sub_tex = g_new (CoglSubTexture, 1);
 
@@ -234,7 +232,7 @@ _cogl_sub_texture_new (CoglHandle next_texture,
   /* If the next texture is also a sub texture we can avoid one level
      of indirection by referencing the full texture of that texture
      instead. */
-  if (_cogl_is_sub_texture (next_texture))
+  if (cogl_is_sub_texture (next_texture))
     {
       CoglSubTexture *other_sub_tex =
         _cogl_sub_texture_pointer_from_handle (next_texture);
@@ -245,8 +243,8 @@ _cogl_sub_texture_new (CoglHandle next_texture,
   else
     full_texture = next_texture;
 
-  sub_tex->next_texture = cogl_handle_ref (next_texture);
-  sub_tex->full_texture = cogl_handle_ref (full_texture);
+  sub_tex->next_texture = cogl_object_ref (next_texture);
+  sub_tex->full_texture = cogl_object_ref (full_texture);
 
   sub_tex->sub_x = sub_x;
   sub_tex->sub_y = sub_y;
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index f8e2d5c..6353374 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -454,8 +454,9 @@ cogl_texture_new_from_foreign (GLuint           gl_handle,
        * coordinates, but the semantics for this function that people
        * depend on are that all returned texture works with normalized
        * coordinates so we wrap with a CoglSubTexture... */
-      sub_texture = _cogl_sub_texture_new (COGL_TEXTURE (texture_rectangle),
-                                           0, 0, width, height);
+      sub_texture = cogl_sub_texture_new (ctx,
+                                          COGL_TEXTURE (texture_rectangle),
+                                          0, 0, width, height);
       return COGL_TEXTURE (sub_texture);
     }
 #endif
@@ -496,8 +497,10 @@ cogl_texture_new_from_sub_texture (CoglTexture *full_texture,
                                    int sub_width,
                                    int sub_height)
 {
-  return _cogl_sub_texture_new (full_texture, sub_x, sub_y,
-                                sub_width, sub_height);
+  _COGL_GET_CONTEXT (ctx, NULL);
+  return COGL_TEXTURE (cogl_sub_texture_new (ctx,
+                                             full_texture, sub_x, sub_y,
+                                             sub_width, sub_height));
 }
 
 CoglTexture *
diff --git a/cogl/cogl.h b/cogl/cogl.h
index aa32948..2ca3967 100644
--- a/cogl/cogl.h
+++ b/cogl/cogl.h
@@ -83,6 +83,7 @@ typedef struct _CoglFramebuffer CoglFramebuffer;
 #include <cogl/cogl-texture-rectangle.h>
 #include <cogl/cogl-texture-3d.h>
 #include <cogl/cogl-texture-2d-sliced.h>
+#include <cogl/cogl-sub-texture.h>
 #include <cogl/cogl-meta-texture.h>
 #include <cogl/cogl-index-buffer.h>
 #include <cogl/cogl-attribute-buffer.h>
diff --git a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
index c65582a..12888ae 100644
--- a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
+++ b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
@@ -329,6 +329,13 @@ cogl_is_texture_3d
 </SECTION>
 
 <SECTION>
+<FILE>cogl-sub-texture</FILE>
+<TITLE>Sub Textures</TITLE>
+cogl_sub_texture_new
+cogl_is_sub_texture
+</SECTION>
+
+<SECTION>
 <FILE>cogl-framebuffer</FILE>
 <TITLE>CoglFramebuffer: The Framebuffer Interface</TITLE>
 CoglFramebuffer



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