OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_factory_impl
.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "content/browser/android/in_process/context_provider_in_process.h" | 11 #include "content/browser/android/in_process/context_provider_in_process.h" |
12 #include "content/browser/android/in_process/synchronous_compositor_context_prov
ider.h" | 12 #include "content/browser/android/in_process/synchronous_compositor_context_prov
ider.h" |
13 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.h" | 13 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.h" |
14 #include "content/browser/android/in_process/synchronous_compositor_impl.h" | 14 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
15 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" | 15 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" |
16 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 16 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
17 #include "content/common/gpu/client/gpu_channel_host.h" | 17 #include "content/common/gpu/client/gpu_channel_host.h" |
18 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 18 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
19 #include "content/gpu/in_process_gpu_thread.h" | 19 #include "content/gpu/in_process_gpu_thread.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/gpu_data_manager.h" | 21 #include "content/public/browser/gpu_data_manager.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "content/renderer/gpu/frame_swap_message_queue.h" | 23 #include "content/renderer/gpu/frame_swap_message_queue.h" |
24 #include "content/renderer/render_thread_impl.h" | 24 #include "content/renderer/render_thread_impl.h" |
25 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" | 25 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" |
26 #include "gpu/command_buffer/client/gl_in_process_context.h" | 26 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 27 #include "gpu/command_buffer/client/gles2_interface.h" |
27 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 28 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
28 #include "ui/gl/android/surface_texture.h" | 29 #include "ui/gl/android/surface_texture.h" |
29 #include "ui/gl/gl_surface.h" | 30 #include "ui/gl/gl_surface.h" |
30 #include "ui/gl/gl_surface_stub.h" | 31 #include "ui/gl/gl_surface_stub.h" |
31 | 32 |
32 using cc_blink::ContextProviderWebContext; | 33 using cc_blink::ContextProviderWebContext; |
33 using gpu_blink::WebGraphicsContext3DImpl; | 34 using gpu_blink::WebGraphicsContext3DImpl; |
34 using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; | 35 using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl; |
35 | 36 |
36 namespace content { | 37 namespace content { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 164 } |
164 | 165 |
165 scoped_ptr<cc::OutputSurface> | 166 scoped_ptr<cc::OutputSurface> |
166 SynchronousCompositorFactoryImpl::CreateOutputSurface( | 167 SynchronousCompositorFactoryImpl::CreateOutputSurface( |
167 int routing_id, | 168 int routing_id, |
168 int surface_id, | 169 int surface_id, |
169 scoped_refptr<content::FrameSwapMessageQueue> frame_swap_message_queue) { | 170 scoped_refptr<content::FrameSwapMessageQueue> frame_swap_message_queue) { |
170 scoped_refptr<cc::ContextProvider> onscreen_context = | 171 scoped_refptr<cc::ContextProvider> onscreen_context = |
171 CreateContextProviderForCompositor(surface_id, RENDER_COMPOSITOR_CONTEXT); | 172 CreateContextProviderForCompositor(surface_id, RENDER_COMPOSITOR_CONTEXT); |
172 scoped_refptr<cc::ContextProvider> worker_context = | 173 scoped_refptr<cc::ContextProvider> worker_context = |
173 CreateContextProviderForCompositor(0, RENDER_WORKER_CONTEXT); | 174 GetSharedWorkerContextProvider(); |
174 | |
175 return make_scoped_ptr(new SynchronousCompositorOutputSurface( | 175 return make_scoped_ptr(new SynchronousCompositorOutputSurface( |
176 onscreen_context, worker_context, routing_id, frame_swap_message_queue)); | 176 onscreen_context, worker_context, routing_id, frame_swap_message_queue)); |
177 } | 177 } |
178 | 178 |
179 InputHandlerManagerClient* | 179 InputHandlerManagerClient* |
180 SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { | 180 SynchronousCompositorFactoryImpl::GetInputHandlerManagerClient() { |
181 return synchronous_input_event_filter(); | 181 return synchronous_input_event_filter(); |
182 } | 182 } |
183 | 183 |
184 scoped_ptr<cc::BeginFrameSource> | 184 scoped_ptr<cc::BeginFrameSource> |
(...skipping 19 matching lines...) Expand all Loading... |
204 debug_name); | 204 debug_name); |
205 } | 205 } |
206 | 206 |
207 scoped_refptr<cc::ContextProvider> | 207 scoped_refptr<cc::ContextProvider> |
208 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor( | 208 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor( |
209 int surface_id, | 209 int surface_id, |
210 CommandBufferContextType type) { | 210 CommandBufferContextType type) { |
211 // This is half of what RenderWidget uses because synchronous compositor | 211 // This is half of what RenderWidget uses because synchronous compositor |
212 // pipeline is only one frame deep. But twice of half for low end here | 212 // pipeline is only one frame deep. But twice of half for low end here |
213 // because 16bit texture is not supported. | 213 // because 16bit texture is not supported. |
| 214 // TODO(reveman): This limit is based on the usage required by async |
| 215 // uploads. Determine what a good limit is now that async uploads are |
| 216 // no longer used. |
214 unsigned int mapped_memory_reclaim_limit = | 217 unsigned int mapped_memory_reclaim_limit = |
215 (base::SysInfo::IsLowEndDevice() ? 2 : 6) * 1024 * 1024; | 218 (base::SysInfo::IsLowEndDevice() ? 2 : 6) * 1024 * 1024; |
216 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); | 219 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); |
217 | 220 |
218 if (use_ipc_command_buffer_) { | 221 if (use_ipc_command_buffer_) { |
219 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits mem_limits; | 222 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits mem_limits; |
220 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; | 223 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; |
221 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context = | 224 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context = |
222 CreateContext3D(surface_id, GetDefaultAttribs(), mem_limits); | 225 CreateContext3D(surface_id, GetDefaultAttribs(), mem_limits); |
223 return make_scoped_refptr( | 226 return make_scoped_refptr( |
224 new SynchronousCompositorContextProvider(context.Pass(), type)); | 227 new SynchronousCompositorContextProvider(context.Pass(), type)); |
225 } | 228 } |
226 | 229 |
227 gpu::GLInProcessContextSharedMemoryLimits mem_limits; | 230 gpu::GLInProcessContextSharedMemoryLimits mem_limits; |
228 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; | 231 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; |
229 ContextHolder holder = | 232 ContextHolder holder = |
230 CreateContextHolder(attributes, GpuThreadService(), mem_limits, true); | 233 CreateContextHolder(attributes, GpuThreadService(), mem_limits, true); |
231 return ContextProviderInProcess::Create(holder.command_buffer.Pass(), | 234 return ContextProviderInProcess::Create(holder.command_buffer.Pass(), |
232 "Child-Compositor"); | 235 "Child-Compositor"); |
233 } | 236 } |
234 | 237 |
| 238 scoped_refptr<cc::ContextProvider> |
| 239 SynchronousCompositorFactoryImpl::GetSharedWorkerContextProvider() { |
| 240 // TODO(reveman): This limit is based on the usage required by async |
| 241 // uploads. Determine what a good limit is now that async uploads are |
| 242 // no longer used. |
| 243 unsigned int mapped_memory_reclaim_limit = |
| 244 (base::SysInfo::IsLowEndDevice() ? 2 : 6) * 1024 * 1024; |
| 245 |
| 246 if (use_ipc_command_buffer_) { |
| 247 bool shared_worker_context_lost = false; |
| 248 if (shared_worker_context_) { |
| 249 // Note: If context is lost, we delete reference after releasing the lock. |
| 250 base::AutoLock lock(*shared_worker_context_->GetLock()); |
| 251 if (shared_worker_context_->ContextGL()->GetGraphicsResetStatusKHR() != |
| 252 GL_NO_ERROR) { |
| 253 shared_worker_context_lost = true; |
| 254 } |
| 255 } |
| 256 if (!shared_worker_context_ || shared_worker_context_lost) { |
| 257 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits mem_limits; |
| 258 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; |
| 259 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context = |
| 260 CreateContext3D(0, GetDefaultAttribs(), mem_limits); |
| 261 shared_worker_context_ = |
| 262 make_scoped_refptr(new SynchronousCompositorContextProvider( |
| 263 context.Pass(), RENDER_WORKER_CONTEXT)); |
| 264 if (!shared_worker_context_->BindToCurrentThread()) |
| 265 shared_worker_context_ = nullptr; |
| 266 if (shared_worker_context_) |
| 267 shared_worker_context_->SetupLock(); |
| 268 } |
| 269 |
| 270 return shared_worker_context_; |
| 271 } |
| 272 |
| 273 bool in_process_shared_worker_context_lost = false; |
| 274 if (in_process_shared_worker_context_) { |
| 275 // Note: If context is lost, we delete reference after releasing the lock. |
| 276 base::AutoLock lock(*in_process_shared_worker_context_->GetLock()); |
| 277 if (in_process_shared_worker_context_->ContextGL() |
| 278 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |
| 279 in_process_shared_worker_context_lost = true; |
| 280 } |
| 281 } |
| 282 if (!in_process_shared_worker_context_ || |
| 283 in_process_shared_worker_context_lost) { |
| 284 gpu::GLInProcessContextSharedMemoryLimits mem_limits; |
| 285 mem_limits.mapped_memory_reclaim_limit = mapped_memory_reclaim_limit; |
| 286 ContextHolder holder = CreateContextHolder( |
| 287 GetDefaultAttribs(), GpuThreadService(), mem_limits, true); |
| 288 in_process_shared_worker_context_ = ContextProviderInProcess::Create( |
| 289 holder.command_buffer.Pass(), "Child-Worker"); |
| 290 if (!in_process_shared_worker_context_->BindToCurrentThread()) |
| 291 in_process_shared_worker_context_ = nullptr; |
| 292 if (in_process_shared_worker_context_) |
| 293 in_process_shared_worker_context_->SetupLock(); |
| 294 } |
| 295 |
| 296 return in_process_shared_worker_context_; |
| 297 } |
| 298 |
235 scoped_refptr<StreamTextureFactory> | 299 scoped_refptr<StreamTextureFactory> |
236 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { | 300 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { |
237 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( | 301 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( |
238 StreamTextureFactorySynchronousImpl::Create( | 302 StreamTextureFactorySynchronousImpl::Create( |
239 base::Bind( | 303 base::Bind( |
240 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, | 304 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, |
241 base::Unretained(this)), | 305 base::Unretained(this)), |
242 frame_id)); | 306 frame_id)); |
243 return factory; | 307 return factory; |
244 } | 308 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 android_view_service_->sync_point_manager()); | 406 android_view_service_->sync_point_manager()); |
343 } | 407 } |
344 return gpu_thread_service_; | 408 return gpu_thread_service_; |
345 } | 409 } |
346 | 410 |
347 void SynchronousCompositorFactoryImpl::SetUseIpcCommandBuffer() { | 411 void SynchronousCompositorFactoryImpl::SetUseIpcCommandBuffer() { |
348 use_ipc_command_buffer_ = true; | 412 use_ipc_command_buffer_ = true; |
349 } | 413 } |
350 | 414 |
351 } // namespace content | 415 } // namespace content |
OLD | NEW |