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 #include "ui/gl/gl_surface_egl.h" | 5 #include "ui/gl/gl_surface_egl.h" |
6 | 6 |
7 #if defined(OS_ANDROID) | 7 #if defined(OS_ANDROID) |
8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #ifndef EGL_ANGLE_platform_angle_d3d | 55 #ifndef EGL_ANGLE_platform_angle_d3d |
56 #define EGL_ANGLE_platform_angle_d3d 1 | 56 #define EGL_ANGLE_platform_angle_d3d 1 |
57 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 | 57 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 |
58 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 | 58 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 |
59 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE 0x3209 | 59 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE 0x3209 |
60 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE 0x320A | 60 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE 0x320A |
61 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE 0x320B | 61 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE 0x320B |
62 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE 0x320C | 62 #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE 0x320C |
63 #endif /* EGL_ANGLE_platform_angle_d3d */ | 63 #endif /* EGL_ANGLE_platform_angle_d3d */ |
64 | 64 |
| 65 #ifndef EGL_ANGLE_platform_angle_opengl |
| 66 #define EGL_ANGLE_platform_angle_opengl 1 |
| 67 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D |
| 68 #define EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE 0x320E |
| 69 #endif /* EGL_ANGLE_platform_angle_opengl */ |
| 70 |
65 using ui::GetLastEGLErrorString; | 71 using ui::GetLastEGLErrorString; |
66 | 72 |
67 namespace gfx { | 73 namespace gfx { |
68 | 74 |
69 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
70 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; | 76 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; |
71 unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_ = 0; | 77 unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_ = 0; |
72 unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_ = 0; | 78 unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_ = 0; |
73 | 79 |
74 const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD = 60; | 80 const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD = 60; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 139 |
134 void DeinitializeEgl() { | 140 void DeinitializeEgl() { |
135 if (g_initialized) { | 141 if (g_initialized) { |
136 g_initialized = false; | 142 g_initialized = false; |
137 eglTerminate(g_display); | 143 eglTerminate(g_display); |
138 } | 144 } |
139 } | 145 } |
140 | 146 |
141 EGLDisplay GetPlatformANGLEDisplay(EGLNativeDisplayType native_display, | 147 EGLDisplay GetPlatformANGLEDisplay(EGLNativeDisplayType native_display, |
142 EGLenum platform_type, | 148 EGLenum platform_type, |
143 EGLenum device_type) { | 149 bool warpDevice) { |
144 const EGLint display_attribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 150 std::vector<EGLint> display_attribs; |
145 platform_type, | 151 |
146 EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, | 152 display_attribs.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE); |
147 device_type, | 153 display_attribs.push_back(platform_type); |
148 EGL_NONE}; | 154 |
| 155 if (warpDevice) { |
| 156 display_attribs.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE); |
| 157 display_attribs.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE); |
| 158 } |
| 159 |
| 160 display_attribs.push_back(EGL_NONE); |
| 161 |
149 return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, | 162 return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, |
150 reinterpret_cast<void*>(native_display), | 163 reinterpret_cast<void*>(native_display), |
151 display_attribs); | 164 &display_attribs[0]); |
152 } | 165 } |
153 | 166 |
154 enum DisplayType { DEFAULT, SWIFT_SHADER, ANGLE_WARP, ANGLE_D3D9, ANGLE_D3D11 }; | |
155 | |
156 EGLDisplay GetDisplayFromType(DisplayType display_type, | 167 EGLDisplay GetDisplayFromType(DisplayType display_type, |
157 EGLNativeDisplayType native_display) { | 168 EGLNativeDisplayType native_display) { |
158 switch (display_type) { | 169 switch (display_type) { |
159 case DEFAULT: | 170 case DEFAULT: |
160 case SWIFT_SHADER: | 171 case SWIFT_SHADER: |
161 return eglGetDisplay(native_display); | 172 return eglGetDisplay(native_display); |
162 case ANGLE_WARP: | 173 case ANGLE_WARP: |
163 return GetPlatformANGLEDisplay(native_display, | 174 return GetPlatformANGLEDisplay(native_display, |
164 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, | 175 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, true); |
165 EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE); | |
166 case ANGLE_D3D9: | 176 case ANGLE_D3D9: |
167 return GetPlatformANGLEDisplay( | 177 return GetPlatformANGLEDisplay(native_display, |
168 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, | 178 EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, false); |
169 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); | |
170 case ANGLE_D3D11: | 179 case ANGLE_D3D11: |
171 return GetPlatformANGLEDisplay( | 180 return GetPlatformANGLEDisplay( |
172 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, | 181 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, false); |
173 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); | 182 case ANGLE_OPENGL: |
| 183 return GetPlatformANGLEDisplay( |
| 184 native_display, EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, false); |
| 185 case ANGLE_OPENGLES: |
| 186 return GetPlatformANGLEDisplay( |
| 187 native_display, EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE, false); |
174 default: | 188 default: |
175 NOTREACHED(); | 189 NOTREACHED(); |
176 return EGL_NO_DISPLAY; | 190 return EGL_NO_DISPLAY; |
177 } | 191 } |
178 } | 192 } |
179 | 193 |
180 const char* DisplayTypeString(DisplayType display_type) { | 194 const char* DisplayTypeString(DisplayType display_type) { |
181 switch (display_type) { | 195 switch (display_type) { |
182 case DEFAULT: | 196 case DEFAULT: |
183 return "Default"; | 197 return "Default"; |
184 case SWIFT_SHADER: | 198 case SWIFT_SHADER: |
185 return "SwiftShader"; | 199 return "SwiftShader"; |
186 case ANGLE_WARP: | 200 case ANGLE_WARP: |
187 return "WARP"; | 201 return "WARP"; |
188 case ANGLE_D3D9: | 202 case ANGLE_D3D9: |
189 return "D3D9"; | 203 return "D3D9"; |
190 case ANGLE_D3D11: | 204 case ANGLE_D3D11: |
191 return "D3D11"; | 205 return "D3D11"; |
| 206 case ANGLE_OPENGL: |
| 207 return "OpenGL"; |
| 208 case ANGLE_OPENGLES: |
| 209 return "OpenGLES"; |
192 default: | 210 default: |
193 NOTREACHED(); | 211 NOTREACHED(); |
194 return "Err"; | 212 return "Err"; |
195 } | 213 } |
196 } | 214 } |
197 | 215 |
198 void GetInitDisplays(bool supports_angle_d3d, | 216 } // namespace |
199 std::vector<DisplayType>* init_displays) { | |
200 const base::CommandLine* command_line = | |
201 base::CommandLine::ForCurrentProcess(); | |
202 bool using_swift_shader = | |
203 command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"; | |
204 | 217 |
| 218 void GetEGLInitDisplays(bool supports_angle_d3d, |
| 219 bool supports_angle_opengl, |
| 220 const base::CommandLine* command_line, |
| 221 std::vector<DisplayType>* init_displays) { |
205 // SwiftShader does not use the platform extensions | 222 // SwiftShader does not use the platform extensions |
206 if (using_swift_shader) { | 223 if (command_line->GetSwitchValueASCII(switches::kUseGL) == |
| 224 kGLImplementationSwiftShaderName) { |
207 init_displays->push_back(SWIFT_SHADER); | 225 init_displays->push_back(SWIFT_SHADER); |
208 return; | 226 return; |
209 } | 227 } |
210 | 228 |
211 // If we're missing the ANGLE extensions, fall back to default. | 229 std::string requested_renderer = |
212 if (!supports_angle_d3d) { | 230 command_line->GetSwitchValueASCII(switches::kUseANGLE); |
213 init_displays->push_back(DEFAULT); | 231 |
214 return; | 232 if (supports_angle_d3d) { |
| 233 bool use_angle_default = |
| 234 !command_line->HasSwitch(switches::kUseANGLE) || |
| 235 requested_renderer == kANGLEImplementationDefaultName; |
| 236 |
| 237 if (use_angle_default) { |
| 238 // Default mode for ANGLE - try D3D11, else try D3D9 |
| 239 if (!command_line->HasSwitch(switches::kDisableD3D11)) { |
| 240 init_displays->push_back(ANGLE_D3D11); |
| 241 } |
| 242 init_displays->push_back(ANGLE_D3D9); |
| 243 } else { |
| 244 if (requested_renderer == kANGLEImplementationD3D11Name) { |
| 245 init_displays->push_back(ANGLE_D3D11); |
| 246 } |
| 247 if (requested_renderer == kANGLEImplementationD3D9Name) { |
| 248 init_displays->push_back(ANGLE_D3D9); |
| 249 } |
| 250 if (requested_renderer == kANGLEImplementationWARPName) { |
| 251 init_displays->push_back(ANGLE_WARP); |
| 252 } |
| 253 } |
215 } | 254 } |
216 | 255 |
217 if (command_line->HasSwitch(switches::kUseWarp)) { | 256 if (supports_angle_opengl) { |
218 init_displays->push_back(ANGLE_WARP); | 257 if (requested_renderer == kANGLEImplementationOpenGLName) { |
219 return; | 258 init_displays->push_back(ANGLE_OPENGL); |
| 259 } |
| 260 if (requested_renderer == kANGLEImplementationOpenGLESName) { |
| 261 init_displays->push_back(ANGLE_OPENGLES); |
| 262 } |
220 } | 263 } |
221 | 264 |
222 if (command_line->HasSwitch(switches::kDisableD3D11)) { | 265 // If no displays are available due to missing angle extensions or invalid |
223 init_displays->push_back(ANGLE_D3D9); | 266 // flags, request the default display. |
224 return; | 267 if (init_displays->empty()) { |
| 268 init_displays->push_back(DEFAULT); |
225 } | 269 } |
226 | |
227 // Default mode for ANGLE - try D3D11, else try D3D9 | |
228 init_displays->push_back(ANGLE_D3D11); | |
229 init_displays->push_back(ANGLE_D3D9); | |
230 } | 270 } |
231 | 271 |
232 } // namespace | |
233 | |
234 GLSurfaceEGL::GLSurfaceEGL() { | 272 GLSurfaceEGL::GLSurfaceEGL() { |
235 ++g_num_surfaces; | 273 ++g_num_surfaces; |
236 if (!g_initialized) { | 274 if (!g_initialized) { |
237 bool result = GLSurfaceEGL::InitializeOneOff(); | 275 bool result = GLSurfaceEGL::InitializeOneOff(); |
238 DCHECK(result); | 276 DCHECK(result); |
239 DCHECK(g_initialized); | 277 DCHECK(g_initialized); |
240 } | 278 } |
241 } | 279 } |
242 | 280 |
243 bool GLSurfaceEGL::InitializeOneOff() { | 281 bool GLSurfaceEGL::InitializeOneOff() { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 } | 449 } |
412 | 450 |
413 g_native_display_type = GetPlatformDefaultEGLNativeDisplay(); | 451 g_native_display_type = GetPlatformDefaultEGLNativeDisplay(); |
414 | 452 |
415 // If EGL_EXT_client_extensions not supported this call to eglQueryString | 453 // If EGL_EXT_client_extensions not supported this call to eglQueryString |
416 // will return NULL. | 454 // will return NULL. |
417 const char* client_extensions = | 455 const char* client_extensions = |
418 eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); | 456 eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); |
419 | 457 |
420 bool supports_angle_d3d = false; | 458 bool supports_angle_d3d = false; |
| 459 bool supports_angle_opengl = false; |
421 // Check for availability of ANGLE extensions. | 460 // Check for availability of ANGLE extensions. |
422 if (client_extensions) { | 461 if (client_extensions && |
| 462 ExtensionsContain(client_extensions, "EGL_ANGLE_platform_angle")) { |
423 supports_angle_d3d = | 463 supports_angle_d3d = |
424 ExtensionsContain(client_extensions, "ANGLE_platform_angle") && | 464 ExtensionsContain(client_extensions, "EGL_ANGLE_platform_angle_d3d"); |
425 ExtensionsContain(client_extensions, "ANGLE_platform_angle_d3d"); | 465 supports_angle_opengl = |
| 466 ExtensionsContain(client_extensions, "EGL_ANGLE_platform_angle_opengl"); |
426 } | 467 } |
427 | 468 |
428 std::vector<DisplayType> init_displays; | 469 std::vector<DisplayType> init_displays; |
429 GetInitDisplays(supports_angle_d3d, &init_displays); | 470 GetEGLInitDisplays(supports_angle_d3d, supports_angle_opengl, |
| 471 base::CommandLine::ForCurrentProcess(), &init_displays); |
430 | 472 |
431 for (size_t disp_index = 0; disp_index < init_displays.size(); ++disp_index) { | 473 for (size_t disp_index = 0; disp_index < init_displays.size(); ++disp_index) { |
432 DisplayType display_type = init_displays[disp_index]; | 474 DisplayType display_type = init_displays[disp_index]; |
433 EGLDisplay display = | 475 EGLDisplay display = |
434 GetDisplayFromType(display_type, g_native_display_type); | 476 GetDisplayFromType(display_type, g_native_display_type); |
435 if (display == EGL_NO_DISPLAY) { | 477 if (display == EGL_NO_DISPLAY) { |
436 LOG(ERROR) << "EGL display query failed with error " | 478 LOG(ERROR) << "EGL display query failed with error " |
437 << GetLastEGLErrorString(); | 479 << GetLastEGLErrorString(); |
438 } | 480 } |
439 | 481 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 } | 960 } |
919 | 961 |
920 void* SurfacelessEGL::GetShareHandle() { | 962 void* SurfacelessEGL::GetShareHandle() { |
921 return NULL; | 963 return NULL; |
922 } | 964 } |
923 | 965 |
924 SurfacelessEGL::~SurfacelessEGL() { | 966 SurfacelessEGL::~SurfacelessEGL() { |
925 } | 967 } |
926 | 968 |
927 } // namespace gfx | 969 } // namespace gfx |
OLD | NEW |