Merge "libgralloc: Add Perform function to get the stride."
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index 6003688..5aca758 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -47,6 +47,8 @@
using namespace gralloc;
using namespace qdutils;
+ANDROID_SINGLETON_STATIC_INSTANCE(AdrenoMemInfo);
+
//Common functions
static bool canFallback(int usage, bool triedSystem)
{
@@ -81,6 +83,35 @@
return false;
}
+//-------------- AdrenoMemInfo-----------------------//
+int AdrenoMemInfo::getStride(int width, int format)
+{
+ int stride = ALIGN(width, 32);
+ switch (format)
+ {
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
+ stride = ALIGN(width, 32);
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
+ stride = ALIGN(width, 128);
+ break;
+ case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_YV12:
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ case HAL_PIXEL_FORMAT_YCrCb_422_SP:
+ stride = ALIGN(width, 16);
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
+ stride = VENUS_Y_STRIDE(COLOR_FMT_NV12, width);
+ break;
+ default: break;
+ }
+ return stride;
+}
+
+//-------------- IAllocController-----------------------//
IAllocController* IAllocController::sController = NULL;
IAllocController* IAllocController::getInstance(void)
{
@@ -176,7 +207,7 @@
{
size_t size;
- alignedw = ALIGN(width, 32);
+ alignedw = AdrenoMemInfo::getInstance().getStride(width, format);
alignedh = ALIGN(height, 32);
switch (format) {
case HAL_PIXEL_FORMAT_RGBA_8888:
@@ -202,7 +233,6 @@
// The chroma plane is subsampled,
// but the pitch in bytes is unchanged
// The GPU needs 4K alignment, but the video decoder needs 8K
- alignedw = ALIGN(width, 128);
size = ALIGN( alignedw * alignedh, 8192);
size += ALIGN( alignedw * ALIGN(height/2, 32), 8192);
break;
@@ -214,7 +244,6 @@
ALOGE("w or h is odd for the YV12 format");
return -EINVAL;
}
- alignedw = ALIGN(width, 16);
alignedh = height;
if (HAL_PIXEL_FORMAT_NV12_ENCODEABLE == format) {
// The encoder requires a 2K aligned chroma offset.
@@ -232,12 +261,10 @@
ALOGE("width is odd for the YUV422_SP format");
return -EINVAL;
}
- alignedw = ALIGN(width, 16);
alignedh = height;
size = ALIGN(alignedw * alignedh * 2, 4096);
break;
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
- alignedw = VENUS_Y_STRIDE(COLOR_FMT_NV12, width);
alignedh = VENUS_Y_SCANLINES(COLOR_FMT_NV12, height);
size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, width, height);
break;
diff --git a/libgralloc/gr.h b/libgralloc/gr.h
index cee47de..c6bd137 100644
--- a/libgralloc/gr.h
+++ b/libgralloc/gr.h
@@ -31,6 +31,7 @@
#include <errno.h>
#include <cutils/native_handle.h>
+#include <utils/Singleton.h>
/*****************************************************************************/
@@ -79,4 +80,16 @@
inline void unlock() { pthread_mutex_unlock(&mutex); }
};
+
+class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo>
+{
+ public:
+ AdrenoMemInfo() {}
+
+ ~AdrenoMemInfo() {}
+
+ int getStride(int width, int format);
+
+ private:
+};
#endif /* GR_H_ */
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 2c50e77..d2f3073 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -85,6 +85,7 @@
/* Gralloc perform enums
*/
GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 1,
+ GRALLOC_MODULE_PERFORM_GET_STRIDE,
};
#define GRALLOC_HEAP_MASK (GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP |\
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index 4f28877..27761be 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -369,6 +369,14 @@
res = 0;
}
break;
+ case GRALLOC_MODULE_PERFORM_GET_STRIDE:
+ {
+ int width = va_arg(args, int);
+ int format = va_arg(args, int);
+ int *stride = va_arg(args, int *);
+ *stride = AdrenoMemInfo::getInstance().getStride(width, format);
+ res = 0;
+ } break;
#endif
default:
break;