OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gl/gl_surface.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "ui/gfx/native_widget_types.h" |
| 10 #include "ui/gfx/ozone/surface_factory_ozone.h" |
| 11 #include "ui/gl/gl_implementation.h" |
| 12 #include "ui/gl/gl_surface_egl.h" |
| 13 #include "ui/gl/gl_surface_osmesa.h" |
| 14 #include "ui/gl/gl_surface_stub.h" |
| 15 |
| 16 namespace gfx { |
| 17 |
| 18 // static |
| 19 bool GLSurface::InitializeOneOffInternal() { |
| 20 switch (GetGLImplementation()) { |
| 21 case kGLImplementationEGLGLES2: |
| 22 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 23 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 24 return false; |
| 25 } |
| 26 default: |
| 27 break; |
| 28 } |
| 29 return true; |
| 30 } |
| 31 |
| 32 // static |
| 33 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 34 gfx::AcceleratedWidget window) { |
| 35 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 36 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 37 if (!surface->Initialize()) |
| 38 return NULL; |
| 39 return surface; |
| 40 } |
| 41 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 42 if (window != kNullAcceleratedWidget) { |
| 43 EGLNativeWindowType egl_window = |
| 44 gfx::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget( |
| 45 window); |
| 46 scoped_ptr<VSyncProvider> sync_provider = |
| 47 gfx::SurfaceFactoryOzone::GetInstance()->CreateVSyncProvider( |
| 48 egl_window); |
| 49 scoped_refptr<NativeViewGLSurfaceEGL> surface = |
| 50 new NativeViewGLSurfaceEGL(egl_window); |
| 51 if (surface->Initialize(sync_provider.Pass())) |
| 52 return surface; |
| 53 } else { |
| 54 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| 55 if (surface->Initialize()) |
| 56 return surface; |
| 57 } |
| 58 return NULL; |
| 59 } |
| 60 |
| 61 // static |
| 62 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
| 63 const gfx::Size& size) { |
| 64 switch (GetGLImplementation()) { |
| 65 case kGLImplementationOSMesaGL: { |
| 66 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(1, size)); |
| 67 if (!surface->Initialize()) |
| 68 return NULL; |
| 69 |
| 70 return surface; |
| 71 } |
| 72 case kGLImplementationEGLGLES2: { |
| 73 scoped_refptr<GLSurface> surface; |
| 74 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
| 75 (size.width() == 0 && size.height() == 0)) { |
| 76 surface = new SurfacelessEGL(size); |
| 77 } else |
| 78 surface = new PbufferGLSurfaceEGL(size); |
| 79 |
| 80 if (!surface->Initialize()) |
| 81 return NULL; |
| 82 return surface; |
| 83 } |
| 84 default: |
| 85 NOTREACHED(); |
| 86 return NULL; |
| 87 } |
| 88 } |
| 89 |
| 90 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 91 return SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
| 92 } |
| 93 |
| 94 } // namespace gfx |
OLD | NEW |