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/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "ui/gl/gl_context.h" | 9 #include "ui/gl/gl_context.h" |
10 #include "ui/gl/gl_context_osmesa.h" | |
11 #include "ui/gl/gl_context_stub.h" | 10 #include "ui/gl/gl_context_stub.h" |
12 #include "ui/gl/gl_implementation.h" | 11 #include "ui/gl/gl_implementation.h" |
13 #include "ui/gl/gl_share_group.h" | 12 #include "ui/gl/gl_share_group.h" |
14 #include "ui/gl/gl_surface.h" | 13 #include "ui/gl/gl_surface.h" |
15 #include "ui/gl/gl_surface_osmesa.h" | |
16 #include "ui/gl/gl_surface_stub.h" | 14 #include "ui/gl/gl_surface_stub.h" |
17 #include "ui/gl/init/ozone_util.h" | 15 #include "ui/gl/init/ozone_util.h" |
18 | 16 |
19 namespace gl { | 17 namespace gl { |
20 namespace init { | 18 namespace init { |
21 | 19 |
22 namespace { | |
23 | |
24 bool HasDefaultImplementation(GLImplementation impl) { | |
25 return impl == kGLImplementationOSMesaGL || impl == kGLImplementationMockGL || | |
26 impl == kGLImplementationStubGL; | |
27 } | |
28 | |
29 scoped_refptr<GLSurface> CreateDefaultViewGLSurface( | |
30 gfx::AcceleratedWidget window) { | |
31 switch (GetGLImplementation()) { | |
32 case kGLImplementationOSMesaGL: | |
33 return InitializeGLSurface(new GLSurfaceOSMesaHeadless()); | |
34 case kGLImplementationMockGL: | |
35 case kGLImplementationStubGL: | |
36 return InitializeGLSurface(new GLSurfaceStub()); | |
37 default: | |
38 NOTREACHED(); | |
39 } | |
40 return nullptr; | |
41 } | |
42 | |
43 scoped_refptr<GLSurface> CreateDefaultOffscreenGLSurface( | |
44 const gfx::Size& size) { | |
45 switch (GetGLImplementation()) { | |
46 case kGLImplementationOSMesaGL: | |
47 return InitializeGLSurface( | |
48 new GLSurfaceOSMesa( | |
49 GLSurfaceFormat(GLSurfaceFormat::PIXEL_LAYOUT_BGRA), size)); | |
50 case kGLImplementationMockGL: | |
51 case kGLImplementationStubGL: | |
52 return InitializeGLSurface(new GLSurfaceStub); | |
53 default: | |
54 NOTREACHED(); | |
55 } | |
56 return nullptr; | |
57 } | |
58 | |
59 } // namespace | |
60 | |
61 std::vector<GLImplementation> GetAllowedGLImplementations() { | 20 std::vector<GLImplementation> GetAllowedGLImplementations() { |
62 ui::OzonePlatform::InitializeForGPU(); | 21 ui::OzonePlatform::InitializeForGPU(); |
63 return GetSurfaceFactoryOzone()->GetAllowedGLImplementations(); | 22 return GetSurfaceFactoryOzone()->GetAllowedGLImplementations(); |
64 } | 23 } |
65 | 24 |
66 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 25 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
67 if (HasGLOzone()) | 26 if (HasGLOzone()) |
68 return GetGLOzone()->GetGLWindowSystemBindingInfo(info); | 27 return GetGLOzone()->GetGLWindowSystemBindingInfo(info); |
69 | 28 |
70 return false; | 29 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
82 | 41 |
83 switch (GetGLImplementation()) { | 42 switch (GetGLImplementation()) { |
84 case kGLImplementationMockGL: | 43 case kGLImplementationMockGL: |
85 return scoped_refptr<GLContext>(new GLContextStub(share_group)); | 44 return scoped_refptr<GLContext>(new GLContextStub(share_group)); |
86 case kGLImplementationStubGL: { | 45 case kGLImplementationStubGL: { |
87 scoped_refptr<GLContextStub> stub_context = | 46 scoped_refptr<GLContextStub> stub_context = |
88 new GLContextStub(share_group); | 47 new GLContextStub(share_group); |
89 stub_context->SetUseStubApi(true); | 48 stub_context->SetUseStubApi(true); |
90 return stub_context; | 49 return stub_context; |
91 } | 50 } |
92 case kGLImplementationOSMesaGL: | |
93 return InitializeGLContext(new GLContextOSMesa(share_group), | |
94 compatible_surface, attribs); | |
95 default: | 51 default: |
96 NOTREACHED(); | 52 NOTREACHED(); |
97 } | 53 } |
98 return nullptr; | 54 return nullptr; |
99 } | 55 } |
100 | 56 |
101 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { | 57 scoped_refptr<GLSurface> CreateViewGLSurface(gfx::AcceleratedWidget window) { |
102 TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface"); | 58 TRACE_EVENT0("gpu", "gl::init::CreateViewGLSurface"); |
103 | 59 |
104 if (HasGLOzone()) | 60 if (HasGLOzone()) |
105 return GetGLOzone()->CreateViewGLSurface(window); | 61 return GetGLOzone()->CreateViewGLSurface(window); |
106 | 62 |
107 if (HasDefaultImplementation(GetGLImplementation())) | 63 switch (GetGLImplementation()) { |
108 return CreateDefaultViewGLSurface(window); | 64 case kGLImplementationMockGL: |
| 65 case kGLImplementationStubGL: |
| 66 return InitializeGLSurface(new GLSurfaceStub()); |
| 67 default: |
| 68 NOTREACHED(); |
| 69 } |
109 | 70 |
110 return nullptr; | 71 return nullptr; |
111 } | 72 } |
112 | 73 |
113 scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( | 74 scoped_refptr<GLSurface> CreateSurfacelessViewGLSurface( |
114 gfx::AcceleratedWidget window) { | 75 gfx::AcceleratedWidget window) { |
115 TRACE_EVENT0("gpu", "gl::init::CreateSurfacelessViewGLSurface"); | 76 TRACE_EVENT0("gpu", "gl::init::CreateSurfacelessViewGLSurface"); |
116 | 77 |
117 if (HasGLOzone()) | 78 if (HasGLOzone()) |
118 return GetGLOzone()->CreateSurfacelessViewGLSurface(window); | 79 return GetGLOzone()->CreateSurfacelessViewGLSurface(window); |
119 | 80 |
120 return nullptr; | 81 return nullptr; |
121 } | 82 } |
122 | 83 |
123 scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat( | 84 scoped_refptr<GLSurface> CreateOffscreenGLSurfaceWithFormat( |
124 const gfx::Size& size, GLSurfaceFormat format) { | 85 const gfx::Size& size, GLSurfaceFormat format) { |
125 TRACE_EVENT0("gpu", "gl::init::CreateOffscreenGLSurface"); | 86 TRACE_EVENT0("gpu", "gl::init::CreateOffscreenGLSurface"); |
126 | 87 |
127 if (!format.IsDefault()) { | 88 if (!format.IsDefault()) { |
128 NOTREACHED() << "FATAL: Ozone only supports default-format surfaces."; | 89 NOTREACHED() << "FATAL: Ozone only supports default-format surfaces."; |
129 return nullptr; | 90 return nullptr; |
130 } | 91 } |
131 | 92 |
132 if (HasGLOzone()) | 93 if (HasGLOzone()) |
133 return GetGLOzone()->CreateOffscreenGLSurface(size); | 94 return GetGLOzone()->CreateOffscreenGLSurface(size); |
134 | 95 |
135 if (HasDefaultImplementation(GetGLImplementation())) | 96 switch (GetGLImplementation()) { |
136 return CreateDefaultOffscreenGLSurface(size); | 97 case kGLImplementationMockGL: |
| 98 case kGLImplementationStubGL: |
| 99 return InitializeGLSurface(new GLSurfaceStub); |
| 100 default: |
| 101 NOTREACHED(); |
| 102 } |
137 | 103 |
138 return nullptr; | 104 return nullptr; |
139 } | 105 } |
140 | 106 |
141 } // namespace init | 107 } // namespace init |
142 } // namespace gl | 108 } // namespace gl |
OLD | NEW |