Chromium Code Reviews| 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/ipc/in_process_command_buffer.h" | 5 #include "gpu/ipc/in_process_command_buffer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 sync_point_order_data_->PauseProcessingOrderNumber(task->order_number); | 536 sync_point_order_data_->PauseProcessingOrderNumber(task->order_number); |
| 537 return; | 537 return; |
| 538 } | 538 } |
| 539 sync_point_order_data_->FinishProcessingOrderNumber(task->order_number); | 539 sync_point_order_data_->FinishProcessingOrderNumber(task->order_number); |
| 540 task_queue_.pop(); | 540 task_queue_.pop(); |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 | 543 |
| 544 CommandBuffer::State InProcessCommandBuffer::GetLastState() { | 544 CommandBuffer::State InProcessCommandBuffer::GetLastState() { |
| 545 CheckSequencedThread(); | 545 CheckSequencedThread(); |
| 546 GetStateFast(); | |
| 546 return last_state_; | 547 return last_state_; |
|
piman
2016/12/07 20:30:13
nit: this whole function is fully equivalent to Ge
| |
| 547 } | 548 } |
| 548 | 549 |
| 549 int32_t InProcessCommandBuffer::GetLastToken() { | |
| 550 CheckSequencedThread(); | |
| 551 GetStateFast(); | |
| 552 return last_state_.token; | |
| 553 } | |
| 554 | |
| 555 void InProcessCommandBuffer::FlushOnGpuThread(int32_t put_offset) { | 550 void InProcessCommandBuffer::FlushOnGpuThread(int32_t put_offset) { |
| 556 CheckSequencedThread(); | 551 CheckSequencedThread(); |
| 557 ScopedEvent handle_flush(&flush_event_); | 552 ScopedEvent handle_flush(&flush_event_); |
| 558 base::AutoLock lock(command_buffer_lock_); | 553 base::AutoLock lock(command_buffer_lock_); |
| 559 | 554 |
| 560 { | 555 { |
| 561 command_buffer_->Flush(put_offset); | 556 command_buffer_->Flush(put_offset); |
| 562 { | 557 { |
| 563 // Update state before signaling the flush event. | 558 // Update state before signaling the flush event. |
| 564 base::AutoLock lock(state_after_last_flush_lock_); | 559 base::AutoLock lock(state_after_last_flush_lock_); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 gpu_thread_weak_ptr_, put_offset); | 605 gpu_thread_weak_ptr_, put_offset); |
| 611 QueueTask(false, task); | 606 QueueTask(false, task); |
| 612 | 607 |
| 613 flushed_fence_sync_release_ = next_fence_sync_release_ - 1; | 608 flushed_fence_sync_release_ = next_fence_sync_release_ - 1; |
| 614 } | 609 } |
| 615 | 610 |
| 616 void InProcessCommandBuffer::OrderingBarrier(int32_t put_offset) { | 611 void InProcessCommandBuffer::OrderingBarrier(int32_t put_offset) { |
| 617 Flush(put_offset); | 612 Flush(put_offset); |
| 618 } | 613 } |
| 619 | 614 |
| 620 void InProcessCommandBuffer::WaitForTokenInRange(int32_t start, int32_t end) { | 615 CommandBuffer::State InProcessCommandBuffer::WaitForTokenInRange(int32_t start, |
| 616 int32_t end) { | |
| 621 CheckSequencedThread(); | 617 CheckSequencedThread(); |
| 622 while (!InRange(start, end, GetLastToken()) && | 618 while (!InRange(start, end, GetLastState().token) && |
| 623 last_state_.error == gpu::error::kNoError) { | 619 GetLastState().error == gpu::error::kNoError) { |
|
piman
2016/12/07 20:30:13
Should we avoid taking the lock twice (2 calls to
sunnyps
2016/12/08 01:14:16
Done.
| |
| 624 flush_event_.Wait(); | 620 flush_event_.Wait(); |
| 625 } | 621 } |
| 622 return last_state_; | |
| 626 } | 623 } |
| 627 | 624 |
| 628 void InProcessCommandBuffer::WaitForGetOffsetInRange(int32_t start, | 625 CommandBuffer::State InProcessCommandBuffer::WaitForGetOffsetInRange( |
| 629 int32_t end) { | 626 int32_t start, |
| 627 int32_t end) { | |
| 630 CheckSequencedThread(); | 628 CheckSequencedThread(); |
| 631 | 629 while (!InRange(start, end, GetLastState().get_offset) && |
| 632 GetStateFast(); | 630 GetLastState().error == gpu::error::kNoError) { |
|
piman
2016/12/07 20:30:13
Ditto
sunnyps
2016/12/08 01:14:16
Done.
| |
| 633 while (!InRange(start, end, last_state_.get_offset) && | |
| 634 last_state_.error == gpu::error::kNoError) { | |
| 635 flush_event_.Wait(); | 631 flush_event_.Wait(); |
| 636 GetStateFast(); | |
| 637 } | 632 } |
| 633 return last_state_; | |
| 638 } | 634 } |
| 639 | 635 |
| 640 void InProcessCommandBuffer::SetGetBuffer(int32_t shm_id) { | 636 void InProcessCommandBuffer::SetGetBuffer(int32_t shm_id) { |
| 641 CheckSequencedThread(); | 637 CheckSequencedThread(); |
| 642 if (last_state_.error != gpu::error::kNoError) | 638 if (last_state_.error != gpu::error::kNoError) |
| 643 return; | 639 return; |
| 644 | 640 |
| 645 base::WaitableEvent completion( | 641 base::WaitableEvent completion( |
| 646 base::WaitableEvent::ResetPolicy::MANUAL, | 642 base::WaitableEvent::ResetPolicy::MANUAL, |
| 647 base::WaitableEvent::InitialState::NOT_SIGNALED); | 643 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 } | 1019 } |
| 1024 | 1020 |
| 1025 bool InProcessCommandBuffer::IsFenceSyncFlushed(uint64_t release) { | 1021 bool InProcessCommandBuffer::IsFenceSyncFlushed(uint64_t release) { |
| 1026 return release <= flushed_fence_sync_release_; | 1022 return release <= flushed_fence_sync_release_; |
| 1027 } | 1023 } |
| 1028 | 1024 |
| 1029 bool InProcessCommandBuffer::IsFenceSyncFlushReceived(uint64_t release) { | 1025 bool InProcessCommandBuffer::IsFenceSyncFlushReceived(uint64_t release) { |
| 1030 return IsFenceSyncFlushed(release); | 1026 return IsFenceSyncFlushed(release); |
| 1031 } | 1027 } |
| 1032 | 1028 |
| 1029 bool InProcessCommandBuffer::IsFenceSyncReleased(uint64_t release) { | |
|
piman
2016/12/07 20:30:13
We will need this one to be thread-safe too for mu
sunnyps
2016/12/08 01:14:16
Made this thread-safe although there's no real ben
| |
| 1030 State state = GetStateFast(); | |
| 1031 return release <= state.release_count; | |
| 1032 } | |
| 1033 | |
| 1033 void InProcessCommandBuffer::SignalSyncToken(const SyncToken& sync_token, | 1034 void InProcessCommandBuffer::SignalSyncToken(const SyncToken& sync_token, |
| 1034 const base::Closure& callback) { | 1035 const base::Closure& callback) { |
| 1035 CheckSequencedThread(); | 1036 CheckSequencedThread(); |
| 1036 QueueTask( | 1037 QueueTask( |
| 1037 true, | 1038 true, |
| 1038 base::Bind(&InProcessCommandBuffer::SignalSyncTokenOnGpuThread, | 1039 base::Bind(&InProcessCommandBuffer::SignalSyncTokenOnGpuThread, |
| 1039 base::Unretained(this), sync_token, WrapCallback(callback))); | 1040 base::Unretained(this), sync_token, WrapCallback(callback))); |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 bool InProcessCommandBuffer::CanWaitUnverifiedSyncToken( | 1043 bool InProcessCommandBuffer::CanWaitUnverifiedSyncToken( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1125 void InProcessCommandBuffer::SetSwapBuffersCompletionCallback( | 1126 void InProcessCommandBuffer::SetSwapBuffersCompletionCallback( |
| 1126 const SwapBuffersCompletionCallback& callback) { | 1127 const SwapBuffersCompletionCallback& callback) { |
| 1127 swap_buffers_completion_callback_ = callback; | 1128 swap_buffers_completion_callback_ = callback; |
| 1128 } | 1129 } |
| 1129 | 1130 |
| 1130 void InProcessCommandBuffer::SetUpdateVSyncParametersCallback( | 1131 void InProcessCommandBuffer::SetUpdateVSyncParametersCallback( |
| 1131 const UpdateVSyncParametersCallback& callback) { | 1132 const UpdateVSyncParametersCallback& callback) { |
| 1132 update_vsync_parameters_completion_callback_ = callback; | 1133 update_vsync_parameters_completion_callback_ = callback; |
| 1133 } | 1134 } |
| 1134 | 1135 |
| 1135 gpu::error::Error InProcessCommandBuffer::GetLastError() { | |
| 1136 CheckSequencedThread(); | |
| 1137 return last_state_.error; | |
| 1138 } | |
| 1139 | |
| 1140 namespace { | 1136 namespace { |
| 1141 | 1137 |
| 1142 void PostCallback( | 1138 void PostCallback( |
| 1143 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 1139 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 1144 const base::Closure& callback) { | 1140 const base::Closure& callback) { |
| 1145 // The task_runner.get() check is to support using InProcessCommandBuffer on | 1141 // The task_runner.get() check is to support using InProcessCommandBuffer on |
| 1146 // a thread without a message loop. | 1142 // a thread without a message loop. |
| 1147 if (task_runner.get() && !task_runner->BelongsToCurrentThread()) { | 1143 if (task_runner.get() && !task_runner->BelongsToCurrentThread()) { |
| 1148 task_runner->PostTask(FROM_HERE, callback); | 1144 task_runner->PostTask(FROM_HERE, callback); |
| 1149 } else { | 1145 } else { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1173 return wrapped_callback; | 1169 return wrapped_callback; |
| 1174 } | 1170 } |
| 1175 | 1171 |
| 1176 InProcessCommandBuffer::GpuTask::GpuTask(const base::Closure& callback, | 1172 InProcessCommandBuffer::GpuTask::GpuTask(const base::Closure& callback, |
| 1177 uint32_t order_number) | 1173 uint32_t order_number) |
| 1178 : callback(callback), order_number(order_number) {} | 1174 : callback(callback), order_number(order_number) {} |
| 1179 | 1175 |
| 1180 InProcessCommandBuffer::GpuTask::~GpuTask() {} | 1176 InProcessCommandBuffer::GpuTask::~GpuTask() {} |
| 1181 | 1177 |
| 1182 } // namespace gpu | 1178 } // namespace gpu |
| OLD | NEW |