Index: ui/gl/gl_surface_egl.cc |
diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc |
index 61c3c055bd0a573a3d541fd34c6ec054d7bf1507..86aeb7c68537509d677ff31c66379bf9e3f50752 100644 |
--- a/ui/gl/gl_surface_egl.cc |
+++ b/ui/gl/gl_surface_egl.cc |
@@ -169,7 +169,33 @@ bool GLSurfaceEGL::InitializeOneOff() { |
return false; |
} |
- if (!eglInitialize(g_display, NULL, NULL)) { |
+ const base::CommandLine* command_line = |
+ base::CommandLine::ForCurrentProcess(); |
+ |
+ bool egl_init_success = |
+ (eglInitialize(g_display, nullptr, nullptr) == EGL_TRUE); |
+#if defined(OS_WIN) |
+ // Try D3D9 if D3D11 init failed for ANGLE |
+ if (!egl_init_success && !command_line->HasSwitch(switches::kDisableD3D11) && |
+ !command_line->HasSwitch(switches::kUseWarp) && |
+ command_line->GetSwitchValueASCII(switches::kUseGL) != "swiftshader") { |
+ LOG(ERROR) << "eglInitialize (D3D11) failed with error " |
+ << GetLastEGLErrorString() << ", trying D3D9"; |
+ |
+ g_display = GetPlatformANGLEDisplay( |
+ g_native_display_type, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, |
+ EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); |
+ |
+ if (!g_display) { |
+ LOG(ERROR) << "eglGetDisplay (D3D9) failed with error " |
+ << GetLastEGLErrorString(); |
+ return false; |
+ } |
+ |
+ egl_init_success = (eglInitialize(g_display, nullptr, nullptr) == EGL_TRUE); |
+ } |
+#endif |
+ if (!egl_init_success) { |
LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); |
return false; |
} |
@@ -177,8 +203,7 @@ bool GLSurfaceEGL::InitializeOneOff() { |
// Choose an EGL configuration. |
// On X this is only used for PBuffer surfaces. |
EGLint renderable_type = EGL_OPENGL_ES2_BIT; |
- if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kEnableUnsafeES3APIs)) { |
+ if (command_line->HasSwitch(switches::kEnableUnsafeES3APIs)) { |
renderable_type = EGL_OPENGL_ES3_BIT; |
} |
const EGLint kConfigAttribs[] = { |
@@ -329,40 +354,67 @@ GLSurfaceEGL::~GLSurfaceEGL() { |
} |
#if defined(OS_WIN) |
-static const EGLint kDisplayAttribsWarp[] { |
- EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
- EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, |
- |
- EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, |
- EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE, |
- |
- EGL_NONE |
-}; |
// static |
EGLDisplay GLSurfaceEGL::GetPlatformDisplay( |
EGLNativeDisplayType native_display) { |
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp)) { |
- // Check for availability of WARP via ANGLE extension. |
- bool supports_warp = false; |
- const char* no_display_extensions = eglQueryString(EGL_NO_DISPLAY, |
- EGL_EXTENSIONS); |
- // If EGL_EXT_client_extensions not supported this call to eglQueryString |
- // will return NULL. |
- if (no_display_extensions) |
- supports_warp = |
- ExtensionsContain(no_display_extensions, "ANGLE_platform_angle") && |
- ExtensionsContain(no_display_extensions, "ANGLE_platform_angle_d3d"); |
- |
- if (!supports_warp) |
- return NULL; |
+ const base::CommandLine* command_line = |
+ base::CommandLine::ForCurrentProcess(); |
+ bool using_swift_shader = |
+ command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"; |
- return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, native_display, |
- kDisplayAttribsWarp); |
+ // SwiftShader does not use the platform extensions |
+ if (using_swift_shader) { |
+ return eglGetDisplay(native_display); |
} |
- return eglGetDisplay(native_display); |
+ // If EGL_EXT_client_extensions not supported this call to eglQueryString |
+ // will return NULL. |
+ const char* client_extensions = |
+ eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); |
+ |
+ bool supports_angle_d3d = false; |
+ // Check for availability of ANGLE extensions. |
+ if (client_extensions) |
piman
2015/04/16 21:51:05
nit: need braces per style guide
zmo
2015/04/16 21:52:34
nit: use {} if the block is more than one line.
Jamie Madill
2015/04/17 19:14:13
Done.
|
+ supports_angle_d3d = |
+ ExtensionsContain(client_extensions, "ANGLE_platform_angle") && |
+ ExtensionsContain(client_extensions, "ANGLE_platform_angle_d3d"); |
+ |
+ // If we aren't using SwiftShader, we're using ANGLE on EGL. |
+ if (!supports_angle_d3d) |
+ return nullptr; |
+ |
+ if (command_line->HasSwitch(switches::kUseWarp)) { |
+ return GetPlatformANGLEDisplay(native_display, |
+ EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, |
+ EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE); |
+ } |
+ |
+ if (command_line->HasSwitch(switches::kDisableD3D11)) { |
+ return GetPlatformANGLEDisplay( |
+ native_display, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, |
+ EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); |
+ } |
+ |
+ return GetPlatformANGLEDisplay(native_display, |
+ EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, |
+ EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); |
} |
+ |
+// static |
+EGLDisplay GLSurfaceEGL::GetPlatformANGLEDisplay( |
+ EGLNativeDisplayType native_display, |
+ EGLenum platform_type, |
+ EGLenum device_type) { |
+ const EGLint display_attribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
+ platform_type, |
+ EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, |
+ device_type, |
+ EGL_NONE}; |
+ return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, native_display, |
+ display_attribs); |
+} |
+ |
#endif |
NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) |