[cogl] texture: add width/height members to base CoglTexture



commit 3236e47723e4287d5e0023f29083521aeffc75dd
Author: Robert Bragg <robert linux intel com>
Date:   Thu Nov 22 21:46:54 2012 +0000

    texture: add width/height members to base CoglTexture
    
    There was a lot of redundancy in how we tracked the width and height of
    different texture types which is greatly simplified by adding width and
    height members to CoglTexture directly and removing the get_width and
    get_height vfuncs from CoglTextureVtable
    
    Reviewed-by: Neil Roberts <neil linux intel com>

 cogl/cogl-atlas-texture.c                     |   21 +-------
 cogl/cogl-sub-texture-private.h               |   14 ++---
 cogl/cogl-sub-texture.c                       |   67 ++++++++++---------------
 cogl/cogl-texture-2d-private.h                |    2 -
 cogl/cogl-texture-2d-sliced-private.h         |   13 ++---
 cogl/cogl-texture-2d-sliced.c                 |   37 ++++----------
 cogl/cogl-texture-2d.c                        |   23 +-------
 cogl/cogl-texture-3d-private.h                |    2 -
 cogl/cogl-texture-3d.c                        |   18 +------
 cogl/cogl-texture-private.h                   |    6 ++-
 cogl/cogl-texture-rectangle-private.h         |    2 -
 cogl/cogl-texture-rectangle.c                 |   30 ++---------
 cogl/cogl-texture.c                           |    8 ++-
 cogl/driver/gl/cogl-texture-2d-gl.c           |    3 +-
 cogl/winsys/cogl-texture-pixmap-x11-private.h |    2 -
 cogl/winsys/cogl-texture-pixmap-x11.c         |   65 ++++++++++--------------
 cogl/winsys/cogl-winsys-egl-x11.c             |   10 ++--
 cogl/winsys/cogl-winsys-glx.c                 |    9 ++--
 18 files changed, 104 insertions(+), 228 deletions(-)
---
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index af98a0e..f717571 100644
--- a/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl-atlas-texture.c
@@ -637,24 +637,6 @@ _cogl_atlas_texture_get_gl_format (CoglTexture *tex)
   return _cogl_texture_gl_get_format (atlas_tex->sub_texture);
 }
 
-static int
-_cogl_atlas_texture_get_width (CoglTexture *tex)
-{
-  CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
-
-  /* Forward on to the sub texture */
-  return cogl_texture_get_width (atlas_tex->sub_texture);
-}
-
-static int
-_cogl_atlas_texture_get_height (CoglTexture *tex)
-{
-  CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
-
-  /* Forward on to the sub texture */
-  return cogl_texture_get_height (atlas_tex->sub_texture);
-}
-
 static CoglBool
 _cogl_atlas_texture_can_use_format (CoglPixelFormat format)
 {
@@ -721,6 +703,7 @@ _cogl_atlas_texture_new_with_size (CoglContext *ctx,
 
   _cogl_texture_init (COGL_TEXTURE (atlas_tex),
                       ctx,
+                      width, height,
                       &cogl_atlas_texture_vtable);
 
   atlas_tex->sub_texture = NULL;
@@ -876,8 +859,6 @@ cogl_atlas_texture_vtable =
     _cogl_atlas_texture_gl_flush_legacy_texobj_wrap_modes,
     _cogl_atlas_texture_get_format,
     _cogl_atlas_texture_get_gl_format,
-    _cogl_atlas_texture_get_width,
-    _cogl_atlas_texture_get_height,
     _cogl_atlas_texture_get_type,
     NULL, /* is_foreign */
     NULL /* set_auto_mipmap */
diff --git a/cogl/cogl-sub-texture-private.h b/cogl/cogl-sub-texture-private.h
index 3b66e3b..32380b1 100644
--- a/cogl/cogl-sub-texture-private.h
+++ b/cogl/cogl-sub-texture-private.h
@@ -44,14 +44,12 @@ struct _CoglSubTexture
      is created */
   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
-     passed to _cogl_sub_texture_new if next_texture is actually
-     already a sub texture */
-  int         sub_x;
-  int         sub_y;
-  int         sub_width;
-  int         sub_height;
+  /* The offset of the region represented by this sub-texture. This is
+   * the offset in full_texture which won't necessarily be the same as
+   * the offset passed to _cogl_sub_texture_new if next_texture is
+   * actually already a sub texture */
+  int sub_x;
+  int sub_y;
 };
 
 #endif /* __COGL_SUB_TEXTURE_PRIVATE_H */
diff --git a/cogl/cogl-sub-texture.c b/cogl/cogl-sub-texture.c
index 1eb7326..6b5ef1f 100644
--- a/cogl/cogl-sub-texture.c
+++ b/cogl/cogl-sub-texture.c
@@ -52,6 +52,8 @@ static void
 _cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex,
                               float *coords)
 {
+  CoglTexture *tex = COGL_TEXTURE (sub_tex);
+
   /* NB: coords[] come in as non-normalized if sub_tex->full_texture
    * is a CoglTextureRectangle otherwhise they are normalized. The
    * coordinates we write out though must always be normalized.
@@ -61,19 +63,19 @@ _cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex,
    */
   if (cogl_is_texture_rectangle (sub_tex->full_texture))
     {
-      coords[0] = (coords[0] - sub_tex->sub_x) / sub_tex->sub_width;
-      coords[1] = (coords[1] - sub_tex->sub_y) / sub_tex->sub_height;
-      coords[2] = (coords[2] - sub_tex->sub_x) / sub_tex->sub_width;
-      coords[3] = (coords[3] - sub_tex->sub_y) / sub_tex->sub_height;
+      coords[0] = (coords[0] - sub_tex->sub_x) / tex->width;
+      coords[1] = (coords[1] - sub_tex->sub_y) / tex->height;
+      coords[2] = (coords[2] - sub_tex->sub_x) / tex->width;
+      coords[3] = (coords[3] - sub_tex->sub_y) / tex->height;
     }
   else
     {
       float width = cogl_texture_get_width (sub_tex->full_texture);
       float height = cogl_texture_get_height (sub_tex->full_texture);
-      coords[0] = (coords[0] * width - sub_tex->sub_x) / sub_tex->sub_width;
-      coords[1] = (coords[1] * height - sub_tex->sub_y) / sub_tex->sub_height;
-      coords[2] = (coords[2] * width - sub_tex->sub_x) / sub_tex->sub_width;
-      coords[3] = (coords[3] * height - sub_tex->sub_y) / sub_tex->sub_height;
+      coords[0] = (coords[0] * width - sub_tex->sub_x) / tex->width;
+      coords[1] = (coords[1] * height - sub_tex->sub_y) / tex->height;
+      coords[2] = (coords[2] * width - sub_tex->sub_x) / tex->width;
+      coords[3] = (coords[3] * height - sub_tex->sub_y) / tex->height;
     }
 }
 
