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 "content/common/gpu/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 "content/common/gpu/client/gpu_channel_host.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/sync_token.h" | 21 #include "gpu/command_buffer/common/sync_token.h" |
23 #include "gpu/command_buffer/service/image_factory.h" | 22 #include "gpu/command_buffer/service/image_factory.h" |
| 23 #include "gpu/ipc/client/gpu_channel_host.h" |
24 #include "gpu/ipc/common/gpu_messages.h" | 24 #include "gpu/ipc/common/gpu_messages.h" |
25 #include "gpu/ipc/common/gpu_param_traits.h" | 25 #include "gpu/ipc/common/gpu_param_traits.h" |
26 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
27 #include "ui/gl/gl_bindings.h" | 27 #include "ui/gl/gl_bindings.h" |
28 | 28 |
29 namespace content { | 29 namespace gpu { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 gpu::CommandBufferId CommandBufferProxyID(int channel_id, int32_t route_id) { | 33 gpu::CommandBufferId CommandBufferProxyID(int channel_id, int32_t route_id) { |
34 return gpu::CommandBufferId::FromUnsafeValue( | 34 return gpu::CommandBufferId::FromUnsafeValue( |
35 (static_cast<uint64_t>(channel_id) << 32) | route_id); | 35 (static_cast<uint64_t>(channel_id) << 32) | route_id); |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
(...skipping 12 matching lines...) Expand all Loading... |
52 flushed_fence_sync_release_(0), | 52 flushed_fence_sync_release_(0), |
53 verified_fence_sync_release_(0), | 53 verified_fence_sync_release_(0), |
54 next_signal_id_(0), | 54 next_signal_id_(0), |
55 weak_this_(AsWeakPtr()), | 55 weak_this_(AsWeakPtr()), |
56 callback_thread_(base::ThreadTaskRunnerHandle::Get()) { | 56 callback_thread_(base::ThreadTaskRunnerHandle::Get()) { |
57 DCHECK(channel); | 57 DCHECK(channel); |
58 DCHECK(stream_id); | 58 DCHECK(stream_id); |
59 } | 59 } |
60 | 60 |
61 CommandBufferProxyImpl::~CommandBufferProxyImpl() { | 61 CommandBufferProxyImpl::~CommandBufferProxyImpl() { |
62 FOR_EACH_OBSERVER(DeletionObserver, | 62 FOR_EACH_OBSERVER(DeletionObserver, deletion_observers_, OnWillDeleteImpl()); |
63 deletion_observers_, | |
64 OnWillDeleteImpl()); | |
65 if (channel_) { | 63 if (channel_) { |
66 channel_->DestroyCommandBuffer(this); | 64 channel_->DestroyCommandBuffer(this); |
67 channel_ = nullptr; | 65 channel_ = nullptr; |
68 } | 66 } |
69 } | 67 } |
70 | 68 |
71 bool CommandBufferProxyImpl::OnMessageReceived(const IPC::Message& message) { | 69 bool CommandBufferProxyImpl::OnMessageReceived(const IPC::Message& message) { |
72 scoped_ptr<base::AutoLock> lock; | 70 scoped_ptr<base::AutoLock> lock; |
73 if (lock_) | 71 if (lock_) |
74 lock.reset(new base::AutoLock(*lock_)); | 72 lock.reset(new base::AutoLock(*lock_)); |
75 bool handled = true; | 73 bool handled = true; |
76 IPC_BEGIN_MESSAGE_MAP(CommandBufferProxyImpl, message) | 74 IPC_BEGIN_MESSAGE_MAP(CommandBufferProxyImpl, message) |
77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed); | 75 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed); |
78 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage); | 76 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage); |
79 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalAck, | 77 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalAck, OnSignalAck); |
80 OnSignalAck); | |
81 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted, | 78 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted, |
82 OnSwapBuffersCompleted); | 79 OnSwapBuffersCompleted); |
83 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateVSyncParameters, | 80 IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_UpdateVSyncParameters, |
84 OnUpdateVSyncParameters); | 81 OnUpdateVSyncParameters); |
85 IPC_MESSAGE_UNHANDLED(handled = false) | 82 IPC_MESSAGE_UNHANDLED(handled = false) |
86 IPC_END_MESSAGE_MAP() | 83 IPC_END_MESSAGE_MAP() |
87 | 84 |
88 if (!handled) { | 85 if (!handled) { |
89 DLOG(ERROR) << "Gpu process sent invalid message."; | 86 DLOG(ERROR) << "Gpu process sent invalid message."; |
90 InvalidGpuMessage(); | 87 InvalidGpuMessage(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 162 } |
166 | 163 |
167 void CommandBufferProxyImpl::SetContextLostCallback( | 164 void CommandBufferProxyImpl::SetContextLostCallback( |
168 const base::Closure& callback) { | 165 const base::Closure& callback) { |
169 CheckLock(); | 166 CheckLock(); |
170 context_lost_callback_ = callback; | 167 context_lost_callback_ = callback; |
171 } | 168 } |
172 | 169 |
173 bool CommandBufferProxyImpl::Initialize() { | 170 bool CommandBufferProxyImpl::Initialize() { |
174 TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize"); | 171 TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize"); |
175 shared_state_shm_.reset(channel_->factory()->AllocateSharedMemory( | 172 shared_state_shm_.reset(channel_->factory() |
176 sizeof(*shared_state())).release()); | 173 ->AllocateSharedMemory(sizeof(*shared_state())) |
| 174 .release()); |
177 if (!shared_state_shm_) | 175 if (!shared_state_shm_) |
178 return false; | 176 return false; |
179 | 177 |
180 if (!shared_state_shm_->Map(sizeof(*shared_state()))) | 178 if (!shared_state_shm_->Map(sizeof(*shared_state()))) |
181 return false; | 179 return false; |
182 | 180 |
183 shared_state()->Initialize(); | 181 shared_state()->Initialize(); |
184 | 182 |
185 // This handle is owned by the GPU process and must be passed to it or it | 183 // This handle is owned by the GPU process and must be passed to it or it |
186 // will leak. In otherwords, do not early out on error between here and the | 184 // will leak. In otherwords, do not early out on error between here and the |
187 // sending of the Initialize IPC below. | 185 // sending of the Initialize IPC below. |
188 base::SharedMemoryHandle handle = | 186 base::SharedMemoryHandle handle = |
189 channel_->ShareToGpuProcess(shared_state_shm_->handle()); | 187 channel_->ShareToGpuProcess(shared_state_shm_->handle()); |
190 if (!base::SharedMemory::IsHandleValid(handle)) | 188 if (!base::SharedMemory::IsHandleValid(handle)) |
191 return false; | 189 return false; |
192 | 190 |
193 bool result = false; | 191 bool result = false; |
194 if (!Send(new GpuCommandBufferMsg_Initialize( | 192 if (!Send(new GpuCommandBufferMsg_Initialize(route_id_, handle, &result, |
195 route_id_, handle, &result, &capabilities_))) { | 193 &capabilities_))) { |
196 LOG(ERROR) << "Could not send GpuCommandBufferMsg_Initialize."; | 194 LOG(ERROR) << "Could not send GpuCommandBufferMsg_Initialize."; |
197 return false; | 195 return false; |
198 } | 196 } |
199 | 197 |
200 if (!result) { | 198 if (!result) { |
201 LOG(ERROR) << "Failed to initialize command buffer service."; | 199 LOG(ERROR) << "Failed to initialize command buffer service."; |
202 return false; | 200 return false; |
203 } | 201 } |
204 | 202 |
205 capabilities_.image = true; | 203 capabilities_.image = true; |
206 | 204 |
207 return true; | 205 return true; |
208 } | 206 } |
209 | 207 |
210 gpu::CommandBuffer::State CommandBufferProxyImpl::GetLastState() { | 208 gpu::CommandBuffer::State CommandBufferProxyImpl::GetLastState() { |
211 return last_state_; | 209 return last_state_; |
212 } | 210 } |
213 | 211 |
214 int32_t CommandBufferProxyImpl::GetLastToken() { | 212 int32_t CommandBufferProxyImpl::GetLastToken() { |
215 TryUpdateState(); | 213 TryUpdateState(); |
216 return last_state_.token; | 214 return last_state_.token; |
217 } | 215 } |
218 | 216 |
219 void CommandBufferProxyImpl::Flush(int32_t put_offset) { | 217 void CommandBufferProxyImpl::Flush(int32_t put_offset) { |
220 CheckLock(); | 218 CheckLock(); |
221 if (last_state_.error != gpu::error::kNoError) | 219 if (last_state_.error != gpu::error::kNoError) |
222 return; | 220 return; |
223 | 221 |
224 TRACE_EVENT1("gpu", | 222 TRACE_EVENT1("gpu", "CommandBufferProxyImpl::Flush", "put_offset", |
225 "CommandBufferProxyImpl::Flush", | |
226 "put_offset", | |
227 put_offset); | 223 put_offset); |
228 | 224 |
229 bool put_offset_changed = last_put_offset_ != put_offset; | 225 bool put_offset_changed = last_put_offset_ != put_offset; |
230 last_put_offset_ = put_offset; | 226 last_put_offset_ = put_offset; |
231 last_barrier_put_offset_ = put_offset; | 227 last_barrier_put_offset_ = put_offset; |
232 | 228 |
233 if (channel_) { | 229 if (channel_) { |
234 const uint32_t flush_id = channel_->OrderingBarrier( | 230 const uint32_t flush_id = channel_->OrderingBarrier( |
235 route_id_, stream_id_, put_offset, ++flush_count_, latency_info_, | 231 route_id_, stream_id_, put_offset, ++flush_count_, latency_info_, |
236 put_offset_changed, true); | 232 put_offset_changed, true); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 288 } |
293 | 289 |
294 void CommandBufferProxyImpl::SetUpdateVSyncParametersCallback( | 290 void CommandBufferProxyImpl::SetUpdateVSyncParametersCallback( |
295 const UpdateVSyncParametersCallback& callback) { | 291 const UpdateVSyncParametersCallback& callback) { |
296 CheckLock(); | 292 CheckLock(); |
297 update_vsync_parameters_completion_callback_ = callback; | 293 update_vsync_parameters_completion_callback_ = callback; |
298 } | 294 } |
299 | 295 |
300 void CommandBufferProxyImpl::WaitForTokenInRange(int32_t start, int32_t end) { | 296 void CommandBufferProxyImpl::WaitForTokenInRange(int32_t start, int32_t end) { |
301 CheckLock(); | 297 CheckLock(); |
302 TRACE_EVENT2("gpu", | 298 TRACE_EVENT2("gpu", "CommandBufferProxyImpl::WaitForToken", "start", start, |
303 "CommandBufferProxyImpl::WaitForToken", | 299 "end", end); |
304 "start", | |
305 start, | |
306 "end", | |
307 end); | |
308 TryUpdateState(); | 300 TryUpdateState(); |
309 if (!InRange(start, end, last_state_.token) && | 301 if (!InRange(start, end, last_state_.token) && |
310 last_state_.error == gpu::error::kNoError) { | 302 last_state_.error == gpu::error::kNoError) { |
311 gpu::CommandBuffer::State state; | 303 gpu::CommandBuffer::State state; |
312 if (Send(new GpuCommandBufferMsg_WaitForTokenInRange( | 304 if (Send(new GpuCommandBufferMsg_WaitForTokenInRange(route_id_, start, end, |
313 route_id_, start, end, &state))) | 305 &state))) |
314 OnUpdateState(state); | 306 OnUpdateState(state); |
315 } | 307 } |
316 if (!InRange(start, end, last_state_.token) && | 308 if (!InRange(start, end, last_state_.token) && |
317 last_state_.error == gpu::error::kNoError) { | 309 last_state_.error == gpu::error::kNoError) { |
318 DLOG(ERROR) << "GPU state invalid after WaitForTokenInRange."; | 310 DLOG(ERROR) << "GPU state invalid after WaitForTokenInRange."; |
319 InvalidGpuReply(); | 311 InvalidGpuReply(); |
320 } | 312 } |
321 } | 313 } |
322 | 314 |
323 void CommandBufferProxyImpl::WaitForGetOffsetInRange(int32_t start, | 315 void CommandBufferProxyImpl::WaitForGetOffsetInRange(int32_t start, |
324 int32_t end) { | 316 int32_t end) { |
325 CheckLock(); | 317 CheckLock(); |
326 TRACE_EVENT2("gpu", | 318 TRACE_EVENT2("gpu", "CommandBufferProxyImpl::WaitForGetOffset", "start", |
327 "CommandBufferProxyImpl::WaitForGetOffset", | 319 start, "end", end); |
328 "start", | |
329 start, | |
330 "end", | |
331 end); | |
332 TryUpdateState(); | 320 TryUpdateState(); |
333 if (!InRange(start, end, last_state_.get_offset) && | 321 if (!InRange(start, end, last_state_.get_offset) && |
334 last_state_.error == gpu::error::kNoError) { | 322 last_state_.error == gpu::error::kNoError) { |
335 gpu::CommandBuffer::State state; | 323 gpu::CommandBuffer::State state; |
336 if (Send(new GpuCommandBufferMsg_WaitForGetOffsetInRange( | 324 if (Send(new GpuCommandBufferMsg_WaitForGetOffsetInRange(route_id_, start, |
337 route_id_, start, end, &state))) | 325 end, &state))) |
338 OnUpdateState(state); | 326 OnUpdateState(state); |
339 } | 327 } |
340 if (!InRange(start, end, last_state_.get_offset) && | 328 if (!InRange(start, end, last_state_.get_offset) && |
341 last_state_.error == gpu::error::kNoError) { | 329 last_state_.error == gpu::error::kNoError) { |
342 DLOG(ERROR) << "GPU state invalid after WaitForGetOffsetInRange."; | 330 DLOG(ERROR) << "GPU state invalid after WaitForGetOffsetInRange."; |
343 InvalidGpuReply(); | 331 InvalidGpuReply(); |
344 } | 332 } |
345 } | 333 } |
346 | 334 |
347 void CommandBufferProxyImpl::SetGetBuffer(int32_t shm_id) { | 335 void CommandBufferProxyImpl::SetGetBuffer(int32_t shm_id) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); | 487 return CreateImage(buffer->AsClientBuffer(), width, height, internal_format); |
500 } | 488 } |
501 | 489 |
502 uint32_t CommandBufferProxyImpl::CreateStreamTexture(uint32_t texture_id) { | 490 uint32_t CommandBufferProxyImpl::CreateStreamTexture(uint32_t texture_id) { |
503 CheckLock(); | 491 CheckLock(); |
504 if (last_state_.error != gpu::error::kNoError) | 492 if (last_state_.error != gpu::error::kNoError) |
505 return 0; | 493 return 0; |
506 | 494 |
507 int32_t stream_id = channel_->GenerateRouteID(); | 495 int32_t stream_id = channel_->GenerateRouteID(); |
508 bool succeeded = false; | 496 bool succeeded = false; |
509 Send(new GpuCommandBufferMsg_CreateStreamTexture( | 497 Send(new GpuCommandBufferMsg_CreateStreamTexture(route_id_, texture_id, |
510 route_id_, texture_id, stream_id, &succeeded)); | 498 stream_id, &succeeded)); |
511 if (!succeeded) { | 499 if (!succeeded) { |
512 DLOG(ERROR) << "GpuCommandBufferMsg_CreateStreamTexture returned failure"; | 500 DLOG(ERROR) << "GpuCommandBufferMsg_CreateStreamTexture returned failure"; |
513 return 0; | 501 return 0; |
514 } | 502 } |
515 return stream_id; | 503 return stream_id; |
516 } | 504 } |
517 | 505 |
518 void CommandBufferProxyImpl::SetLock(base::Lock* lock) { | 506 void CommandBufferProxyImpl::SetLock(base::Lock* lock) { |
519 lock_ = lock; | 507 lock_ = lock; |
520 } | 508 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 weak_this_)); | 725 weak_this_)); |
738 } | 726 } |
739 | 727 |
740 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() { | 728 void CommandBufferProxyImpl::InvalidGpuReplyOnClientThread() { |
741 scoped_ptr<base::AutoLock> lock; | 729 scoped_ptr<base::AutoLock> lock; |
742 if (lock_) | 730 if (lock_) |
743 lock.reset(new base::AutoLock(*lock_)); | 731 lock.reset(new base::AutoLock(*lock_)); |
744 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext); | 732 OnDestroyed(gpu::error::kInvalidGpuMessage, gpu::error::kLostContext); |
745 } | 733 } |
746 | 734 |
747 } // namespace content | 735 } // namespace gpu |
OLD | NEW |