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 // This include must be here so that the includes provided transitively | 5 // This include must be here so that the includes provided transitively |
6 // by gl_surface_egl.h don't make it impossible to compile this code. | 6 // by gl_surface_egl.h don't make it impossible to compile this code. |
7 #include "third_party/mesa/src/include/GL/osmesa.h" | 7 #include "third_party/mesa/src/include/GL/osmesa.h" |
8 | 8 |
9 #include "ui/gl/gl_surface_egl.h" | 9 #include "ui/gl/gl_surface_egl.h" |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 EGLConfig g_config; | 50 EGLConfig g_config; |
51 EGLDisplay g_display; | 51 EGLDisplay g_display; |
52 EGLNativeDisplayType g_native_display; | 52 EGLNativeDisplayType g_native_display; |
53 | 53 |
54 const char* g_egl_extensions = NULL; | 54 const char* g_egl_extensions = NULL; |
55 bool g_egl_create_context_robustness_supported = false; | 55 bool g_egl_create_context_robustness_supported = false; |
56 bool g_egl_sync_control_supported = false; | 56 bool g_egl_sync_control_supported = false; |
57 bool g_egl_surfaceless_context_supported = false; | |
57 | 58 |
58 class EGLSyncControlVSyncProvider | 59 class EGLSyncControlVSyncProvider |
59 : public gfx::SyncControlVSyncProvider { | 60 : public gfx::SyncControlVSyncProvider { |
60 public: | 61 public: |
61 explicit EGLSyncControlVSyncProvider(EGLSurface surface) | 62 explicit EGLSyncControlVSyncProvider(EGLSurface surface) |
62 : SyncControlVSyncProvider(), | 63 : SyncControlVSyncProvider(), |
63 surface_(surface) { | 64 surface_(surface) { |
64 } | 65 } |
65 | 66 |
66 virtual ~EGLSyncControlVSyncProvider() { } | 67 virtual ~EGLSyncControlVSyncProvider() { } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 << GetLastEGLErrorString(); | 178 << GetLastEGLErrorString(); |
178 return false; | 179 return false; |
179 } | 180 } |
180 | 181 |
181 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); | 182 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
182 g_egl_create_context_robustness_supported = | 183 g_egl_create_context_robustness_supported = |
183 HasEGLExtension("EGL_EXT_create_context_robustness"); | 184 HasEGLExtension("EGL_EXT_create_context_robustness"); |
184 g_egl_sync_control_supported = | 185 g_egl_sync_control_supported = |
185 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 186 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
186 | 187 |
188 // Check if SurfacelessEGL is supported. | |
kalyank
2013/10/31 23:49:12
On a second thought another possible solution to a
| |
189 g_egl_surfaceless_context_supported = | |
190 HasEGLExtension("EGL_KHR_surfaceless_context"); | |
191 if (g_egl_surfaceless_context_supported) { | |
192 // EGL_KHR_surfaceless_context is supported but ensure | |
193 // GL_OES_surfaceless_context is also supported. We need a current context | |
194 // to query for supported GL extensions. | |
195 scoped_refptr<GLSurface> surface = new SurfacelessEGL(Size(1, 1)); | |
196 scoped_refptr<GLContext> context = GLContext::CreateGLContext( | |
197 NULL, surface.get(), PreferIntegratedGpu); | |
198 if (!context->MakeCurrent(surface.get())) | |
199 g_egl_surfaceless_context_supported = false; | |
200 | |
201 // Ensure context supports GL_OES_surfaceless_context. | |
202 if (g_egl_surfaceless_context_supported) { | |
203 g_egl_surfaceless_context_supported = context->HasExtension( | |
204 "GL_OES_surfaceless_context"); | |
205 context->ReleaseCurrent(surface.get()); | |
206 } | |
207 } | |
208 | |
187 initialized = true; | 209 initialized = true; |
188 | 210 |
189 return true; | 211 return true; |
190 } | 212 } |
191 | 213 |
192 EGLDisplay GLSurfaceEGL::GetDisplay() { | 214 EGLDisplay GLSurfaceEGL::GetDisplay() { |
193 return g_display; | 215 return g_display; |
194 } | 216 } |
195 | 217 |
196 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { | 218 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 } | 608 } |
587 | 609 |
588 return handle; | 610 return handle; |
589 #endif | 611 #endif |
590 } | 612 } |
591 | 613 |
592 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { | 614 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { |
593 Destroy(); | 615 Destroy(); |
594 } | 616 } |
595 | 617 |
618 SurfacelessEGL::SurfacelessEGL(const gfx::Size& size) | |
619 : size_(size) { | |
620 } | |
621 | |
622 bool SurfacelessEGL::Initialize() { | |
623 return true; | |
624 } | |
625 | |
626 void SurfacelessEGL::Destroy() { | |
627 } | |
628 | |
629 EGLConfig SurfacelessEGL::GetConfig() { | |
630 return g_config; | |
631 } | |
632 | |
633 bool SurfacelessEGL::IsOffscreen() { | |
634 return true; | |
635 } | |
636 | |
637 bool SurfacelessEGL::SwapBuffers() { | |
638 LOG(ERROR) << "Attempted to call SwapBuffers with SurfacelessEGL."; | |
639 return false; | |
640 } | |
641 | |
642 gfx::Size SurfacelessEGL::GetSize() { | |
643 return size_; | |
644 } | |
645 | |
646 bool SurfacelessEGL::Resize(const gfx::Size& size) { | |
647 size_ = size; | |
648 return true; | |
649 } | |
650 | |
651 EGLSurface SurfacelessEGL::GetHandle() { | |
652 return EGL_NO_SURFACE; | |
653 } | |
654 | |
655 void* SurfacelessEGL::GetShareHandle() { | |
656 return NULL; | |
657 } | |
658 | |
659 SurfacelessEGL::~SurfacelessEGL() { | |
660 } | |
661 | |
596 #if defined(ANDROID) || defined(USE_OZONE) | 662 #if defined(ANDROID) || defined(USE_OZONE) |
597 | 663 |
598 // A thin subclass of |GLSurfaceOSMesa| that can be used in place | 664 // A thin subclass of |GLSurfaceOSMesa| that can be used in place |
599 // of a native hardware-provided surface when a native surface | 665 // of a native hardware-provided surface when a native surface |
600 // provider is not available. | 666 // provider is not available. |
601 class GLSurfaceOSMesaHeadless : public GLSurfaceOSMesa { | 667 class GLSurfaceOSMesaHeadless : public GLSurfaceOSMesa { |
602 public: | 668 public: |
603 explicit GLSurfaceOSMesaHeadless(gfx::AcceleratedWidget window); | 669 explicit GLSurfaceOSMesaHeadless(gfx::AcceleratedWidget window); |
604 | 670 |
605 virtual bool IsOffscreen() OVERRIDE; | 671 virtual bool IsOffscreen() OVERRIDE; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) { | 740 GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) { |
675 switch (GetGLImplementation()) { | 741 switch (GetGLImplementation()) { |
676 case kGLImplementationOSMesaGL: { | 742 case kGLImplementationOSMesaGL: { |
677 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(1, size)); | 743 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(1, size)); |
678 if (!surface->Initialize()) | 744 if (!surface->Initialize()) |
679 return NULL; | 745 return NULL; |
680 | 746 |
681 return surface; | 747 return surface; |
682 } | 748 } |
683 case kGLImplementationEGLGLES2: { | 749 case kGLImplementationEGLGLES2: { |
684 scoped_refptr<PbufferGLSurfaceEGL> surface( | 750 scoped_refptr<GLSurface> surface; |
685 new PbufferGLSurfaceEGL(size)); | 751 if (g_egl_surfaceless_context_supported && |
752 (size.width() == 1 && size.height() == 1)) { | |
piman
2013/10/31 22:51:24
How about checking with 0,0 so that we don't regre
kalyank
2013/10/31 23:18:07
Ya, I am k with that. I see that GPUChannerManager
| |
753 surface = new SurfacelessEGL(size); | |
754 } else | |
755 surface = new PbufferGLSurfaceEGL(size); | |
756 | |
686 if (!surface->Initialize()) | 757 if (!surface->Initialize()) |
687 return NULL; | 758 return NULL; |
688 return surface; | 759 return surface; |
689 } | 760 } |
690 default: | 761 default: |
691 NOTREACHED(); | 762 NOTREACHED(); |
692 return NULL; | 763 return NULL; |
693 } | 764 } |
694 } | 765 } |
695 | 766 |
696 #endif | 767 #endif |
697 | 768 |
698 } // namespace gfx | 769 } // namespace gfx |
OLD | NEW |