OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/init/gl_factory.h" | 5 #include "ui/gl/init/gl_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" |
8 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "ui/gl/gl_bindings.h" |
9 #include "ui/gl/gl_context_cgl.h" | 11 #include "ui/gl/gl_context_cgl.h" |
10 #include "ui/gl/gl_context_osmesa.h" | 12 #include "ui/gl/gl_context_osmesa.h" |
11 #include "ui/gl/gl_context_stub.h" | 13 #include "ui/gl/gl_context_stub.h" |
12 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
13 #include "ui/gl/gl_share_group.h" | 15 #include "ui/gl/gl_share_group.h" |
14 #include "ui/gl/gl_surface.h" | 16 #include "ui/gl/gl_surface.h" |
| 17 #include "ui/gl/gl_surface_osmesa.h" |
| 18 #include "ui/gl/gl_surface_stub.h" |
15 | 19 |
16 namespace gl { | 20 namespace gl { |
17 namespace init { | 21 namespace init { |
18 | 22 |
| 23 namespace { |
| 24 |
| 25 // A "no-op" surface. It is not required that a CGLContextObj have an |
| 26 // associated drawable (pbuffer or fullscreen context) in order to be |
| 27 // made current. Everywhere this surface type is used, we allocate an |
| 28 // FBO at the user level as the drawable of the associated context. |
| 29 class NoOpGLSurface : public GLSurface { |
| 30 public: |
| 31 explicit NoOpGLSurface(const gfx::Size& size) : size_(size) {} |
| 32 |
| 33 // Implement GLSurface. |
| 34 bool Initialize(GLSurface::Format format) override { return true; } |
| 35 void Destroy() override {} |
| 36 bool IsOffscreen() override { return true; } |
| 37 gfx::SwapResult SwapBuffers() override { |
| 38 NOTREACHED() << "Cannot call SwapBuffers on a NoOpGLSurface."; |
| 39 return gfx::SwapResult::SWAP_FAILED; |
| 40 } |
| 41 gfx::Size GetSize() override { return size_; } |
| 42 void* GetHandle() override { return nullptr; } |
| 43 void* GetDisplay() override { return nullptr; } |
| 44 bool IsSurfaceless() const override { return true; } |
| 45 |
| 46 protected: |
| 47 ~NoOpGLSurface() override {} |
| 48 |
| 49 private: |
| 50 gfx::Size size_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(NoOpGLSurface); |
| 53 }; |
| 54 |
| 55 } // namespace |
| 56 |
19 scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, | 57 scoped_refptr<GLContext> CreateGLContext(GLShareGroup* share_group, |
20 GLSurface* compatible_surface, | 58 GLSurface* compatible_surface, |
21 GpuPreference gpu_preference) { | 59 GpuPreference gpu_preference) { |
22 TRACE_EVENT0("gpu", "gl::init::CreateGLContext"); | 60 TRACE_EVENT0("gpu", "gl::init::CreateGLContext"); |
23 switch (GetGLImplementation()) { | 61 switch (GetGLImplementation()) { |
24 case kGLImplementationDesktopGL: | 62 case kGLImplementationDesktopGL: |
25 case kGLImplementationDesktopGLCoreProfile: | 63 case kGLImplementationDesktopGLCoreProfile: |
26 case kGLImplementationAppleGL: | 64 case kGLImplementationAppleGL: |
27 // Note that with virtualization we might still be able to make current | 65 // Note that with virtualization we might still be able to make current |
28 // a different onscreen surface with this context later. But we should | 66 // a different onscreen surface with this context later. But we should |
29 // always be creating the context with an offscreen surface first. | 67 // always be creating the context with an offscreen surface first. |
30 DCHECK(compatible_surface->IsOffscreen()); | 68 DCHECK(compatible_surface->IsOffscreen()); |
31 return InitializeGLContext(new GLContextCGL(share_group), | 69 return InitializeGLContext(new GLContextCGL(share_group), |
32 compatible_surface, gpu_preference); | 70 compatible_surface, gpu_preference); |
33 case kGLImplementationOSMesaGL: | 71 case kGLImplementationOSMesaGL: |
34 return InitializeGLContext(new GLContextOSMesa(share_group), | 72 return InitializeGLContext(new GLContextOSMesa(share_group), |
35 compatible_surface, gpu_preference); | 73 compatible_surface, gpu_preference); |
36 case kGLImplementationMockGL: | 74 case kGLImplementationMockGL: |
37 return new GLContextStub(share_group); | 75 return new GLContextStub(share_group); |
38 default: | 76 default: |
39 NOTREACHED(); | 77 NOTREACHED(); |
40 return nullptr; | 78 return nullptr; |
41 } | 79 } |
42 } | 80 } |
43 | 81 |
| 82 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { |
| 83 TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface"); |
| 84 switch (GetGLImplementation()) { |
| 85 case kGLImplementationDesktopGL: |
| 86 case kGLImplementationDesktopGLCoreProfile: |
| 87 case kGLImplementationAppleGL: { |
| 88 NOTIMPLEMENTED() << "No onscreen support on Mac."; |
| 89 return nullptr; |
| 90 } |
| 91 case kGLImplementationOSMesaGL: { |
| 92 return InitializeGLSurface(new GLSurfaceOSMesaHeadless()); |
| 93 } |
| 94 case kGLImplementationMockGL: |
| 95 return new GLSurfaceStub; |
| 96 default: |
| 97 NOTREACHED(); |
| 98 return nullptr; |
| 99 } |
| 100 } |
| 101 |
| 102 scoped_refptr<GLSurface> CreateOffscreenGLSurface(const gfx::Size& size) { |
| 103 TRACE_EVENT0("gpu", "gl::init::CreateOffscreenGLSurface"); |
| 104 switch (GetGLImplementation()) { |
| 105 case kGLImplementationOSMesaGL: |
| 106 return InitializeGLSurface( |
| 107 new GLSurfaceOSMesa(GLSurface::SURFACE_OSMESA_RGBA, size)); |
| 108 case kGLImplementationDesktopGL: |
| 109 case kGLImplementationDesktopGLCoreProfile: |
| 110 case kGLImplementationAppleGL: |
| 111 return InitializeGLSurface(new NoOpGLSurface(size)); |
| 112 case kGLImplementationMockGL: |
| 113 return new GLSurfaceStub; |
| 114 default: |
| 115 NOTREACHED(); |
| 116 return nullptr; |
| 117 } |
| 118 } |
| 119 |
44 } // namespace init | 120 } // namespace init |
45 } // namespace gl | 121 } // namespace gl |
OLD | NEW |