Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ui/gl/gl_surface_egl.cc

Issue 1123343004: Add a --use-angle flag for selecting the ANGLE renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 }; 167 enum DisplayType {
168 DEFAULT,
169 SWIFT_SHADER,
170 ANGLE_WARP,
171 ANGLE_D3D9,
172 ANGLE_D3D11,
173 ANGLE_OPENGL,
174 ANGLE_OPENGLES,
175 };
155 176
156 EGLDisplay GetDisplayFromType(DisplayType display_type, 177 EGLDisplay GetDisplayFromType(DisplayType display_type,
157 EGLNativeDisplayType native_display) { 178 EGLNativeDisplayType native_display) {
158 switch (display_type) { 179 switch (display_type) {
159 case DEFAULT: 180 case DEFAULT:
160 case SWIFT_SHADER: 181 case SWIFT_SHADER:
161 return eglGetDisplay(native_display); 182 return eglGetDisplay(native_display);
162 case ANGLE_WARP: 183 case ANGLE_WARP:
163 return GetPlatformANGLEDisplay(native_display, 184 return GetPlatformANGLEDisplay(
164 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, 185 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, true);
165 EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE);
166 case ANGLE_D3D9: 186 case ANGLE_D3D9:
167 return GetPlatformANGLEDisplay( 187 return GetPlatformANGLEDisplay(
168 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, 188 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, false);
169 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE);
170 case ANGLE_D3D11: 189 case ANGLE_D3D11:
171 return GetPlatformANGLEDisplay( 190 return GetPlatformANGLEDisplay(
172 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, 191 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, false);
173 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); 192 case ANGLE_OPENGL:
193 return GetPlatformANGLEDisplay(
194 native_display, EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, false);
195 case ANGLE_OPENGLES:
Jamie Madill 2015/05/07 18:53:13 maybe we wouldn't want to immediately expose ES if
Geoff Lang 2015/05/11 13:31:50 I'm not sure, the OpenGL renderer will be fairly u
196 return GetPlatformANGLEDisplay(
197 native_display, EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE, false);
174 default: 198 default:
175 NOTREACHED(); 199 NOTREACHED();
176 return EGL_NO_DISPLAY; 200 return EGL_NO_DISPLAY;
177 } 201 }
178 } 202 }
179 203
180 const char* DisplayTypeString(DisplayType display_type) { 204 const char* DisplayTypeString(DisplayType display_type) {
181 switch (display_type) { 205 switch (display_type) {
182 case DEFAULT: 206 case DEFAULT:
183 return "Default"; 207 return "Default";
184 case SWIFT_SHADER: 208 case SWIFT_SHADER:
185 return "SwiftShader"; 209 return "SwiftShader";
186 case ANGLE_WARP: 210 case ANGLE_WARP:
187 return "WARP"; 211 return "WARP";
188 case ANGLE_D3D9: 212 case ANGLE_D3D9:
189 return "D3D9"; 213 return "D3D9";
190 case ANGLE_D3D11: 214 case ANGLE_D3D11:
191 return "D3D11"; 215 return "D3D11";
216 case ANGLE_OPENGL:
217 return "OpenGL";
218 case ANGLE_OPENGLES:
219 return "OpenGLES";
192 default: 220 default:
193 NOTREACHED(); 221 NOTREACHED();
194 return "Err"; 222 return "Err";
195 } 223 }
196 } 224 }
197 225
198 void GetInitDisplays(bool supports_angle_d3d, 226 void GetInitDisplays(bool supports_angle_d3d, bool supports_angle_opengl,
199 std::vector<DisplayType>* init_displays) { 227 std::vector<DisplayType>* init_displays) {
200 const base::CommandLine* command_line = 228 const base::CommandLine* command_line =
201 base::CommandLine::ForCurrentProcess(); 229 base::CommandLine::ForCurrentProcess();
202 bool using_swift_shader = 230 bool using_swift_shader =
203 command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"; 231 command_line->GetSwitchValueASCII(switches::kUseGL) ==
232 kGLImplementationSwiftShaderName;
204 233
205 // SwiftShader does not use the platform extensions 234 // SwiftShader does not use the platform extensions
206 if (using_swift_shader) { 235 if (using_swift_shader) {
207 init_displays->push_back(SWIFT_SHADER); 236 init_displays->push_back(SWIFT_SHADER);
208 return; 237 return;
209 } 238 }
210 239
211 // If we're missing the ANGLE extensions, fall back to default. 240 bool angle_renderer_requested =
212 if (!supports_angle_d3d) { 241 command_line->HasSwitch(switches::kUseANGLE);
213 init_displays->push_back(DEFAULT); 242 std::string requested_renderer =
214 return; 243 command_line->GetSwitchValueASCII(switches::kUseANGLE);
244
245 if (supports_angle_d3d) {
246 bool use_angle_default = !angle_renderer_requested ||
247 requested_renderer == kANGLEImplementationDefaultName;
248
Jamie Madill 2015/05/07 18:53:13 could probably simplify this float bit by separati
Geoff Lang 2015/05/11 13:31:50 Done, reorganized a bit.
249 // Default mode for ANGLE - try D3D11, else try D3D9
250 bool use_angle_d3d11 = angle_renderer_requested &&
251 requested_renderer == kANGLEImplementationD3D11Name;
252 bool disable_d3d11 = command_line->HasSwitch(switches::kDisableD3D11);
253 if ((use_angle_default && !disable_d3d11) || use_angle_d3d11) {
254 init_displays->push_back(ANGLE_D3D11);
255 }
256
257 bool use_angle_d3d9 = angle_renderer_requested &&
258 requested_renderer == kANGLEImplementationD3D9Name;
259 if (use_angle_default || use_angle_d3d9) {
260 init_displays->push_back(ANGLE_D3D9);
261 }
262
263 // Use warp only if it is requested
264 bool use_angle_warp = angle_renderer_requested &&
265 requested_renderer == kANGLEImplementationWARPName;
266 if (use_angle_warp) {
267 init_displays->push_back(ANGLE_WARP);
268 }
215 } 269 }
216 270
217 if (command_line->HasSwitch(switches::kUseWarp)) { 271 if (supports_angle_opengl) {
218 init_displays->push_back(ANGLE_WARP); 272 // Non-default OpenGL renderers, must be specifically requested
219 return; 273 bool use_angle_opengl = angle_renderer_requested &&
274 requested_renderer == kANGLEImplementationOpenGLName;
275 if (use_angle_opengl) {
276 init_displays->push_back(ANGLE_OPENGL);
277 }
278
279 bool use_angle_opengles = angle_renderer_requested &&
280 requested_renderer == kANGLEImplementationOpenGLESName;
281 if (use_angle_opengles) {
282 init_displays->push_back(ANGLE_OPENGLES);
283 }
220 } 284 }
221 285
222 if (command_line->HasSwitch(switches::kDisableD3D11)) { 286 // If no displays are available due to missing angle extensions or invalid
223 init_displays->push_back(ANGLE_D3D9); 287 // flags, request the default display.
224 return; 288 if (init_displays->empty()) {
289 init_displays->push_back(DEFAULT);
Ken Russell (switch to Gerrit) 2015/05/07 20:58:09 There's a fair bit of logic here and it would be i
Geoff Lang 2015/05/11 13:31:50 Done, added a test.
225 } 290 }
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 } 291 }
231 292
232 } // namespace 293 } // namespace
233 294
234 GLSurfaceEGL::GLSurfaceEGL() { 295 GLSurfaceEGL::GLSurfaceEGL() {
235 ++g_num_surfaces; 296 ++g_num_surfaces;
236 if (!g_initialized) { 297 if (!g_initialized) {
237 bool result = GLSurfaceEGL::InitializeOneOff(); 298 bool result = GLSurfaceEGL::InitializeOneOff();
238 DCHECK(result); 299 DCHECK(result);
239 DCHECK(g_initialized); 300 DCHECK(g_initialized);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 472 }
412 473
413 g_native_display_type = GetPlatformDefaultEGLNativeDisplay(); 474 g_native_display_type = GetPlatformDefaultEGLNativeDisplay();
414 475
415 // If EGL_EXT_client_extensions not supported this call to eglQueryString 476 // If EGL_EXT_client_extensions not supported this call to eglQueryString
416 // will return NULL. 477 // will return NULL.
417 const char* client_extensions = 478 const char* client_extensions =
418 eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); 479 eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
419 480
420 bool supports_angle_d3d = false; 481 bool supports_angle_d3d = false;
482 bool supports_angle_opengl = false;
421 // Check for availability of ANGLE extensions. 483 // Check for availability of ANGLE extensions.
422 if (client_extensions) { 484 if (client_extensions &&
485 ExtensionsContain(client_extensions, "ANGLE_platform_angle")) {
423 supports_angle_d3d = 486 supports_angle_d3d =
424 ExtensionsContain(client_extensions, "ANGLE_platform_angle") &&
425 ExtensionsContain(client_extensions, "ANGLE_platform_angle_d3d"); 487 ExtensionsContain(client_extensions, "ANGLE_platform_angle_d3d");
488 supports_angle_opengl =
489 ExtensionsContain(client_extensions, "EGL_ANGLE_platform_angle_opengl");
Ken Russell (switch to Gerrit) 2015/05/07 20:58:09 The use of EGL_ for this extension but not the oth
Geoff Lang 2015/05/11 13:31:50 Fixed, we should always be using EGL_
426 } 490 }
427 491
428 std::vector<DisplayType> init_displays; 492 std::vector<DisplayType> init_displays;
429 GetInitDisplays(supports_angle_d3d, &init_displays); 493 GetInitDisplays(supports_angle_d3d, supports_angle_opengl, &init_displays);
430 494
431 for (size_t disp_index = 0; disp_index < init_displays.size(); ++disp_index) { 495 for (size_t disp_index = 0; disp_index < init_displays.size(); ++disp_index) {
432 DisplayType display_type = init_displays[disp_index]; 496 DisplayType display_type = init_displays[disp_index];
433 EGLDisplay display = 497 EGLDisplay display =
434 GetDisplayFromType(display_type, g_native_display_type); 498 GetDisplayFromType(display_type, g_native_display_type);
435 if (display == EGL_NO_DISPLAY) { 499 if (display == EGL_NO_DISPLAY) {
436 LOG(ERROR) << "EGL display query failed with error " 500 LOG(ERROR) << "EGL display query failed with error "
437 << GetLastEGLErrorString(); 501 << GetLastEGLErrorString();
438 } 502 }
439 503
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 } 982 }
919 983
920 void* SurfacelessEGL::GetShareHandle() { 984 void* SurfacelessEGL::GetShareHandle() {
921 return NULL; 985 return NULL;
922 } 986 }
923 987
924 SurfacelessEGL::~SurfacelessEGL() { 988 SurfacelessEGL::~SurfacelessEGL() {
925 } 989 }
926 990
927 } // namespace gfx 991 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698