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_external_beg
in_frame_source.h" | 12 #include "content/browser/android/in_process/synchronous_compositor_external_beg
in_frame_source.h" |
13 #include "content/browser/android/in_process/synchronous_compositor_impl.h" | 13 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
14 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" | 14 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" |
15 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 15 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 16 #include "content/gpu/in_process_gpu_thread.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/gpu_data_manager.h" | 18 #include "content/public/browser/gpu_data_manager.h" |
18 #include "content/renderer/gpu/frame_swap_message_queue.h" | 19 #include "content/renderer/gpu/frame_swap_message_queue.h" |
19 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" | 20 #include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h" |
20 #include "gpu/command_buffer/client/gl_in_process_context.h" | 21 #include "gpu/command_buffer/client/gl_in_process_context.h" |
21 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 22 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
22 #include "gpu/command_buffer/service/gpu_switches.h" | 23 #include "gpu/command_buffer/service/gpu_switches.h" |
23 #include "ui/gl/android/surface_texture.h" | 24 #include "ui/gl/android/surface_texture.h" |
24 #include "ui/gl/gl_surface.h" | 25 #include "ui/gl/gl_surface.h" |
25 #include "ui/gl/gl_surface_stub.h" | 26 #include "ui/gl/gl_surface_stub.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( | 164 SynchronousCompositorFactoryImpl::CreateExternalBeginFrameSource( |
164 int routing_id) { | 165 int routing_id) { |
165 return make_scoped_ptr( | 166 return make_scoped_ptr( |
166 new SynchronousCompositorExternalBeginFrameSource(routing_id)); | 167 new SynchronousCompositorExternalBeginFrameSource(routing_id)); |
167 } | 168 } |
168 | 169 |
169 scoped_refptr<ContextProviderWebContext> | 170 scoped_refptr<ContextProviderWebContext> |
170 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( | 171 SynchronousCompositorFactoryImpl::CreateOffscreenContextProvider( |
171 const blink::WebGraphicsContext3D::Attributes& attributes, | 172 const blink::WebGraphicsContext3D::Attributes& attributes, |
172 const std::string& debug_name) { | 173 const std::string& debug_name) { |
173 ContextHolder holder = CreateContextHolder( | 174 ContextHolder holder = |
174 attributes, nullptr, gpu::GLInProcessContextSharedMemoryLimits(), true); | 175 CreateContextHolder(attributes, GpuThreadService(), |
| 176 gpu::GLInProcessContextSharedMemoryLimits(), true); |
175 return ContextProviderInProcess::Create(holder.command_buffer.Pass(), | 177 return ContextProviderInProcess::Create(holder.command_buffer.Pass(), |
176 debug_name); | 178 debug_name); |
177 } | 179 } |
178 | 180 |
179 scoped_refptr<cc::ContextProvider> | 181 scoped_refptr<cc::ContextProvider> |
180 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { | 182 SynchronousCompositorFactoryImpl::CreateContextProviderForCompositor() { |
181 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); | 183 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); |
182 gpu::GLInProcessContextSharedMemoryLimits mem_limits; | 184 gpu::GLInProcessContextSharedMemoryLimits mem_limits; |
183 // This is half of what RenderWidget uses because synchronous compositor | 185 // This is half of what RenderWidget uses because synchronous compositor |
184 // pipeline is only one frame deep. | 186 // pipeline is only one frame deep. |
185 if (base::SysInfo::IsLowEndDevice()) { | 187 if (base::SysInfo::IsLowEndDevice()) { |
186 // But twice of half here because 16bit texture is not supported. | 188 // But twice of half here because 16bit texture is not supported. |
187 mem_limits.mapped_memory_reclaim_limit = 2 * 1024 * 1024; | 189 mem_limits.mapped_memory_reclaim_limit = 2 * 1024 * 1024; |
188 } else { | 190 } else { |
189 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024; | 191 mem_limits.mapped_memory_reclaim_limit = 6 * 1024 * 1024; |
190 } | 192 } |
191 ContextHolder holder = | 193 ContextHolder holder = |
192 CreateContextHolder(attributes, nullptr, mem_limits, true); | 194 CreateContextHolder(attributes, GpuThreadService(), mem_limits, true); |
193 return ContextProviderInProcess::Create(holder.command_buffer.Pass(), | 195 return ContextProviderInProcess::Create(holder.command_buffer.Pass(), |
194 "Child-Compositor"); | 196 "Child-Compositor"); |
195 } | 197 } |
196 | 198 |
197 scoped_refptr<StreamTextureFactory> | 199 scoped_refptr<StreamTextureFactory> |
198 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { | 200 SynchronousCompositorFactoryImpl::CreateStreamTextureFactory(int frame_id) { |
199 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( | 201 scoped_refptr<StreamTextureFactorySynchronousImpl> factory( |
200 StreamTextureFactorySynchronousImpl::Create( | 202 StreamTextureFactorySynchronousImpl::Create( |
201 base::Bind( | 203 base::Bind( |
202 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, | 204 &SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory, |
203 base::Unretained(this)), | 205 base::Unretained(this)), |
204 frame_id)); | 206 frame_id)); |
205 return factory; | 207 return factory; |
206 } | 208 } |
207 | 209 |
208 WebGraphicsContext3DInProcessCommandBufferImpl* | 210 WebGraphicsContext3DInProcessCommandBufferImpl* |
209 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( | 211 SynchronousCompositorFactoryImpl::CreateOffscreenGraphicsContext3D( |
210 const blink::WebGraphicsContext3D::Attributes& attributes) { | 212 const blink::WebGraphicsContext3D::Attributes& attributes) { |
211 ContextHolder holder = CreateContextHolder( | 213 ContextHolder holder = |
212 attributes, nullptr, | 214 CreateContextHolder(attributes, GpuThreadService(), |
213 gpu::GLInProcessContextSharedMemoryLimits(), true); | 215 gpu::GLInProcessContextSharedMemoryLimits(), true); |
214 return holder.command_buffer.release(); | 216 return holder.command_buffer.release(); |
215 } | 217 } |
216 | 218 |
217 gpu::GPUInfo SynchronousCompositorFactoryImpl::GetGPUInfo() const { | 219 gpu::GPUInfo SynchronousCompositorFactoryImpl::GetGPUInfo() const { |
218 return content::GpuDataManager::GetInstance()->GetGPUInfo(); | 220 return content::GpuDataManager::GetInstance()->GetGPUInfo(); |
219 } | 221 } |
220 | 222 |
221 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { | 223 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { |
222 base::AutoLock lock(num_hardware_compositor_lock_); | 224 base::AutoLock lock(num_hardware_compositor_lock_); |
223 num_hardware_compositors_++; | 225 num_hardware_compositors_++; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 // Always fail creation even if |video_context_provider_| is not NULL. | 258 // Always fail creation even if |video_context_provider_| is not NULL. |
257 // This is to avoid synchronous calls that may deadlock. Setting | 259 // This is to avoid synchronous calls that may deadlock. Setting |
258 // |video_context_provider_| to null is also not safe since it makes | 260 // |video_context_provider_| to null is also not safe since it makes |
259 // synchronous destruction uncontrolled and possibly deadlock. | 261 // synchronous destruction uncontrolled and possibly deadlock. |
260 if (!CanCreateMainThreadContext()) { | 262 if (!CanCreateMainThreadContext()) { |
261 return | 263 return |
262 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); | 264 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); |
263 } | 265 } |
264 | 266 |
265 if (!video_context_provider_.get()) { | 267 if (!video_context_provider_.get()) { |
266 DCHECK(service_.get()); | 268 DCHECK(android_view_service_.get()); |
267 | 269 |
268 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); | 270 blink::WebGraphicsContext3D::Attributes attributes = GetDefaultAttribs(); |
269 attributes.shareResources = false; | 271 attributes.shareResources = false; |
270 // This needs to run in on-screen |service_| context due to SurfaceTexture | 272 // This needs to run in on-screen |android_view_service_| context due to |
271 // limitations. | 273 // SurfaceTexture limitations. |
272 ContextHolder holder = | 274 ContextHolder holder = |
273 CreateContextHolder(attributes, service_, | 275 CreateContextHolder(attributes, android_view_service_, |
274 gpu::GLInProcessContextSharedMemoryLimits(), false); | 276 gpu::GLInProcessContextSharedMemoryLimits(), false); |
275 video_context_provider_ = new VideoContextProvider( | 277 video_context_provider_ = new VideoContextProvider( |
276 ContextProviderInProcess::Create(holder.command_buffer.Pass(), | 278 ContextProviderInProcess::Create(holder.command_buffer.Pass(), |
277 "Video-Offscreen-main-thread"), | 279 "Video-Offscreen-main-thread"), |
278 holder.gl_in_process_context); | 280 holder.gl_in_process_context); |
279 } | 281 } |
280 return video_context_provider_; | 282 return video_context_provider_; |
281 } | 283 } |
282 | 284 |
283 void SynchronousCompositorFactoryImpl::SetDeferredGpuService( | 285 void SynchronousCompositorFactoryImpl::SetDeferredGpuService( |
284 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 286 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
285 DCHECK(!service_.get()); | 287 DCHECK(!android_view_service_.get()); |
286 service_ = service; | 288 android_view_service_ = service; |
| 289 } |
| 290 |
| 291 base::Thread* SynchronousCompositorFactoryImpl::CreateInProcessGpuThread( |
| 292 const InProcessChildThreadParams& params) { |
| 293 DCHECK(android_view_service_.get()); |
| 294 return new InProcessGpuThread(params, |
| 295 android_view_service_->sync_point_manager()); |
| 296 } |
| 297 |
| 298 scoped_refptr<gpu::InProcessCommandBuffer::Service> |
| 299 SynchronousCompositorFactoryImpl::GpuThreadService() { |
| 300 DCHECK(android_view_service_.get()); |
| 301 // Create thread lazily on first use. |
| 302 if (!gpu_thread_service_.get()) { |
| 303 gpu_thread_service_ = new gpu::GpuInProcessThread( |
| 304 android_view_service_->sync_point_manager()); |
| 305 } |
| 306 return gpu_thread_service_; |
287 } | 307 } |
288 | 308 |
289 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( | 309 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( |
290 bool record_full_document) { | 310 bool record_full_document) { |
291 record_full_layer_ = record_full_document; | 311 record_full_layer_ = record_full_document; |
292 } | 312 } |
293 | 313 |
294 } // namespace content | 314 } // namespace content |
OLD | NEW |