@@ -81,6 +83,8 @@ static void
 _cogl_sub_texture_map_quad (CoglSubTexture *sub_tex,
                             float *coords)
 {
+  CoglTexture *tex = COGL_TEXTURE (sub_tex);
+
   /* NB: coords[] always come in as normalized coordinates but may go
    * out as non-normalized if sub_tex->full_texture is a
    * CoglTextureRectangle.
@@ -91,19 +95,19 @@ _cogl_sub_texture_map_quad (CoglSubTexture *sub_tex,
 
   if (cogl_is_texture_rectangle (sub_tex->full_texture))
     {
-      coords[0] = coords[0] * sub_tex->sub_width + sub_tex->sub_x;
-      coords[1] = coords[1] * sub_tex->sub_height + sub_tex->sub_y;
-      coords[2] = coords[2] * sub_tex->sub_width + sub_tex->sub_x;
-      coords[3] = coords[3] * sub_tex->sub_height + sub_tex->sub_y;
+      coords[0] = coords[0] * tex->width + sub_tex->sub_x;
+      coords[1] = coords[1] * tex->height + sub_tex->sub_y;
+      coords[2] = coords[2] * tex->width + sub_tex->sub_x;
+      coords[3] = coords[3] * tex->height + sub_tex->sub_y;
     }
   else
     {
       float width = cogl_texture_get_width (sub_tex->full_texture);
       float height = cogl_texture_get_height (sub_tex->full_texture);
-      coords[0] = (coords[0] * sub_tex->sub_width + sub_tex->sub_x) / width;
-      coords[1] = (coords[1] * sub_tex->sub_height + sub_tex->sub_y) / height;
-      coords[2] = (coords[2] * sub_tex->sub_width + sub_tex->sub_x) / width;
-      coords[3] = (coords[3] * sub_tex->sub_height + sub_tex->sub_y) / height;
+      coords[0] = (coords[0] * tex->width + sub_tex->sub_x) / width;
+      coords[1] = (coords[1] * tex->height + sub_tex->sub_y) / height;
+      coords[2] = (coords[2] * tex->width + sub_tex->sub_x) / width;
+      coords[3] = (coords[3] * tex->height + sub_tex->sub_y) / height;
     }
 }
 
@@ -230,7 +234,8 @@ cogl_sub_texture_new (CoglContext *ctx,
 
   tex = COGL_TEXTURE (sub_tex);
 
-  _cogl_texture_init (tex, ctx, &cogl_sub_texture_vtable);
+  _cogl_texture_init (tex, ctx, sub_width, sub_height,
+                      &cogl_sub_texture_vtable);
 
   /* If the next texture is also a sub texture we can avoid one level
      of indirection by referencing the full texture of that texture
@@ -250,8 +255,6 @@ cogl_sub_texture_new (CoglContext *ctx,
 
   sub_tex->sub_x = sub_x;
   sub_tex->sub_y = sub_y;
-  sub_tex->sub_width = sub_width;
-  sub_tex->sub_height = sub_height;
 
   return _cogl_sub_texture_object_new (sub_tex);
 }
@@ -285,9 +288,9 @@ _cogl_sub_texture_can_hardware_repeat (CoglTexture *tex)
 
   /* We can hardware repeat if the subtexture actually represents all of the
      of the full texture */
-  return (sub_tex->sub_width ==
+  return (tex->width ==
           cogl_texture_get_width (sub_tex->full_texture) &&
-          sub_tex->sub_height ==
+          tex->height ==
           cogl_texture_get_height (sub_tex->full_texture) &&
           _cogl_texture_can_hardware_repeat (sub_tex->full_texture));
 }
@@ -301,9 +304,9 @@ _cogl_sub_texture_transform_coords_to_gl (CoglTexture *tex,
 
   /* This won't work if the sub texture is not the size of the full
      texture and the coordinates are outside the range [0,1] */
-  *s = ((*s * sub_tex->sub_width + sub_tex->sub_x) /
+  *s = ((*s * tex->width + sub_tex->sub_x) /
         cogl_texture_get_width (sub_tex->full_texture));
-  *t = ((*t * sub_tex->sub_height + sub_tex->sub_y) /
+  *t = ((*t * tex->height + sub_tex->sub_y) /
         cogl_texture_get_height (sub_tex->full_texture));
 
   _cogl_texture_transform_coords_to_gl (sub_tex->full_texture, s, t);
@@ -418,22 +421,6 @@ _cogl_sub_texture_get_gl_format (CoglTexture *tex)
   return _cogl_texture_gl_get_format (sub_tex->full_texture);
 }
 
-static int
-_cogl_sub_texture_get_width (CoglTexture *tex)
-{
-  CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
-
-  return sub_tex->sub_width;
-}
-
-static int
-_cogl_sub_texture_get_height (CoglTexture *tex)
-{
-  CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
-
-  return sub_tex->sub_height;
-}
-
 static CoglTextureType
 _cogl_sub_texture_get_type (CoglTexture *tex)
 {
@@ -461,8 +448,6 @@ cogl_sub_texture_vtable =
     _cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes,
     _cogl_sub_texture_get_format,
     _cogl_sub_texture_get_gl_format,
-    _cogl_sub_texture_get_width,
-    _cogl_sub_texture_get_height,
     _cogl_sub_texture_get_type,
     NULL, /* is_foreign */
     NULL /* set_auto_mipmap */
diff --git a/cogl/cogl-texture-2d-private.h b/cogl/cogl-texture-2d-private.h
index 39c9f25..3ae8ded 100644
--- a/cogl/cogl-texture-2d-private.h
+++ b/cogl/cogl-texture-2d-private.h
@@ -40,8 +40,6 @@ struct _CoglTexture2D
   /* The internal format of the GL texture represented as a
      CoglPixelFormat */
   CoglPixelFormat format;
-  int width;
-  int height;
 
   CoglBool auto_mipmap;
   CoglBool mipmaps_dirty;
diff --git a/cogl/cogl-texture-2d-sliced-private.h b/cogl/cogl-texture-2d-sliced-private.h
index 9a43bdf..5bc4e5f 100644
--- a/cogl/cogl-texture-2d-sliced-private.h
+++ b/cogl/cogl-texture-2d-sliced-private.h
@@ -33,14 +33,11 @@
 
 struct _CoglTexture2DSliced
 {
-  CoglTexture       _parent;
-  GArray           *slice_x_spans;
-  GArray           *slice_y_spans;
-  GArray           *slice_textures;
-  int               max_waste;
-
-  int               width;
-  int               height;
+  CoglTexture _parent;
+  GArray *slice_x_spans;
+  GArray *slice_y_spans;
+  GArray *slice_textures;
+  int max_waste;
 };
 
 CoglTexture2DSliced *
diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c
index 636f565..8d155d0 100644
--- a/cogl/cogl-texture-2d-sliced.c
+++ b/cogl/cogl-texture-2d-sliced.c
@@ -112,8 +112,8 @@ _cogl_texture_2d_sliced_foreach_sub_texture_in_region (
 
   data.callback = callback;
   data.user_data = user_data;
-  data.x_normalize_factor = 1.0f / tex_2ds->width;
-  data.y_normalize_factor = 1.0f / tex_2ds->height;
+  data.x_normalize_factor = 1.0f / tex->width;
+  data.y_normalize_factor = 1.0f / tex->height;
 
   un_normalized_coords[0] = virtual_tx_1 * data.x_normalize_factor;
   un_normalized_coords[1] = virtual_ty_1 * data.y_normalize_factor;
@@ -428,6 +428,7 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
                                                 GLuint source_gl_type,
                                                 CoglError **error)
 {
+  CoglTexture *tex = COGL_TEXTURE (tex_2ds);
   CoglSpan *x_span;
   CoglSpan *y_span;
   CoglSpanIter x_iter;
@@ -449,7 +450,7 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
        _cogl_span_iter_begin (&y_iter,
                               (CoglSpan *)tex_2ds->slice_y_spans->data,
                               tex_2ds->slice_y_spans->len,
-                              tex_2ds->height,
+                              tex->height,
                               dst_y,
                               dst_y + height,
                               COGL_PIPELINE_WRAP_MODE_REPEAT);
@@ -467,7 +468,7 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
            _cogl_span_iter_begin (&x_iter,
                                   (CoglSpan *)tex_2ds->slice_x_spans->data,
                                   tex_2ds->slice_x_spans->len,
-                                  tex_2ds->width,
+                                  tex->width,
                                   dst_x,
                                   dst_x + width,
                                   COGL_PIPELINE_WRAP_MODE_REPEAT);
@@ -866,7 +867,7 @@ _cogl_texture_2d_sliced_init_base (CoglContext *ctx,
 {
   CoglTexture *tex = COGL_TEXTURE (tex_2ds);
 
-  _cogl_texture_init (tex, ctx, &cogl_texture_2d_sliced_vtable);
+  _cogl_texture_init (tex, ctx, width, height, &cogl_texture_2d_sliced_vtable);
 
   tex_2ds->slice_x_spans = NULL;
   tex_2ds->slice_y_spans = NULL;
@@ -880,9 +881,6 @@ _cogl_texture_2d_sliced_init_base (CoglContext *ctx,
                                               internal_format))
     return FALSE;
 
-  tex_2ds->width = width;
-  tex_2ds->height = height;
-
   return TRUE;
 }
 
@@ -1052,10 +1050,9 @@ _cogl_texture_2d_sliced_new_from_foreign (CoglContext *ctx,
   tex_2ds = g_new0 (CoglTexture2DSliced, 1);
 
   tex = COGL_TEXTURE (tex_2ds);
-  tex->vtable = &cogl_texture_2d_sliced_vtable;
+  _cogl_texture_init (tex, ctx, gl_width, gl_height,
+                      &cogl_texture_2d_sliced_vtable);
 
-  tex_2ds->width = gl_width - x_pot_waste;
-  tex_2ds->height = gl_height - y_pot_waste;
   tex_2ds->max_waste = 0;
 
   /* Create slice arrays */
@@ -1163,8 +1160,8 @@ _cogl_texture_2d_sliced_transform_coords_to_gl (CoglTexture *tex,
   x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, 0);
   y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, 0);
 
-  *s *= tex_2ds->width / (float)x_span->size;
-  *t *= tex_2ds->height / (float)y_span->size;
+  *s *= tex->width / (float)x_span->size;
+  *t *= tex->height / (float)y_span->size;
 
   /* Let the child texture further transform the coords */
   slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0);
@@ -1356,18 +1353,6 @@ _cogl_texture_2d_sliced_get_gl_format (CoglTexture *tex)
   return _cogl_texture_gl_get_format (COGL_TEXTURE (slice_tex));
 }
 
-static int
-_cogl_texture_2d_sliced_get_width (CoglTexture *tex)
-{
-  return COGL_TEXTURE_2D_SLICED (tex)->width;
-}
-
-static int
-_cogl_texture_2d_sliced_get_height (CoglTexture *tex)
-{
-  return COGL_TEXTURE_2D_SLICED (tex)->height;
-}
-
 static CoglTextureType
 _cogl_texture_2d_sliced_get_type (CoglTexture *tex)
 {
@@ -1393,8 +1378,6 @@ cogl_texture_2d_sliced_vtable =
     _cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes,
     _cogl_texture_2d_sliced_get_format,
     _cogl_texture_2d_sliced_get_gl_format,
-    _cogl_texture_2d_sliced_get_width,
-    _cogl_texture_2d_sliced_get_height,
     _cogl_texture_2d_sliced_get_type,
     _cogl_texture_2d_sliced_is_foreign,
     NULL /* set_auto_mipmap */
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index 9df370d..74ab1ab 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -112,10 +112,8 @@ _cogl_texture_2d_create_base (CoglContext *ctx,
   CoglTexture2D *tex_2d = g_new (CoglTexture2D, 1);
   CoglTexture *tex = COGL_TEXTURE (tex_2d);
 
-  _cogl_texture_init (tex, ctx, &cogl_texture_2d_vtable);
+  _cogl_texture_init (tex, ctx, width, height, &cogl_texture_2d_vtable);
 
-  tex_2d->width = width;
-  tex_2d->height = height;
   tex_2d->mipmaps_dirty = TRUE;
   tex_2d->auto_mipmap = TRUE;
 
@@ -382,12 +380,11 @@ _cogl_texture_2d_is_sliced (CoglTexture *tex)
 static CoglBool
 _cogl_texture_2d_can_hardware_repeat (CoglTexture *tex)
 {
-  CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
   CoglContext *ctx = tex->context;
 
   if (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_REPEAT) ||
-      (_cogl_util_is_pot (tex_2d->width) &&
-       _cogl_util_is_pot (tex_2d->height)))
+      (_cogl_util_is_pot (tex->width) &&
+       _cogl_util_is_pot (tex->height)))
     return TRUE;
   else
     return FALSE;
@@ -537,18 +534,6 @@ _cogl_texture_2d_get_gl_format (CoglTexture *tex)
   return COGL_TEXTURE_2D (tex)->gl_internal_format;
 }
 
-static int
-_cogl_texture_2d_get_width (CoglTexture *tex)
-{
-  return COGL_TEXTURE_2D (tex)->width;
-}
-
-static int
-_cogl_texture_2d_get_height (CoglTexture *tex)
-{
-  return COGL_TEXTURE_2D (tex)->height;
-}
-
 static CoglBool
 _cogl_texture_2d_is_foreign (CoglTexture *tex)
 {
@@ -580,8 +565,6 @@ cogl_texture_2d_vtable =
     _cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes,
     _cogl_texture_2d_get_format,
     _cogl_texture_2d_get_gl_format,
-    _cogl_texture_2d_get_width,
-    _cogl_texture_2d_get_height,
     _cogl_texture_2d_get_type,
     _cogl_texture_2d_is_foreign,
     _cogl_texture_2d_set_auto_mipmap
diff --git a/cogl/cogl-texture-3d-private.h b/cogl/cogl-texture-3d-private.h
index 7df5b9f..88f7026 100644
--- a/cogl/cogl-texture-3d-private.h
+++ b/cogl/cogl-texture-3d-private.h
@@ -37,8 +37,6 @@ struct _CoglTexture3D
   /* The internal format of the texture represented as a
      CoglPixelFormat */
   CoglPixelFormat format;
-  int width;
-  int height;
   int depth;
   CoglBool auto_mipmap;
   CoglBool mipmaps_dirty;
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
index e7a9051..ab7c7e1 100644
--- a/cogl/cogl-texture-3d.c
+++ b/cogl/cogl-texture-3d.c
@@ -120,10 +120,8 @@ _cogl_texture_3d_create_base (CoglContext *ctx,
   CoglTexture3D *tex_3d = g_new (CoglTexture3D, 1);
   CoglTexture *tex = COGL_TEXTURE (tex_3d);
 
-  _cogl_texture_init (tex, ctx, &cogl_texture_3d_vtable);
+  _cogl_texture_init (tex, ctx, width, height, &cogl_texture_3d_vtable);
 
-  tex_3d->width = width;
-  tex_3d->height = height;
   tex_3d->depth = depth;
   tex_3d->mipmaps_dirty = TRUE;
   tex_3d->auto_mipmap = TRUE;
@@ -639,18 +637,6 @@ _cogl_texture_3d_get_gl_format (CoglTexture *tex)
   return COGL_TEXTURE_3D (tex)->gl_format;
 }
 
-static int
-_cogl_texture_3d_get_width (CoglTexture *tex)
-{
-  return COGL_TEXTURE_3D (tex)->width;
-}
-
-static int
-_cogl_texture_3d_get_height (CoglTexture *tex)
-{
-  return COGL_TEXTURE_3D (tex)->height;
-}
-
 static CoglTextureType
 _cogl_texture_3d_get_type (CoglTexture *tex)
 {
@@ -676,8 +662,6 @@ cogl_texture_3d_vtable =
     _cogl_texture_3d_gl_flush_legacy_texobj_wrap_modes,
     _cogl_texture_3d_get_format,
     _cogl_texture_3d_get_gl_format,
-    _cogl_texture_3d_get_width,
-    _cogl_texture_3d_get_height,
     _cogl_texture_3d_get_type,
     NULL, /* is_foreign */
     _cogl_texture_3d_set_auto_mipmap
diff --git a/cogl/cogl-texture-private.h b/cogl/cogl-texture-private.h
index 881d722..0e7a15e 100644
--- a/cogl/cogl-texture-private.h
+++ b/cogl/cogl-texture-private.h
@@ -126,8 +126,6 @@ struct _CoglTextureVtable
 
   CoglPixelFormat (* get_format) (CoglTexture *tex);
   GLenum (* get_gl_format) (CoglTexture *tex);
-  int (* get_width) (CoglTexture *tex);
-  int (* get_height) (CoglTexture *tex);
 
   CoglTextureType (* get_type) (CoglTexture *tex);
 
@@ -144,6 +142,8 @@ struct _CoglTexture
   CoglContext *context;
   GList *framebuffers;
   int max_level;
+  int width;
+  int height;
   const CoglTextureVtable *vtable;
 };
 
@@ -177,6 +177,8 @@ struct _CoglTexturePixel
 void
 _cogl_texture_init (CoglTexture *texture,
                     CoglContext *ctx,
+                    int width,
+                    int height,
                     const CoglTextureVtable *vtable);
 
 void
diff --git a/cogl/cogl-texture-rectangle-private.h b/cogl/cogl-texture-rectangle-private.h
index 366d58c..e6592a5 100644
--- a/cogl/cogl-texture-rectangle-private.h
+++ b/cogl/cogl-texture-rectangle-private.h
@@ -35,8 +35,6 @@ struct _CoglTextureRectangle
   /* The internal format of the texture represented as a
      CoglPixelFormat */
   CoglPixelFormat format;
-  int width;
-  int height;
 
   /* TODO: factor out these OpenGL specific members into some form
    * of driver private state. */
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
index 28dcd57..ee4cfcf 100644
--- a/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl-texture-rectangle.c
@@ -171,10 +171,7 @@ _cogl_texture_rectangle_create_base (CoglContext *ctx,
   CoglTextureRectangle *tex_rect = g_new (CoglTextureRectangle, 1);
   CoglTexture *tex = COGL_TEXTURE (tex_rect);
 
-  _cogl_texture_init (tex, ctx, &cogl_texture_rectangle_vtable);
-
-  tex_rect->width = width;
-  tex_rect->height = height;
+  _cogl_texture_init (tex, ctx, width, height, &cogl_texture_rectangle_vtable);
 
   /* We default to GL_LINEAR for both filters */
   tex_rect->gl_legacy_texobj_min_filter = GL_LINEAR;
@@ -462,17 +459,14 @@ _cogl_texture_rectangle_transform_coords_to_gl (CoglTexture *tex,
                                                 float *s,
                                                 float *t)
 {
-  CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
-
-  *s *= tex_rect->width;
-  *t *= tex_rect->height;
+  *s *= tex->width;
+  *t *= tex->height;
 }
 
 static CoglTransformResult
 _cogl_texture_rectangle_transform_quad_coords_to_gl (CoglTexture *tex,
                                                      float *coords)
 {
-  CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
   CoglBool need_repeat = FALSE;
   int i;
 
@@ -480,7 +474,7 @@ _cogl_texture_rectangle_transform_quad_coords_to_gl (CoglTexture *tex,
     {
       if (coords[i] < 0.0f || coords[i] > 1.0f)
         need_repeat = TRUE;
-      coords[i] *= (i & 1) ? tex_rect->height : tex_rect->width;
+      coords[i] *= (i & 1) ? tex->height : tex->width;
     }
 
   return (need_repeat ? COGL_TRANSFORM_SOFTWARE_REPEAT
@@ -614,7 +608,7 @@ _cogl_texture_rectangle_get_data (CoglTexture *tex,
 
   ctx->texture_driver->prep_gl_for_pixels_download (ctx,
                                                     rowstride,
-                                                    tex_rect->width,
+                                                    tex->width,
                                                     bpp);
 
   _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
@@ -639,18 +633,6 @@ _cogl_texture_rectangle_get_gl_format (CoglTexture *tex)
   return COGL_TEXTURE_RECTANGLE (tex)->gl_format;
 }
 
-static int
-_cogl_texture_rectangle_get_width (CoglTexture *tex)
-{
-  return COGL_TEXTURE_RECTANGLE (tex)->width;
-}
-
-static int
-_cogl_texture_rectangle_get_height (CoglTexture *tex)
-{
-  return COGL_TEXTURE_RECTANGLE (tex)->height;
-}
-
 static CoglBool
 _cogl_texture_rectangle_is_foreign (CoglTexture *tex)
 {
@@ -682,8 +664,6 @@ cogl_texture_rectangle_vtable =
     _cogl_texture_rectangle_gl_flush_legacy_texobj_wrap_modes,
     _cogl_texture_rectangle_get_format,
     _cogl_texture_rectangle_get_gl_format,
-    _cogl_texture_rectangle_get_width,
-    _cogl_texture_rectangle_get_height,
     _cogl_texture_rectangle_get_type,
     _cogl_texture_rectangle_is_foreign,
     _cogl_texture_rectangle_set_auto_mipmap
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index d0ba54d..4803388 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -100,10 +100,14 @@ cogl_is_texture (void *object)
 void
 _cogl_texture_init (CoglTexture *texture,
                     CoglContext *context,
+                    int width,
+                    int height,
                     const CoglTextureVtable *vtable)
 {
   texture->context = context;
   texture->max_level = 0;
+  texture->width = width;
+  texture->height = height;
   texture->vtable = vtable;
   texture->framebuffers = NULL;
 }
@@ -251,13 +255,13 @@ _cogl_texture_is_foreign (CoglTexture *texture)
 unsigned int
 cogl_texture_get_width (CoglTexture *texture)
 {
-  return texture->vtable->get_width (texture);
+  return texture->width;
 }
 
 unsigned int
 cogl_texture_get_height (CoglTexture *texture)
 {
-  return texture->vtable->get_height (texture);
+  return texture->height;
 }
 
 CoglPixelFormat
diff --git a/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/driver/gl/cogl-texture-2d-gl.c
index dadbc19..267b4d2 100644
--- a/cogl/driver/gl/cogl-texture-2d-gl.c
+++ b/cogl/driver/gl/cogl-texture-2d-gl.c
@@ -607,6 +607,7 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
 {
   CoglContext *ctx = COGL_TEXTURE (tex_2d)->context;
   int bpp;
+  int width = COGL_TEXTURE (tex_2d)->width;
   GLenum gl_format;
   GLenum gl_type;
 
@@ -620,7 +621,7 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
 
   ctx->texture_driver->prep_gl_for_pixels_download (ctx,
                                                     rowstride,
-                                                    tex_2d->width,
+                                                    width,
                                                     bpp);
 
   _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
diff --git a/cogl/winsys/cogl-texture-pixmap-x11-private.h b/cogl/winsys/cogl-texture-pixmap-x11-private.h
index 1c21ea0..b99dfa6 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11-private.h
+++ b/cogl/winsys/cogl-texture-pixmap-x11-private.h
@@ -57,8 +57,6 @@ struct _CoglTexturePixmapX11
 
   unsigned int depth;
   Visual *visual;
-  unsigned int width;
-  unsigned int height;
 
   XImage *image;
 
diff --git a/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/winsys/cogl-texture-pixmap-x11.c
index 22e952a..6823074 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11.c
+++ b/cogl/winsys/cogl-texture-pixmap-x11.c
@@ -125,6 +125,7 @@ static void
 process_damage_event (CoglTexturePixmapX11 *tex_pixmap,
                       XDamageNotifyEvent *damage_event)
 {
+  CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
   Display *display;
   enum { DO_NOTHING, NEEDS_SUBTRACT, NEED_BOUNDING_BOX } handle_mode;
   const CoglWinsysVtable *winsys;
@@ -167,8 +168,8 @@ process_damage_event (CoglTexturePixmapX11 *tex_pixmap,
      need to request the bounding box of the region because we're
      going to update the whole texture anyway. */
   if (cogl_damage_rectangle_is_whole (&tex_pixmap->damage_rect,
-                                      tex_pixmap->width,
-                                      tex_pixmap->height))
+                                      tex->width,
+                                      tex->height))
     {
       if (handle_mode != DO_NOTHING)
         XDamageSubtract (display, tex_pixmap->damage, None, None);
@@ -283,24 +284,16 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
   Display *display = cogl_xlib_renderer_get_display (ctxt->display->renderer);
   Window pixmap_root_window;
   int pixmap_x, pixmap_y;
+  unsigned int pixmap_width, pixmap_height;
   unsigned int pixmap_border_width;
   CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
   XWindowAttributes window_attributes;
   int damage_base;
   const CoglWinsysVtable *winsys;
 
-  _cogl_texture_init (tex, ctxt, &cogl_texture_pixmap_x11_vtable);
-
-  tex_pixmap->pixmap = pixmap;
-  tex_pixmap->image = NULL;
-  tex_pixmap->shm_info.shmid = -1;
-  tex_pixmap->tex = NULL;
-  tex_pixmap->damage_owned = FALSE;
-  tex_pixmap->damage = 0;
-
   if (!XGetGeometry (display, pixmap, &pixmap_root_window,
                      &pixmap_x, &pixmap_y,
-                     &tex_pixmap->width, &tex_pixmap->height,
+                     &pixmap_width, &pixmap_height,
                      &pixmap_border_width, &tex_pixmap->depth))
     {
       g_free (tex_pixmap);
@@ -311,6 +304,16 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
       return NULL;
     }
 
+  _cogl_texture_init (tex, ctxt, pixmap_width, pixmap_height,
+                      &cogl_texture_pixmap_x11_vtable);
+
+  tex_pixmap->pixmap = pixmap;
+  tex_pixmap->image = NULL;
+  tex_pixmap->shm_info.shmid = -1;
+  tex_pixmap->tex = NULL;
+  tex_pixmap->damage_owned = FALSE;
+  tex_pixmap->damage = 0;
+
   /* We need a visual to use for shared memory images so we'll query
      it from the pixmap's root window */
   if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
@@ -342,9 +345,9 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
 
   /* Assume the entire pixmap is damaged to begin with */
   tex_pixmap->damage_rect.x1 = 0;
-  tex_pixmap->damage_rect.x2 = tex_pixmap->width;
+  tex_pixmap->damage_rect.x2 = tex->width;
   tex_pixmap->damage_rect.y1 = 0;
-  tex_pixmap->damage_rect.y2 = tex_pixmap->height;
+  tex_pixmap->damage_rect.y2 = tex->height;
 
   winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap);
   if (winsys->texture_pixmap_x11_create)
@@ -366,6 +369,7 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
 static void
 try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap)
 {
+  CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
   XImage *dummy_image;
   Display *display;
 
@@ -392,8 +396,8 @@ try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap)
                      ZPixmap,
                      NULL,
                      NULL, /* shminfo, */
-                     tex_pixmap->width,
-                     tex_pixmap->height);
+                     tex->width,
+                     tex->height);
   if (!dummy_image)
     goto failed_image_create;
 
@@ -479,6 +483,7 @@ cogl_texture_pixmap_x11_set_damage_object (CoglTexturePixmapX11 *tex_pixmap,
 static void
 _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
 {
+  CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
   Display *display;
   Visual *visual;
   CoglPixelFormat image_format;
@@ -516,8 +521,8 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
                         : COGL_PIXEL_FORMAT_RGB_888);
 
       tex_pixmap->tex = cogl_texture_new_with_size (ctx,
-                                                    tex_pixmap->width,
-                                                    tex_pixmap->height,
+                                                    tex->width,
+                                                    tex->height,
                                                     COGL_TEXTURE_NONE,
                                                     texture_format,
                                                     NULL);
@@ -543,7 +548,7 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
           tex_pixmap->image = XGetImage (display,
                                          tex_pixmap->pixmap,
                                          0, 0,
-                                         tex_pixmap->width, tex_pixmap->height,
+                                         tex->width, tex->height,
                                          AllPlanes, ZPixmap);
           image = tex_pixmap->image;
           src_x = x;
@@ -776,8 +781,8 @@ _cogl_texture_pixmap_x11_foreach_sub_texture_in_region
   if (cogl_is_texture_rectangle (child_tex))
     {
       NormalizeCoordsWrapperData data;
-      int width = tex_pixmap->width;
-      int height = tex_pixmap->height;
+      int width = tex->width;
+      int height = tex->height;
 
       virtual_tx_1 *= width;
       virtual_ty_1 *= height;
@@ -948,22 +953,6 @@ _cogl_texture_pixmap_x11_get_gl_format (CoglTexture *tex)
   return _cogl_texture_gl_get_format (child_tex);
 }
 
-static int
-_cogl_texture_pixmap_x11_get_width (CoglTexture *tex)
-{
-  CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (tex);
-
-  return tex_pixmap->width;
-}
-
-static int
-_cogl_texture_pixmap_x11_get_height (CoglTexture *tex)
-{
-  CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (tex);
-
-  return tex_pixmap->height;
-}
-
 static CoglTextureType
 _cogl_texture_pixmap_x11_get_type (CoglTexture *tex)
 {
@@ -1030,8 +1019,6 @@ cogl_texture_pixmap_x11_vtable =
     _cogl_texture_pixmap_x11_gl_flush_legacy_texobj_wrap_modes,
     _cogl_texture_pixmap_x11_get_format,
     _cogl_texture_pixmap_x11_get_gl_format,
-    _cogl_texture_pixmap_x11_get_width,
-    _cogl_texture_pixmap_x11_get_height,
     _cogl_texture_pixmap_x11_get_type,
     NULL, /* is_foreign */
     NULL /* set_auto_mipmap */
diff --git a/cogl/winsys/cogl-winsys-egl-x11.c b/cogl/winsys/cogl-winsys-egl-x11.c
index 43ac07e..d792f07 100644
--- a/cogl/winsys/cogl-winsys-egl-x11.c
+++ b/cogl/winsys/cogl-winsys-egl-x11.c
@@ -685,15 +685,13 @@ _cogl_winsys_poll_dispatch (CoglContext *context,
 static CoglBool
 _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap)
 {
+  CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
+  CoglContext *ctx = tex->context;
   CoglTexturePixmapEGL *egl_tex_pixmap;
   EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
   CoglPixelFormat texture_format;
   CoglRendererEGL *egl_renderer;
 
-  /* FIXME: It should be possible to get to a CoglContext from any
-   * CoglTexture pointer. */
-  _COGL_GET_CONTEXT (ctx, FALSE);
-
   egl_renderer = ctx->display->renderer->winsys;
 
   if (!(egl_renderer->private_features &
@@ -724,8 +722,8 @@ _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap)
 
   egl_tex_pixmap->texture = COGL_TEXTURE (
     _cogl_egl_texture_2d_new_from_image (ctx,
-                                         tex_pixmap->width,
-                                         tex_pixmap->height,
+                                         tex->width,
+                                         tex->height,
                                          texture_format,
                                          egl_tex_pixmap->image,
                                          NULL));
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 2750200..8e50a05 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -1920,6 +1920,7 @@ static CoglBool
 _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
                                         CoglBool needs_mipmap)
 {
+  CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
   CoglContext *ctx = COGL_TEXTURE (tex_pixmap)->context;
   CoglTexturePixmapGLX *glx_tex_pixmap = tex_pixmap->winsys;
   CoglGLXRenderer *glx_renderer;
@@ -1944,8 +1945,8 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
         {
           glx_tex_pixmap->glx_tex = COGL_TEXTURE (
             cogl_texture_rectangle_new_with_size (ctx,
-                                                  tex_pixmap->width,
-                                                  tex_pixmap->height,
+                                                  tex->width,
+                                                  tex->height,
                                                   texture_format,
                                                   &error));
 
@@ -1966,8 +1967,8 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
         {
           glx_tex_pixmap->glx_tex = COGL_TEXTURE (
             cogl_texture_2d_new_with_size (ctx,
-                                           tex_pixmap->width,
-                                           tex_pixmap->height,
+                                           tex->width,
+                                           tex->height,
                                            texture_format,
                                            NULL));
 



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