[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 | |||||
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 16 | #if defined(USE_AURA) |
17 | #include "ui/gfx/gl/gl_surface_nsview.h" | ||||
18 | #endif | ||||
19 | |||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 20 | namespace gfx { |
21 | |||||
[email protected] | 0f5e888 | 2011-11-08 22:29:38 | [diff] [blame] | 22 | bool GLSurface::InitializeOneOffInternal() { |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 23 | switch (GetGLImplementation()) { |
24 | case kGLImplementationDesktopGL: | ||||
[email protected] | 020d047e | 2011-12-07 19:15:42 | [diff] [blame] | 25 | case kGLImplementationAppleGL: |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 26 | if (!GLSurfaceCGL::InitializeOneOff()) { |
27 | LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; | ||||
28 | return false; | ||||
29 | } | ||||
30 | break; | ||||
31 | default: | ||||
32 | break; | ||||
33 | } | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 34 | return true; |
35 | } | ||||
36 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 37 | scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 38 | bool software, |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 39 | gfx::PluginWindowHandle window) { |
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 40 | #if defined(USE_AURA) |
41 | if (software) | ||||
42 | return NULL; | ||||
43 | |||||
44 | switch (GetGLImplementation()) { | ||||
[email protected] | 020d047e | 2011-12-07 19:15:42 | [diff] [blame] | 45 | case kGLImplementationDesktopGL: |
46 | case kGLImplementationAppleGL: { | ||||
[email protected] | 2f47fc45 | 2011-11-21 03:12:17 | [diff] [blame] | 47 | scoped_refptr<GLSurface> surface(new GLSurfaceNSView(window)); |
48 | if (!surface->Initialize()) | ||||
49 | return NULL; | ||||
50 | |||||
51 | return surface; | ||||
52 | } | ||||
53 | case kGLImplementationMockGL: | ||||
54 | return new GLSurfaceStub; | ||||
55 | default: | ||||
56 | NOTREACHED(); | ||||
57 | return NULL; | ||||
58 | } | ||||
59 | #else | ||||
60 | return CreateOffscreenGLSurface(software, gfx::Size(1,1)); | ||||
61 | #endif | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 62 | } |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 63 | |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 64 | scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
[email protected] | f81f595 | 2011-07-21 18:52:47 | [diff] [blame] | 65 | bool software, |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 66 | const gfx::Size& size) { |
[email protected] | f81f595 | 2011-07-21 18:52:47 | [diff] [blame] | 67 | if (software) |
68 | return NULL; | ||||
69 | |||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 70 | switch (GetGLImplementation()) { |
71 | case kGLImplementationOSMesaGL: { | ||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 72 | scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA, |
73 | size)); | ||||
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 74 | if (!surface->Initialize()) |
75 | return NULL; | ||||
76 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 77 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 78 | } |
[email protected] | 020d047e | 2011-12-07 19:15:42 | [diff] [blame] | 79 | case kGLImplementationDesktopGL: |
80 | case kGLImplementationAppleGL: { | ||||
[email protected] | 51e6f6a7 | 2011-12-21 19:42:55 | [diff] [blame^] | 81 | scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size)); |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 82 | if (!surface->Initialize()) |
83 | return NULL; | ||||
84 | |||||
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 85 | return surface; |
[email protected] | ffae402 | 2011-05-12 22:54:29 | [diff] [blame] | 86 | } |
87 | case kGLImplementationMockGL: | ||||
88 | return new GLSurfaceStub; | ||||
89 | default: | ||||
90 | NOTREACHED(); | ||||
91 | return NULL; | ||||
92 | } | ||||
93 | } | ||||
94 | |||||
95 | } // namespace gfx |