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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 #define EGL_DIRECT_COMPOSITION_ANGLE 0x33A5 | 96 #define EGL_DIRECT_COMPOSITION_ANGLE 0x33A5 |
97 #endif /* EGL_ANGLE_direct_composition */ | 97 #endif /* EGL_ANGLE_direct_composition */ |
98 | 98 |
99 #ifndef EGL_ANGLE_flexible_surface_compatibility | 99 #ifndef EGL_ANGLE_flexible_surface_compatibility |
100 #define EGL_ANGLE_flexible_surface_compatibility 1 | 100 #define EGL_ANGLE_flexible_surface_compatibility 1 |
101 #define EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE 0x33A6 | 101 #define EGL_FLEXIBLE_SURFACE_COMPATIBILITY_SUPPORTED_ANGLE 0x33A6 |
102 #endif /* EGL_ANGLE_flexible_surface_compatibility */ | 102 #endif /* EGL_ANGLE_flexible_surface_compatibility */ |
103 | 103 |
104 using ui::GetLastEGLErrorString; | 104 using ui::GetLastEGLErrorString; |
105 | 105 |
106 namespace gfx { | 106 namespace gl { |
107 | 107 |
108 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
109 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; | 109 unsigned int NativeViewGLSurfaceEGL::current_swap_generation_ = 0; |
110 unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_ = 0; | 110 unsigned int NativeViewGLSurfaceEGL::swaps_this_generation_ = 0; |
111 unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_ = 0; | 111 unsigned int NativeViewGLSurfaceEGL::last_multiswap_generation_ = 0; |
112 | 112 |
113 const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD = 60; | 113 const unsigned int MULTISWAP_FRAME_VSYNC_THRESHOLD = 60; |
114 #endif | 114 #endif |
115 | 115 |
116 namespace { | 116 namespace { |
117 | 117 |
118 EGLDisplay g_display; | 118 EGLDisplay g_display; |
119 EGLNativeDisplayType g_native_display; | 119 EGLNativeDisplayType g_native_display; |
120 | 120 |
121 const char* g_egl_extensions = NULL; | 121 const char* g_egl_extensions = NULL; |
122 bool g_egl_create_context_robustness_supported = false; | 122 bool g_egl_create_context_robustness_supported = false; |
123 bool g_egl_sync_control_supported = false; | 123 bool g_egl_sync_control_supported = false; |
124 bool g_egl_window_fixed_size_supported = false; | 124 bool g_egl_window_fixed_size_supported = false; |
125 bool g_egl_surfaceless_context_supported = false; | 125 bool g_egl_surfaceless_context_supported = false; |
126 bool g_egl_surface_orientation_supported = false; | 126 bool g_egl_surface_orientation_supported = false; |
127 bool g_use_direct_composition = false; | 127 bool g_use_direct_composition = false; |
128 | 128 |
129 class EGLSyncControlVSyncProvider | 129 class EGLSyncControlVSyncProvider : public gl::SyncControlVSyncProvider { |
130 : public gfx::SyncControlVSyncProvider { | |
131 public: | 130 public: |
132 explicit EGLSyncControlVSyncProvider(EGLSurface surface) | 131 explicit EGLSyncControlVSyncProvider(EGLSurface surface) |
133 : SyncControlVSyncProvider(), | 132 : SyncControlVSyncProvider(), |
134 surface_(surface) { | 133 surface_(surface) { |
135 } | 134 } |
136 | 135 |
137 ~EGLSyncControlVSyncProvider() override {} | 136 ~EGLSyncControlVSyncProvider() override {} |
138 | 137 |
139 protected: | 138 protected: |
140 bool GetSyncValues(int64_t* system_time, | 139 bool GetSyncValues(int64_t* system_time, |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 #if defined(OS_ANDROID) | 480 #if defined(OS_ANDROID) |
482 DCHECK(!g_egl_surfaceless_context_supported); | 481 DCHECK(!g_egl_surfaceless_context_supported); |
483 #else | 482 #else |
484 // Check if SurfacelessEGL is supported. | 483 // Check if SurfacelessEGL is supported. |
485 g_egl_surfaceless_context_supported = | 484 g_egl_surfaceless_context_supported = |
486 HasEGLExtension("EGL_KHR_surfaceless_context"); | 485 HasEGLExtension("EGL_KHR_surfaceless_context"); |
487 if (g_egl_surfaceless_context_supported) { | 486 if (g_egl_surfaceless_context_supported) { |
488 // EGL_KHR_surfaceless_context is supported but ensure | 487 // EGL_KHR_surfaceless_context is supported but ensure |
489 // GL_OES_surfaceless_context is also supported. We need a current context | 488 // GL_OES_surfaceless_context is also supported. We need a current context |
490 // to query for supported GL extensions. | 489 // to query for supported GL extensions. |
491 scoped_refptr<GLSurface> surface = new SurfacelessEGL(Size(1, 1)); | 490 scoped_refptr<GLSurface> surface = new SurfacelessEGL(gfx::Size(1, 1)); |
492 scoped_refptr<GLContext> context = GLContext::CreateGLContext( | 491 scoped_refptr<GLContext> context = GLContext::CreateGLContext( |
493 NULL, surface.get(), PreferIntegratedGpu); | 492 NULL, surface.get(), PreferIntegratedGpu); |
494 if (!context->MakeCurrent(surface.get())) | 493 if (!context->MakeCurrent(surface.get())) |
495 g_egl_surfaceless_context_supported = false; | 494 g_egl_surfaceless_context_supported = false; |
496 | 495 |
497 // Ensure context supports GL_OES_surfaceless_context. | 496 // Ensure context supports GL_OES_surfaceless_context. |
498 if (g_egl_surfaceless_context_supported) { | 497 if (g_egl_surfaceless_context_supported) { |
499 g_egl_surfaceless_context_supported = context->HasExtension( | 498 g_egl_surfaceless_context_supported = context->HasExtension( |
500 "GL_OES_surfaceless_context"); | 499 "GL_OES_surfaceless_context"); |
501 context->ReleaseCurrent(surface.get()); | 500 context->ReleaseCurrent(surface.get()); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 size_ = gfx::Rect(windowRect).size(); | 629 size_ = gfx::Rect(windowRect).size(); |
631 #endif | 630 #endif |
632 } | 631 } |
633 | 632 |
634 bool NativeViewGLSurfaceEGL::Initialize(GLSurface::Format format) { | 633 bool NativeViewGLSurfaceEGL::Initialize(GLSurface::Format format) { |
635 format_ = format; | 634 format_ = format; |
636 return Initialize(nullptr); | 635 return Initialize(nullptr); |
637 } | 636 } |
638 | 637 |
639 bool NativeViewGLSurfaceEGL::Initialize( | 638 bool NativeViewGLSurfaceEGL::Initialize( |
640 std::unique_ptr<VSyncProvider> sync_provider) { | 639 std::unique_ptr<gfx::VSyncProvider> sync_provider) { |
641 DCHECK(!surface_); | 640 DCHECK(!surface_); |
642 | 641 |
643 if (!GetDisplay()) { | 642 if (!GetDisplay()) { |
644 LOG(ERROR) << "Trying to create surface with invalid display."; | 643 LOG(ERROR) << "Trying to create surface with invalid display."; |
645 return false; | 644 return false; |
646 } | 645 } |
647 | 646 |
648 // We need to make sure that window_ is correctly initialized with all | 647 // We need to make sure that window_ is correctly initialized with all |
649 // the platform-dependant quirks, if any, before creating the surface. | 648 // the platform-dependant quirks, if any, before creating the surface. |
650 if (!InitializeNativeWindow()) { | 649 if (!InitializeNativeWindow()) { |
651 LOG(ERROR) << "Error trying to initialize the native window."; | 650 LOG(ERROR) << "Error trying to initialize the native window."; |
652 return false; | 651 return false; |
653 } | 652 } |
654 | 653 |
655 std::vector<EGLint> egl_window_attributes; | 654 std::vector<EGLint> egl_window_attributes; |
656 | 655 |
657 if (g_egl_window_fixed_size_supported && enable_fixed_size_angle_) { | 656 if (g_egl_window_fixed_size_supported && enable_fixed_size_angle_) { |
658 egl_window_attributes.push_back(EGL_FIXED_SIZE_ANGLE); | 657 egl_window_attributes.push_back(EGL_FIXED_SIZE_ANGLE); |
659 egl_window_attributes.push_back(EGL_TRUE); | 658 egl_window_attributes.push_back(EGL_TRUE); |
660 egl_window_attributes.push_back(EGL_WIDTH); | 659 egl_window_attributes.push_back(EGL_WIDTH); |
661 egl_window_attributes.push_back(size_.width()); | 660 egl_window_attributes.push_back(size_.width()); |
662 egl_window_attributes.push_back(EGL_HEIGHT); | 661 egl_window_attributes.push_back(EGL_HEIGHT); |
663 egl_window_attributes.push_back(size_.height()); | 662 egl_window_attributes.push_back(size_.height()); |
664 } | 663 } |
665 | 664 |
666 if (gfx::g_driver_egl.ext.b_EGL_NV_post_sub_buffer) { | 665 if (gl::g_driver_egl.ext.b_EGL_NV_post_sub_buffer) { |
667 egl_window_attributes.push_back(EGL_POST_SUB_BUFFER_SUPPORTED_NV); | 666 egl_window_attributes.push_back(EGL_POST_SUB_BUFFER_SUPPORTED_NV); |
668 egl_window_attributes.push_back(EGL_TRUE); | 667 egl_window_attributes.push_back(EGL_TRUE); |
669 } | 668 } |
670 | 669 |
671 if (g_egl_surface_orientation_supported) { | 670 if (g_egl_surface_orientation_supported) { |
672 EGLint attrib; | 671 EGLint attrib; |
673 eglGetConfigAttrib(GetDisplay(), GetConfig(), | 672 eglGetConfigAttrib(GetDisplay(), GetConfig(), |
674 EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE, &attrib); | 673 EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE, &attrib); |
675 flips_vertically_ = (attrib == EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE); | 674 flips_vertically_ = (attrib == EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE); |
676 } | 675 } |
(...skipping 16 matching lines...) Expand all Loading... |
693 surface_ = eglCreateWindowSurface( | 692 surface_ = eglCreateWindowSurface( |
694 GetDisplay(), GetConfig(), window_, &egl_window_attributes[0]); | 693 GetDisplay(), GetConfig(), window_, &egl_window_attributes[0]); |
695 | 694 |
696 if (!surface_) { | 695 if (!surface_) { |
697 LOG(ERROR) << "eglCreateWindowSurface failed with error " | 696 LOG(ERROR) << "eglCreateWindowSurface failed with error " |
698 << GetLastEGLErrorString(); | 697 << GetLastEGLErrorString(); |
699 Destroy(); | 698 Destroy(); |
700 return false; | 699 return false; |
701 } | 700 } |
702 | 701 |
703 if (gfx::g_driver_egl.ext.b_EGL_NV_post_sub_buffer) { | 702 if (gl::g_driver_egl.ext.b_EGL_NV_post_sub_buffer) { |
704 EGLint surfaceVal; | 703 EGLint surfaceVal; |
705 EGLBoolean retVal = eglQuerySurface( | 704 EGLBoolean retVal = eglQuerySurface( |
706 GetDisplay(), surface_, EGL_POST_SUB_BUFFER_SUPPORTED_NV, &surfaceVal); | 705 GetDisplay(), surface_, EGL_POST_SUB_BUFFER_SUPPORTED_NV, &surfaceVal); |
707 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE; | 706 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE; |
708 } | 707 } |
709 | 708 |
710 if (sync_provider) | 709 if (sync_provider) |
711 vsync_provider_.reset(sync_provider.release()); | 710 vsync_provider_.reset(sync_provider.release()); |
712 else if (g_egl_sync_control_supported) | 711 else if (g_egl_sync_control_supported) |
713 vsync_provider_.reset(new EGLSyncControlVSyncProvider(surface_)); | 712 vsync_provider_.reset(new EGLSyncControlVSyncProvider(surface_)); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 | 884 |
886 gfx::SwapResult NativeViewGLSurfaceEGL::CommitOverlayPlanes() { | 885 gfx::SwapResult NativeViewGLSurfaceEGL::CommitOverlayPlanes() { |
887 DCHECK(SupportsCommitOverlayPlanes()); | 886 DCHECK(SupportsCommitOverlayPlanes()); |
888 // Here we assume that the overlays scheduled on this surface will display | 887 // Here we assume that the overlays scheduled on this surface will display |
889 // themselves to the screen right away in |CommitAndClearPendingOverlays|, | 888 // themselves to the screen right away in |CommitAndClearPendingOverlays|, |
890 // rather than being queued and waiting for a "swap" signal. | 889 // rather than being queued and waiting for a "swap" signal. |
891 return CommitAndClearPendingOverlays() ? gfx::SwapResult::SWAP_ACK | 890 return CommitAndClearPendingOverlays() ? gfx::SwapResult::SWAP_ACK |
892 : gfx::SwapResult::SWAP_FAILED; | 891 : gfx::SwapResult::SWAP_FAILED; |
893 } | 892 } |
894 | 893 |
895 VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { | 894 gfx::VSyncProvider* NativeViewGLSurfaceEGL::GetVSyncProvider() { |
896 return vsync_provider_.get(); | 895 return vsync_provider_.get(); |
897 } | 896 } |
898 | 897 |
899 bool NativeViewGLSurfaceEGL::ScheduleOverlayPlane(int z_order, | 898 bool NativeViewGLSurfaceEGL::ScheduleOverlayPlane( |
900 OverlayTransform transform, | 899 int z_order, |
901 gl::GLImage* image, | 900 gfx::OverlayTransform transform, |
902 const Rect& bounds_rect, | 901 gl::GLImage* image, |
903 const RectF& crop_rect) { | 902 const gfx::Rect& bounds_rect, |
| 903 const gfx::RectF& crop_rect) { |
904 #if !defined(OS_ANDROID) | 904 #if !defined(OS_ANDROID) |
905 NOTIMPLEMENTED(); | 905 NOTIMPLEMENTED(); |
906 return false; | 906 return false; |
907 #else | 907 #else |
908 pending_overlays_.push_back( | 908 pending_overlays_.push_back( |
909 GLSurfaceOverlay(z_order, transform, image, bounds_rect, crop_rect)); | 909 GLSurfaceOverlay(z_order, transform, image, bounds_rect, crop_rect)); |
910 return true; | 910 return true; |
911 #endif | 911 #endif |
912 } | 912 } |
913 | 913 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 | 1049 |
1050 EGLSurface PbufferGLSurfaceEGL::GetHandle() { | 1050 EGLSurface PbufferGLSurfaceEGL::GetHandle() { |
1051 return surface_; | 1051 return surface_; |
1052 } | 1052 } |
1053 | 1053 |
1054 void* PbufferGLSurfaceEGL::GetShareHandle() { | 1054 void* PbufferGLSurfaceEGL::GetShareHandle() { |
1055 #if defined(OS_ANDROID) | 1055 #if defined(OS_ANDROID) |
1056 NOTREACHED(); | 1056 NOTREACHED(); |
1057 return NULL; | 1057 return NULL; |
1058 #else | 1058 #else |
1059 if (!gfx::g_driver_egl.ext.b_EGL_ANGLE_query_surface_pointer) | 1059 if (!gl::g_driver_egl.ext.b_EGL_ANGLE_query_surface_pointer) |
1060 return NULL; | 1060 return NULL; |
1061 | 1061 |
1062 if (!gfx::g_driver_egl.ext.b_EGL_ANGLE_surface_d3d_texture_2d_share_handle) | 1062 if (!gl::g_driver_egl.ext.b_EGL_ANGLE_surface_d3d_texture_2d_share_handle) |
1063 return NULL; | 1063 return NULL; |
1064 | 1064 |
1065 void* handle; | 1065 void* handle; |
1066 if (!eglQuerySurfacePointerANGLE(g_display, | 1066 if (!eglQuerySurfacePointerANGLE(g_display, |
1067 GetHandle(), | 1067 GetHandle(), |
1068 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, | 1068 EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, |
1069 &handle)) { | 1069 &handle)) { |
1070 return NULL; | 1070 return NULL; |
1071 } | 1071 } |
1072 | 1072 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 return EGL_NO_SURFACE; | 1123 return EGL_NO_SURFACE; |
1124 } | 1124 } |
1125 | 1125 |
1126 void* SurfacelessEGL::GetShareHandle() { | 1126 void* SurfacelessEGL::GetShareHandle() { |
1127 return NULL; | 1127 return NULL; |
1128 } | 1128 } |
1129 | 1129 |
1130 SurfacelessEGL::~SurfacelessEGL() { | 1130 SurfacelessEGL::~SurfacelessEGL() { |
1131 } | 1131 } |
1132 | 1132 |
1133 } // namespace gfx | 1133 } // namespace gl |
OLD | NEW |