OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/service/in_process_command_buffer.h" | 5 #include "gpu/command_buffer/service/in_process_command_buffer.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 204 } |
205 | 205 |
206 InProcessCommandBuffer::InProcessCommandBuffer( | 206 InProcessCommandBuffer::InProcessCommandBuffer( |
207 const scoped_refptr<Service>& service) | 207 const scoped_refptr<Service>& service) |
208 : context_lost_(false), | 208 : context_lost_(false), |
209 idle_work_pending_(false), | 209 idle_work_pending_(false), |
210 last_put_offset_(-1), | 210 last_put_offset_(-1), |
211 flush_event_(false, false), | 211 flush_event_(false, false), |
212 service_(service.get() ? service : GetDefaultService()), | 212 service_(service.get() ? service : GetDefaultService()), |
213 gpu_thread_weak_ptr_factory_(this) { | 213 gpu_thread_weak_ptr_factory_(this) { |
214 if (!service) { | 214 if (!service.get()) { |
215 base::AutoLock lock(default_thread_clients_lock_.Get()); | 215 base::AutoLock lock(default_thread_clients_lock_.Get()); |
216 default_thread_clients_.Get().insert(this); | 216 default_thread_clients_.Get().insert(this); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 InProcessCommandBuffer::~InProcessCommandBuffer() { | 220 InProcessCommandBuffer::~InProcessCommandBuffer() { |
221 Destroy(); | 221 Destroy(); |
222 base::AutoLock lock(default_thread_clients_lock_.Get()); | 222 base::AutoLock lock(default_thread_clients_lock_.Get()); |
223 default_thread_clients_.Get().erase(this); | 223 default_thread_clients_.Get().erase(this); |
224 } | 224 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 bool is_offscreen, | 263 bool is_offscreen, |
264 gfx::AcceleratedWidget window, | 264 gfx::AcceleratedWidget window, |
265 const gfx::Size& size, | 265 const gfx::Size& size, |
266 const std::vector<int32>& attribs, | 266 const std::vector<int32>& attribs, |
267 gfx::GpuPreference gpu_preference, | 267 gfx::GpuPreference gpu_preference, |
268 const base::Closure& context_lost_callback, | 268 const base::Closure& context_lost_callback, |
269 InProcessCommandBuffer* share_group) { | 269 InProcessCommandBuffer* share_group) { |
270 DCHECK(!share_group || service_ == share_group->service_); | 270 DCHECK(!share_group || service_ == share_group->service_); |
271 context_lost_callback_ = WrapCallback(context_lost_callback); | 271 context_lost_callback_ = WrapCallback(context_lost_callback); |
272 | 272 |
273 if (surface) { | 273 if (surface.get()) { |
274 // GPU thread must be the same as client thread due to GLSurface not being | 274 // GPU thread must be the same as client thread due to GLSurface not being |
275 // thread safe. | 275 // thread safe. |
276 sequence_checker_.reset(new base::SequenceChecker); | 276 sequence_checker_.reset(new base::SequenceChecker); |
277 surface_ = surface; | 277 surface_ = surface; |
278 } | 278 } |
279 | 279 |
280 gpu::Capabilities capabilities; | 280 gpu::Capabilities capabilities; |
281 InitializeOnGpuThreadParams params(is_offscreen, | 281 InitializeOnGpuThreadParams params(is_offscreen, |
282 window, | 282 window, |
283 size, | 283 size, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 bind_generates_resource))); | 348 bind_generates_resource))); |
349 | 349 |
350 gpu_scheduler_.reset( | 350 gpu_scheduler_.reset( |
351 new GpuScheduler(command_buffer.get(), decoder_.get(), decoder_.get())); | 351 new GpuScheduler(command_buffer.get(), decoder_.get(), decoder_.get())); |
352 command_buffer->SetGetBufferChangeCallback(base::Bind( | 352 command_buffer->SetGetBufferChangeCallback(base::Bind( |
353 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); | 353 &GpuScheduler::SetGetBuffer, base::Unretained(gpu_scheduler_.get()))); |
354 command_buffer_ = command_buffer.Pass(); | 354 command_buffer_ = command_buffer.Pass(); |
355 | 355 |
356 decoder_->set_engine(gpu_scheduler_.get()); | 356 decoder_->set_engine(gpu_scheduler_.get()); |
357 | 357 |
358 if (!surface_) { | 358 if (!surface_.get()) { |
359 if (params.is_offscreen) | 359 if (params.is_offscreen) |
360 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(params.size); | 360 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(params.size); |
361 else | 361 else |
362 surface_ = gfx::GLSurface::CreateViewGLSurface(params.window); | 362 surface_ = gfx::GLSurface::CreateViewGLSurface(params.window); |
363 } | 363 } |
364 | 364 |
365 if (!surface_.get()) { | 365 if (!surface_.get()) { |
366 LOG(ERROR) << "Could not create GLSurface."; | 366 LOG(ERROR) << "Could not create GLSurface."; |
367 DestroyOnGpuThread(); | 367 DestroyOnGpuThread(); |
368 return false; | 368 return false; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 QueueTask( | 433 QueueTask( |
434 base::Bind(&RunTaskWithResult<bool>, destroy_task, &result, &completion)); | 434 base::Bind(&RunTaskWithResult<bool>, destroy_task, &result, &completion)); |
435 completion.Wait(); | 435 completion.Wait(); |
436 } | 436 } |
437 | 437 |
438 bool InProcessCommandBuffer::DestroyOnGpuThread() { | 438 bool InProcessCommandBuffer::DestroyOnGpuThread() { |
439 CheckSequencedThread(); | 439 CheckSequencedThread(); |
440 gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs(); | 440 gpu_thread_weak_ptr_factory_.InvalidateWeakPtrs(); |
441 command_buffer_.reset(); | 441 command_buffer_.reset(); |
442 // Clean up GL resources if possible. | 442 // Clean up GL resources if possible. |
443 bool have_context = context_ && context_->MakeCurrent(surface_); | 443 bool have_context = context_.get() && context_->MakeCurrent(surface_.get()); |
444 if (decoder_) { | 444 if (decoder_) { |
445 decoder_->Destroy(have_context); | 445 decoder_->Destroy(have_context); |
446 decoder_.reset(); | 446 decoder_.reset(); |
447 } | 447 } |
448 context_ = NULL; | 448 context_ = NULL; |
449 surface_ = NULL; | 449 surface_ = NULL; |
450 gl_share_group_ = NULL; | 450 gl_share_group_ = NULL; |
451 #if defined(OS_ANDROID) | 451 #if defined(OS_ANDROID) |
452 stream_texture_manager_.reset(); | 452 stream_texture_manager_.reset(); |
453 #endif | 453 #endif |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 642 |
643 void InProcessCommandBuffer::RegisterGpuMemoryBufferOnGpuThread( | 643 void InProcessCommandBuffer::RegisterGpuMemoryBufferOnGpuThread( |
644 int32 id, | 644 int32 id, |
645 const gfx::GpuMemoryBufferHandle& handle, | 645 const gfx::GpuMemoryBufferHandle& handle, |
646 size_t width, | 646 size_t width, |
647 size_t height, | 647 size_t height, |
648 unsigned internalformat) { | 648 unsigned internalformat) { |
649 scoped_refptr<gfx::GLImage> image = | 649 scoped_refptr<gfx::GLImage> image = |
650 g_gpu_memory_buffer_factory->CreateImageForGpuMemoryBuffer( | 650 g_gpu_memory_buffer_factory->CreateImageForGpuMemoryBuffer( |
651 handle, gfx::Size(width, height), internalformat); | 651 handle, gfx::Size(width, height), internalformat); |
652 if (!image) | 652 if (!image.get()) |
653 return; | 653 return; |
654 | 654 |
655 // For Android specific workaround. | 655 // For Android specific workaround. |
656 gles2::ContextGroup* context_group = decoder_->GetContextGroup(); | 656 gles2::ContextGroup* context_group = decoder_->GetContextGroup(); |
657 if (context_group->feature_info()->workarounds().release_image_after_use) | 657 if (context_group->feature_info()->workarounds().release_image_after_use) |
658 image->SetReleaseAfterUse(); | 658 image->SetReleaseAfterUse(); |
659 | 659 |
660 if (decoder_) { | 660 if (decoder_) { |
661 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); | 661 gpu::gles2::ImageManager* image_manager = decoder_->GetImageManager(); |
662 DCHECK(image_manager); | 662 DCHECK(image_manager); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 } | 841 } |
842 #endif | 842 #endif |
843 | 843 |
844 // static | 844 // static |
845 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( | 845 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( |
846 InProcessGpuMemoryBufferFactory* factory) { | 846 InProcessGpuMemoryBufferFactory* factory) { |
847 g_gpu_memory_buffer_factory = factory; | 847 g_gpu_memory_buffer_factory = factory; |
848 } | 848 } |
849 | 849 |
850 } // namespace gpu | 850 } // namespace gpu |
OLD | NEW |