Index: ui/gl/gl_surface_egl.cc |
diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc |
index 7401fbb320745808b18ebf6da531782b2422e1b3..7c31dd22d443503241056671bb0ab216d3b3cad0 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; |