Chromium Code Reviews| Index: ui/gl/gl_surface_ozone.cc |
| diff --git a/ui/gl/gl_surface_ozone.cc b/ui/gl/gl_surface_ozone.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a0233770e9073d67217e2d39f3633a7ed55baf8d |
| --- /dev/null |
| +++ b/ui/gl/gl_surface_ozone.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gl/gl_surface.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "ui/gfx/native_widget_types.h" |
| +#include "ui/gfx/ozone/surface_factory_ozone.h" |
| +#include "ui/gl/gl_implementation.h" |
| +#include "ui/gl/gl_surface_egl.h" |
| +#include "ui/gl/gl_surface_osmesa.h" |
| +#include "ui/gl/gl_surface_stub.h" |
| + |
| +namespace gfx { |
| + |
| +namespace { |
| + |
| +EGLNativeDisplayType GetEGLDisplay() { |
|
rjkroege
2014/03/24 15:27:25
per other comment: you've already done what I sugg
spang
2014/03/24 18:17:08
Move to GetPlatformDefaultEGLNativeDisplay().
|
| + return SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
| +} |
| +}; |
| + |
| +// static |
| +bool GLSurface::InitializeOneOffInternal() { |
| + switch (GetGLImplementation()) { |
| + case kGLImplementationEGLGLES2: |
| + if (!GLSurfaceEGL::InitializeOneOff(GetEGLDisplay())) { |
| + LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| + return false; |
| + } |
| + default: |
| + break; |
| + } |
| + return true; |
| +} |
| + |
| +// static |
| +scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| + gfx::AcceleratedWidget window) { |
| + if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| + scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| + if (!surface->Initialize()) |
| + return NULL; |
| + return surface; |
| + } |
| + DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| + if (window != kNullAcceleratedWidget) { |
| + EGLNativeWindowType egl_window = |
| + gfx::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget( |
| + window); |
| + scoped_ptr<VSyncProvider> sync_provider = |
| + gfx::SurfaceFactoryOzone::GetInstance()->CreateVSyncProvider( |
| + egl_window); |
| + scoped_refptr<NativeViewGLSurfaceEGL> surface = |
| + new NativeViewGLSurfaceEGL(egl_window); |
| + if (surface->Initialize(sync_provider.Pass())) |
| + return surface; |
| + } else { |
| + scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| + if (surface->Initialize()) |
| + return surface; |
| + } |
| + return NULL; |
| +} |
| + |
| +// static |
| +scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
| + const gfx::Size& size) { |
| + switch (GetGLImplementation()) { |
| + case kGLImplementationOSMesaGL: { |
| + scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(1, size)); |
| + if (!surface->Initialize()) |
| + return NULL; |
| + |
| + return surface; |
| + } |
| + case kGLImplementationEGLGLES2: { |
| + scoped_refptr<GLSurface> surface; |
| + if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
| + (size.width() == 0 && size.height() == 0)) { |
| + surface = new SurfacelessEGL(size); |
| + } else |
| + surface = new PbufferGLSurfaceEGL(size); |
| + |
| + if (!surface->Initialize()) |
| + return NULL; |
| + return surface; |
| + } |
| + default: |
| + NOTREACHED(); |
| + return NULL; |
| + } |
| +} |
| + |
| +} // namespace gfx |