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 = 0; | |
|
kalyank
2014/01/20 14:48:31
choose_attributes could point to config_attribs_88
sivag
2014/01/21 07:44:05
Done.
| |
| 165 #if defined(OS_ANDROID) | |
| 166 if (base::android::SysUtils::IsLowEndDevice()) { | |
| 167 choose_attributes = config_attribs_565; | |
| 168 } else { | |
| 169 choose_attributes = config_attribs_8888; | |
| 170 } | |
| 171 #else | |
| 172 choose_attributes = config_attribs_8888; | |
| 173 #endif | |
| 174 | |
| 151 #if defined(USE_OZONE) | 175 #if defined(USE_OZONE) |
| 152 const EGLint* config_attribs = | 176 const EGLint* config_attribs = |
| 153 surface_factory->GetEGLSurfaceProperties(kConfigAttribs); | 177 surface_factory->GetEGLSurfaceProperties(choose_attributes); |
| 154 #else | 178 #else |
| 155 const EGLint* config_attribs = kConfigAttribs; | 179 const EGLint* config_attribs = choose_attributes; |
| 156 #endif | 180 #endif |
| 157 | 181 |
| 158 EGLint num_configs; | 182 EGLint num_configs; |
| 159 if (!eglChooseConfig(g_display, | 183 if (!eglChooseConfig(g_display, |
| 160 config_attribs, | 184 config_attribs, |
| 161 NULL, | 185 NULL, |
| 162 0, | 186 0, |
| 163 &num_configs)) { | 187 &num_configs)) { |
| 164 LOG(ERROR) << "eglChooseConfig failed with error " | 188 LOG(ERROR) << "eglChooseConfig failed with error " |
| 165 << GetLastEGLErrorString(); | 189 << GetLastEGLErrorString(); |
| 166 return false; | 190 return false; |
| 167 } | 191 } |
| 168 | 192 |
| 169 if (num_configs == 0) { | 193 if (num_configs == 0) { |
| 170 LOG(ERROR) << "No suitable EGL configs found."; | 194 LOG(ERROR) << "No suitable EGL configs found."; |
| 171 return false; | 195 return false; |
| 172 } | 196 } |
| 173 | 197 |
| 198 int config_size = 1; | |
| 199 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.
| |
| 200 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.
| |
| 201 | |
| 202 #if defined(OS_ANDROID) | |
| 203 if (base::android::SysUtils::IsLowEndDevice()) { | |
| 204 config_size = num_configs; | |
| 205 config_data = matching_configs.get(); | |
| 206 } else { | |
| 207 config_size = 1; | |
| 208 config_data = &g_config; | |
| 209 } | |
| 210 #else | |
| 211 config_size = 1; | |
| 212 config_data = &g_config; | |
| 213 #endif | |
| 214 | |
| 174 if (!eglChooseConfig(g_display, | 215 if (!eglChooseConfig(g_display, |
| 175 config_attribs, | 216 config_attribs, |
| 176 &g_config, | 217 config_data, |
| 177 1, | 218 config_size, |
| 178 &num_configs)) { | 219 &num_configs)) { |
| 179 LOG(ERROR) << "eglChooseConfig failed with error " | 220 LOG(ERROR) << "eglChooseConfig failed with error " |
| 180 << GetLastEGLErrorString(); | 221 << GetLastEGLErrorString(); |
| 181 return false; | 222 return false; |
| 182 } | 223 } |
| 183 | 224 |
| 225 #if defined(OS_ANDROID) | |
| 226 if (base::android::SysUtils::IsLowEndDevice()) { | |
| 227 // Because of the EGL config sort order, we have to iterate | |
| 228 // through all of them (it'll put higher sum(R,G,B) bits | |
| 229 // first with the above attribs). | |
| 230 bool match_found = false; | |
| 231 int default_format = 0; | |
| 232 for (int i = 0; i < num_configs; i++) { | |
| 233 EGLBoolean success; | |
| 234 EGLint red, green, blue, alpha; | |
| 235 // Read the relevent attributes of the EGLConfig. | |
| 236 success = eglGetConfigAttrib(g_display, matching_configs[i], | |
| 237 EGL_RED_SIZE, &red); | |
| 238 success &= eglGetConfigAttrib(g_display, matching_configs[i], | |
| 239 EGL_BLUE_SIZE, &blue); | |
| 240 success &= eglGetConfigAttrib(g_display, matching_configs[i], | |
| 241 EGL_GREEN_SIZE, &green); | |
| 242 success &= eglGetConfigAttrib(g_display, matching_configs[i], | |
| 243 EGL_ALPHA_SIZE, &alpha); | |
| 244 if ((success == EGL_TRUE) && (red == 8) && | |
| 245 (green == 8) && (blue == 8) && (alpha == 8)) { | |
| 246 // Fallback to default format when the device fails to support 565. | |
| 247 default_format = i; | |
| 248 } | |
| 249 // Check that no error occurred and the attributes match. | |
| 250 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.
| |
| 251 (green == 6) && (blue == 5)) { | |
| 252 g_config = matching_configs[i]; | |
| 253 match_found = true; | |
| 254 break; | |
| 255 } | |
| 256 } | |
| 257 if (!match_found) { | |
| 258 LOG (ERROR) << "Falling back to default 32 bit format"; | |
| 259 g_config = matching_configs[default_format]; | |
| 260 } | |
| 261 } | |
| 262 #endif | |
| 263 | |
| 184 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); | 264 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
| 185 g_egl_create_context_robustness_supported = | 265 g_egl_create_context_robustness_supported = |
| 186 HasEGLExtension("EGL_EXT_create_context_robustness"); | 266 HasEGLExtension("EGL_EXT_create_context_robustness"); |
| 187 g_egl_sync_control_supported = | 267 g_egl_sync_control_supported = |
| 188 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 268 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
| 189 | 269 |
| 190 // Check if SurfacelessEGL is supported. | 270 // Check if SurfacelessEGL is supported. |
| 191 g_egl_surfaceless_context_supported = | 271 g_egl_surfaceless_context_supported = |
| 192 HasEGLExtension("EGL_KHR_surfaceless_context"); | 272 HasEGLExtension("EGL_KHR_surfaceless_context"); |
| 193 if (g_egl_surfaceless_context_supported) { | 273 if (g_egl_surfaceless_context_supported) { |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 } | 846 } |
| 767 default: | 847 default: |
| 768 NOTREACHED(); | 848 NOTREACHED(); |
| 769 return NULL; | 849 return NULL; |
| 770 } | 850 } |
| 771 } | 851 } |
| 772 | 852 |
| 773 #endif | 853 #endif |
| 774 | 854 |
| 775 } // namespace gfx | 855 } // namespace gfx |
| OLD | NEW |