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 "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h" | 7 #include "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/renderer/gpu/frame_swap_message_queue.h" | 9 #include "content/renderer/gpu/frame_swap_message_queue.h" |
10 #include "gpu/command_buffer/client/gl_in_process_context.h" | 10 #include "gpu/command_buffer/client/gl_in_process_context.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 | 225 |
226 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { | 226 void SynchronousCompositorFactoryImpl::CompositorInitializedHardwareDraw() { |
227 base::AutoLock lock(num_hardware_compositor_lock_); | 227 base::AutoLock lock(num_hardware_compositor_lock_); |
228 num_hardware_compositors_++; | 228 num_hardware_compositors_++; |
229 } | 229 } |
230 | 230 |
231 void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() { | 231 void SynchronousCompositorFactoryImpl::CompositorReleasedHardwareDraw() { |
232 base::AutoLock lock(num_hardware_compositor_lock_); | 232 base::AutoLock lock(num_hardware_compositor_lock_); |
233 DCHECK_GT(num_hardware_compositors_, 0u); | 233 DCHECK_GT(num_hardware_compositors_, 0u); |
234 num_hardware_compositors_--; | 234 num_hardware_compositors_--; |
235 if (num_hardware_compositors_ == 0) { | |
236 // Nullify the video_context_provider_ now so that it is not null only if | |
237 // there is at least 1 hardware compositor | |
238 video_context_provider_ = NULL; | |
239 } | |
240 } | 235 } |
241 | 236 |
242 bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() { | 237 bool SynchronousCompositorFactoryImpl::CanCreateMainThreadContext() { |
243 base::AutoLock lock(num_hardware_compositor_lock_); | 238 base::AutoLock lock(num_hardware_compositor_lock_); |
244 return num_hardware_compositors_ > 0; | 239 return num_hardware_compositors_ > 0; |
245 } | 240 } |
246 | 241 |
247 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> | 242 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> |
248 SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { | 243 SynchronousCompositorFactoryImpl::TryCreateStreamTextureFactory() { |
249 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> | 244 // Always fail creation even if |video_context_provider_| is not NULL. |
250 context_provider; | 245 // This is to avoid synchronous calls that may deadlock. Setting |
251 // This check only guarantees the main thread context is created after | 246 // |video_context_provider_| to null is also not safe since it makes |
252 // a compositor did successfully initialize hardware draw in the past. | 247 // synchronous destruction uncontrolled and possibly deadlock. |
253 // When all compositors have released hardware draw, main thread context | 248 if (!CanCreateMainThreadContext()) { |
254 // creation is guaranteed to fail. | 249 return |
255 if (CanCreateMainThreadContext() && !video_context_provider_) { | 250 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>(); |
hush (inactive)
2014/08/22 17:49:38
can we just return null here?
boliu
2014/08/22 17:54:17
Hmm, compiler seems happy, but not sure if it fits
boliu
2014/08/22 18:14:30
Took a cursory look and didn't find any instance o
hush (inactive)
2014/08/22 18:26:43
alright.
lgtm
sorry that I broke this thing...
On
| |
251 } | |
252 | |
253 if (!video_context_provider_) { | |
256 DCHECK(service_); | 254 DCHECK(service_); |
257 DCHECK(share_context_.get()); | 255 DCHECK(share_context_.get()); |
258 | 256 |
259 video_context_provider_ = new VideoContextProvider( | 257 video_context_provider_ = new VideoContextProvider( |
260 CreateContext(service_, | 258 CreateContext(service_, |
261 share_context_.get(), | 259 share_context_.get(), |
262 gpu::GLInProcessContextSharedMemoryLimits())); | 260 gpu::GLInProcessContextSharedMemoryLimits())); |
263 } | 261 } |
264 return video_context_provider_; | 262 return video_context_provider_; |
265 } | 263 } |
266 | 264 |
267 void SynchronousCompositorFactoryImpl::SetDeferredGpuService( | 265 void SynchronousCompositorFactoryImpl::SetDeferredGpuService( |
268 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { | 266 scoped_refptr<gpu::InProcessCommandBuffer::Service> service) { |
269 DCHECK(!service_); | 267 DCHECK(!service_); |
270 service_ = service; | 268 service_ = service; |
271 } | 269 } |
272 | 270 |
273 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( | 271 void SynchronousCompositorFactoryImpl::SetRecordFullDocument( |
274 bool record_full_document) { | 272 bool record_full_document) { |
275 record_full_layer_ = record_full_document; | 273 record_full_layer_ = record_full_document; |
276 } | 274 } |
277 | 275 |
278 } // namespace content | 276 } // namespace content |
OLD | NEW |