diff options
Diffstat (limited to 'ui/gl')
-rw-r--r-- | ui/gl/gl_surface_egl.cc | 75 | ||||
-rw-r--r-- | ui/gl/gl_surface_egl.h | 26 |
2 files changed, 99 insertions, 2 deletions
diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc index 7401fbb..7c31dd2 100644 --- a/ui/gl/gl_surface_egl.cc +++ b/ui/gl/gl_surface_egl.cc @@ -54,6 +54,7 @@ EGLNativeDisplayType g_native_display; const char* g_egl_extensions = NULL; bool g_egl_create_context_robustness_supported = false; bool g_egl_sync_control_supported = false; +bool g_egl_surfaceless_context_supported = false; class EGLSyncControlVSyncProvider : public gfx::SyncControlVSyncProvider { @@ -184,6 +185,27 @@ bool GLSurfaceEGL::InitializeOneOff() { g_egl_sync_control_supported = HasEGLExtension("EGL_CHROMIUM_sync_control"); + // Check if SurfacelessEGL is supported. + g_egl_surfaceless_context_supported = + HasEGLExtension("EGL_KHR_surfaceless_context"); + if (g_egl_surfaceless_context_supported) { + // EGL_KHR_surfaceless_context is supported but ensure + // GL_OES_surfaceless_context is also supported. We need a current context + // to query for supported GL extensions. + scoped_refptr<GLSurface> surface = new SurfacelessEGL(Size(1, 1)); + scoped_refptr<GLContext> context = GLContext::CreateGLContext( + NULL, surface.get(), PreferIntegratedGpu); + if (!context->MakeCurrent(surface.get())) + g_egl_surfaceless_context_supported = false; + + // Ensure context supports GL_OES_surfaceless_context. + if (g_egl_surfaceless_context_supported) { + g_egl_surfaceless_context_supported = context->HasExtension( + "GL_OES_surfaceless_context"); + context->ReleaseCurrent(surface.get()); + } + } + initialized = true; return true; @@ -593,6 +615,50 @@ PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { Destroy(); } +SurfacelessEGL::SurfacelessEGL(const gfx::Size& size) + : size_(size) { +} + +bool SurfacelessEGL::Initialize() { + return true; +} + +void SurfacelessEGL::Destroy() { +} + +EGLConfig SurfacelessEGL::GetConfig() { + return g_config; +} + +bool SurfacelessEGL::IsOffscreen() { + return true; +} + +bool SurfacelessEGL::SwapBuffers() { + LOG(ERROR) << "Attempted to call SwapBuffers with SurfacelessEGL."; + return false; +} + +gfx::Size SurfacelessEGL::GetSize() { + return size_; +} + +bool SurfacelessEGL::Resize(const gfx::Size& size) { + size_ = size; + return true; +} + +EGLSurface SurfacelessEGL::GetHandle() { + return EGL_NO_SURFACE; +} + +void* SurfacelessEGL::GetShareHandle() { + return NULL; +} + +SurfacelessEGL::~SurfacelessEGL() { +} + #if defined(ANDROID) || defined(USE_OZONE) // A thin subclass of |GLSurfaceOSMesa| that can be used in place @@ -681,8 +747,13 @@ GLSurface::CreateOffscreenGLSurface(const gfx::Size& size) { return surface; } case kGLImplementationEGLGLES2: { - scoped_refptr<PbufferGLSurfaceEGL> surface( - new PbufferGLSurfaceEGL(size)); + scoped_refptr<GLSurface> surface; + if (g_egl_surfaceless_context_supported && + (size.width() == 0 && size.height() == 0)) { + surface = new SurfacelessEGL(size); + } else + surface = new PbufferGLSurfaceEGL(size); + if (!surface->Initialize()) return NULL; return surface; diff --git a/ui/gl/gl_surface_egl.h b/ui/gl/gl_surface_egl.h index 68a99af..6cdaf5d 100644 --- a/ui/gl/gl_surface_egl.h +++ b/ui/gl/gl_surface_egl.h @@ -111,6 +111,32 @@ class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL { DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL); }; +// SurfacelessEGL is used as Offscreen surface when platform supports +// KHR_surfaceless_context and GL_OES_surfaceless_context. This would avoid the +// need to create a dummy EGLsurface in case we render to client API targets. +class GL_EXPORT SurfacelessEGL : public GLSurfaceEGL { + public: + explicit SurfacelessEGL(const gfx::Size& size); + + // Implement GLSurface. + virtual EGLConfig GetConfig() OVERRIDE; + virtual bool Initialize() OVERRIDE; + virtual void Destroy() OVERRIDE; + virtual bool IsOffscreen() OVERRIDE; + virtual bool SwapBuffers() OVERRIDE; + virtual gfx::Size GetSize() OVERRIDE; + virtual bool Resize(const gfx::Size& size) OVERRIDE; + virtual EGLSurface GetHandle() OVERRIDE; + virtual void* GetShareHandle() OVERRIDE; + + protected: + virtual ~SurfacelessEGL(); + + private: + gfx::Size size_; + DISALLOW_COPY_AND_ASSIGN(SurfacelessEGL); +}; + } // namespace gfx #endif // UI_GL_GL_SURFACE_EGL_H_ |