OSDN Git Service

minigbm: add bytes per pixel function
authorGurchetan Singh <gurchetansingh@chromium.org>
Thu, 23 Mar 2017 18:29:26 +0000 (11:29 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Thu, 30 Mar 2017 07:15:53 +0000 (00:15 -0700)
We were using the drv_stride_from_format as a shorthand to calculate
bytes per pixel. This is incorrect with the addition of
DRM_FORMAT_YVU420_ANDROID, which always aligns to 16 bytes.

Let's have a separate bytes_per_pixel function to better express what
we want.

BUG=chromium:616275
TEST=android.media.cts.DecodeAccuracyTest
     #testVP9GLViewLargerHeightVideoDecode

passes on veyron_minnie-cheets.

Change-Id: I2d740828d66031c3a032932c09d79dbce21b8986
Reviewed-on: https://chromium-review.googlesource.com/458978
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
cros_gralloc/cros_alloc_device.cc
drv.c
drv.h
helpers.c
helpers.h

index e9cadd2..2281fa0 100644 (file)
@@ -95,7 +95,7 @@ static struct cros_gralloc_handle *cros_gralloc_handle_from_bo(struct bo *bo)
        hnd->magic = cros_gralloc_magic();
 
        hnd->pixel_stride = hnd->strides[0];
-       hnd->pixel_stride /= drv_stride_from_format(hnd->format, 1, 0);
+       hnd->pixel_stride /= drv_bytes_per_pixel(hnd->format, 0);
 
        return hnd;
 }
diff --git a/drv.c b/drv.c
index 1b94bd6..41bd1f1 100644 (file)
--- a/drv.c
+++ b/drv.c
@@ -501,39 +501,6 @@ uint32_t drv_resolve_format(struct driver *drv, uint32_t format)
        return format;
 }
 
-/*
- * This function returns the stride for a given format, width and plane.
- */
-int drv_stride_from_format(uint32_t format, uint32_t width, size_t plane)
-{
-       int stride = DIV_ROUND_UP(width * drv_bpp_from_format(format, plane),
-                                 8);
-
-       /*
-        * Only downsample for certain multiplanar formats which have horizontal
-        * subsampling for chroma planes.  Only formats supported by our drivers
-        * are listed here -- add more as needed.
-        */
-       if (plane != 0) {
-               switch (format) {
-               case DRM_FORMAT_NV12:
-               case DRM_FORMAT_YVU420:
-               case DRM_FORMAT_YVU420_ANDROID:
-                       stride = DIV_ROUND_UP(stride, 2);
-                       break;
-               }
-       }
-
-       /*
-        * The stride of Android YV12 buffers is required to be aligned to 16 bytes
-        * (see <system/graphics.h>).
-        */
-       if (format == DRM_FORMAT_YVU420_ANDROID)
-               stride = ALIGN(stride, 16);
-
-       return stride;
-}
-
 size_t drv_num_planes_from_format(uint32_t format)
 {
        switch (format) {
@@ -596,6 +563,12 @@ size_t drv_num_planes_from_format(uint32_t format)
        return 0;
 }
 
+uint32_t
+drv_bytes_per_pixel(uint32_t format, size_t plane)
+{
+       return DIV_ROUND_UP(drv_bpp_from_format(format, plane), 8);
+}
+
 uint32_t drv_size_from_format(uint32_t format, uint32_t stride,
                              uint32_t height, size_t plane)
 {
diff --git a/drv.h b/drv.h
index 6863dfa..42bc2ce 100644 (file)
--- a/drv.h
+++ b/drv.h
@@ -162,13 +162,13 @@ drv_bo_get_format(struct bo *bo);
 uint32_t
 drv_resolve_format(struct driver *drv, uint32_t format);
 
-int
-drv_stride_from_format(uint32_t format, uint32_t width, size_t plane);
-
 size_t
 drv_num_planes_from_format(uint32_t format);
 
 uint32_t
+drv_bytes_per_pixel(uint32_t format, size_t plane);
+
+uint32_t
 drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height,
                     size_t plane);
 
index 8e76929..951093c 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -106,6 +106,39 @@ int drv_bpp_from_format(uint32_t format, size_t plane)
 }
 
 /*
+ * This function returns the stride for a given format, width and plane.
+ */
+uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane)
+{
+       uint32_t stride = DIV_ROUND_UP(width * drv_bpp_from_format(format, plane),
+                                      8);
+
+       /*
+        * Only downsample for certain multiplanar formats which have horizontal
+        * subsampling for chroma planes.  Only formats supported by our drivers
+        * are listed here -- add more as needed.
+        */
+       if (plane != 0) {
+               switch (format) {
+               case DRM_FORMAT_NV12:
+               case DRM_FORMAT_YVU420:
+               case DRM_FORMAT_YVU420_ANDROID:
+                       stride = DIV_ROUND_UP(stride, 2);
+                       break;
+               }
+       }
+
+       /*
+        * The stride of Android YV12 buffers is required to be aligned to 16 bytes
+        * (see <system/graphics.h>).
+        */
+       if (format == DRM_FORMAT_YVU420_ANDROID)
+               stride = ALIGN(stride, 16);
+
+       return stride;
+}
+
+/*
  * This function fills in the buffer object given driver aligned dimensions
  * (in pixels) and a format. This function assumes there is just one kernel
  * buffer per buffer object.
@@ -145,7 +178,7 @@ int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height,
 
        aligned_width = width;
        aligned_height = height;
-       bytes_per_pixel = DIV_ROUND_UP(drv_bpp_from_format(format, 0), 8);
+       bytes_per_pixel = drv_bytes_per_pixel(format, 0);
        if (format == DRM_FORMAT_YVU420_ANDROID) {
                /*
                 * Align width to 16 pixels, so chroma strides are 16 bytes as
index 4289e44..a8e685c 100644 (file)
--- a/helpers.h
+++ b/helpers.h
@@ -10,6 +10,7 @@
 #include "drv.h"
 
 int drv_bpp_from_format(uint32_t format, size_t plane);
+uint32_t drv_stride_from_format(uint32_t format, uint32_t width, size_t plane);
 int drv_bo_from_format(struct bo *bo, uint32_t aligned_width,
                       uint32_t aligned_height, uint32_t format);
 int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height,