| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/client/command_buffer_proxy_impl.h" | 5 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "gpu/command_buffer/client/gpu_control_client.h" | |
| 17 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 16 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
| 18 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 17 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
| 19 #include "gpu/command_buffer/common/command_buffer_id.h" | 18 #include "gpu/command_buffer/common/command_buffer_id.h" |
| 20 #include "gpu/command_buffer/common/command_buffer_shared.h" | 19 #include "gpu/command_buffer/common/command_buffer_shared.h" |
| 21 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 20 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 22 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | 21 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
| 23 #include "gpu/command_buffer/common/sync_token.h" | 22 #include "gpu/command_buffer/common/sync_token.h" |
| 24 #include "gpu/ipc/client/gpu_channel_host.h" | 23 #include "gpu/ipc/client/gpu_channel_host.h" |
| 25 #include "gpu/ipc/common/gpu_messages.h" | 24 #include "gpu/ipc/common/gpu_messages.h" |
| 26 #include "gpu/ipc/common/gpu_param_traits.h" | 25 #include "gpu/ipc/common/gpu_param_traits.h" |
| 27 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
| 28 #include "ui/gl/gl_bindings.h" | 27 #include "ui/gl/gl_bindings.h" |
| 29 | 28 |
| 30 namespace gpu { | 29 namespace gpu { |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 gpu::CommandBufferId CommandBufferProxyID(int channel_id, int32_t route_id) { | 33 gpu::CommandBufferId CommandBufferProxyID(int channel_id, int32_t route_id) { |
| 35 return gpu::CommandBufferId::FromUnsafeValue( | 34 return gpu::CommandBufferId::FromUnsafeValue( |
| 36 (static_cast<uint64_t>(channel_id) << 32) | route_id); | 35 (static_cast<uint64_t>(channel_id) << 32) | route_id); |
| 37 } | 36 } |
| 38 | 37 |
| 39 } // namespace | 38 } // namespace |
| 40 | 39 |
| 41 CommandBufferProxyImpl::CommandBufferProxyImpl(GpuChannelHost* channel, | 40 CommandBufferProxyImpl::CommandBufferProxyImpl(GpuChannelHost* channel, |
| 42 int32_t route_id, | 41 int32_t route_id, |
| 43 int32_t stream_id) | 42 int32_t stream_id) |
| 44 : lock_(nullptr), | 43 : lock_(nullptr), |
| 45 gpu_control_client_(nullptr), | |
| 46 channel_(channel), | 44 channel_(channel), |
| 47 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)), | 45 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)), |
| 48 route_id_(route_id), | 46 route_id_(route_id), |
| 49 stream_id_(stream_id), | 47 stream_id_(stream_id), |
| 50 flush_count_(0), | 48 flush_count_(0), |
| 51 last_put_offset_(-1), | 49 last_put_offset_(-1), |
| 52 last_barrier_put_offset_(-1), | 50 last_barrier_put_offset_(-1), |
| 53 next_fence_sync_release_(1), | 51 next_fence_sync_release_(1), |
| 54 flushed_fence_sync_release_(0), | 52 flushed_fence_sync_release_(0), |
| 55 verified_fence_sync_release_(0), | 53 verified_fence_sync_release_(0), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // (exit_on_context_lost), so try to find out the original reason. | 102 // (exit_on_context_lost), so try to find out the original reason. |
| 105 if (last_state_.error == gpu::error::kLostContext) | 103 if (last_state_.error == gpu::error::kLostContext) |
| 106 context_lost_reason = last_state_.context_lost_reason; | 104 context_lost_reason = last_state_.context_lost_reason; |
| 107 } | 105 } |
| 108 OnDestroyed(context_lost_reason, gpu::error::kLostContext); | 106 OnDestroyed(context_lost_reason, gpu::error::kLostContext); |
| 109 } | 107 } |
| 110 | 108 |
| 111 void CommandBufferProxyImpl::OnDestroyed(gpu::error::ContextLostReason reason, | 109 void CommandBufferProxyImpl::OnDestroyed(gpu::error::ContextLostReason reason, |
| 112 gpu::error::Error error) { | 110 gpu::error::Error error) { |
| 113 CheckLock(); | 111 CheckLock(); |
| 112 // Prevent any further messages from being sent. |
| 113 if (channel_) { |
| 114 channel_->DestroyCommandBuffer(this); |
| 115 channel_ = nullptr; |
| 116 } |
| 114 | 117 |
| 115 // When the client sees that the context is lost, they should delete this | 118 // When the client sees that the context is lost, they should delete this |
| 116 // CommandBufferProxyImpl and create a new one. | 119 // CommandBufferProxyImpl and create a new one. |
| 117 last_state_.error = error; | 120 last_state_.error = error; |
| 118 last_state_.context_lost_reason = reason; | 121 last_state_.context_lost_reason = reason; |
| 119 | 122 |
| 120 // Prevent any further messages from being sent, and ensure we only call | 123 if (!context_lost_callback_.is_null()) { |
| 121 // the client for lost context a single time. | 124 context_lost_callback_.Run(); |
| 122 if (channel_) { | 125 // Avoid calling the error callback more than once. |
| 123 channel_->DestroyCommandBuffer(this); | 126 context_lost_callback_.Reset(); |
| 124 channel_ = nullptr; | |
| 125 if (gpu_control_client_) | |
| 126 gpu_control_client_->OnGpuControlLostContext(); | |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 void CommandBufferProxyImpl::OnConsoleMessage( | 130 void CommandBufferProxyImpl::OnConsoleMessage( |
| 131 const GPUCommandBufferConsoleMessage& message) { | 131 const GPUCommandBufferConsoleMessage& message) { |
| 132 if (gpu_control_client_) | 132 if (!console_message_callback_.is_null()) { |
| 133 gpu_control_client_->OnGpuControlErrorMessage(message.message.c_str(), | 133 console_message_callback_.Run(message.message, message.id); |
| 134 message.id); | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) { | 137 void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) { |
| 138 scoped_ptr<base::AutoLock> lock; | 138 scoped_ptr<base::AutoLock> lock; |
| 139 if (lock_) | 139 if (lock_) |
| 140 lock.reset(new base::AutoLock(*lock_)); | 140 lock.reset(new base::AutoLock(*lock_)); |
| 141 deletion_observers_.AddObserver(observer); | 141 deletion_observers_.AddObserver(observer); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void CommandBufferProxyImpl::RemoveDeletionObserver( | 144 void CommandBufferProxyImpl::RemoveDeletionObserver( |
| 145 DeletionObserver* observer) { | 145 DeletionObserver* observer) { |
| 146 scoped_ptr<base::AutoLock> lock; | 146 scoped_ptr<base::AutoLock> lock; |
| 147 if (lock_) | 147 if (lock_) |
| 148 lock.reset(new base::AutoLock(*lock_)); | 148 lock.reset(new base::AutoLock(*lock_)); |
| 149 deletion_observers_.RemoveObserver(observer); | 149 deletion_observers_.RemoveObserver(observer); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) { | 152 void CommandBufferProxyImpl::OnSignalAck(uint32_t id) { |
| 153 SignalTaskMap::iterator it = signal_tasks_.find(id); | 153 SignalTaskMap::iterator it = signal_tasks_.find(id); |
| 154 if (it == signal_tasks_.end()) { | 154 if (it == signal_tasks_.end()) { |
| 155 DLOG(ERROR) << "Gpu process sent invalid SignalAck."; | 155 DLOG(ERROR) << "Gpu process sent invalid SignalAck."; |
| 156 InvalidGpuMessage(); | 156 InvalidGpuMessage(); |
| 157 return; | 157 return; |
| 158 } | 158 } |
| 159 base::Closure callback = it->second; | 159 base::Closure callback = it->second; |
| 160 signal_tasks_.erase(it); | 160 signal_tasks_.erase(it); |
| 161 callback.Run(); | 161 callback.Run(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void CommandBufferProxyImpl::SetContextLostCallback( |
| 165 const base::Closure& callback) { |
| 166 CheckLock(); |
| 167 context_lost_callback_ = callback; |
| 168 } |
| 169 |
| 164 bool CommandBufferProxyImpl::Initialize() { | 170 bool CommandBufferProxyImpl::Initialize() { |
| 165 TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize"); | 171 TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize"); |
| 166 shared_state_shm_.reset(channel_->factory() | 172 shared_state_shm_.reset(channel_->factory() |
| 167 ->AllocateSharedMemory(sizeof(*shared_state())) | 173 ->AllocateSharedMemory(sizeof(*shared_state())) |
| 168 .release()); | 174 .release()); |
| 169 if (!shared_state_shm_) | 175 if (!shared_state_shm_) |
| 170 return false; | 176 return false; |
| 171 | 177 |
| 172 if (!shared_state_shm_->Map(sizeof(*shared_state()))) | 178 if (!shared_state_shm_->Map(sizeof(*shared_state()))) |
| 173 return false; | 179 return false; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 387 } |
| 382 | 388 |
| 383 void CommandBufferProxyImpl::DestroyTransferBuffer(int32_t id) { | 389 void CommandBufferProxyImpl::DestroyTransferBuffer(int32_t id) { |
| 384 CheckLock(); | 390 CheckLock(); |
| 385 if (last_state_.error != gpu::error::kNoError) | 391 if (last_state_.error != gpu::error::kNoError) |
| 386 return; | 392 return; |
| 387 | 393 |
| 388 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); | 394 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); |
| 389 } | 395 } |
| 390 | 396 |
| 391 void CommandBufferProxyImpl::SetGpuControlClient(GpuControlClient* client) { | |
| 392 CheckLock(); | |
| 393 gpu_control_client_ = client; | |
| 394 } | |
| 395 | |
| 396 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { | 397 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { |
| 397 return capabilities_; | 398 return capabilities_; |
| 398 } | 399 } |
| 399 | 400 |
| 400 int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, | 401 int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, |
| 401 size_t width, | 402 size_t width, |
| 402 size_t height, | 403 size_t height, |
| 403 unsigned internal_format) { | 404 unsigned internal_format) { |
| 404 CheckLock(); | 405 CheckLock(); |
| 405 if (last_state_.error != gpu::error::kNoError) | 406 if (last_state_.error != gpu::error::kNoError) |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 } | 655 } |
| 655 | 656 |
| 656 void CommandBufferProxyImpl::OnUpdateState( | 657 void CommandBufferProxyImpl::OnUpdateState( |
| 657 const gpu::CommandBuffer::State& state) { | 658 const gpu::CommandBuffer::State& state) { |
| 658 // Handle wraparound. It works as long as we don't have more than 2B state | 659 // Handle wraparound. It works as long as we don't have more than 2B state |
| 659 // updates in flight across which reordering occurs. | 660 // updates in flight across which reordering occurs. |
| 660 if (state.generation - last_state_.generation < 0x80000000U) | 661 if (state.generation - last_state_.generation < 0x80000000U) |
| 661 last_state_ = state; | 662 last_state_ = state; |
| 662 } | 663 } |
| 663 | 664 |
| 665 void CommandBufferProxyImpl::SetOnConsoleMessageCallback( |
| 666 const GpuConsoleMessageCallback& callback) { |
| 667 CheckLock(); |
| 668 console_message_callback_ = callback; |
| 669 } |
| 670 |
| 664 void CommandBufferProxyImpl::TryUpdateState() { | 671 void CommandBufferProxyImpl::TryUpdateState() { |
| 665 if (last_state_.error == gpu::error::kNoError) | 672 if (last_state_.error == gpu::error::kNoError) |
| 666 shared_state()->Read(&last_state_); | 673 shared_state()->Read(&last_state_); |
| 667 } | 674 } |
| 668 | 675 |
| 669 void CommandBufferProxyImpl::UpdateVerifiedReleases(uint32_t verified_flush) { | 676 void CommandBufferProxyImpl::UpdateVerifiedReleases(uint32_t verified_flush) { |
| 670 while (!flushed_release_flush_id_.empty()) { | 677 while (!flushed_release_flush_id_.empty()) { |
| 671 const std::pair<uint64_t, uint32_t>& front_item = | 678 const std::pair<uint64_t, uint32_t>& front_item = |
| 672 flushed_release_flush_id_.front(); | 679 flushed_release_flush_id_.front(); |
| 673 if (front_item.second > verified_flush) | 680 if (front_item.second > verified_flush) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 } | 726 } |
| 720 | 727 |
| 721 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() { | 728 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() { |
| 722 scoped_ptr<base::AutoLock> lock; | 729 scoped_ptr<base::AutoLock> lock; |
| 723 if (lock_) | 730 if (lock_) |
| 724 lock.reset(new base::AutoLock(*lock_)); | 731 lock.reset(new base::AutoLock(*lock_)); |
| 725 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext); | 732 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext); |
| 726 } | 733 } |
| 727 | 734 |
| 728 } // namespace gpu | 735 } // namespace gpu |
| OLD | NEW |