OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/client/gl_in_process_context.h" | 5 #include "gpu/command_buffer/client/gl_in_process_context.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "ui/gl/gl_image.h" | 36 #include "ui/gl/gl_image.h" |
37 | 37 |
38 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
39 #include "ui/gl/android/surface_texture.h" | 39 #include "ui/gl/android/surface_texture.h" |
40 #endif | 40 #endif |
41 | 41 |
42 namespace gpu { | 42 namespace gpu { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 const int32_t kDefaultCommandBufferSize = 1024 * 1024; | |
47 const unsigned int kDefaultStartTransferBufferSize = 4 * 1024 * 1024; | |
48 const unsigned int kDefaultMinTransferBufferSize = 1 * 256 * 1024; | |
49 const unsigned int kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; | |
50 | |
51 class GLInProcessContextImpl | 46 class GLInProcessContextImpl |
52 : public GLInProcessContext, | 47 : public GLInProcessContext, |
53 public base::SupportsWeakPtr<GLInProcessContextImpl> { | 48 public base::SupportsWeakPtr<GLInProcessContextImpl> { |
54 public: | 49 public: |
55 explicit GLInProcessContextImpl( | 50 GLInProcessContextImpl(); |
56 const GLInProcessContextSharedMemoryLimits& mem_limits); | |
57 ~GLInProcessContextImpl() override; | 51 ~GLInProcessContextImpl() override; |
58 | 52 |
59 bool Initialize(scoped_refptr<gfx::GLSurface> surface, | 53 bool Initialize(scoped_refptr<gfx::GLSurface> surface, |
60 bool is_offscreen, | 54 bool is_offscreen, |
61 GLInProcessContext* share_context, | 55 GLInProcessContext* share_context, |
62 gfx::AcceleratedWidget window, | 56 gfx::AcceleratedWidget window, |
63 const gfx::Size& size, | 57 const gfx::Size& size, |
64 const gpu::gles2::ContextCreationAttribHelper& attribs, | 58 const gpu::gles2::ContextCreationAttribHelper& attribs, |
65 gfx::GpuPreference gpu_preference, | 59 gfx::GpuPreference gpu_preference, |
66 const scoped_refptr<InProcessCommandBuffer::Service>& service, | 60 const scoped_refptr<InProcessCommandBuffer::Service>& service, |
| 61 const SharedMemoryLimits& mem_limits, |
67 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 62 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
68 ImageFactory* image_factory); | 63 ImageFactory* image_factory); |
69 | 64 |
70 // GLInProcessContext implementation: | 65 // GLInProcessContext implementation: |
71 gles2::GLES2Implementation* GetImplementation() override; | 66 gles2::GLES2Implementation* GetImplementation() override; |
72 size_t GetMappedMemoryLimit() override; | |
73 void SetLock(base::Lock* lock) override; | 67 void SetLock(base::Lock* lock) override; |
74 | 68 |
75 private: | 69 private: |
76 void Destroy(); | 70 void Destroy(); |
77 void OnSignalSyncPoint(const base::Closure& callback); | 71 void OnSignalSyncPoint(const base::Closure& callback); |
78 | 72 |
79 std::unique_ptr<gles2::GLES2CmdHelper> gles2_helper_; | 73 std::unique_ptr<gles2::GLES2CmdHelper> gles2_helper_; |
80 std::unique_ptr<TransferBuffer> transfer_buffer_; | 74 std::unique_ptr<TransferBuffer> transfer_buffer_; |
81 std::unique_ptr<gles2::GLES2Implementation> gles2_implementation_; | 75 std::unique_ptr<gles2::GLES2Implementation> gles2_implementation_; |
82 std::unique_ptr<InProcessCommandBuffer> command_buffer_; | 76 std::unique_ptr<InProcessCommandBuffer> command_buffer_; |
83 | 77 |
84 const GLInProcessContextSharedMemoryLimits mem_limits_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); | 78 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); |
87 }; | 79 }; |
88 | 80 |
89 GLInProcessContextImpl::GLInProcessContextImpl( | 81 GLInProcessContextImpl::GLInProcessContextImpl() = default; |
90 const GLInProcessContextSharedMemoryLimits& mem_limits) | |
91 : mem_limits_(mem_limits) {} | |
92 | 82 |
93 GLInProcessContextImpl::~GLInProcessContextImpl() { | 83 GLInProcessContextImpl::~GLInProcessContextImpl() { |
94 Destroy(); | 84 Destroy(); |
95 } | 85 } |
96 | 86 |
97 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { | 87 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { |
98 return gles2_implementation_.get(); | 88 return gles2_implementation_.get(); |
99 } | 89 } |
100 | 90 |
101 size_t GLInProcessContextImpl::GetMappedMemoryLimit() { | |
102 return mem_limits_.mapped_memory_reclaim_limit; | |
103 } | |
104 | |
105 void GLInProcessContextImpl::SetLock(base::Lock* lock) { | 91 void GLInProcessContextImpl::SetLock(base::Lock* lock) { |
106 NOTREACHED(); | 92 NOTREACHED(); |
107 } | 93 } |
108 | 94 |
109 bool GLInProcessContextImpl::Initialize( | 95 bool GLInProcessContextImpl::Initialize( |
110 scoped_refptr<gfx::GLSurface> surface, | 96 scoped_refptr<gfx::GLSurface> surface, |
111 bool is_offscreen, | 97 bool is_offscreen, |
112 GLInProcessContext* share_context, | 98 GLInProcessContext* share_context, |
113 gfx::AcceleratedWidget window, | 99 gfx::AcceleratedWidget window, |
114 const gfx::Size& size, | 100 const gfx::Size& size, |
115 const gles2::ContextCreationAttribHelper& attribs, | 101 const gles2::ContextCreationAttribHelper& attribs, |
116 gfx::GpuPreference gpu_preference, | 102 gfx::GpuPreference gpu_preference, |
117 const scoped_refptr<InProcessCommandBuffer::Service>& service, | 103 const scoped_refptr<InProcessCommandBuffer::Service>& service, |
| 104 const SharedMemoryLimits& mem_limits, |
118 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 105 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
119 ImageFactory* image_factory) { | 106 ImageFactory* image_factory) { |
120 DCHECK(size.width() >= 0 && size.height() >= 0); | 107 DCHECK(size.width() >= 0 && size.height() >= 0); |
121 | 108 |
122 std::vector<int32_t> attrib_vector; | 109 std::vector<int32_t> attrib_vector; |
123 attribs.Serialize(&attrib_vector); | 110 attribs.Serialize(&attrib_vector); |
124 | 111 |
125 command_buffer_.reset(new InProcessCommandBuffer(service)); | 112 command_buffer_.reset(new InProcessCommandBuffer(service)); |
126 | 113 |
127 scoped_refptr<gles2::ShareGroup> share_group; | 114 scoped_refptr<gles2::ShareGroup> share_group; |
(...skipping 15 matching lines...) Expand all Loading... |
143 gpu_preference, | 130 gpu_preference, |
144 share_command_buffer, | 131 share_command_buffer, |
145 gpu_memory_buffer_manager, | 132 gpu_memory_buffer_manager, |
146 image_factory)) { | 133 image_factory)) { |
147 DLOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; | 134 DLOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; |
148 return false; | 135 return false; |
149 } | 136 } |
150 | 137 |
151 // Create the GLES2 helper, which writes the command buffer protocol. | 138 // Create the GLES2 helper, which writes the command buffer protocol. |
152 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); | 139 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); |
153 if (!gles2_helper_->Initialize(mem_limits_.command_buffer_size)) { | 140 if (!gles2_helper_->Initialize(mem_limits.command_buffer_size)) { |
154 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; | 141 LOG(ERROR) << "Failed to initialize GLES2CmdHelper"; |
155 Destroy(); | 142 Destroy(); |
156 return false; | 143 return false; |
157 } | 144 } |
158 | 145 |
159 // Create a transfer buffer. | 146 // Create a transfer buffer. |
160 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); | 147 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
161 | 148 |
162 // Check for consistency. | 149 // Check for consistency. |
163 DCHECK(!attribs.bind_generates_resource); | 150 DCHECK(!attribs.bind_generates_resource); |
164 const bool bind_generates_resource = false; | 151 const bool bind_generates_resource = false; |
165 const bool support_client_side_arrays = false; | 152 const bool support_client_side_arrays = false; |
166 | 153 |
167 // Create the object exposing the OpenGL API. | 154 // Create the object exposing the OpenGL API. |
168 gles2_implementation_.reset( | 155 gles2_implementation_.reset( |
169 new gles2::GLES2Implementation(gles2_helper_.get(), | 156 new gles2::GLES2Implementation(gles2_helper_.get(), |
170 share_group.get(), | 157 share_group.get(), |
171 transfer_buffer_.get(), | 158 transfer_buffer_.get(), |
172 bind_generates_resource, | 159 bind_generates_resource, |
173 attribs.lose_context_when_out_of_memory, | 160 attribs.lose_context_when_out_of_memory, |
174 support_client_side_arrays, | 161 support_client_side_arrays, |
175 command_buffer_.get())); | 162 command_buffer_.get())); |
176 | 163 |
177 if (!gles2_implementation_->Initialize( | 164 if (!gles2_implementation_->Initialize( |
178 mem_limits_.start_transfer_buffer_size, | 165 mem_limits.start_transfer_buffer_size, |
179 mem_limits_.min_transfer_buffer_size, | 166 mem_limits.min_transfer_buffer_size, |
180 mem_limits_.max_transfer_buffer_size, | 167 mem_limits.max_transfer_buffer_size, |
181 mem_limits_.mapped_memory_reclaim_limit)) { | 168 mem_limits.mapped_memory_reclaim_limit)) { |
182 return false; | 169 return false; |
183 } | 170 } |
184 | 171 |
185 return true; | 172 return true; |
186 } | 173 } |
187 | 174 |
188 void GLInProcessContextImpl::Destroy() { | 175 void GLInProcessContextImpl::Destroy() { |
189 if (gles2_implementation_) { | 176 if (gles2_implementation_) { |
190 // First flush the context to ensure that any pending frees of resources | 177 // First flush the context to ensure that any pending frees of resources |
191 // are completed. Otherwise, if this context is part of a share group, | 178 // are completed. Otherwise, if this context is part of a share group, |
192 // those resources might leak. Also, any remaining side effects of commands | 179 // those resources might leak. Also, any remaining side effects of commands |
193 // issued on this context might not be visible to other contexts in the | 180 // issued on this context might not be visible to other contexts in the |
194 // share group. | 181 // share group. |
195 gles2_implementation_->Flush(); | 182 gles2_implementation_->Flush(); |
196 | 183 |
197 gles2_implementation_.reset(); | 184 gles2_implementation_.reset(); |
198 } | 185 } |
199 | 186 |
200 transfer_buffer_.reset(); | 187 transfer_buffer_.reset(); |
201 gles2_helper_.reset(); | 188 gles2_helper_.reset(); |
202 command_buffer_.reset(); | 189 command_buffer_.reset(); |
203 } | 190 } |
204 | 191 |
205 } // anonymous namespace | 192 } // anonymous namespace |
206 | 193 |
207 GLInProcessContextSharedMemoryLimits::GLInProcessContextSharedMemoryLimits() | |
208 : command_buffer_size(kDefaultCommandBufferSize), | |
209 start_transfer_buffer_size(kDefaultStartTransferBufferSize), | |
210 min_transfer_buffer_size(kDefaultMinTransferBufferSize), | |
211 max_transfer_buffer_size(kDefaultMaxTransferBufferSize), | |
212 mapped_memory_reclaim_limit(SharedMemoryLimits::kNoLimit) {} | |
213 | |
214 // static | 194 // static |
215 GLInProcessContext* GLInProcessContext::Create( | 195 GLInProcessContext* GLInProcessContext::Create( |
216 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, | 196 scoped_refptr<gpu::InProcessCommandBuffer::Service> service, |
217 scoped_refptr<gfx::GLSurface> surface, | 197 scoped_refptr<gfx::GLSurface> surface, |
218 bool is_offscreen, | 198 bool is_offscreen, |
219 gfx::AcceleratedWidget window, | 199 gfx::AcceleratedWidget window, |
220 const gfx::Size& size, | 200 const gfx::Size& size, |
221 GLInProcessContext* share_context, | 201 GLInProcessContext* share_context, |
222 const ::gpu::gles2::ContextCreationAttribHelper& attribs, | 202 const ::gpu::gles2::ContextCreationAttribHelper& attribs, |
223 gfx::GpuPreference gpu_preference, | 203 gfx::GpuPreference gpu_preference, |
224 const GLInProcessContextSharedMemoryLimits& memory_limits, | 204 const SharedMemoryLimits& memory_limits, |
225 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 205 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
226 ImageFactory* image_factory) { | 206 ImageFactory* image_factory) { |
227 if (surface.get()) { | 207 if (surface.get()) { |
228 DCHECK_EQ(surface->IsOffscreen(), is_offscreen); | 208 DCHECK_EQ(surface->IsOffscreen(), is_offscreen); |
229 DCHECK(surface->GetSize() == size); | 209 DCHECK(surface->GetSize() == size); |
230 DCHECK_EQ(gfx::kNullAcceleratedWidget, window); | 210 DCHECK_EQ(gfx::kNullAcceleratedWidget, window); |
231 } | 211 } |
232 | 212 |
233 std::unique_ptr<GLInProcessContextImpl> context( | 213 std::unique_ptr<GLInProcessContextImpl> context(new GLInProcessContextImpl); |
234 new GLInProcessContextImpl(memory_limits)); | 214 if (!context->Initialize(surface, is_offscreen, share_context, window, size, |
235 if (!context->Initialize(surface, | 215 attribs, gpu_preference, service, memory_limits, |
236 is_offscreen, | 216 gpu_memory_buffer_manager, image_factory)) |
237 share_context, | |
238 window, | |
239 size, | |
240 attribs, | |
241 gpu_preference, | |
242 service, | |
243 gpu_memory_buffer_manager, | |
244 image_factory)) | |
245 return NULL; | 217 return NULL; |
246 | 218 |
247 return context.release(); | 219 return context.release(); |
248 } | 220 } |
249 | 221 |
250 } // namespace gpu | 222 } // namespace gpu |
OLD | NEW |