Index: ui/gl/init/gl_factory_ozone.cc |
diff --git a/ui/gl/init/gl_factory_ozone.cc b/ui/gl/init/gl_factory_ozone.cc |
index 097f249a6b8b8b9d18adb8a6b1fb2f428348ed63..9df9e01482231b4412da94ea47e720220663cb7b 100644 |
--- a/ui/gl/init/gl_factory_ozone.cc |
+++ b/ui/gl/init/gl_factory_ozone.cc |
@@ -24,48 +24,114 @@ |
namespace gl { |
namespace init { |
-scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, |
- GLSurface* compatible_surface, |
- GpuPreference gpu_preference) { |
- TRACE_EVENT0("gpu", "gl::init::CreateGLContext"); |
+namespace { |
+ |
+ui::SurfaceFactoryOzone* GetSurfaceFactory() { |
+ return ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone(); |
+} |
+ |
+bool HasDefaultImplementation(GLImplementation impl) { |
+ return impl == kGLImplementationOSMesaGL || impl == kGLImplementationMockGL; |
+} |
+ |
+scoped_refptr<GLSurface> CreateDefaultViewGLSurface( |
+ gfx::AcceleratedWidget window) { |
switch (GetGLImplementation()) { |
- case kGLImplementationMockGL: |
- return scoped_refptr<GLContext>(new GLContextStub(share_group)); |
case kGLImplementationOSMesaGL: |
- return InitializeGLContext(new GLContextOSMesa(share_group), |
- compatible_surface, gpu_preference); |
- case kGLImplementationEGLGLES2: |
- return InitializeGLContext(new GLContextEGL(share_group), |
- compatible_surface, gpu_preference); |
- |
+ return InitializeGLSurface(new GLSurfaceOSMesaHeadless()); |
+ case kGLImplementationMockGL: |
+ return InitializeGLSurface(new GLSurfaceStub()); |
default: |
NOTREACHED(); |
- return nullptr; |
} |
+ return nullptr; |
} |
-scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { |
- TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface"); |
+scoped_refptr<GLSurface> CreateDefaultOffscreenGLSurface( |
+ const gfx::Size& size) { |
switch (GetGLImplementation()) { |
case kGLImplementationOSMesaGL: |
- return InitializeGLSurface(new GLSurfaceOSMesaHeadless()); |
+ return InitializeGLSurface( |
+ new GLSurfaceOSMesa(GLSurface::SURFACE_OSMESA_BGRA, size)); |
+ case kGLImplementationMockGL: |
+ return InitializeGLSurface(new GLSurfaceStub); |
+ default: |
+ NOTREACHED(); |
+ } |
+ return nullptr; |
+} |
+ |
+// TODO(kylechar): Remove when all implementations are switched over. |
+scoped_refptr<GLSurface> CreateViewGLSurfaceOld(gfx::AcceleratedWidget window) { |
+ switch (GetGLImplementation()) { |
case kGLImplementationEGLGLES2: { |
DCHECK_NE(window, gfx::kNullAcceleratedWidget); |
scoped_refptr<GLSurface> surface; |
- if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) |
+ if (!surface && GLSurfaceEGL::IsEGLSurfacelessContextSupported()) |
surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); |
if (!surface) |
surface = CreateViewGLSurfaceOzone(window); |
return surface; |
} |
+ default: |
+ NOTREACHED(); |
+ return nullptr; |
+ } |
+} |
+ |
+// TODO(kylechar): Remove when all implementations are switched over. |
+scoped_refptr<GLSurface> CreateOffscreenGLSurfaceOld(const gfx::Size& size) { |
+ switch (GetGLImplementation()) { |
+ case kGLImplementationEGLGLES2: |
+ if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
+ (size.width() == 0 && size.height() == 0)) { |
+ return InitializeGLSurface(new SurfacelessEGL(size)); |
+ } else { |
+ return InitializeGLSurface(new PbufferGLSurfaceEGL(size)); |
+ } |
+ default: |
+ NOTREACHED(); |
+ } |
+ return nullptr; |
+} |
+ |
+} // namespace |
+ |
+scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, |
+ GLSurface* compatible_surface, |
+ GpuPreference gpu_preference) { |
+ TRACE_EVENT0("gpu", "gl::init::CreateGLContext"); |
+ switch (GetGLImplementation()) { |
case kGLImplementationMockGL: |
- return InitializeGLSurface(new GLSurfaceStub()); |
+ return scoped_refptr<GLContext>(new GLContextStub(share_group)); |
+ case kGLImplementationOSMesaGL: |
+ return InitializeGLContext(new GLContextOSMesa(share_group), |
+ compatible_surface, gpu_preference); |
+ case kGLImplementationEGLGLES2: |
+ return InitializeGLContext(new GLContextEGL(share_group), |
+ compatible_surface, gpu_preference); |
+ |
default: |
NOTREACHED(); |
return nullptr; |
} |
} |
+scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { |
+ TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface"); |
+ |
+ if (HasDefaultImplementation(GetGLImplementation())) |
+ return CreateDefaultViewGLSurface(window); |
+ |
+ // TODO(kylechar): This is deprecated, remove when possible. |
+ if (!GetSurfaceFactory()->UseNewSurfaceAPI()) |
+ return CreateViewGLSurfaceOld(window); |
+ |
+ return GetSurfaceFactory()->CreateViewGLSurface(GetGLImplementation(), |
+ window); |
+} |
+ |
+// TODO(kylechar): Update to use new API. |
scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( |
gfx::AcceleratedWidget window) { |
TRACE_EVENT0("gpu", "gl::init::CreateSurfacelessViewGLSurface"); |
@@ -79,23 +145,16 @@ scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( |
scoped_refptr<GLSurface> CreateOffscreenGLSurface(const gfx::Size& size) { |
TRACE_EVENT0("gpu", "gl::init::CreateOffscreenGLSurface"); |
- switch (GetGLImplementation()) { |
- case kGLImplementationOSMesaGL: |
- return InitializeGLSurface( |
- new GLSurfaceOSMesa(GLSurface::SURFACE_OSMESA_BGRA, size)); |
- case kGLImplementationEGLGLES2: |
- if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
- (size.width() == 0 && size.height() == 0)) { |
- return InitializeGLSurface(new SurfacelessEGL(size)); |
- } else { |
- return InitializeGLSurface(new PbufferGLSurfaceEGL(size)); |
- } |
- case kGLImplementationMockGL: |
- return new GLSurfaceStub; |
- default: |
- NOTREACHED(); |
- return nullptr; |
- } |
+ |
+ if (HasDefaultImplementation(GetGLImplementation())) |
+ return CreateDefaultOffscreenGLSurface(size); |
+ |
+ // TODO(kylechar): This is deprecated, remove when possible. |
+ if (!GetSurfaceFactory()->UseNewSurfaceAPI()) |
+ return CreateOffscreenGLSurfaceOld(size); |
+ |
+ return GetSurfaceFactory()->CreateOffscreenGLSurface(GetGLImplementation(), |
+ size); |
} |
} // namespace init |