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