| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | |
| 8 | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/trace_event/trace_event.h" | |
| 14 #include "ui/gfx/native_widget_types.h" | 7 #include "ui/gfx/native_widget_types.h" |
| 15 #include "ui/gl/gl_bindings.h" | 8 #include "ui/gfx/x/x11_types.h" |
| 16 #include "ui/gl/gl_implementation.h" | |
| 17 #include "ui/gl/gl_surface_egl.h" | 9 #include "ui/gl/gl_surface_egl.h" |
| 18 #include "ui/gl/gl_surface_egl_x11.h" | |
| 19 #include "ui/gl/gl_surface_glx.h" | |
| 20 #include "ui/gl/gl_surface_osmesa_x11.h" | |
| 21 #include "ui/gl/gl_surface_stub.h" | |
| 22 | 10 |
| 23 namespace gl { | 11 namespace gl { |
| 24 | 12 |
| 25 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | |
| 26 gfx::AcceleratedWidget window) { | |
| 27 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); | |
| 28 switch (GetGLImplementation()) { | |
| 29 case kGLImplementationOSMesaGL: { | |
| 30 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaX11(window)); | |
| 31 if (!surface->Initialize()) | |
| 32 return NULL; | |
| 33 | |
| 34 return surface; | |
| 35 } | |
| 36 case kGLImplementationDesktopGL: { | |
| 37 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLX(window)); | |
| 38 if (!surface->Initialize()) | |
| 39 return NULL; | |
| 40 | |
| 41 return surface; | |
| 42 } | |
| 43 case kGLImplementationEGLGLES2: { | |
| 44 DCHECK(window != gfx::kNullAcceleratedWidget); | |
| 45 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGLX11(window)); | |
| 46 if (!surface->Initialize()) | |
| 47 return NULL; | |
| 48 | |
| 49 return surface; | |
| 50 } | |
| 51 case kGLImplementationMockGL: | |
| 52 return new GLSurfaceStub; | |
| 53 default: | |
| 54 NOTREACHED(); | |
| 55 return NULL; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | |
| 60 const gfx::Size& size) { | |
| 61 TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface"); | |
| 62 switch (GetGLImplementation()) { | |
| 63 case kGLImplementationOSMesaGL: { | |
| 64 scoped_refptr<GLSurface> surface( | |
| 65 new GLSurfaceOSMesa(SURFACE_OSMESA_RGBA, size)); | |
| 66 if (!surface->Initialize()) | |
| 67 return NULL; | |
| 68 | |
| 69 return surface; | |
| 70 } | |
| 71 case kGLImplementationDesktopGL: { | |
| 72 scoped_refptr<GLSurface> surface( | |
| 73 new UnmappedNativeViewGLSurfaceGLX(size)); | |
| 74 if (!surface->Initialize()) | |
| 75 return NULL; | |
| 76 | |
| 77 return surface; | |
| 78 } | |
| 79 case kGLImplementationEGLGLES2: { | |
| 80 scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(size)); | |
| 81 if (!surface->Initialize()) | |
| 82 return NULL; | |
| 83 | |
| 84 return surface; | |
| 85 } | |
| 86 case kGLImplementationMockGL: | |
| 87 return new GLSurfaceStub; | |
| 88 default: | |
| 89 NOTREACHED(); | |
| 90 return NULL; | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 13 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 95 return gfx::GetXDisplay(); | 14 return gfx::GetXDisplay(); |
| 96 } | 15 } |
| 97 | 16 |
| 98 } // namespace gl | 17 } // namespace gl |
| OLD | NEW |