From 7d39ef37720a0fc13087c2bc6e5e5394985c3f5c Mon Sep 17 00:00:00 2001 From: Guy Zadikario Date: Sun, 5 Jun 2011 13:13:11 +0300 Subject: [PATCH] emulator opengl: Fix gralloc color buffer uploads Use the correct OpenGL pixel type enum when uploading color buffer content to host. Change-Id: Idc859306c0398850505f0f348796bc4f12b63b6a --- .../opengl/system/OpenglSystemCommon/gralloc_cb.h | 5 ++++- tools/emulator/opengl/system/gralloc/gralloc.cpp | 15 +++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h b/tools/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h index 03b9b6d17..117378d60 100644 --- a/tools/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h +++ b/tools/emulator/opengl/system/OpenglSystemCommon/gralloc_cb.h @@ -14,13 +14,15 @@ struct cb_handle_t : public native_handle { cb_handle_t(int p_fd, int p_ashmemSize, int p_usage, - int p_width, int p_height, int p_glFormat) : + int p_width, int p_height, + int p_glFormat, int p_glType) : fd(p_fd), magic(BUFFER_HANDLE_MAGIC), usage(p_usage), width(p_width), height(p_height), glFormat(p_glFormat), + glType(p_glType), ashmemSize(p_ashmemSize), ashmemBase(NULL), ashmemBasePid(0), @@ -70,6 +72,7 @@ struct cb_handle_t : public native_handle { int width; // buffer width int height; // buffer height int glFormat; // OpenGL format enum used for host h/w color buffer + int glType; // OpenGL type enum used when uploading to host int ashmemSize; // ashmem region size for the buffer (0 unless is HW_FB buffer or // s/w access is needed) int ashmemBase; // CPU address of the mapped ashmem region diff --git a/tools/emulator/opengl/system/gralloc/gralloc.cpp b/tools/emulator/opengl/system/gralloc/gralloc.cpp index 103bed5d1..04a8f2f2b 100644 --- a/tools/emulator/opengl/system/gralloc/gralloc.cpp +++ b/tools/emulator/opengl/system/gralloc/gralloc.cpp @@ -121,6 +121,7 @@ static int gralloc_alloc(alloc_device_t* dev, int ashmem_size = 0; *pStride = 0; GLenum glFormat = 0; + GLenum glType = 0; int bpp = 0; switch (format) { @@ -129,22 +130,27 @@ static int gralloc_alloc(alloc_device_t* dev, case HAL_PIXEL_FORMAT_BGRA_8888: bpp = 4; glFormat = GL_RGBA; + glType = GL_UNSIGNED_BYTE; break; case HAL_PIXEL_FORMAT_RGB_888: bpp = 3; glFormat = GL_RGB; + glType = GL_UNSIGNED_BYTE; break; case HAL_PIXEL_FORMAT_RGB_565: bpp = 2; glFormat = GL_RGB565_OES; + glType = GL_UNSIGNED_SHORT_5_6_5; break; case HAL_PIXEL_FORMAT_RGBA_5551: bpp = 2; glFormat = GL_RGB5_A1_OES; + glType = GL_UNSIGNED_SHORT_5_5_5_1; break; case HAL_PIXEL_FORMAT_RGBA_4444: bpp = 2; glFormat = GL_RGBA4_OES; + glType = GL_UNSIGNED_SHORT_4_4_4_4; break; default: @@ -181,7 +187,8 @@ static int gralloc_alloc(alloc_device_t* dev, } } - cb_handle_t *cb = new cb_handle_t(fd, ashmem_size, usage, w, h, glFormat); + cb_handle_t *cb = new cb_handle_t(fd, ashmem_size, usage, + w, h, glFormat, glType); if (ashmem_size > 0) { // @@ -556,7 +563,7 @@ static int gralloc_unlock(gralloc_module_t const* module, } if (cb->lockedWidth < cb->width || cb->lockedHeight < cb->height) { - int bpp = glUtilsPixelBitSize(cb->glFormat, GL_UNSIGNED_BYTE) >> 3; + int bpp = glUtilsPixelBitSize(cb->glFormat, cb->glType) >> 3; char *tmpBuf = new char[cb->lockedWidth * cb->lockedHeight * bpp]; int dst_line_len = cb->lockedWidth * bpp; @@ -572,7 +579,7 @@ static int gralloc_unlock(gralloc_module_t const* module, rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle, cb->lockedLeft, cb->lockedTop, cb->lockedWidth, cb->lockedHeight, - cb->glFormat, GL_UNSIGNED_BYTE, + cb->glFormat, cb->glType, tmpBuf); delete [] tmpBuf; @@ -580,7 +587,7 @@ static int gralloc_unlock(gralloc_module_t const* module, else { rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle, 0, 0, cb->width, cb->height, - cb->glFormat, GL_UNSIGNED_BYTE, + cb->glFormat, cb->glType, cpu_addr); } }