| 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 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 EGLNativeDisplayType g_native_display = EGL_DEFAULT_DISPLAY; | 127 EGLNativeDisplayType g_native_display = EGL_DEFAULT_DISPLAY; |
| 128 | 128 |
| 129 const char* g_egl_extensions = nullptr; | 129 const char* g_egl_extensions = nullptr; |
| 130 bool g_egl_create_context_robustness_supported = false; | 130 bool g_egl_create_context_robustness_supported = false; |
| 131 bool g_egl_create_context_bind_generates_resource_supported = false; | 131 bool g_egl_create_context_bind_generates_resource_supported = false; |
| 132 bool g_egl_create_context_webgl_compatability_supported = false; | 132 bool g_egl_create_context_webgl_compatability_supported = false; |
| 133 bool g_egl_sync_control_supported = false; | 133 bool g_egl_sync_control_supported = false; |
| 134 bool g_egl_window_fixed_size_supported = false; | 134 bool g_egl_window_fixed_size_supported = false; |
| 135 bool g_egl_surfaceless_context_supported = false; | 135 bool g_egl_surfaceless_context_supported = false; |
| 136 bool g_egl_surface_orientation_supported = false; | 136 bool g_egl_surface_orientation_supported = false; |
| 137 bool g_egl_context_priority_supported = false; |
| 137 bool g_use_direct_composition = false; | 138 bool g_use_direct_composition = false; |
| 138 | 139 |
| 139 base::LazyInstance<ANGLEPlatformImpl> g_angle_platform_impl = | 140 base::LazyInstance<ANGLEPlatformImpl> g_angle_platform_impl = |
| 140 LAZY_INSTANCE_INITIALIZER; | 141 LAZY_INSTANCE_INITIALIZER; |
| 141 ANGLEPlatformShutdownFunc g_angle_platform_shutdown = nullptr; | 142 ANGLEPlatformShutdownFunc g_angle_platform_shutdown = nullptr; |
| 142 | 143 |
| 143 EGLDisplay GetPlatformANGLEDisplay(EGLNativeDisplayType native_display, | 144 EGLDisplay GetPlatformANGLEDisplay(EGLNativeDisplayType native_display, |
| 144 EGLenum platform_type, | 145 EGLenum platform_type, |
| 145 bool warpDevice) { | 146 bool warpDevice) { |
| 146 std::vector<EGLint> display_attribs; | 147 std::vector<EGLint> display_attribs; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 236 } |
| 236 if (*num_configs == 0) { | 237 if (*num_configs == 0) { |
| 237 return false; | 238 return false; |
| 238 } | 239 } |
| 239 return true; | 240 return true; |
| 240 } | 241 } |
| 241 | 242 |
| 242 EGLConfig ChooseConfig(GLSurfaceFormat format) { | 243 EGLConfig ChooseConfig(GLSurfaceFormat format) { |
| 243 // Choose an EGL configuration. | 244 // Choose an EGL configuration. |
| 244 // On X this is only used for PBuffer surfaces. | 245 // On X this is only used for PBuffer surfaces. |
| 246 |
| 245 std::vector<EGLint> renderable_types; | 247 std::vector<EGLint> renderable_types; |
| 246 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 248 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 247 switches::kDisableES3GLContext)) { | 249 switches::kDisableES3GLContext)) { |
| 248 renderable_types.push_back(EGL_OPENGL_ES3_BIT); | 250 renderable_types.push_back(EGL_OPENGL_ES3_BIT); |
| 249 } | 251 } |
| 250 renderable_types.push_back(EGL_OPENGL_ES2_BIT); | 252 renderable_types.push_back(EGL_OPENGL_ES2_BIT); |
| 251 | 253 |
| 252 EGLint buffer_size = format.GetBufferSize(); | 254 EGLint buffer_size = format.GetBufferSize(); |
| 253 EGLint alpha_size = 8; | 255 EGLint alpha_size = 8; |
| 254 bool want_rgb565 = buffer_size == 16; | 256 bool want_rgb565 = buffer_size == 16; |
| 257 EGLint depth_size = format.GetDepthBits(); |
| 258 EGLint stencil_size = format.GetStencilBits(); |
| 259 EGLint samples = format.GetSamples(); |
| 255 | 260 |
| 256 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 261 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 257 // If we're using ANGLE_NULL, we may not have a display, in which case we | 262 // If we're using ANGLE_NULL, we may not have a display, in which case we |
| 258 // can't use XVisualManager. | 263 // can't use XVisualManager. |
| 259 if (g_native_display) { | 264 if (g_native_display) { |
| 260 ui::XVisualManager::GetInstance()->ChooseVisualForWindow( | 265 ui::XVisualManager::GetInstance()->ChooseVisualForWindow( |
| 261 true, nullptr, &buffer_size, nullptr, nullptr); | 266 true, nullptr, &buffer_size, nullptr, nullptr); |
| 262 alpha_size = buffer_size == 32 ? 8 : 0; | 267 alpha_size = buffer_size == 32 ? 8 : 0; |
| 263 } | 268 } |
| 264 #endif | 269 #endif |
| 265 | 270 |
| 266 EGLint surface_type = (format.IsSurfaceless() | 271 EGLint surface_type = (format.IsSurfaceless() |
| 267 ? EGL_DONT_CARE | 272 ? EGL_DONT_CARE |
| 268 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT); | 273 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT); |
| 269 | 274 |
| 270 for (auto renderable_type : renderable_types) { | 275 for (auto renderable_type : renderable_types) { |
| 271 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE, | 276 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE, |
| 272 buffer_size, | 277 buffer_size, |
| 273 EGL_ALPHA_SIZE, | 278 EGL_ALPHA_SIZE, |
| 274 alpha_size, | 279 alpha_size, |
| 275 EGL_BLUE_SIZE, | 280 EGL_BLUE_SIZE, |
| 276 8, | 281 8, |
| 277 EGL_GREEN_SIZE, | 282 EGL_GREEN_SIZE, |
| 278 8, | 283 8, |
| 279 EGL_RED_SIZE, | 284 EGL_RED_SIZE, |
| 280 8, | 285 8, |
| 286 EGL_SAMPLES, |
| 287 samples, |
| 288 EGL_DEPTH_SIZE, |
| 289 depth_size, |
| 290 EGL_STENCIL_SIZE, |
| 291 stencil_size, |
| 281 EGL_RENDERABLE_TYPE, | 292 EGL_RENDERABLE_TYPE, |
| 282 renderable_type, | 293 renderable_type, |
| 283 EGL_SURFACE_TYPE, | 294 EGL_SURFACE_TYPE, |
| 284 surface_type, | 295 surface_type, |
| 285 EGL_NONE}; | 296 EGL_NONE}; |
| 286 | 297 |
| 287 EGLint config_attribs_565[] = {EGL_BUFFER_SIZE, | 298 EGLint config_attribs_565[] = {EGL_BUFFER_SIZE, |
| 288 16, | 299 16, |
| 289 EGL_BLUE_SIZE, | 300 EGL_BLUE_SIZE, |
| 290 5, | 301 5, |
| 291 EGL_GREEN_SIZE, | 302 EGL_GREEN_SIZE, |
| 292 6, | 303 6, |
| 293 EGL_RED_SIZE, | 304 EGL_RED_SIZE, |
| 294 5, | 305 5, |
| 306 EGL_SAMPLES, |
| 307 samples, |
| 308 EGL_DEPTH_SIZE, |
| 309 depth_size, |
| 310 EGL_STENCIL_SIZE, |
| 311 stencil_size, |
| 295 EGL_RENDERABLE_TYPE, | 312 EGL_RENDERABLE_TYPE, |
| 296 renderable_type, | 313 renderable_type, |
| 297 EGL_SURFACE_TYPE, | 314 EGL_SURFACE_TYPE, |
| 298 surface_type, | 315 surface_type, |
| 299 EGL_NONE}; | 316 EGL_NONE}; |
| 300 | 317 |
| 301 EGLint* choose_attributes = config_attribs_8888; | 318 EGLint* choose_attributes = config_attribs_8888; |
| 302 if (want_rgb565) { | 319 if (want_rgb565) { |
| 303 choose_attributes = config_attribs_565; | 320 choose_attributes = config_attribs_565; |
| 304 } | 321 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 g_egl_create_context_bind_generates_resource_supported = | 515 g_egl_create_context_bind_generates_resource_supported = |
| 499 HasEGLExtension("EGL_CHROMIUM_create_context_bind_generates_resource"); | 516 HasEGLExtension("EGL_CHROMIUM_create_context_bind_generates_resource"); |
| 500 g_egl_create_context_webgl_compatability_supported = | 517 g_egl_create_context_webgl_compatability_supported = |
| 501 HasEGLExtension("EGL_ANGLE_create_context_webgl_compatibility"); | 518 HasEGLExtension("EGL_ANGLE_create_context_webgl_compatibility"); |
| 502 g_egl_sync_control_supported = | 519 g_egl_sync_control_supported = |
| 503 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 520 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
| 504 g_egl_window_fixed_size_supported = | 521 g_egl_window_fixed_size_supported = |
| 505 HasEGLExtension("EGL_ANGLE_window_fixed_size"); | 522 HasEGLExtension("EGL_ANGLE_window_fixed_size"); |
| 506 g_egl_surface_orientation_supported = | 523 g_egl_surface_orientation_supported = |
| 507 HasEGLExtension("EGL_ANGLE_surface_orientation"); | 524 HasEGLExtension("EGL_ANGLE_surface_orientation"); |
| 525 // According to |
| 526 // https://source.android.com/compatibility/android-cdd.html the |
| 527 // EGL_IMG_context_priority extension is mandatory for Virtual |
| 528 // Reality High Performance support, but it's not showing in the |
| 529 // list of reported EGL extensions even though it's supported on |
| 530 // Daydream ready devices. As a fallback, check if other related |
| 531 // extensions that were added for VR support are present, and assume |
| 532 // that this implies context priority is also supported. |
| 533 // TODO(klausw): is there a better way to do this? Filed |
| 534 // https://github.com/googlevr/gvr-android-sdk/issues/330 for |
| 535 // followup. |
| 536 g_egl_context_priority_supported = |
| 537 HasEGLExtension("EGL_IMG_context_priority") || ( |
| 538 HasEGLExtension("EGL_ANDROID_front_buffer_auto_refresh") && |
| 539 HasEGLExtension("EGL_ANDROID_create_native_client_buffer")); |
| 508 | 540 |
| 509 // Need EGL_ANGLE_flexible_surface_compatibility to allow surfaces with and | 541 // Need EGL_ANGLE_flexible_surface_compatibility to allow surfaces with and |
| 510 // without alpha to be bound to the same context. | 542 // without alpha to be bound to the same context. |
| 511 g_use_direct_composition = | 543 g_use_direct_composition = |
| 512 HasEGLExtension("EGL_ANGLE_direct_composition") && | 544 HasEGLExtension("EGL_ANGLE_direct_composition") && |
| 513 HasEGLExtension("EGL_ANGLE_flexible_surface_compatibility") && | 545 HasEGLExtension("EGL_ANGLE_flexible_surface_compatibility") && |
| 514 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 546 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 515 switches::kDisableDirectComposition); | 547 switches::kDisableDirectComposition); |
| 516 | 548 |
| 517 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary | 549 // TODO(oetuaho@nvidia.com): Surfaceless is disabled on Android as a temporary |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 eglTerminate(g_display); | 589 eglTerminate(g_display); |
| 558 g_display = EGL_NO_DISPLAY; | 590 g_display = EGL_NO_DISPLAY; |
| 559 | 591 |
| 560 g_egl_extensions = nullptr; | 592 g_egl_extensions = nullptr; |
| 561 g_egl_create_context_robustness_supported = false; | 593 g_egl_create_context_robustness_supported = false; |
| 562 g_egl_create_context_bind_generates_resource_supported = false; | 594 g_egl_create_context_bind_generates_resource_supported = false; |
| 563 g_egl_create_context_webgl_compatability_supported = false; | 595 g_egl_create_context_webgl_compatability_supported = false; |
| 564 g_egl_sync_control_supported = false; | 596 g_egl_sync_control_supported = false; |
| 565 g_egl_window_fixed_size_supported = false; | 597 g_egl_window_fixed_size_supported = false; |
| 566 g_egl_surface_orientation_supported = false; | 598 g_egl_surface_orientation_supported = false; |
| 599 g_egl_context_priority_supported = false; |
| 567 g_use_direct_composition = false; | 600 g_use_direct_composition = false; |
| 568 g_egl_surfaceless_context_supported = false; | 601 g_egl_surfaceless_context_supported = false; |
| 569 | 602 |
| 570 initialized_ = false; | 603 initialized_ = false; |
| 571 } | 604 } |
| 572 | 605 |
| 573 // static | 606 // static |
| 574 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { | 607 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { |
| 575 return g_display; | 608 return g_display; |
| 576 } | 609 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 602 bool GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() { | 635 bool GLSurfaceEGL::IsCreateContextWebGLCompatabilitySupported() { |
| 603 return g_egl_create_context_webgl_compatability_supported; | 636 return g_egl_create_context_webgl_compatability_supported; |
| 604 } | 637 } |
| 605 | 638 |
| 606 // static | 639 // static |
| 607 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { | 640 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { |
| 608 return g_egl_surfaceless_context_supported; | 641 return g_egl_surfaceless_context_supported; |
| 609 } | 642 } |
| 610 | 643 |
| 611 // static | 644 // static |
| 645 bool GLSurfaceEGL::IsEGLContextPrioritySupported() { |
| 646 return g_egl_context_priority_supported; |
| 647 } |
| 648 |
| 649 // static |
| 612 bool GLSurfaceEGL::IsDirectCompositionSupported() { | 650 bool GLSurfaceEGL::IsDirectCompositionSupported() { |
| 613 return g_use_direct_composition; | 651 return g_use_direct_composition; |
| 614 } | 652 } |
| 615 | 653 |
| 616 GLSurfaceEGL::~GLSurfaceEGL() {} | 654 GLSurfaceEGL::~GLSurfaceEGL() {} |
| 617 | 655 |
| 618 // InitializeDisplay is necessary because the static binding code | 656 // InitializeDisplay is necessary because the static binding code |
| 619 // needs a full Display init before it can query the Display extensions. | 657 // needs a full Display init before it can query the Display extensions. |
| 620 // static | 658 // static |
| 621 EGLDisplay GLSurfaceEGL::InitializeDisplay( | 659 EGLDisplay GLSurfaceEGL::InitializeDisplay( |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 } | 1279 } |
| 1242 | 1280 |
| 1243 void* SurfacelessEGL::GetShareHandle() { | 1281 void* SurfacelessEGL::GetShareHandle() { |
| 1244 return NULL; | 1282 return NULL; |
| 1245 } | 1283 } |
| 1246 | 1284 |
| 1247 SurfacelessEGL::~SurfacelessEGL() { | 1285 SurfacelessEGL::~SurfacelessEGL() { |
| 1248 } | 1286 } |
| 1249 | 1287 |
| 1250 } // namespace gl | 1288 } // namespace gl |
| OLD | NEW |