| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 DCHECK(service.get()); | 199 DCHECK(service.get()); |
| 200 } else { | 200 } else { |
| 201 service = new GpuInProcessThread; | 201 service = new GpuInProcessThread; |
| 202 } | 202 } |
| 203 return service; | 203 return service; |
| 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 last_put_offset_(-1), | 210 last_put_offset_(-1), |
| 210 flush_event_(false, false), | 211 flush_event_(false, false), |
| 211 service_(service.get() ? service : GetDefaultService()), | 212 service_(service.get() ? service : GetDefaultService()), |
| 212 gpu_thread_weak_ptr_factory_(this) { | 213 gpu_thread_weak_ptr_factory_(this) { |
| 213 if (!service) { | 214 if (!service) { |
| 214 base::AutoLock lock(default_thread_clients_lock_.Get()); | 215 base::AutoLock lock(default_thread_clients_lock_.Get()); |
| 215 default_thread_clients_.Get().insert(this); | 216 default_thread_clients_.Get().insert(this); |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 | 219 |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 base::AutoLock lock(state_after_last_flush_lock_); | 499 base::AutoLock lock(state_after_last_flush_lock_); |
| 499 state_after_last_flush_ = command_buffer_->GetLastState(); | 500 state_after_last_flush_ = command_buffer_->GetLastState(); |
| 500 } | 501 } |
| 501 DCHECK((!error::IsError(state_after_last_flush_.error) && !context_lost_) || | 502 DCHECK((!error::IsError(state_after_last_flush_.error) && !context_lost_) || |
| 502 (error::IsError(state_after_last_flush_.error) && context_lost_)); | 503 (error::IsError(state_after_last_flush_.error) && context_lost_)); |
| 503 | 504 |
| 504 // If we've processed all pending commands but still have pending queries, | 505 // If we've processed all pending commands but still have pending queries, |
| 505 // pump idle work until the query is passed. | 506 // pump idle work until the query is passed. |
| 506 if (put_offset == state_after_last_flush_.get_offset && | 507 if (put_offset == state_after_last_flush_.get_offset && |
| 507 gpu_scheduler_->HasMoreWork()) { | 508 gpu_scheduler_->HasMoreWork()) { |
| 508 service_->ScheduleIdleWork( | 509 ScheduleIdleWorkOnGpuThread(); |
| 509 base::Bind(&InProcessCommandBuffer::ScheduleMoreIdleWork, | |
| 510 gpu_thread_weak_ptr_)); | |
| 511 } | 510 } |
| 512 } | 511 } |
| 513 | 512 |
| 514 void InProcessCommandBuffer::ScheduleMoreIdleWork() { | 513 void InProcessCommandBuffer::PerformIdleWork() { |
| 515 CheckSequencedThread(); | 514 CheckSequencedThread(); |
| 515 idle_work_pending_ = false; |
| 516 base::AutoLock lock(command_buffer_lock_); | 516 base::AutoLock lock(command_buffer_lock_); |
| 517 if (gpu_scheduler_->HasMoreWork()) { | 517 if (gpu_scheduler_->HasMoreWork()) { |
| 518 gpu_scheduler_->PerformIdleWork(); | 518 gpu_scheduler_->PerformIdleWork(); |
| 519 service_->ScheduleIdleWork( | 519 ScheduleIdleWorkOnGpuThread(); |
| 520 base::Bind(&InProcessCommandBuffer::ScheduleMoreIdleWork, | |
| 521 gpu_thread_weak_ptr_)); | |
| 522 } | 520 } |
| 523 } | 521 } |
| 524 | 522 |
| 523 void InProcessCommandBuffer::ScheduleIdleWorkOnGpuThread() { |
| 524 CheckSequencedThread(); |
| 525 if (idle_work_pending_) |
| 526 return; |
| 527 idle_work_pending_ = true; |
| 528 service_->ScheduleIdleWork( |
| 529 base::Bind(&InProcessCommandBuffer::PerformIdleWork, |
| 530 gpu_thread_weak_ptr_)); |
| 531 } |
| 532 |
| 525 void InProcessCommandBuffer::Flush(int32 put_offset) { | 533 void InProcessCommandBuffer::Flush(int32 put_offset) { |
| 526 CheckSequencedThread(); | 534 CheckSequencedThread(); |
| 527 if (last_state_.error != gpu::error::kNoError) | 535 if (last_state_.error != gpu::error::kNoError) |
| 528 return; | 536 return; |
| 529 | 537 |
| 530 if (last_put_offset_ == put_offset) | 538 if (last_put_offset_ == put_offset) |
| 531 return; | 539 return; |
| 532 | 540 |
| 533 last_put_offset_ = put_offset; | 541 last_put_offset_ = put_offset; |
| 534 base::Closure task = base::Bind(&InProcessCommandBuffer::FlushOnGpuThread, | 542 base::Closure task = base::Bind(&InProcessCommandBuffer::FlushOnGpuThread, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 } | 841 } |
| 834 #endif | 842 #endif |
| 835 | 843 |
| 836 // static | 844 // static |
| 837 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( | 845 void InProcessCommandBuffer::SetGpuMemoryBufferFactory( |
| 838 InProcessGpuMemoryBufferFactory* factory) { | 846 InProcessGpuMemoryBufferFactory* factory) { |
| 839 g_gpu_memory_buffer_factory = factory; | 847 g_gpu_memory_buffer_factory = factory; |
| 840 } | 848 } |
| 841 | 849 |
| 842 } // namespace gpu | 850 } // namespace gpu |
| OLD | NEW |