Commit aaec29d5 by Nicolas Capens

Determine the framebuffer format from the fb0 device.

Bug 25390254 Change-Id: I21ed5b6d4a918bb6c3ac9ccc31ee5d47e193bd7f Reviewed-on: https://swiftshader-review.googlesource.com/4184Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent e328681a
......@@ -26,6 +26,9 @@
#ifdef __ANDROID__
#include <system/window.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <fcntl.h>
#endif
#include <algorithm>
......@@ -594,6 +597,66 @@ sw::Format Display::getDisplayFormat() const
default: UNREACHABLE(bpp); // Unexpected display mode color depth
}
#elif defined(__ANDROID__)
static const char *const framebuffer[] =
{
"/dev/graphics/fb0",
"/dev/fb0",
0
};
for(int i = 0; framebuffer[i]; i++)
{
int fd = open(framebuffer[i], O_RDONLY, 0);
if(fd != -1)
{
struct fb_var_screeninfo info;
if(ioctl(fd, FBIOGET_VSCREENINFO, &info) >= 0)
{
switch(info.bits_per_pixel)
{
case 16:
return sw::FORMAT_R5G6B5;
case 32:
if(info.red.length == 8 && info.red.offset == 16 &&
info.green.length == 8 && info.green.offset == 8 &&
info.blue.length == 8 && info.blue.offset == 0 &&
info.transp.length == 0)
{
return sw::FORMAT_X8R8G8B8;
}
if(info.red.length == 8 && info.red.offset == 0 &&
info.green.length == 8 && info.green.offset == 8 &&
info.blue.length == 8 && info.blue.offset == 16 &&
info.transp.length == 0)
{
return sw::FORMAT_X8B8G8R8;
}
if(info.red.length == 8 && info.red.offset == 16 &&
info.green.length == 8 && info.green.offset == 8 &&
info.blue.length == 8 && info.blue.offset == 0 &&
info.transp.length == 8 && info.transp.offset == 24)
{
return sw::FORMAT_A8R8G8B8;
}
if(info.red.length == 8 && info.red.offset == 0 &&
info.green.length == 8 && info.green.offset == 8 &&
info.blue.length == 8 && info.blue.offset == 16 &&
info.transp.length == 8 && info.transp.offset == 24)
{
return sw::FORMAT_A8B8G8R8;
}
else UNIMPLEMENTED();
default:
UNIMPLEMENTED();
}
}
close(fd);
}
}
// No framebuffer device found, or we're in user space
return sw::FORMAT_X8R8G8B8;
#else
if(platform == EGL_PLATFORM_X11_EXT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment