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..35d50a9b5e95a0c0ebee3831428ebfdbd72a2734 100644 |
| --- a/ui/gl/gl_surface_egl.cc |
| +++ b/ui/gl/gl_surface_egl.cc |
| @@ -12,6 +12,7 @@ |
| #include <android/native_window_jni.h> |
| #endif |
| +#include "base/android/sys_utils.h" |
|
kalyank
2014/01/20 14:48:31
We could include this only on Android platform.
kalyank
2014/01/20 14:49:52
sorry, ignore this. I was looking at wrong version
|
| #include "base/command_line.h" |
| #include "base/debug/trace_event.h" |
| #include "base/logging.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 configattribs_8888[] = { |
|
piman
2014/01/17 18:20:01
nit: config_attribs_8888
sivag
2014/01/20 14:10:37
Done.
|
| EGL_BUFFER_SIZE, 32, |
| EGL_ALPHA_SIZE, 8, |
| EGL_BLUE_SIZE, 8, |
| @@ -148,16 +149,39 @@ bool GLSurfaceEGL::InitializeOneOff() { |
| EGL_NONE |
| }; |
| +#if defined(OS_ANDROID) |
| + static EGLint configattribs_565[] = { |
|
piman
2014/01/17 18:20:01
nit: config_attribs_565
sivag
2014/01/20 14:10:37
Done.
|
| + 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; |
| +#if defined(OS_ANDROID) |
| + if (base::android::SysUtils::IsLowEndDevice()) { |
| + choose_attributes = configattribs_565; |
| + } else { |
| + choose_attributes = configattribs_8888; |
| + } |
| +#else |
| + choose_attributes = configattribs_8888; |
| +#endif |
| + |
| #if defined(USE_OZONE) |
| - const EGLint* config_attribs = |
| - surface_factory->GetEGLSurfaceProperties(kConfigAttribs); |
| + const EGLint* kConfigAttribs = |
|
no sievers
2014/01/17 18:05:30
nit: Just use |choose_attributes| here and below.
sivag
2014/01/20 14:10:37
Done.
|
| + surface_factory->GetEGLSurfaceProperties(choose_attributes); |
| #else |
| - const EGLint* config_attribs = kConfigAttribs; |
| + const EGLint* kConfigAttribs = choose_attributes; |
| #endif |
| EGLint num_configs; |
| if (!eglChooseConfig(g_display, |
| - config_attribs, |
| + kConfigAttribs, |
| NULL, |
| 0, |
| &num_configs)) { |
| @@ -171,16 +195,66 @@ bool GLSurfaceEGL::InitializeOneOff() { |
| return false; |
| } |
| + EGLConfig* matching_configs = NULL; |
| + int config_size = 1; |
| + |
| +#if defined(OS_ANDROID) |
| + if (base::android::SysUtils::IsLowEndDevice()) { |
| + matching_configs = (EGLConfig*)malloc(num_configs * sizeof(EGLConfig)); |
|
no sievers
2014/01/17 18:05:30
Instead of malloc/free, you can use:
scoped_ptr<EG
sivag
2014/01/20 14:10:37
Done.
|
| + config_size = num_configs; |
| + } else { |
| + matching_configs = &g_config; |
| + config_size = 1; |
| + } |
| +#else |
| + matching_configs = &g_config; |
| + config_size = 1; |
| +#endif |
| + |
| if (!eglChooseConfig(g_display, |
| - config_attribs, |
| - &g_config, |
| - 1, |
| + kConfigAttribs, |
| + matching_configs, |
| + config_size, |
| &num_configs)) { |
| LOG(ERROR) << "eglChooseConfig failed with error " |
| << GetLastEGLErrorString(); |
| return false; |
| } |
| +#if defined(OS_ANDROID) |
| + if (base::android::SysUtils::IsLowEndDevice()) { |
| + bool match_found = false; |
| + for (int i = 0; i < num_configs; i++) |
| + { |
|
piman
2014/01/17 18:20:01
nit: { on previous line
sivag
2014/01/20 14:10:37
Done.
|
| + EGLBoolean success; |
| + EGLint red, green, blue; |
| + // 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); |
| + // Check that no error occurred and the attributes match. |
| + if ((success == EGL_TRUE) && (red == 5) && |
| + (green == 6) && (blue == 5)) { |
| + g_config = matching_configs[i]; |
| + match_found = true; |
| + break; |
| + } |
| + } |
| + if (matching_configs) { |
| + free(matching_configs); |
| + matching_configs = NULL; |
| + } |
| + if (!match_found) { |
| + LOG(ERROR) << "eglChooseConfig failed with error for lowend device" |
| + << GetLastEGLErrorString(); |
| + return false; |
|
no sievers
2014/01/17 18:05:30
We should fall back to 32bit, since not all driver
sivag
2014/01/20 14:10:37
Done.
|
| + } |
| + } |
| +#endif |
| + |
| g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
| g_egl_create_context_robustness_supported = |
| HasEGLExtension("EGL_EXT_create_context_robustness"); |