emulator opengl: Fix gralloc color buffer uploads
Use the correct OpenGL pixel type enum when uploading color buffer content to host. Change-Id: Idc859306c0398850505f0f348796bc4f12b63b6a
This commit is contained in:
committed by
David 'Digit' Turner
parent
5960b2717c
commit
7d39ef3772
@@ -14,13 +14,15 @@
|
|||||||
struct cb_handle_t : public native_handle {
|
struct cb_handle_t : public native_handle {
|
||||||
|
|
||||||
cb_handle_t(int p_fd, int p_ashmemSize, int p_usage,
|
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),
|
fd(p_fd),
|
||||||
magic(BUFFER_HANDLE_MAGIC),
|
magic(BUFFER_HANDLE_MAGIC),
|
||||||
usage(p_usage),
|
usage(p_usage),
|
||||||
width(p_width),
|
width(p_width),
|
||||||
height(p_height),
|
height(p_height),
|
||||||
glFormat(p_glFormat),
|
glFormat(p_glFormat),
|
||||||
|
glType(p_glType),
|
||||||
ashmemSize(p_ashmemSize),
|
ashmemSize(p_ashmemSize),
|
||||||
ashmemBase(NULL),
|
ashmemBase(NULL),
|
||||||
ashmemBasePid(0),
|
ashmemBasePid(0),
|
||||||
@@ -70,6 +72,7 @@ struct cb_handle_t : public native_handle {
|
|||||||
int width; // buffer width
|
int width; // buffer width
|
||||||
int height; // buffer height
|
int height; // buffer height
|
||||||
int glFormat; // OpenGL format enum used for host h/w color buffer
|
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
|
int ashmemSize; // ashmem region size for the buffer (0 unless is HW_FB buffer or
|
||||||
// s/w access is needed)
|
// s/w access is needed)
|
||||||
int ashmemBase; // CPU address of the mapped ashmem region
|
int ashmemBase; // CPU address of the mapped ashmem region
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ static int gralloc_alloc(alloc_device_t* dev,
|
|||||||
int ashmem_size = 0;
|
int ashmem_size = 0;
|
||||||
*pStride = 0;
|
*pStride = 0;
|
||||||
GLenum glFormat = 0;
|
GLenum glFormat = 0;
|
||||||
|
GLenum glType = 0;
|
||||||
|
|
||||||
int bpp = 0;
|
int bpp = 0;
|
||||||
switch (format) {
|
switch (format) {
|
||||||
@@ -129,22 +130,27 @@ static int gralloc_alloc(alloc_device_t* dev,
|
|||||||
case HAL_PIXEL_FORMAT_BGRA_8888:
|
case HAL_PIXEL_FORMAT_BGRA_8888:
|
||||||
bpp = 4;
|
bpp = 4;
|
||||||
glFormat = GL_RGBA;
|
glFormat = GL_RGBA;
|
||||||
|
glType = GL_UNSIGNED_BYTE;
|
||||||
break;
|
break;
|
||||||
case HAL_PIXEL_FORMAT_RGB_888:
|
case HAL_PIXEL_FORMAT_RGB_888:
|
||||||
bpp = 3;
|
bpp = 3;
|
||||||
glFormat = GL_RGB;
|
glFormat = GL_RGB;
|
||||||
|
glType = GL_UNSIGNED_BYTE;
|
||||||
break;
|
break;
|
||||||
case HAL_PIXEL_FORMAT_RGB_565:
|
case HAL_PIXEL_FORMAT_RGB_565:
|
||||||
bpp = 2;
|
bpp = 2;
|
||||||
glFormat = GL_RGB565_OES;
|
glFormat = GL_RGB565_OES;
|
||||||
|
glType = GL_UNSIGNED_SHORT_5_6_5;
|
||||||
break;
|
break;
|
||||||
case HAL_PIXEL_FORMAT_RGBA_5551:
|
case HAL_PIXEL_FORMAT_RGBA_5551:
|
||||||
bpp = 2;
|
bpp = 2;
|
||||||
glFormat = GL_RGB5_A1_OES;
|
glFormat = GL_RGB5_A1_OES;
|
||||||
|
glType = GL_UNSIGNED_SHORT_5_5_5_1;
|
||||||
break;
|
break;
|
||||||
case HAL_PIXEL_FORMAT_RGBA_4444:
|
case HAL_PIXEL_FORMAT_RGBA_4444:
|
||||||
bpp = 2;
|
bpp = 2;
|
||||||
glFormat = GL_RGBA4_OES;
|
glFormat = GL_RGBA4_OES;
|
||||||
|
glType = GL_UNSIGNED_SHORT_4_4_4_4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
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) {
|
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) {
|
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];
|
char *tmpBuf = new char[cb->lockedWidth * cb->lockedHeight * bpp];
|
||||||
|
|
||||||
int dst_line_len = cb->lockedWidth * 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,
|
rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle,
|
||||||
cb->lockedLeft, cb->lockedTop,
|
cb->lockedLeft, cb->lockedTop,
|
||||||
cb->lockedWidth, cb->lockedHeight,
|
cb->lockedWidth, cb->lockedHeight,
|
||||||
cb->glFormat, GL_UNSIGNED_BYTE,
|
cb->glFormat, cb->glType,
|
||||||
tmpBuf);
|
tmpBuf);
|
||||||
|
|
||||||
delete [] tmpBuf;
|
delete [] tmpBuf;
|
||||||
@@ -580,7 +587,7 @@ static int gralloc_unlock(gralloc_module_t const* module,
|
|||||||
else {
|
else {
|
||||||
rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle, 0, 0,
|
rcEnc->rcUpdateColorBuffer(rcEnc, cb->hostHandle, 0, 0,
|
||||||
cb->width, cb->height,
|
cb->width, cb->height,
|
||||||
cb->glFormat, GL_UNSIGNED_BYTE,
|
cb->glFormat, cb->glType,
|
||||||
cpu_addr);
|
cpu_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user