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/gralloc.cpp b/modules/gralloc/gralloc.cpp
index 07bbfba..87bda97 100644
--- a/modules/gralloc/gralloc.cpp
+++ b/modules/gralloc/gralloc.cpp
@@ -101,7 +101,7 @@
/*****************************************************************************/
static int gralloc_alloc_framebuffer_locked(alloc_device_t* dev,
- size_t size, int usage, buffer_handle_t* pHandle)
+ size_t size, int format, int usage, buffer_handle_t* pHandle)
{
private_module_t* m = reinterpret_cast<private_module_t*>(
dev->common.module);
@@ -110,7 +110,7 @@
if (m->framebuffer == NULL) {
// initialize the framebuffer, the framebuffer is mapped once
// and forever.
- int err = mapFrameBufferLocked(m);
+ int err = mapFrameBufferLocked(m, format);
if (err < 0) {
return err;
}
@@ -154,12 +154,12 @@
}
static int gralloc_alloc_framebuffer(alloc_device_t* dev,
- size_t size, int usage, buffer_handle_t* pHandle)
+ size_t size, int format, int usage, buffer_handle_t* pHandle)
{
private_module_t* m = reinterpret_cast<private_module_t*>(
dev->common.module);
pthread_mutex_lock(&m->lock);
- int err = gralloc_alloc_framebuffer_locked(dev, size, usage, pHandle);
+ int err = gralloc_alloc_framebuffer_locked(dev, size, format, usage, pHandle);
pthread_mutex_unlock(&m->lock);
return err;
}
@@ -236,7 +236,7 @@
int err;
if (usage & GRALLOC_USAGE_HW_FB) {
- err = gralloc_alloc_framebuffer(dev, size, usage, pHandle);
+ err = gralloc_alloc_framebuffer(dev, size, format, usage, pHandle);
} else {
err = gralloc_alloc_buffer(dev, size, usage, pHandle);
}