OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "third_party/mesa/src/include/GL/osmesa.h" | 10 #include "base/message_loop.h" |
11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
13 #include "ui/gl/gl_surface_cgl.h" | 13 #include "ui/gl/gl_surface_egl.h" |
14 #include "ui/gl/gl_surface_osmesa.h" | |
15 #include "ui/gl/gl_surface_stub.h" | 14 #include "ui/gl/gl_surface_stub.h" |
16 | 15 |
17 #if defined(USE_AURA) | |
18 #include "ui/gl/gl_surface_nsview.h" | |
19 #endif | |
20 | |
21 namespace gfx { | 16 namespace gfx { |
22 | 17 |
23 bool GLSurface::InitializeOneOffInternal() { | 18 bool GLSurface::InitializeOneOffInternal() { |
24 switch (GetGLImplementation()) { | 19 switch (GetGLImplementation()) { |
25 case kGLImplementationDesktopGL: | 20 case kGLImplementationEGLGLES2: |
26 case kGLImplementationAppleGL: | 21 if (!GLSurfaceEGL::InitializeOneOff()) { |
27 if (!GLSurfaceCGL::InitializeOneOff()) { | 22 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
28 LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; | |
29 return false; | 23 return false; |
30 } | 24 } |
31 break; | 25 break; |
32 default: | 26 default: |
33 break; | 27 break; |
34 } | 28 } |
| 29 |
35 return true; | 30 return true; |
36 } | 31 } |
37 | 32 |
38 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 33 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
39 bool software, | 34 bool software, |
40 gfx::AcceleratedWidget window) { | 35 gfx::AcceleratedWidget window) { |
41 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); | 36 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); |
42 #if defined(USE_AURA) | |
43 if (software) | 37 if (software) |
44 return NULL; | 38 return NULL; |
45 | 39 |
46 switch (GetGLImplementation()) { | 40 switch (GetGLImplementation()) { |
47 case kGLImplementationDesktopGL: | 41 case kGLImplementationEGLGLES2: { |
48 case kGLImplementationAppleGL: { | 42 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGL( |
49 scoped_refptr<GLSurface> surface(new GLSurfaceNSView(window)); | 43 false, window)); |
50 if (!surface->Initialize()) | 44 if (!surface->Initialize()) |
51 return NULL; | 45 return NULL; |
52 | 46 |
53 return surface; | 47 return surface; |
54 } | 48 } |
55 case kGLImplementationMockGL: | 49 case kGLImplementationMockGL: |
56 return new GLSurfaceStub; | 50 return new GLSurfaceStub; |
57 default: | 51 default: |
58 NOTREACHED(); | 52 NOTREACHED(); |
59 return NULL; | 53 return NULL; |
60 } | 54 } |
61 #else | |
62 return CreateOffscreenGLSurface(software, gfx::Size(1,1)); | |
63 #endif | |
64 } | 55 } |
65 | 56 |
66 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | 57 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
67 bool software, | 58 bool software, |
68 const gfx::Size& size) { | 59 const gfx::Size& size) { |
69 TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface"); | 60 TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface"); |
70 if (software) | 61 if (software) |
71 return NULL; | 62 return NULL; |
72 | 63 |
73 switch (GetGLImplementation()) { | 64 switch (GetGLImplementation()) { |
74 case kGLImplementationOSMesaGL: { | 65 case kGLImplementationEGLGLES2: { |
75 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA, | 66 scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(false, size)); |
76 size)); | |
77 if (!surface->Initialize()) | 67 if (!surface->Initialize()) |
78 return NULL; | 68 return NULL; |
79 | 69 |
80 return surface; | |
81 } | |
82 case kGLImplementationDesktopGL: | |
83 case kGLImplementationAppleGL: { | |
84 scoped_refptr<GLSurface> surface(new NoOpGLSurfaceCGL(size)); | |
85 if (!surface->Initialize()) | |
86 return NULL; | |
87 | |
88 return surface; | 70 return surface; |
89 } | 71 } |
90 case kGLImplementationMockGL: | 72 case kGLImplementationMockGL: |
91 return new GLSurfaceStub; | 73 return new GLSurfaceStub; |
92 default: | 74 default: |
93 NOTREACHED(); | 75 NOTREACHED(); |
94 return NULL; | 76 return NULL; |
95 } | 77 } |
96 } | 78 } |
97 | 79 |
98 } // namespace gfx | 80 } // namespace gfx |
OLD | NEW |