gralloc: Configure framebuffer mode according to requested image format.
Previously we were ignoring the requested image format when mapping a graphics
device via gralloc_alloc, and using the mode that the framebuffer started up
in. This meant that on devices whose framebuffer starts up in a mode other
than RGBA8888, we would map the framebuffer in the other mode and attempt to
use it as an RGBA8888 framebuffer, which would lead to crashes or incorrecet
rendering. This is the case in the ARM FVP, whose framebuffer starts up in
RGB565 mode.
Unfortunately there is no preferred image format passed in to fb_device_open,
and we presumably cannot start passing one in for backwards compatibility
reasons. Therefore, we set the image format to RGBA8888, which appears to
be the only format that the platform ends up using.
Bug: 142352330
Change-Id: I24000fd36910b4044ce7659605efc423e36cba00
diff --git a/modules/gralloc/framebuffer.cpp b/modules/gralloc/framebuffer.cpp
index c171711..b2ec3e4 100644
--- a/modules/gralloc/framebuffer.cpp
+++ b/modules/gralloc/framebuffer.cpp
@@ -117,7 +117,7 @@
/*****************************************************************************/
-int mapFrameBufferLocked(struct private_module_t* module)
+int mapFrameBufferLocked(struct private_module_t* module, int format)
{
// already initialized...
if (module->framebuffer) {
@@ -161,6 +161,20 @@
*/
info.yres_virtual = info.yres * NUM_BUFFERS;
+ switch (format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ info.bits_per_pixel = 32;
+ info.red.offset = 0;
+ info.red.length = 8;
+ info.green.offset = 8;
+ info.green.length = 8;
+ info.blue.offset = 16;
+ info.blue.length = 8;
+ break;
+ default:
+ ALOGW("unknown format: %d", format);
+ break;
+ }
uint32_t flags = PAGE_FLIP;
#if USE_PAN_DISPLAY
@@ -280,7 +294,8 @@
static int mapFrameBuffer(struct private_module_t* module)
{
pthread_mutex_lock(&module->lock);
- int err = mapFrameBufferLocked(module);
+ // Request RGBA8888 because the platform assumes support for RGBA8888.
+ int err = mapFrameBufferLocked(module, HAL_PIXEL_FORMAT_RGBA_8888);
pthread_mutex_unlock(&module->lock);
return err;
}