gralloc: Add vstride to gralloc handles, pad rgb surfaces
authorRebecca Schultz Zavin <rebecca@android.com>
Wed, 15 Aug 2012 18:17:04 +0000 (11:17 -0700)
committerRebecca Schultz Zavin <rebecca@android.com>
Wed, 15 Aug 2012 18:22:22 +0000 (11:22 -0700)
If rgb surfaces are padded to nearest 16 pixels in height,
the gscalar can accept them.  This change increases the number
of cases where the hardware composer can make use of the
gscalar.

Change-Id: Iffacbdb2637c8b80c5cd0a8a62d015e854950a43
Signed-off-by: Rebecca Schultz Zavin <rebecca@android.com>
gralloc/gralloc.cpp
include/gralloc_priv.h

index 4937bbbaf634252b386d9238de5597cb037e49e7..85774b5a9cc780294ba2685833a9f639690f4db8 100644 (file)
@@ -115,7 +115,7 @@ static int gralloc_alloc_rgb(int ionfd, int w, int h, int format, int flags,
                              private_handle_t **hnd, int *stride)
 {
     size_t size, bpr;
-    int bpp = 0, fd, err;
+    int bpp = 0, vstride, fd, err;
     switch (format) {
         case HAL_PIXEL_FORMAT_RGBA_8888:
         case HAL_PIXEL_FORMAT_RGBX_8888:
@@ -138,12 +138,13 @@ static int gralloc_alloc_rgb(int ionfd, int w, int h, int format, int flags,
             return -EINVAL;
     }
     bpr = ALIGN(w*bpp, 16);
-    size = bpr * h;
+    vstride = ALIGN(h, 16);
+    size = bpr * vstride;
     *stride = bpr / bpp;
     size = ALIGN(size, PAGE_SIZE);
 
     err = ion_alloc_fd(ionfd, size, 0, 1 << ION_HEAP_TYPE_SYSTEM, flags, &fd);
-    *hnd = new private_handle_t(fd, size, 0, w, h, format, *stride);
+    *hnd = new private_handle_t(fd, size, 0, w, h, format, *stride, vstride);
 
     return err;
 }
@@ -153,15 +154,16 @@ static int gralloc_alloc_yuv(int ionfd, int w, int h, int format, int flags,
 {
     size_t luma_size, chroma_size;
     int err, planes, fd, fd1, fd2 = 0;
+    size_t luma_vstride;
     *stride = ALIGN(w, 16);
 
     switch (format) {
         ALOGE("invalid yuv format %d\n", format);
         case HAL_PIXEL_FORMAT_YV12:
         {
-            size_t vstride = ALIGN(h, 16);
-            luma_size = vstride * *stride;
-            chroma_size = (vstride / 2) * ALIGN(*stride / 2, 16);
+            luma_vstride = ALIGN(h, 16);
+            luma_size = luma_vstride * *stride;
+            chroma_size = (luma_vstride / 2) * ALIGN(*stride / 2, 16);
             planes = 3;
             break;
         }
@@ -169,8 +171,8 @@ static int gralloc_alloc_yuv(int ionfd, int w, int h, int format, int flags,
         case HAL_PIXEL_FORMAT_YCbCr_420_SP:
         case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
         {
-            size_t luma_vstride = ALIGN(h, 32);
             size_t chroma_vstride = ALIGN(h / 2, 32);
+            luma_vstride = ALIGN(h, 32);
             luma_size = luma_vstride * *stride;
             chroma_size = chroma_vstride * *stride;
             planes = 2;
@@ -197,7 +199,7 @@ static int gralloc_alloc_yuv(int ionfd, int w, int h, int format, int flags,
     }
 
     *hnd = new private_handle_t(fd, fd1, fd2, luma_size, 0, w, h, format,
-                                *stride);
+                                *stride, luma_vstride);
     return err;
 
 err2:
index 9c35e85c5ea83d5f19b46b6569007729fa37fcd2..8a9890d8db2388eccf147e23f41b85e7ba6bd760 100644 (file)
@@ -85,20 +85,22 @@ struct private_handle_t {
     int     width;
     int     height;
     int     stride;
+    int     vstride;
 
     // FIXME: the attributes below should be out-of-line
     void    *base;
 
 #ifdef __cplusplus
     static const int sNumFds = 3;
-    static const int sNumInts = 9;
+    static const int sNumInts = 10;
     static const int sMagic = 0x3141592;
 
 
     private_handle_t(int fd, int size, int flags, int w,
-                    int h, int format, int stride) :
+                    int h, int format, int stride, int vstride) :
         fd(fd), magic(sMagic), flags(flags), size(size),
-       offset(0), format(format), width(w), height(h), stride(stride), base(0)
+        offset(0), format(format), width(w), height(h), stride(stride),
+        vstride(vstride), base(0)
     {
         version = sizeof(native_handle);
         numInts = sNumInts;
@@ -108,9 +110,10 @@ struct private_handle_t {
     }
 
     private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w,
-                    int h, int format, int stride) :
+                    int h, int format, int stride, int vstride) :
         fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size),
-       offset(0), format(format), width(w), height(h), stride(stride), base(0)
+        offset(0), format(format), width(w), height(h), stride(stride),
+        vstride(vstride), base(0)
     {
         version = sizeof(native_handle);
         numInts = sNumInts;