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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 #if defined(OS_WIN) | 109 #if defined(OS_WIN) |
110 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; | 110 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; |
111 unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_ = 0; | 111 unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_ = 0; |
112 unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_ = 0; | 112 unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_ = 0; |
113 | 113 |
114 const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD = 60; | 114 const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD = 60; |
115 #endif | 115 #endif |
116 | 116 |
117 namespace { | 117 namespace { |
118 | 118 |
119 EGLDisplay g_display; | 119 EGLDisplay g_display = EGL_NO_DISPLAY; |
120 EGLNativeDisplayType g_native_display; | 120 EGLNativeDisplayType g_native_display = EGL_DEFAULT_DISPLAY; |
121 | 121 |
122 const char* g_egl_extensions = NULL; | 122 const char* g_egl_extensions = nullptr; |
123 bool g_egl_create_context_robustness_supported = false; | 123 bool g_egl_create_context_robustness_supported = false; |
124 bool g_egl_sync_control_supported = false; | 124 bool g_egl_sync_control_supported = false; |
125 bool g_egl_window_fixed_size_supported = false; | 125 bool g_egl_window_fixed_size_supported = false; |
126 bool g_egl_surfaceless_context_supported = false; | 126 bool g_egl_surfaceless_context_supported = false; |
127 bool g_egl_surface_orientation_supported = false; | 127 bool g_egl_surface_orientation_supported = false; |
128 bool g_use_direct_composition = false; | 128 bool g_use_direct_composition = false; |
129 | 129 |
130 class EGLSyncControlVSyncProvider : public SyncControlVSyncProvider { | 130 class EGLSyncControlVSyncProvider : public SyncControlVSyncProvider { |
131 public: | 131 public: |
132 explicit EGLSyncControlVSyncProvider(EGLSurface surface) | 132 explicit EGLSyncControlVSyncProvider(EGLSurface surface) |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 | 440 |
441 // If no displays are available due to missing angle extensions or invalid | 441 // If no displays are available due to missing angle extensions or invalid |
442 // flags, request the default display. | 442 // flags, request the default display. |
443 if (init_displays->empty()) { | 443 if (init_displays->empty()) { |
444 init_displays->push_back(DEFAULT); | 444 init_displays->push_back(DEFAULT); |
445 } | 445 } |
446 } | 446 } |
447 | 447 |
448 GLSurfaceEGL::GLSurfaceEGL() {} | 448 GLSurfaceEGL::GLSurfaceEGL() {} |
449 | 449 |
450 bool GLSurfaceEGL::InitializeOneOff() { | 450 GLSurface::Format GLSurfaceEGL::GetFormat() { |
| 451 return format_; |
| 452 } |
| 453 |
| 454 EGLDisplay GLSurfaceEGL::GetDisplay() { |
| 455 return g_display; |
| 456 } |
| 457 |
| 458 EGLConfig GLSurfaceEGL::GetConfig() { |
| 459 if (!config_) { |
| 460 config_ = ChooseConfig(format_); |
| 461 } |
| 462 return config_; |
| 463 } |
| 464 |
| 465 // static |
| 466 bool GLSurfaceEGL::InitializeOneOff(EGLNativeDisplayType native_display) { |
451 static bool initialized = false; | 467 static bool initialized = false; |
452 if (initialized) | 468 if (initialized) |
453 return true; | 469 return true; |
454 | 470 |
455 InitializeDisplay(); | 471 // Must be called before InitializeDisplay(). |
| 472 g_driver_egl.InitializeClientExtensionBindings(); |
| 473 |
| 474 InitializeDisplay(native_display); |
456 if (g_display == EGL_NO_DISPLAY) | 475 if (g_display == EGL_NO_DISPLAY) |
457 return false; | 476 return false; |
458 | 477 |
| 478 // Must be called after InitializeDisplay(). |
| 479 g_driver_egl.InitializeExtensionBindings(); |
| 480 |
459 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); | 481 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
460 g_egl_create_context_robustness_supported = | 482 g_egl_create_context_robustness_supported = |
461 HasEGLExtension("EGL_EXT_create_context_robustness"); | 483 HasEGLExtension("EGL_EXT_create_context_robustness"); |
462 g_egl_sync_control_supported = | 484 g_egl_sync_control_supported = |
463 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 485 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
464 g_egl_window_fixed_size_supported = | 486 g_egl_window_fixed_size_supported = |
465 HasEGLExtension("EGL_ANGLE_window_fixed_size"); | 487 HasEGLExtension("EGL_ANGLE_window_fixed_size"); |
466 g_egl_surface_orientation_supported = | 488 g_egl_surface_orientation_supported = |
467 HasEGLExtension("EGL_ANGLE_surface_orientation"); | 489 HasEGLExtension("EGL_ANGLE_surface_orientation"); |
468 | 490 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 context->ReleaseCurrent(surface.get()); | 523 context->ReleaseCurrent(surface.get()); |
502 } | 524 } |
503 } | 525 } |
504 #endif | 526 #endif |
505 | 527 |
506 initialized = true; | 528 initialized = true; |
507 | 529 |
508 return true; | 530 return true; |
509 } | 531 } |
510 | 532 |
511 GLSurface::Format GLSurfaceEGL::GetFormat() { | 533 // static |
512 return format_; | |
513 } | |
514 | |
515 EGLDisplay GLSurfaceEGL::GetDisplay() { | |
516 return g_display; | |
517 } | |
518 | |
519 EGLConfig GLSurfaceEGL::GetConfig() { | |
520 if (!config_) { | |
521 config_ = ChooseConfig(format_); | |
522 } | |
523 return config_; | |
524 } | |
525 | |
526 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { | 534 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { |
527 return g_display; | 535 return g_display; |
528 } | 536 } |
529 | 537 |
| 538 // static |
530 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { | 539 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { |
531 return g_native_display; | 540 return g_native_display; |
532 } | 541 } |
533 | 542 |
| 543 // static |
534 const char* GLSurfaceEGL::GetEGLExtensions() { | 544 const char* GLSurfaceEGL::GetEGLExtensions() { |
535 return g_egl_extensions; | 545 return g_egl_extensions; |
536 } | 546 } |
537 | 547 |
| 548 // static |
538 bool GLSurfaceEGL::HasEGLExtension(const char* name) { | 549 bool GLSurfaceEGL::HasEGLExtension(const char* name) { |
539 return ExtensionsContain(GetEGLExtensions(), name); | 550 return ExtensionsContain(GetEGLExtensions(), name); |
540 } | 551 } |
541 | 552 |
| 553 // static |
542 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() { | 554 bool GLSurfaceEGL::IsCreateContextRobustnessSupported() { |
543 return g_egl_create_context_robustness_supported; | 555 return g_egl_create_context_robustness_supported; |
544 } | 556 } |
545 | 557 |
| 558 // static |
546 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { | 559 bool GLSurfaceEGL::IsEGLSurfacelessContextSupported() { |
547 return g_egl_surfaceless_context_supported; | 560 return g_egl_surfaceless_context_supported; |
548 } | 561 } |
549 | 562 |
| 563 // static |
550 bool GLSurfaceEGL::IsDirectCompositionSupported() { | 564 bool GLSurfaceEGL::IsDirectCompositionSupported() { |
551 return g_use_direct_composition; | 565 return g_use_direct_composition; |
552 } | 566 } |
553 | 567 |
554 GLSurfaceEGL::~GLSurfaceEGL() {} | 568 GLSurfaceEGL::~GLSurfaceEGL() {} |
555 | 569 |
556 // InitializeDisplay is necessary because the static binding code | 570 // InitializeDisplay is necessary because the static binding code |
557 // needs a full Display init before it can query the Display extensions. | 571 // needs a full Display init before it can query the Display extensions. |
558 // static | 572 // static |
559 EGLDisplay GLSurfaceEGL::InitializeDisplay() { | 573 EGLDisplay GLSurfaceEGL::InitializeDisplay( |
| 574 EGLNativeDisplayType native_display) { |
560 if (g_display != EGL_NO_DISPLAY) { | 575 if (g_display != EGL_NO_DISPLAY) { |
561 return g_display; | 576 return g_display; |
562 } | 577 } |
563 | 578 |
564 g_native_display = GetPlatformDefaultEGLNativeDisplay(); | 579 g_native_display = native_display; |
565 | 580 |
566 // If EGL_EXT_client_extensions not supported this call to eglQueryString | 581 // If EGL_EXT_client_extensions not supported this call to eglQueryString |
567 // will return NULL. | 582 // will return NULL. |
568 const char* client_extensions = | 583 const char* client_extensions = |
569 eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); | 584 eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); |
570 | 585 |
571 bool supports_angle_d3d = false; | 586 bool supports_angle_d3d = false; |
572 bool supports_angle_opengl = false; | 587 bool supports_angle_opengl = false; |
573 // Check for availability of ANGLE extensions. | 588 // Check for availability of ANGLE extensions. |
574 if (client_extensions && | 589 if (client_extensions && |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 } | 1140 } |
1126 | 1141 |
1127 void* SurfacelessEGL::GetShareHandle() { | 1142 void* SurfacelessEGL::GetShareHandle() { |
1128 return NULL; | 1143 return NULL; |
1129 } | 1144 } |
1130 | 1145 |
1131 SurfacelessEGL::~SurfacelessEGL() { | 1146 SurfacelessEGL::~SurfacelessEGL() { |
1132 } | 1147 } |
1133 | 1148 |
1134 } // namespace gl | 1149 } // namespace gl |
OLD | NEW |