| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gl/gl_surface.h" | 5 #include "ui/gl/gl_surface.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "third_party/khronos/EGL/egl.h" | 7 #include "third_party/khronos/EGL/egl.h" |
| 10 #include "ui/gfx/native_widget_types.h" | |
| 11 #include "ui/gl/gl_implementation.h" | |
| 12 #include "ui/gl/gl_surface_egl.h" | 8 #include "ui/gl/gl_surface_egl.h" |
| 13 #include "ui/gl/gl_surface_osmesa.h" | |
| 14 #include "ui/gl/gl_surface_stub.h" | |
| 15 | 9 |
| 16 namespace gl { | 10 namespace gl { |
| 17 | 11 |
| 18 // static | |
| 19 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | |
| 20 gfx::AcceleratedWidget window) { | |
| 21 CHECK_NE(kGLImplementationNone, GetGLImplementation()); | |
| 22 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | |
| 23 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | |
| 24 if (!surface->Initialize()) | |
| 25 return NULL; | |
| 26 return surface; | |
| 27 } | |
| 28 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | |
| 29 if (window != gfx::kNullAcceleratedWidget) { | |
| 30 scoped_refptr<GLSurface> surface = new NativeViewGLSurfaceEGL(window); | |
| 31 if (surface->Initialize()) | |
| 32 return surface; | |
| 33 } else { | |
| 34 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | |
| 35 if (surface->Initialize()) | |
| 36 return surface; | |
| 37 } | |
| 38 return NULL; | |
| 39 } | |
| 40 | |
| 41 // static | |
| 42 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | |
| 43 const gfx::Size& size) { | |
| 44 CHECK_NE(kGLImplementationNone, GetGLImplementation()); | |
| 45 switch (GetGLImplementation()) { | |
| 46 case kGLImplementationOSMesaGL: { | |
| 47 scoped_refptr<GLSurface> surface( | |
| 48 new GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, size)); | |
| 49 if (!surface->Initialize()) | |
| 50 return NULL; | |
| 51 | |
| 52 return surface; | |
| 53 } | |
| 54 case kGLImplementationEGLGLES2: { | |
| 55 scoped_refptr<GLSurface> surface; | |
| 56 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && | |
| 57 (size.width() == 0 && size.height() == 0)) { | |
| 58 surface = new SurfacelessEGL(size); | |
| 59 } else { | |
| 60 surface = new PbufferGLSurfaceEGL(size); | |
| 61 } | |
| 62 | |
| 63 if (!surface->Initialize()) | |
| 64 return NULL; | |
| 65 return surface; | |
| 66 } | |
| 67 case kGLImplementationMockGL: | |
| 68 return new GLSurfaceStub; | |
| 69 default: | |
| 70 NOTREACHED(); | |
| 71 return NULL; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 12 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 76 return EGL_DEFAULT_DISPLAY; | 13 return EGL_DEFAULT_DISPLAY; |
| 77 } | 14 } |
| 78 | 15 |
| 79 } // namespace gl | 16 } // namespace gl |
| OLD | NEW |