From 5ec953deef40a1429cfa69dc126e196cf61260f2 Mon Sep 17 00:00:00 2001 From: Yochai Shefi Simchon Date: Wed, 29 Jun 2011 17:05:34 +0300 Subject: [PATCH] Make sure RGB_565 config is available to emulator There are Android applications (notably BootAnimation) which require exactly an RGB_565 configuration, and are not satisfied by an e.g. RGBA_8888 configuration. This doens't make too much sense, and I think such apps should be fixed. However, until that happens, there is an issue when the host does not have an RGB_565 FBConfig, which is typical to many OpenGL implementations. In such cases, BootAnimation doesn't run. The workaround is to add an RGB_565 config to the list maintained by the translator, which is basically an 888 config in disguise. --- .../host/libs/Translator/EGL/EglConfig.cpp | 38 +++++++++++++++ .../host/libs/Translator/EGL/EglConfig.h | 6 +++ .../host/libs/Translator/EGL/EglDisplay.cpp | 47 +++++++++++++++++++ .../host/libs/Translator/EGL/EglDisplay.h | 2 + 4 files changed, 93 insertions(+) diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp index 1814dad09..3d9a95e14 100644 --- a/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp +++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.cpp @@ -105,6 +105,44 @@ EglConfig::EglConfig(EGLint red_size, m_nativeFormat(conf.m_nativeFormat) {}; +EglConfig::EglConfig(const EglConfig& conf, + EGLint config_id, + EGLint red_size, + EGLint green_size, + EGLint blue_size, + EGLint alpha_size): + + m_buffer_size(red_size + green_size + blue_size + alpha_size), + m_red_size(red_size), + m_green_size(green_size), + m_blue_size(blue_size), + m_alpha_size(alpha_size), + m_bind_to_tex_rgb(conf.m_bind_to_tex_rgb), + m_bind_to_tex_rgba(conf.m_bind_to_tex_rgba), + m_caveat(conf.m_caveat), + m_config_id(config_id), + m_frame_buffer_level(conf.m_frame_buffer_level), + m_depth_size(conf.m_depth_size), + m_max_pbuffer_width(conf.m_max_pbuffer_width), + m_max_pbuffer_height(conf.m_max_pbuffer_height), + m_max_pbuffer_size(conf.m_max_pbuffer_size), + m_max_swap_interval(conf.m_max_swap_interval), + m_min_swap_interval(conf.m_min_swap_interval), + m_native_renderable(conf.m_native_renderable), + m_renderable_type(conf.m_renderable_type), + m_native_visual_id(conf.m_native_visual_id), + m_native_visual_type(conf.m_native_visual_type), + m_sample_buffers_num(conf.m_sample_buffers_num), + m_samples_per_pixel(conf.m_samples_per_pixel), + m_stencil_size(conf.m_stencil_size), + m_surface_type(conf.m_surface_type), + m_transparent_type(conf.m_transparent_type), + m_trans_red_val(conf.m_trans_red_val), + m_trans_green_val(conf.m_trans_green_val), + m_trans_blue_val(conf.m_trans_blue_val), + m_conformant(conf.m_conformant), + m_nativeFormat(conf.m_nativeFormat) {}; + bool EglConfig::getConfAttrib(EGLint attrib,EGLint* val) const { switch(attrib) { diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.h index ad4e37d2d..b9da52e0f 100644 --- a/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.h +++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglConfig.h @@ -60,6 +60,12 @@ public: EglConfig(const EglConfig& conf); + EglConfig(const EglConfig& conf, + EGLint config_id, + EGLint red_size, + EGLint green_size, + EGLint blue_size, + EGLint alpha_size); private: diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp index ad64c9061..2bf9d185b 100644 --- a/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp +++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.cpp @@ -67,9 +67,52 @@ static bool compareEglConfigsPtrs(EglConfig* first,EglConfig* second) { return *first < *second ; } +void EglDisplay::addMissingConfigs(void) +{ + m_configs.sort(compareEglConfigsPtrs); + + EGLConfig match; + EGLNativePixelFormatType tmpfrmt = PIXEL_FORMAT_INITIALIZER; + EglConfig dummy(5, 6, 5, 0, // RGB_565 + EGL_DONT_CARE,EGL_DONT_CARE, + 16, // Depth + EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE, + EGL_DONT_CARE, EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,EGL_DONT_CARE,tmpfrmt); + + if(!doChooseConfigs(dummy, &match, 1)) + { + return; + } + + const EglConfig* config = (EglConfig*)match; + + int bSize; + config->getConfAttrib(EGL_BUFFER_SIZE,&bSize); + + if(bSize == 16) + { + return; + } + + int max_config_id = 0; + + for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() ;it++) { + EGLint id; + (*it)->getConfAttrib(EGL_CONFIG_ID, &id); + if(id > max_config_id) + max_config_id = id; + } + + EglConfig* newConfig = new EglConfig(*config,max_config_id+1,5,6,5,0); + + m_configs.push_back(newConfig); +} + void EglDisplay::initConfigurations(int renderableType) { if(m_configInitialized) return; EglOS::queryConfigs(m_dpy,renderableType,m_configs); + + addMissingConfigs(); m_configs.sort(compareEglConfigsPtrs); } @@ -181,6 +224,10 @@ int EglDisplay::getConfigs(EGLConfig* configs,int config_size) { int EglDisplay::chooseConfigs(const EglConfig& dummy,EGLConfig* configs,int config_size) { android::Mutex::Autolock mutex(m_lock); + return doChooseConfigs(dummy, configs, config_size); +} + +int EglDisplay::doChooseConfigs(const EglConfig& dummy,EGLConfig* configs,int config_size) { int added = 0; for(ConfigsList::iterator it = m_configs.begin(); it != m_configs.end() && (added < config_size || !configs);it++) { diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h index dadda0926..c5262b197 100644 --- a/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h +++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglDisplay.h @@ -67,6 +67,8 @@ public: bool destroyImageKHR(EGLImageKHR img); private: + int doChooseConfigs(const EglConfig& dummy,EGLConfig* configs,int config_size); + void addMissingConfigs(void); void initConfigurations(int renderableType); EGLNativeDisplayType m_dpy;