Chromium Code Reviews| Index: ui/gl/gl_surface_egl.cc |
| diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc |
| index b6a7184c129f7e3e18588c69864f775420ab7ae3..ab03b131d42f609c308d3cfd0b20c906e07c1286 100644 |
| --- a/ui/gl/gl_surface_egl.cc |
| +++ b/ui/gl/gl_surface_egl.cc |
| @@ -10,6 +10,7 @@ |
| #if defined(OS_ANDROID) |
| #include <android/native_window_jni.h> |
| +#include "base/android/sys_utils.h" |
| #endif |
| #include "base/command_line.h" |
| @@ -137,7 +138,7 @@ bool GLSurfaceEGL::InitializeOneOff() { |
| // Choose an EGL configuration. |
| // On X this is only used for PBuffer surfaces. |
| - static const EGLint kConfigAttribs[] = { |
| + static EGLint config_attribs_8888[] = { |
| EGL_BUFFER_SIZE, 32, |
| EGL_ALPHA_SIZE, 8, |
| EGL_BLUE_SIZE, 8, |
| @@ -148,11 +149,31 @@ bool GLSurfaceEGL::InitializeOneOff() { |
| EGL_NONE |
| }; |
| +#if defined(OS_ANDROID) |
| + static EGLint config_attribs_565[] = { |
| + EGL_BUFFER_SIZE, 16, |
| + EGL_BLUE_SIZE, 5, |
| + EGL_GREEN_SIZE, 6, |
| + EGL_RED_SIZE, 5, |
| + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| + EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| + EGL_NONE |
| + }; |
| +#endif |
| + |
| + EGLint* choose_attributes = config_attribs_8888; |
| + |
| +#if defined(OS_ANDROID) |
| + if (base::android::SysUtils::IsLowEndDevice()) { |
| + choose_attributes = config_attribs_565; |
| + } |
| +#endif |
| + |
| #if defined(USE_OZONE) |
| const EGLint* config_attribs = |
| - surface_factory->GetEGLSurfaceProperties(kConfigAttribs); |
| + surface_factory->GetEGLSurfaceProperties(choose_attributes); |
| #else |
| - const EGLint* config_attribs = kConfigAttribs; |
| + const EGLint* config_attribs = choose_attributes; |
| #endif |
| EGLint num_configs; |
| @@ -171,16 +192,64 @@ bool GLSurfaceEGL::InitializeOneOff() { |
| return false; |
| } |
| + int config_size = 1; |
| + EGLConfig* config_data = &g_config; |
| + |
| +#if defined(OS_ANDROID) |
| + scoped_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]); |
| + if (base::android::SysUtils::IsLowEndDevice()) { |
| + config_size = num_configs; |
| + config_data = matching_configs.get(); |
| + } |
| +#endif |
| + |
| if (!eglChooseConfig(g_display, |
| config_attribs, |
| - &g_config, |
| - 1, |
| + config_data, |
| + config_size, |
| &num_configs)) { |
| LOG(ERROR) << "eglChooseConfig failed with error " |
| << GetLastEGLErrorString(); |
| return false; |
| } |
| +#if defined(OS_ANDROID) |
| + if (base::android::SysUtils::IsLowEndDevice()) { |
| + // Because of the EGL config sort order, we have to iterate |
| + // through all of them (it'll put higher sum(R,G,B) bits |
| + // first with the above attribs). |
| + bool match_found = false; |
| + int default_format = 0; |
| + for (int i = 0; i < num_configs; i++) { |
| + EGLBoolean success; |
| + EGLint red, green, blue, alpha; |
| + // Read the relevent attributes of the EGLConfig. |
| + success = eglGetConfigAttrib(g_display, matching_configs[i], |
| + EGL_RED_SIZE, &red); |
| + success &= eglGetConfigAttrib(g_display, matching_configs[i], |
| + EGL_BLUE_SIZE, &blue); |
| + success &= eglGetConfigAttrib(g_display, matching_configs[i], |
| + EGL_GREEN_SIZE, &green); |
| + success &= eglGetConfigAttrib(g_display, matching_configs[i], |
| + EGL_ALPHA_SIZE, &alpha); |
| + if ((success == EGL_TRUE) && (red == 8) && |
| + (green == 8) && (blue == 8) && (alpha == 8)) { |
|
no sievers
2014/01/21 19:47:46
Do you think it might be better to take the first
sivag
2014/01/22 15:48:20
I think we should go with the first match as per t
sivag
2014/01/23 11:50:02
Done.
sivag
2014/01/23 11:50:02
Done.
|
| + // Fallback to default format when the device fails to support 565. |
| + default_format = i; |
|
no sievers
2014/01/21 19:47:46
nit: indent
sivag
2014/01/23 11:50:02
Done.
|
| + } else if ((success == EGL_TRUE) && (red == 5) && |
| + (green == 6) && (blue == 5)) { |
| + g_config = matching_configs[i]; |
| + match_found = true; |
| + break; |
| + } |
| + } |
| + if (!match_found) { |
| + LOG (ERROR) << "Falling back to default 32 bit format"; |
|
no sievers
2014/01/21 19:47:46
nit: no space after LOG. Also maybe make it WARNIN
sivag
2014/01/23 11:50:02
Done.
|
| + g_config = matching_configs[default_format]; |
| + } |
| + } |
| +#endif |
| + |
| g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
| g_egl_create_context_robustness_supported = |
| HasEGLExtension("EGL_EXT_create_context_robustness"); |