Chromium Code Reviews| Index: ui/gl/gl_surface_egl.cc |
| diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc |
| index af32f5297c742e24051dc8724839aae5cd872cd2..f81246c9b3179470a9fdfe80ea23a305366b7778 100644 |
| --- a/ui/gl/gl_surface_egl.cc |
| +++ b/ui/gl/gl_surface_egl.cc |
| @@ -62,6 +62,12 @@ extern "C" { |
| #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_REFERENCE_ANGLE 0x320C |
| #endif /* EGL_ANGLE_platform_angle_d3d */ |
| +#ifndef EGL_ANGLE_platform_angle_opengl |
| +#define EGL_ANGLE_platform_angle_opengl 1 |
| +#define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D |
| +#define EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE 0x320E |
| +#endif /* EGL_ANGLE_platform_angle_opengl */ |
| + |
| using ui::GetLastEGLErrorString; |
| namespace gfx { |
| @@ -140,18 +146,33 @@ void DeinitializeEgl() { |
| EGLDisplay 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}; |
| + bool warpDevice) { |
| + std::vector<EGLint> display_attribs; |
| + |
| + display_attribs.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE); |
| + display_attribs.push_back(platform_type); |
| + |
| + if (warpDevice) { |
| + display_attribs.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE); |
| + display_attribs.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE); |
| + } |
| + |
| + display_attribs.push_back(EGL_NONE); |
| + |
| return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, |
| reinterpret_cast<void*>(native_display), |
| - display_attribs); |
| + &display_attribs[0]); |
| } |
| -enum DisplayType { DEFAULT, SWIFT_SHADER, ANGLE_WARP, ANGLE_D3D9, ANGLE_D3D11 }; |
| +enum DisplayType { |
| + DEFAULT, |
| + SWIFT_SHADER, |
| + ANGLE_WARP, |
| + ANGLE_D3D9, |
| + ANGLE_D3D11, |
| + ANGLE_OPENGL, |
| + ANGLE_OPENGLES, |
| +}; |
| EGLDisplay GetDisplayFromType(DisplayType display_type, |
| EGLNativeDisplayType native_display) { |
| @@ -160,17 +181,20 @@ EGLDisplay GetDisplayFromType(DisplayType display_type, |
| case SWIFT_SHADER: |
| return eglGetDisplay(native_display); |
| case ANGLE_WARP: |
| - return GetPlatformANGLEDisplay(native_display, |
| - EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, |
| - EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE); |
| + return GetPlatformANGLEDisplay( |
| + native_display, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, true); |
| case ANGLE_D3D9: |
| return GetPlatformANGLEDisplay( |
| - native_display, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, |
| - EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); |
| + native_display, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, false); |
| case ANGLE_D3D11: |
| return GetPlatformANGLEDisplay( |
| - native_display, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, |
| - EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); |
| + native_display, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, false); |
| + case ANGLE_OPENGL: |
| + return GetPlatformANGLEDisplay( |
| + native_display, EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, false); |
| + 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
|
| + return GetPlatformANGLEDisplay( |
| + native_display, EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE, false); |
| default: |
| NOTREACHED(); |
| return EGL_NO_DISPLAY; |
| @@ -189,18 +213,23 @@ const char* DisplayTypeString(DisplayType display_type) { |
| return "D3D9"; |
| case ANGLE_D3D11: |
| return "D3D11"; |
| + case ANGLE_OPENGL: |
| + return "OpenGL"; |
| + case ANGLE_OPENGLES: |
| + return "OpenGLES"; |
| default: |
| NOTREACHED(); |
| return "Err"; |
| } |
| } |
| -void GetInitDisplays(bool supports_angle_d3d, |
| +void GetInitDisplays(bool supports_angle_d3d, bool supports_angle_opengl, |
| std::vector<DisplayType>* init_displays) { |
| const base::CommandLine* command_line = |
| base::CommandLine::ForCurrentProcess(); |
| bool using_swift_shader = |
| - command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"; |
| + command_line->GetSwitchValueASCII(switches::kUseGL) == |
| + kGLImplementationSwiftShaderName; |
| // SwiftShader does not use the platform extensions |
| if (using_swift_shader) { |
| @@ -208,25 +237,57 @@ void GetInitDisplays(bool supports_angle_d3d, |
| return; |
| } |
| - // If we're missing the ANGLE extensions, fall back to default. |
| - if (!supports_angle_d3d) { |
| - init_displays->push_back(DEFAULT); |
| - return; |
| - } |
| + bool angle_renderer_requested = |
| + command_line->HasSwitch(switches::kUseANGLE); |
| + std::string requested_renderer = |
| + command_line->GetSwitchValueASCII(switches::kUseANGLE); |
| - if (command_line->HasSwitch(switches::kUseWarp)) { |
| - init_displays->push_back(ANGLE_WARP); |
| - return; |
| + if (supports_angle_d3d) { |
| + bool use_angle_default = !angle_renderer_requested || |
| + requested_renderer == kANGLEImplementationDefaultName; |
| + |
|
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.
|
| + // Default mode for ANGLE - try D3D11, else try D3D9 |
| + bool use_angle_d3d11 = angle_renderer_requested && |
| + requested_renderer == kANGLEImplementationD3D11Name; |
| + bool disable_d3d11 = command_line->HasSwitch(switches::kDisableD3D11); |
| + if ((use_angle_default && !disable_d3d11) || use_angle_d3d11) { |
| + init_displays->push_back(ANGLE_D3D11); |
| + } |
| + |
| + bool use_angle_d3d9 = angle_renderer_requested && |
| + requested_renderer == kANGLEImplementationD3D9Name; |
| + if (use_angle_default || use_angle_d3d9) { |
| + init_displays->push_back(ANGLE_D3D9); |
| + } |
| + |
| + // Use warp only if it is requested |
| + bool use_angle_warp = angle_renderer_requested && |
| + requested_renderer == kANGLEImplementationWARPName; |
| + if (use_angle_warp) { |
| + init_displays->push_back(ANGLE_WARP); |
| + } |
| } |
| - if (command_line->HasSwitch(switches::kDisableD3D11)) { |
| - init_displays->push_back(ANGLE_D3D9); |
| - return; |
| + if (supports_angle_opengl) { |
| + // Non-default OpenGL renderers, must be specifically requested |
| + bool use_angle_opengl = angle_renderer_requested && |
| + requested_renderer == kANGLEImplementationOpenGLName; |
| + if (use_angle_opengl) { |
| + init_displays->push_back(ANGLE_OPENGL); |
| + } |
| + |
| + bool use_angle_opengles = angle_renderer_requested && |
| + requested_renderer == kANGLEImplementationOpenGLESName; |
| + if (use_angle_opengles) { |
| + init_displays->push_back(ANGLE_OPENGLES); |
| + } |
| } |
| - // Default mode for ANGLE - try D3D11, else try D3D9 |
| - init_displays->push_back(ANGLE_D3D11); |
| - init_displays->push_back(ANGLE_D3D9); |
| + // If no displays are available due to missing angle extensions or invalid |
| + // flags, request the default display. |
| + if (init_displays->empty()) { |
| + 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.
|
| + } |
| } |
| } // namespace |
| @@ -418,15 +479,18 @@ EGLDisplay GLSurfaceEGL::InitializeDisplay() { |
| eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); |
| bool supports_angle_d3d = false; |
| + bool supports_angle_opengl = false; |
| // Check for availability of ANGLE extensions. |
| - if (client_extensions) { |
| + if (client_extensions && |
| + ExtensionsContain(client_extensions, "ANGLE_platform_angle")) { |
| supports_angle_d3d = |
| - ExtensionsContain(client_extensions, "ANGLE_platform_angle") && |
| ExtensionsContain(client_extensions, "ANGLE_platform_angle_d3d"); |
| + supports_angle_opengl = |
| + 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_
|
| } |
| std::vector<DisplayType> init_displays; |
| - GetInitDisplays(supports_angle_d3d, &init_displays); |
| + GetInitDisplays(supports_angle_d3d, supports_angle_opengl, &init_displays); |
| for (size_t disp_index = 0; disp_index < init_displays.size(); ++disp_index) { |
| DisplayType display_type = init_displays[disp_index]; |