[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 1 | // Copyright (c) 2011 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/gfx/gl/gl_surface.h" | ||||
6 | |||||
7 | #include "base/logging.h" | ||||
8 | #include "base/memory/scoped_ptr.h" | ||||
9 | #include "third_party/mesa/MesaLib/include/GL/osmesa.h" | ||||
10 | #include "ui/gfx/gl/gl_bindings.h" | ||||
11 | #include "ui/gfx/gl/gl_implementation.h" | ||||
12 | #include "ui/gfx/gl/gl_surface_cgl.h" | ||||
13 | #include "ui/gfx/gl/gl_surface_osmesa.h" | ||||
14 | #include "ui/gfx/gl/gl_surface_stub.h" | ||||
15 | |||||
16 | namespace gfx { | ||||
17 | |||||
[email protected] | 0f5e888 | 2011-11-08 22:29:38 | [diff] [blame^] | 18 | bool GLSurface::InitializeOneOffInternal() { |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 19 | switch (GetGLImplementation()) { |
20 | case kGLImplementationDesktopGL: | ||||
21 | if (!GLSurfaceCGL::InitializeOneOff()) { | ||||
22 | LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; | ||||
23 | return false; | ||||
24 | } | ||||
25 | break; | ||||
26 | default: | ||||
27 | break; | ||||
28 | } | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 29 | return true; |
30 | } | ||||
31 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 32 | scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 33 | bool software, |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 34 | gfx::PluginWindowHandle window) { |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 35 | return CreateOffscreenGLSurface(software, gfx::Size(1, 1)); |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 36 | } |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 37 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 38 | scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
[email protected] | f81f595 | 2011-07-21 18:52:47 | [diff] [blame] | 39 | bool software, |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 40 | const gfx::Size& size) { |
[email protected] | f81f595 | 2011-07-21 18:52:47 | [diff] [blame] | 41 | if (software) |
42 | return NULL; | ||||
43 | |||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 44 | switch (GetGLImplementation()) { |
45 | case kGLImplementationOSMesaGL: { | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 46 | scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA, |
47 | size)); | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 48 | if (!surface->Initialize()) |
49 | return NULL; | ||||
50 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 51 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 52 | } |
53 | case kGLImplementationDesktopGL: { | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 54 | scoped_refptr<GLSurface> surface(new PbufferGLSurfaceCGL(size)); |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 55 | if (!surface->Initialize()) |
56 | return NULL; | ||||
57 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 58 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 59 | } |
60 | case kGLImplementationMockGL: | ||||
61 | return new GLSurfaceStub; | ||||
62 | default: | ||||
63 | NOTREACHED(); | ||||
64 | return NULL; | ||||
65 | } | ||||
66 | } | ||||
67 | |||||
68 | } // namespace gfx |