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..f66cbb67c2591f06aed3d419e2ac46ff44357f36 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,34 @@ 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 = 0; |
kalyank
2014/01/20 14:48:31
choose_attributes could point to config_attribs_88
sivag
2014/01/21 07:44:05
Done.
|
+#if defined(OS_ANDROID) |
+ if (base::android::SysUtils::IsLowEndDevice()) { |
+ choose_attributes = config_attribs_565; |
+ } else { |
+ choose_attributes = config_attribs_8888; |
+ } |
+#else |
+ choose_attributes = config_attribs_8888; |
+#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 +195,72 @@ bool GLSurfaceEGL::InitializeOneOff() { |
return false; |
} |
+ int config_size = 1; |
+ scoped_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]); |
kalyank
2014/01/20 14:48:31
matching_configs could be defined under #if define
sivag
2014/01/21 07:44:05
Done.
|
+ EGLConfig *config_data = NULL; |
kalyank
2014/01/20 14:48:31
config_data could point to g_config here ? This wo
kalyank
2014/01/20 14:48:31
nit: asterisk to left i.e. EGLConfig* config_data
sivag
2014/01/21 07:44:05
Done.
sivag
2014/01/21 08:41:30
Done.
|
+ |
+#if defined(OS_ANDROID) |
+ if (base::android::SysUtils::IsLowEndDevice()) { |
+ config_size = num_configs; |
+ config_data = matching_configs.get(); |
+ } else { |
+ config_size = 1; |
+ config_data = &g_config; |
+ } |
+#else |
+ config_size = 1; |
+ config_data = &g_config; |
+#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)) { |
+ // Fallback to default format when the device fails to support 565. |
+ default_format = i; |
+ } |
+ // Check that no error occurred and the attributes match. |
+ if ((success == EGL_TRUE) && (red == 5) && |
kalyank
2014/01/20 14:48:31
nit: as we are trying to find an exact match, we c
sivag
2014/01/21 07:44:05
We dont know whether we found the exact match or n
kalyank
2014/01/21 08:10:02
Sorry, I probably wasn't clear enough. I meant som
sivag
2014/01/21 08:41:30
Done.
|
+ (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"; |
+ 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"); |