Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This include must be here so that the includes provided transitively | 5 // This include must be here so that the includes provided transitively |
| 6 // by gl_surface_egl.h don't make it impossible to compile this code. | 6 // by gl_surface_egl.h don't make it impossible to compile this code. |
| 7 #include "third_party/mesa/src/include/GL/osmesa.h" | 7 #include "third_party/mesa/src/include/GL/osmesa.h" |
| 8 | 8 |
| 9 #include "ui/gl/gl_surface_egl.h" | 9 #include "ui/gl/gl_surface_egl.h" |
| 10 | 10 |
| 11 #if defined(OS_ANDROID) | 11 #if defined(OS_ANDROID) |
| 12 #include <android/native_window_jni.h> | 12 #include <android/native_window_jni.h> |
| 13 #include "base/android/sys_utils.h" | |
| 13 #endif | 14 #endif |
| 14 | 15 |
| 15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 16 #include "base/debug/trace_event.h" | 17 #include "base/debug/trace_event.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "ui/gl/egl_util.h" | 22 #include "ui/gl/egl_util.h" |
| 22 #include "ui/gl/gl_context.h" | 23 #include "ui/gl/gl_context.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 return false; | 131 return false; |
| 131 } | 132 } |
| 132 | 133 |
| 133 if (!eglInitialize(g_display, NULL, NULL)) { | 134 if (!eglInitialize(g_display, NULL, NULL)) { |
| 134 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); | 135 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); |
| 135 return false; | 136 return false; |
| 136 } | 137 } |
| 137 | 138 |
| 138 // Choose an EGL configuration. | 139 // Choose an EGL configuration. |
| 139 // On X this is only used for PBuffer surfaces. | 140 // On X this is only used for PBuffer surfaces. |
| 140 static const EGLint kConfigAttribs[] = { | 141 static EGLint config_attribs_8888[] = { |
| 141 EGL_BUFFER_SIZE, 32, | 142 EGL_BUFFER_SIZE, 32, |
| 142 EGL_ALPHA_SIZE, 8, | 143 EGL_ALPHA_SIZE, 8, |
| 143 EGL_BLUE_SIZE, 8, | 144 EGL_BLUE_SIZE, 8, |
| 144 EGL_GREEN_SIZE, 8, | 145 EGL_GREEN_SIZE, 8, |
| 145 EGL_RED_SIZE, 8, | 146 EGL_RED_SIZE, 8, |
| 146 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 147 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 147 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | 148 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| 148 EGL_NONE | 149 EGL_NONE |
| 149 }; | 150 }; |
| 150 | 151 |
| 152 #if defined(OS_ANDROID) | |
| 153 static EGLint config_attribs_565[] = { | |
| 154 EGL_BUFFER_SIZE, 16, | |
| 155 EGL_BLUE_SIZE, 5, | |
| 156 EGL_GREEN_SIZE, 6, | |
| 157 EGL_RED_SIZE, 5, | |
| 158 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | |
| 159 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | |
| 160 EGL_NONE | |
| 161 }; | |
| 162 #endif | |
| 163 | |
| 164 EGLint* choose_attributes = config_attribs_8888; | |
| 165 | |
| 166 #if defined(OS_ANDROID) | |
| 167 if (base::android::SysUtils::IsLowEndDevice()) { | |
| 168 choose_attributes = config_attribs_565; | |
| 169 } | |
| 170 #endif | |
| 171 | |
| 151 #if defined(USE_OZONE) | 172 #if defined(USE_OZONE) |
| 152 const EGLint* config_attribs = | 173 const EGLint* config_attribs = |
| 153 surface_factory->GetEGLSurfaceProperties(kConfigAttribs); | 174 surface_factory->GetEGLSurfaceProperties(choose_attributes); |
| 154 #else | 175 #else |
| 155 const EGLint* config_attribs = kConfigAttribs; | 176 const EGLint* config_attribs = choose_attributes; |
| 156 #endif | 177 #endif |
| 157 | 178 |
| 158 EGLint num_configs; | 179 EGLint num_configs; |
| 159 if (!eglChooseConfig(g_display, | 180 if (!eglChooseConfig(g_display, |
| 160 config_attribs, | 181 config_attribs, |
| 161 NULL, | 182 NULL, |
| 162 0, | 183 0, |
| 163 &num_configs)) { | 184 &num_configs)) { |
| 164 LOG(ERROR) << "eglChooseConfig failed with error " | 185 LOG(ERROR) << "eglChooseConfig failed with error " |
| 165 << GetLastEGLErrorString(); | 186 << GetLastEGLErrorString(); |
| 166 return false; | 187 return false; |
| 167 } | 188 } |
| 168 | 189 |
| 169 if (num_configs == 0) { | 190 if (num_configs == 0) { |
| 170 LOG(ERROR) << "No suitable EGL configs found."; | 191 LOG(ERROR) << "No suitable EGL configs found."; |
| 171 return false; | 192 return false; |
| 172 } | 193 } |
| 173 | 194 |
| 195 int config_size = 1; | |
| 196 EGLConfig* config_data = &g_config; | |
| 197 | |
| 198 #if defined(OS_ANDROID) | |
| 199 scoped_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]); | |
| 200 if (base::android::SysUtils::IsLowEndDevice()) { | |
| 201 config_size = num_configs; | |
| 202 config_data = matching_configs.get(); | |
| 203 } | |
| 204 #endif | |
| 205 | |
| 174 if (!eglChooseConfig(g_display, | 206 if (!eglChooseConfig(g_display, |
| 175 config_attribs, | 207 config_attribs, |
| 176 &g_config, | 208 config_data, |
| 177 1, | 209 config_size, |
| 178 &num_configs)) { | 210 &num_configs)) { |
| 179 LOG(ERROR) << "eglChooseConfig failed with error " | 211 LOG(ERROR) << "eglChooseConfig failed with error " |
| 180 << GetLastEGLErrorString(); | 212 << GetLastEGLErrorString(); |
| 181 return false; | 213 return false; |
| 182 } | 214 } |
| 183 | 215 |
| 216 #if defined(OS_ANDROID) | |
| 217 if (base::android::SysUtils::IsLowEndDevice()) { | |
| 218 // Because of the EGL config sort order, we have to iterate | |
| 219 // through all of them (it'll put higher sum(R,G,B) bits | |
| 220 // first with the above attribs). | |
| 221 bool match_found = false; | |
| 222 int default_format = 0; | |
| 223 for (int i = 0; i < num_configs; i++) { | |
| 224 EGLBoolean success; | |
| 225 EGLint red, green, blue, alpha; | |
| 226 // Read the relevent attributes of the EGLConfig. | |
| 227 success = eglGetConfigAttrib(g_display, matching_configs[i], | |
| 228 EGL_RED_SIZE, &red); | |
| 229 success &= eglGetConfigAttrib(g_display, matching_configs[i], | |
| 230 EGL_BLUE_SIZE, &blue); | |
| 231 success &= eglGetConfigAttrib(g_display, matching_configs[i], | |
| 232 EGL_GREEN_SIZE, &green); | |
| 233 success &= eglGetConfigAttrib(g_display, matching_configs[i], | |
| 234 EGL_ALPHA_SIZE, &alpha); | |
| 235 if ((success == EGL_TRUE) && (red == 8) && | |
| 236 (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.
| |
| 237 // Fallback to default format when the device fails to support 565. | |
| 238 default_format = i; | |
|
no sievers
2014/01/21 19:47:46
nit: indent
sivag
2014/01/23 11:50:02
Done.
| |
| 239 } else if ((success == EGL_TRUE) && (red == 5) && | |
| 240 (green == 6) && (blue == 5)) { | |
| 241 g_config = matching_configs[i]; | |
| 242 match_found = true; | |
| 243 break; | |
| 244 } | |
| 245 } | |
| 246 if (!match_found) { | |
| 247 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.
| |
| 248 g_config = matching_configs[default_format]; | |
| 249 } | |
| 250 } | |
| 251 #endif | |
| 252 | |
| 184 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); | 253 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
| 185 g_egl_create_context_robustness_supported = | 254 g_egl_create_context_robustness_supported = |
| 186 HasEGLExtension("EGL_EXT_create_context_robustness"); | 255 HasEGLExtension("EGL_EXT_create_context_robustness"); |
| 187 g_egl_sync_control_supported = | 256 g_egl_sync_control_supported = |
| 188 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 257 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
| 189 | 258 |
| 190 // Check if SurfacelessEGL is supported. | 259 // Check if SurfacelessEGL is supported. |
| 191 g_egl_surfaceless_context_supported = | 260 g_egl_surfaceless_context_supported = |
| 192 HasEGLExtension("EGL_KHR_surfaceless_context"); | 261 HasEGLExtension("EGL_KHR_surfaceless_context"); |
| 193 if (g_egl_surfaceless_context_supported) { | 262 if (g_egl_surfaceless_context_supported) { |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 } | 835 } |
| 767 default: | 836 default: |
| 768 NOTREACHED(); | 837 NOTREACHED(); |
| 769 return NULL; | 838 return NULL; |
| 770 } | 839 } |
| 771 } | 840 } |
| 772 | 841 |
| 773 #endif | 842 #endif |
| 774 | 843 |
| 775 } // namespace gfx | 844 } // namespace gfx |
| OLD | NEW |