[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 | |||||
18 | bool GLSurface::InitializeOneOff() { | ||||
19 | static bool initialized = false; | ||||
20 | if (initialized) | ||||
21 | return true; | ||||
22 | |||||
23 | static const GLImplementation kAllowedGLImplementations[] = { | ||||
24 | kGLImplementationDesktopGL, | ||||
25 | kGLImplementationOSMesaGL | ||||
26 | }; | ||||
27 | |||||
28 | if (!InitializeRequestedGLBindings( | ||||
29 | kAllowedGLImplementations, | ||||
30 | kAllowedGLImplementations + arraysize(kAllowedGLImplementations), | ||||
31 | kGLImplementationDesktopGL)) { | ||||
32 | LOG(ERROR) << "InitializeRequestedGLBindings failed."; | ||||
33 | return false; | ||||
34 | } | ||||
35 | |||||
36 | switch (GetGLImplementation()) { | ||||
37 | case kGLImplementationDesktopGL: | ||||
38 | if (!GLSurfaceCGL::InitializeOneOff()) { | ||||
39 | LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; | ||||
40 | return false; | ||||
41 | } | ||||
42 | break; | ||||
43 | default: | ||||
44 | break; | ||||
45 | } | ||||
46 | |||||
47 | initialized = true; | ||||
48 | return true; | ||||
49 | } | ||||
50 | |||||
51 | // TODO(apatrick): support ViewGLSurface on mac. | ||||
52 | #if 0 | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 53 | scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
54 | gfx::PluginWindowHandle window) { | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 55 | switch (GetGLImplementation()) { |
56 | case kGLImplementationOSMesaGL: { | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 57 | scoped_refptr<GLSurface> surface( |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 58 | new NativeViewGLSurfaceOSMesa(window)); |
59 | if (!surface->Initialize()) | ||||
60 | return NULL; | ||||
61 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 62 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 63 | } |
64 | case kGLImplementationDesktopGL: { | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 65 | scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceCGL( |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 66 | window)); |
67 | if (!surface->Initialize()) | ||||
68 | return NULL; | ||||
69 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 70 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 71 | } |
72 | case kGLImplementationMockGL: | ||||
73 | return new GLSurfaceStub; | ||||
74 | default: | ||||
75 | NOTREACHED(); | ||||
76 | return NULL; | ||||
77 | } | ||||
78 | } | ||||
79 | #endif | ||||
80 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 81 | scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
82 | const gfx::Size& size) { | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 83 | switch (GetGLImplementation()) { |
84 | case kGLImplementationOSMesaGL: { | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 85 | scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA, |
86 | size)); | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 87 | if (!surface->Initialize()) |
88 | return NULL; | ||||
89 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 90 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 91 | } |
92 | case kGLImplementationDesktopGL: { | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 93 | scoped_refptr<GLSurface> surface(new PbufferGLSurfaceCGL(size)); |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 94 | if (!surface->Initialize()) |
95 | return NULL; | ||||
96 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame^] | 97 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 98 | } |
99 | case kGLImplementationMockGL: | ||||
100 | return new GLSurfaceStub; | ||||
101 | default: | ||||
102 | NOTREACHED(); | ||||
103 | return NULL; | ||||
104 | } | ||||
105 | } | ||||
106 | |||||
107 | } // namespace gfx |