[cogl] texture: assert set_region size <= src size



commit ba02f709619aafe24158390315dc74597ec30657
Author: Robert Bragg <robert linux intel com>
Date:   Tue Nov 22 12:06:40 2011 +0000

    texture: assert set_region size <= src size
    
    This improves the documentation for cogl_texture_set_region() and
    cogl_texture_set_region_from_bitmap() to explain that the region can't
    be larger than the source data and also adds runtime assertions that
    such a request isn't made.
    
    Reviewed-by: Neil Roberts <neil linux intel com>

 cogl/cogl-texture.c |    8 ++++++++
 cogl/cogl-texture.h |   19 ++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 6353374..23fcf8c 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -676,6 +676,11 @@ cogl_texture_set_region_from_bitmap (CoglTexture *texture,
 {
   gboolean ret;
 
+  _COGL_RETURN_VAL_IF_FAIL ((_cogl_bitmap_get_width (bmp) - src_x)
+                            >= dst_width, FALSE);
+  _COGL_RETURN_VAL_IF_FAIL ((_cogl_bitmap_get_height (bmp) - src_y)
+                            >= dst_height, FALSE);
+
   /* Shortcut out early if the image is empty */
   if (dst_width == 0 || dst_height == 0)
     return TRUE;
@@ -713,6 +718,9 @@ cogl_texture_set_region (CoglTexture     *texture,
   CoglBitmap *source_bmp;
   gboolean    ret;
 
+  _COGL_RETURN_VAL_IF_FAIL ((width - src_x) >= dst_width, FALSE);
+  _COGL_RETURN_VAL_IF_FAIL ((height - src_y) >= dst_height, FALSE);
+
   /* Check for valid format */
   if (format == COGL_PIXEL_FORMAT_ANY)
     return FALSE;
diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h
index ed947de..6fedfb2 100644
--- a/cogl/cogl-texture.h
+++ b/cogl/cogl-texture.h
@@ -366,8 +366,10 @@ cogl_texture_get_data (CoglTexture *texture,
  * @src_y: upper left coordinate to use from source data.
  * @dst_x: upper left destination horizontal coordinate.
  * @dst_y: upper left destination vertical coordinate.
- * @dst_width: width of destination region to write.
- * @dst_height: height of destination region to write.
+ * @dst_width: width of destination region to write. (Must be less
+ *   than or equal to @width)
+ * @dst_height: height of destination region to write. (Must be less
+ *   than or equal to @height)
  * @width: width of source data buffer.
  * @height: height of source data buffer.
  * @format: the #CoglPixelFormat used in the source buffer.
@@ -375,9 +377,11 @@ cogl_texture_get_data (CoglTexture *texture,
  * specified)
  * @data: the actual pixel data.
  *
- * Sets the pixels in a rectangular subregion of @handle from an in-memory
+ * Sets the pixels in a rectangular subregion of @texture from an in-memory
  * buffer containing pixel data.
  *
+ * <note>The region set can't be larger than the source @data</note>
+ *
  * Return value: %TRUE if the subregion upload was successful, and
  *   %FALSE otherwise
  */
@@ -406,13 +410,18 @@ cogl_texture_set_region (CoglTexture     *texture,
  * @src_y: upper left coordinate to use from the source bitmap
  * @dst_x: upper left destination horizontal coordinate.
  * @dst_y: upper left destination vertical coordinate.
- * @dst_width: width of destination region to write.
- * @dst_height: height of destination region to write.
+ * @dst_width: width of destination region to write. (Must be less
+ *   than or equal to the bitmap width)
+ * @dst_height: height of destination region to write. (Must be less
+ *   than or equal to the bitmap height)
  * @bitmap: The source bitmap to read from
  *
  * Copies a specified source region from @bitmap to the position
  * (@src_x, @src_y) of the given destination texture @handle.
  *
+ * <note>The region updated can't be larger than the source
+ * bitmap</note>
+ *
  * Return value: %TRUE if the subregion upload was successful, and
  *   %FALSE otherwise
  *



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