| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 168 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 169 switches::kDisableGpuProgramCache)) { | 169 switches::kDisableGpuProgramCache)) { |
| 170 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); | 170 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); |
| 171 } | 171 } |
| 172 return program_cache_.get(); | 172 return program_cache_.get(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 InProcessCommandBuffer::InProcessCommandBuffer( | 175 InProcessCommandBuffer::InProcessCommandBuffer( |
| 176 const scoped_refptr<Service>& service) | 176 const scoped_refptr<Service>& service) |
| 177 : context_lost_(false), | 177 : context_lost_(false), |
| 178 idle_work_pending_(false), | 178 delayed_work_pending_(false), |
| 179 image_factory_(nullptr), | 179 image_factory_(nullptr), |
| 180 last_put_offset_(-1), | 180 last_put_offset_(-1), |
| 181 gpu_memory_buffer_manager_(nullptr), | 181 gpu_memory_buffer_manager_(nullptr), |
| 182 flush_event_(false, false), | 182 flush_event_(false, false), |
| 183 service_(GetInitialService(service)), | 183 service_(GetInitialService(service)), |
| 184 gpu_thread_weak_ptr_factory_(this) { | 184 gpu_thread_weak_ptr_factory_(this) { |
| 185 DCHECK(service_.get()); | 185 DCHECK(service_.get()); |
| 186 next_image_id_.GetNext(); | 186 next_image_id_.GetNext(); |
| 187 } | 187 } |
| 188 | 188 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 // Update state before signaling the flush event. | 487 // Update state before signaling the flush event. |
| 488 base::AutoLock lock(state_after_last_flush_lock_); | 488 base::AutoLock lock(state_after_last_flush_lock_); |
| 489 state_after_last_flush_ = command_buffer_->GetLastState(); | 489 state_after_last_flush_ = command_buffer_->GetLastState(); |
| 490 } | 490 } |
| 491 DCHECK((!error::IsError(state_after_last_flush_.error) && !context_lost_) || | 491 DCHECK((!error::IsError(state_after_last_flush_.error) && !context_lost_) || |
| 492 (error::IsError(state_after_last_flush_.error) && context_lost_)); | 492 (error::IsError(state_after_last_flush_.error) && context_lost_)); |
| 493 | 493 |
| 494 // If we've processed all pending commands but still have pending queries, | 494 // If we've processed all pending commands but still have pending queries, |
| 495 // pump idle work until the query is passed. | 495 // pump idle work until the query is passed. |
| 496 if (put_offset == state_after_last_flush_.get_offset && | 496 if (put_offset == state_after_last_flush_.get_offset && |
| 497 gpu_scheduler_->HasMoreWork()) { | 497 (gpu_scheduler_->HasMoreIdleWork() || |
| 498 ScheduleIdleWorkOnGpuThread(); | 498 gpu_scheduler_->HasPendingQueries())) { |
| 499 ScheduleDelayedWorkOnGpuThread(); |
| 499 } | 500 } |
| 500 } | 501 } |
| 501 | 502 |
| 502 void InProcessCommandBuffer::PerformIdleWork() { | 503 void InProcessCommandBuffer::PerformDelayedWork() { |
| 503 CheckSequencedThread(); | 504 CheckSequencedThread(); |
| 504 idle_work_pending_ = false; | 505 delayed_work_pending_ = false; |
| 505 base::AutoLock lock(command_buffer_lock_); | 506 base::AutoLock lock(command_buffer_lock_); |
| 506 if (MakeCurrent() && gpu_scheduler_->HasMoreWork()) { | 507 if (MakeCurrent()) { |
| 507 gpu_scheduler_->PerformIdleWork(); | 508 gpu_scheduler_->PerformIdleWork(); |
| 508 ScheduleIdleWorkOnGpuThread(); | 509 gpu_scheduler_->ProcessPendingQueries(); |
| 510 if (gpu_scheduler_->HasMoreIdleWork() || |
| 511 gpu_scheduler_->HasPendingQueries()) { |
| 512 ScheduleDelayedWorkOnGpuThread(); |
| 513 } |
| 509 } | 514 } |
| 510 } | 515 } |
| 511 | 516 |
| 512 void InProcessCommandBuffer::ScheduleIdleWorkOnGpuThread() { | 517 void InProcessCommandBuffer::ScheduleDelayedWorkOnGpuThread() { |
| 513 CheckSequencedThread(); | 518 CheckSequencedThread(); |
| 514 if (idle_work_pending_) | 519 if (delayed_work_pending_) |
| 515 return; | 520 return; |
| 516 idle_work_pending_ = true; | 521 delayed_work_pending_ = true; |
| 517 service_->ScheduleIdleWork( | 522 service_->ScheduleDelayedWork(base::Bind( |
| 518 base::Bind(&InProcessCommandBuffer::PerformIdleWork, | 523 &InProcessCommandBuffer::PerformDelayedWork, gpu_thread_weak_ptr_)); |
| 519 gpu_thread_weak_ptr_)); | |
| 520 } | 524 } |
| 521 | 525 |
| 522 void InProcessCommandBuffer::Flush(int32 put_offset) { | 526 void InProcessCommandBuffer::Flush(int32 put_offset) { |
| 523 CheckSequencedThread(); | 527 CheckSequencedThread(); |
| 524 if (last_state_.error != gpu::error::kNoError) | 528 if (last_state_.error != gpu::error::kNoError) |
| 525 return; | 529 return; |
| 526 | 530 |
| 527 if (last_put_offset_ == put_offset) | 531 if (last_put_offset_ == put_offset) |
| 528 return; | 532 return; |
| 529 | 533 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 base::RefCountedThreadSafe<GpuInProcessThread>::AddRef(); | 926 base::RefCountedThreadSafe<GpuInProcessThread>::AddRef(); |
| 923 } | 927 } |
| 924 void GpuInProcessThread::Release() const { | 928 void GpuInProcessThread::Release() const { |
| 925 base::RefCountedThreadSafe<GpuInProcessThread>::Release(); | 929 base::RefCountedThreadSafe<GpuInProcessThread>::Release(); |
| 926 } | 930 } |
| 927 | 931 |
| 928 void GpuInProcessThread::ScheduleTask(const base::Closure& task) { | 932 void GpuInProcessThread::ScheduleTask(const base::Closure& task) { |
| 929 task_runner()->PostTask(FROM_HERE, task); | 933 task_runner()->PostTask(FROM_HERE, task); |
| 930 } | 934 } |
| 931 | 935 |
| 932 void GpuInProcessThread::ScheduleIdleWork(const base::Closure& callback) { | 936 void GpuInProcessThread::ScheduleDelayedWork(const base::Closure& callback) { |
| 933 // Match delay with GpuCommandBufferStub. | 937 // Match delay with GpuCommandBufferStub. |
| 934 task_runner()->PostDelayedTask(FROM_HERE, callback, | 938 task_runner()->PostDelayedTask(FROM_HERE, callback, |
| 935 base::TimeDelta::FromMilliseconds(2)); | 939 base::TimeDelta::FromMilliseconds(2)); |
| 936 } | 940 } |
| 937 | 941 |
| 938 bool GpuInProcessThread::UseVirtualizedGLContexts() { | 942 bool GpuInProcessThread::UseVirtualizedGLContexts() { |
| 939 return false; | 943 return false; |
| 940 } | 944 } |
| 941 | 945 |
| 942 scoped_refptr<gles2::ShaderTranslatorCache> | 946 scoped_refptr<gles2::ShaderTranslatorCache> |
| 943 GpuInProcessThread::shader_translator_cache() { | 947 GpuInProcessThread::shader_translator_cache() { |
| 944 if (!shader_translator_cache_.get()) | 948 if (!shader_translator_cache_.get()) |
| 945 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; | 949 shader_translator_cache_ = new gpu::gles2::ShaderTranslatorCache; |
| 946 return shader_translator_cache_; | 950 return shader_translator_cache_; |
| 947 } | 951 } |
| 948 | 952 |
| 949 scoped_refptr<gles2::FramebufferCompletenessCache> | 953 scoped_refptr<gles2::FramebufferCompletenessCache> |
| 950 GpuInProcessThread::framebuffer_completeness_cache() { | 954 GpuInProcessThread::framebuffer_completeness_cache() { |
| 951 if (!framebuffer_completeness_cache_.get()) | 955 if (!framebuffer_completeness_cache_.get()) |
| 952 framebuffer_completeness_cache_ = | 956 framebuffer_completeness_cache_ = |
| 953 new gpu::gles2::FramebufferCompletenessCache; | 957 new gpu::gles2::FramebufferCompletenessCache; |
| 954 return framebuffer_completeness_cache_; | 958 return framebuffer_completeness_cache_; |
| 955 } | 959 } |
| 956 | 960 |
| 957 SyncPointManager* GpuInProcessThread::sync_point_manager() { | 961 SyncPointManager* GpuInProcessThread::sync_point_manager() { |
| 958 return sync_point_manager_; | 962 return sync_point_manager_; |
| 959 } | 963 } |
| 960 | 964 |
| 961 } // namespace gpu | 965 } // namespace gpu |
| OLD | NEW |