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 #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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 g_display = GetPlatformDisplay(g_native_display_type); | 162 g_display = GetPlatformDisplay(g_native_display_type); |
| 163 #else | 163 #else |
| 164 g_display = eglGetDisplay(g_native_display_type); | 164 g_display = eglGetDisplay(g_native_display_type); |
| 165 #endif | 165 #endif |
| 166 | 166 |
| 167 if (!g_display) { | 167 if (!g_display) { |
| 168 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); | 168 LOG(ERROR) << "eglGetDisplay failed with error " << GetLastEGLErrorString(); |
| 169 return false; | 169 return false; |
| 170 } | 170 } |
| 171 | 171 |
| 172 if (!eglInitialize(g_display, NULL, NULL)) { | 172 const base::CommandLine* command_line = |
| 173 base::CommandLine::ForCurrentProcess(); | |
| 174 | |
| 175 bool egl_init_success = | |
| 176 (eglInitialize(g_display, nullptr, nullptr) == EGL_TRUE); | |
| 177 #if defined(OS_WIN) | |
| 178 // Try D3D9 if D3D11 init failed for ANGLE | |
| 179 if (!egl_init_success && !command_line->HasSwitch(switches::kDisableD3D11) && | |
| 180 !command_line->HasSwitch(switches::kUseWarp) && | |
| 181 command_line->GetSwitchValueASCII(switches::kUseGL) != "swiftshader") { | |
| 182 LOG(ERROR) << "eglInitialize (D3D11) failed with error " | |
| 183 << GetLastEGLErrorString() << ", trying D3D9"; | |
| 184 | |
| 185 g_display = GetPlatformANGLEDisplay( | |
| 186 g_native_display_type, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, | |
| 187 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); | |
| 188 | |
| 189 if (!g_display) { | |
| 190 LOG(ERROR) << "eglGetDisplay (D3D9) failed with error " | |
| 191 << GetLastEGLErrorString(); | |
| 192 return false; | |
| 193 } | |
| 194 | |
| 195 egl_init_success = (eglInitialize(g_display, nullptr, nullptr) == EGL_TRUE); | |
| 196 } | |
| 197 #endif | |
| 198 if (!egl_init_success) { | |
| 173 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); | 199 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); |
| 174 return false; | 200 return false; |
| 175 } | 201 } |
| 176 | 202 |
| 177 // Choose an EGL configuration. | 203 // Choose an EGL configuration. |
| 178 // On X this is only used for PBuffer surfaces. | 204 // On X this is only used for PBuffer surfaces. |
| 179 EGLint renderable_type = EGL_OPENGL_ES2_BIT; | 205 EGLint renderable_type = EGL_OPENGL_ES2_BIT; |
| 180 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 206 if (command_line->HasSwitch(switches::kEnableUnsafeES3APIs)) { |
| 181 switches::kEnableUnsafeES3APIs)) { | |
| 182 renderable_type = EGL_OPENGL_ES3_BIT; | 207 renderable_type = EGL_OPENGL_ES3_BIT; |
| 183 } | 208 } |
| 184 const EGLint kConfigAttribs[] = { | 209 const EGLint kConfigAttribs[] = { |
| 185 EGL_BUFFER_SIZE, 32, | 210 EGL_BUFFER_SIZE, 32, |
| 186 EGL_ALPHA_SIZE, 8, | 211 EGL_ALPHA_SIZE, 8, |
| 187 EGL_BLUE_SIZE, 8, | 212 EGL_BLUE_SIZE, 8, |
| 188 EGL_GREEN_SIZE, 8, | 213 EGL_GREEN_SIZE, 8, |
| 189 EGL_RED_SIZE, 8, | 214 EGL_RED_SIZE, 8, |
| 190 EGL_RENDERABLE_TYPE, renderable_type, | 215 EGL_RENDERABLE_TYPE, renderable_type, |
| 191 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | 216 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 | 347 |
| 323 GLSurfaceEGL::~GLSurfaceEGL() { | 348 GLSurfaceEGL::~GLSurfaceEGL() { |
| 324 DCHECK_GT(g_num_surfaces, 0) << "Bad surface count"; | 349 DCHECK_GT(g_num_surfaces, 0) << "Bad surface count"; |
| 325 if (--g_num_surfaces == 0 && g_terminate_pending) { | 350 if (--g_num_surfaces == 0 && g_terminate_pending) { |
| 326 DeinitializeEgl(); | 351 DeinitializeEgl(); |
| 327 g_terminate_pending = false; | 352 g_terminate_pending = false; |
| 328 } | 353 } |
| 329 } | 354 } |
| 330 | 355 |
| 331 #if defined(OS_WIN) | 356 #if defined(OS_WIN) |
| 332 static const EGLint kDisplayAttribsWarp[] { | |
| 333 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | |
| 334 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, | |
| 335 | |
| 336 EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, | |
| 337 EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE, | |
| 338 | |
| 339 EGL_NONE | |
| 340 }; | |
| 341 | 357 |
| 342 // static | 358 // static |
| 343 EGLDisplay GLSurfaceEGL::GetPlatformDisplay( | 359 EGLDisplay GLSurfaceEGL::GetPlatformDisplay( |
| 344 EGLNativeDisplayType native_display) { | 360 EGLNativeDisplayType native_display) { |
| 345 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseWarp)) { | 361 const base::CommandLine* command_line = |
| 346 // Check for availability of WARP via ANGLE extension. | 362 base::CommandLine::ForCurrentProcess(); |
| 347 bool supports_warp = false; | 363 bool using_swift_shader = |
| 348 const char* no_display_extensions = eglQueryString(EGL_NO_DISPLAY, | 364 command_line->GetSwitchValueASCII(switches::kUseGL) == "swiftshader"; |
| 349 EGL_EXTENSIONS); | |
| 350 // If EGL_EXT_client_extensions not supported this call to eglQueryString | |
| 351 // will return NULL. | |
| 352 if (no_display_extensions) | |
| 353 supports_warp = | |
| 354 ExtensionsContain(no_display_extensions, "ANGLE_platform_angle") && | |
| 355 ExtensionsContain(no_display_extensions, "ANGLE_platform_angle_d3d"); | |
| 356 | 365 |
| 357 if (!supports_warp) | 366 // SwiftShader does not use the platform extensions |
| 358 return NULL; | 367 if (using_swift_shader) { |
| 359 | 368 return eglGetDisplay(native_display); |
| 360 return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, native_display, | |
| 361 kDisplayAttribsWarp); | |
| 362 } | 369 } |
| 363 | 370 |
| 364 return eglGetDisplay(native_display); | 371 // If EGL_EXT_client_extensions not supported this call to eglQueryString |
| 372 // will return NULL. | |
| 373 const char* client_extensions = | |
| 374 eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); | |
| 375 | |
| 376 bool supports_angle_d3d = false; | |
| 377 // Check for availability of ANGLE extensions. | |
| 378 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.
| |
| 379 supports_angle_d3d = | |
| 380 ExtensionsContain(client_extensions, "ANGLE_platform_angle") && | |
| 381 ExtensionsContain(client_extensions, "ANGLE_platform_angle_d3d"); | |
| 382 | |
| 383 // If we aren't using SwiftShader, we're using ANGLE on EGL. | |
| 384 if (!supports_angle_d3d) | |
| 385 return nullptr; | |
| 386 | |
| 387 if (command_line->HasSwitch(switches::kUseWarp)) { | |
| 388 return GetPlatformANGLEDisplay(native_display, | |
| 389 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, | |
| 390 EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE); | |
| 391 } | |
| 392 | |
| 393 if (command_line->HasSwitch(switches::kDisableD3D11)) { | |
| 394 return GetPlatformANGLEDisplay( | |
| 395 native_display, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, | |
| 396 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); | |
| 397 } | |
| 398 | |
| 399 return GetPlatformANGLEDisplay(native_display, | |
| 400 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, | |
| 401 EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE); | |
| 365 } | 402 } |
| 403 | |
| 404 // static | |
| 405 EGLDisplay GLSurfaceEGL::GetPlatformANGLEDisplay( | |
| 406 EGLNativeDisplayType native_display, | |
| 407 EGLenum platform_type, | |
| 408 EGLenum device_type) { | |
| 409 const EGLint display_attribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE, | |
| 410 platform_type, | |
| 411 EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, | |
| 412 device_type, | |
| 413 EGL_NONE}; | |
| 414 return eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, native_display, | |
| 415 display_attribs); | |
| 416 } | |
| 417 | |
| 366 #endif | 418 #endif |
| 367 | 419 |
| 368 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) | 420 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) |
| 369 : window_(window), | 421 : window_(window), |
| 370 surface_(NULL), | 422 surface_(NULL), |
| 371 supports_post_sub_buffer_(false), | 423 supports_post_sub_buffer_(false), |
| 372 config_(NULL), | 424 config_(NULL), |
| 373 size_(1, 1), | 425 size_(1, 1), |
| 374 swap_interval_(1) { | 426 swap_interval_(1) { |
| 375 #if defined(OS_ANDROID) | 427 #if defined(OS_ANDROID) |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 } | 883 } |
| 832 | 884 |
| 833 void* SurfacelessEGL::GetShareHandle() { | 885 void* SurfacelessEGL::GetShareHandle() { |
| 834 return NULL; | 886 return NULL; |
| 835 } | 887 } |
| 836 | 888 |
| 837 SurfacelessEGL::~SurfacelessEGL() { | 889 SurfacelessEGL::~SurfacelessEGL() { |
| 838 } | 890 } |
| 839 | 891 |
| 840 } // namespace gfx | 892 } // namespace gfx |
| OLD | NEW |