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 "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" |
| 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 |
| 36 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 37 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 38 if (!surface->Initialize()) |
| 39 return NULL; |
| 40 return surface; |
| 41 } |
| 42 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 43 if (window != kNullAcceleratedWidget) { |
| 44 scoped_refptr<GLSurface> surface = new NativeViewGLSurfaceEGL(window); |
| 45 if (surface->Initialize()) |
| 46 return surface; |
| 47 } else { |
| 48 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| 49 if (surface->Initialize()) |
| 50 return surface; |
| 51 } |
| 52 return NULL; |
| 53 } |
| 54 |
| 55 // static |
| 56 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
| 57 const gfx::Size& size) { |
| 58 switch (GetGLImplementation()) { |
| 59 case kGLImplementationOSMesaGL: { |
| 60 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(1, size)); |
| 61 if (!surface->Initialize()) |
| 62 return NULL; |
| 63 |
| 64 return surface; |
| 65 } |
| 66 case kGLImplementationEGLGLES2: { |
| 67 scoped_refptr<GLSurface> surface; |
| 68 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
| 69 (size.width() == 0 && size.height() == 0)) { |
| 70 surface = new SurfacelessEGL(size); |
| 71 } else { |
| 72 surface = new PbufferGLSurfaceEGL(size); |
| 73 } |
| 74 |
| 75 if (!surface->Initialize()) |
| 76 return NULL; |
| 77 return surface; |
| 78 } |
| 79 default: |
| 80 NOTREACHED(); |
| 81 return NULL; |
| 82 } |
| 83 } |
| 84 |
| 85 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 86 return EGL_DEFAULT_DISPLAY; |
| 87 } |
| 88 |
| 89 } // namespace gfx |
OLD | NEW |