gralloc: Add adreno_utils header
Add adreno_utils header to define Adreno pixel formats, which are
needed by gralloc to map HAL format to corresponding Adreno format.
Change-Id: I6d38f34583955e3990393801f1dca0dd9aa2013b
diff --git a/libgralloc/adreno_utils.h b/libgralloc/adreno_utils.h
new file mode 100644
index 0000000..6cb7810
--- /dev/null
+++ b/libgralloc/adreno_utils.h
@@ -0,0 +1,51 @@
+/*
+* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+* * Redistributions of source code must retain the above copyright notice, this list of
+* conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright notice, this list of
+* conditions and the following disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its contributors may be used to
+* endorse or promote products derived from this software without specific prior written
+* permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+// Adreno Pixel Formats
+typedef enum {
+
+ ADRENO_PIXELFORMAT_UNKNOWN = 0,
+ ADRENO_PIXELFORMAT_R8G8B8A8 = 27,
+ ADRENO_PIXELFORMAT_R8G8B8A8_SRGB = 29,
+ ADRENO_PIXELFORMAT_B5G6R5 = 85,
+ ADRENO_PIXELFORMAT_B5G5R5A1 = 86,
+ ADRENO_PIXELFORMAT_B8G8R8A8 = 90,
+ ADRENO_PIXELFORMAT_B8G8R8A8_SRGB = 91,
+ ADRENO_PIXELFORMAT_B8G8R8X8_SRGB = 93,
+ ADRENO_PIXELFORMAT_NV12 = 103,
+ ADRENO_PIXELFORMAT_YUY2 = 107,
+ ADRENO_PIXELFORMAT_B4G4R4A4 = 115,
+ ADRENO_PIXELFORMAT_R8G8B8 = 508, // GL_RGB8
+ ADRENO_PIXELFORMAT_A1B5G5R5 = 519, // GL_RGB5_A1
+ ADRENO_PIXELFORMAT_R8G8B8X8_SRGB = 520, // GL_SRGB8
+ ADRENO_PIXELFORMAT_R8G8B8_SRGB = 521, // GL_SRGB8
+ ADRENO_PIXELFORMAT_R5G6B5 = 610, // RGBA version of B5G6R5
+ ADRENO_PIXELFORMAT_R5G5B5A1 = 611, // RGBA version of B5G5R5A1
+ ADRENO_PIXELFORMAT_R4G4B4A4 = 612, // RGBA version of B4G4R4A4
+ ADRENO_PIXELFORMAT_UYVY = 614, // YUV 4:2:2 packed progressive (1 plane)
+ ADRENO_PIXELFORMAT_NV21 = 619,
+ ADRENO_PIXELFORMAT_Y8U8V8A8 = 620, // YUV 4:4:4 packed (1 plane)
+ ADRENO_PIXELFORMAT_Y8 = 625, // Single 8-bit luma only channel YUV format
+
+} ADRENOPIXELFORMAT;
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index fe86018..a7c4a9a 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -101,6 +101,7 @@
LINK_adreno_compute_padding = NULL;
LINK_adreno_isMacroTilingSupportedByGpu = NULL;
LINK_adreno_compute_compressedfmt_aligned_width_and_height = NULL;
+ LINK_adreno_isUBWCSupportedByGpu = NULL;
libadreno_utils = ::dlopen("libadreno_utils.so", RTLD_NOW);
if (libadreno_utils) {
@@ -113,6 +114,8 @@
*(void **)&LINK_adreno_compute_compressedfmt_aligned_width_and_height =
::dlsym(libadreno_utils,
"compute_compressedfmt_aligned_width_and_height");
+ *(void **)&LINK_adreno_isUBWCSupportedByGpu =
+ ::dlsym(libadreno_utils, "isUBWCSupportedByGpu");
}
}
@@ -285,11 +288,35 @@
int AdrenoMemInfo::isUBWCSupportedByGPU(int format)
{
- // TODO: Convert HAL pixel format to corresponding Adreno format,
- // then query GPU with Adreno format.
+ if (libadreno_utils) {
+ if (LINK_adreno_isUBWCSupportedByGpu) {
+ ADRENOPIXELFORMAT gpu_format = getGpuPixelFormat(format);
+ return LINK_adreno_isUBWCSupportedByGpu(gpu_format);
+ }
+ }
return 0;
}
+ADRENOPIXELFORMAT AdrenoMemInfo::getGpuPixelFormat(int hal_format)
+{
+ switch (hal_format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ return ADRENO_PIXELFORMAT_R8G8B8A8;
+ case HAL_PIXEL_FORMAT_RGB_565:
+ return ADRENO_PIXELFORMAT_B5G6R5;
+ case HAL_PIXEL_FORMAT_sRGB_A_8888:
+ return ADRENO_PIXELFORMAT_R8G8B8A8_SRGB;
+ case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
+ return ADRENO_PIXELFORMAT_NV12;
+ default:
+ ALOGE("%s: No map for format: 0x%x", __FUNCTION__, hal_format);
+ break;
+ }
+ return ADRENO_PIXELFORMAT_UNKNOWN;
+}
+
//-------------- IAllocController-----------------------//
IAllocController* IAllocController::sController = NULL;
IAllocController* IAllocController::getInstance(void)
diff --git a/libgralloc/gr.h b/libgralloc/gr.h
index 492f495..5ee0cf8 100644
--- a/libgralloc/gr.h
+++ b/libgralloc/gr.h
@@ -27,6 +27,7 @@
#include <cutils/native_handle.h>
#include <utils/Singleton.h>
+#include "adreno_utils.h"
/*****************************************************************************/
@@ -141,6 +142,11 @@
*/
int isUBWCSupportedByGPU(int format);
+ /*
+ * Function to get the corresponding Adreno format for given HAL format
+ */
+ ADRENOPIXELFORMAT getGpuPixelFormat(int hal_format);
+
private:
// Pointer to the padding library.
void *libadreno_utils;
@@ -172,5 +178,7 @@
int *aligned_w,
int *aligned_h,
int *bpp);
+
+ int (*LINK_adreno_isUBWCSupportedByGpu) (ADRENOPIXELFORMAT format);
};
#endif /* GR_H_ */