Chromium Code Reviews| 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 "content/common/gpu/client/command_buffer_proxy_impl.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 deletion_observers_.RemoveObserver(observer); | 162 deletion_observers_.RemoveObserver(observer); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void CommandBufferProxyImpl::OnSetMemoryAllocation( | 165 void CommandBufferProxyImpl::OnSetMemoryAllocation( |
| 166 const gpu::MemoryAllocation& allocation) { | 166 const gpu::MemoryAllocation& allocation) { |
| 167 if (!memory_allocation_changed_callback_.is_null()) | 167 if (!memory_allocation_changed_callback_.is_null()) |
| 168 memory_allocation_changed_callback_.Run(allocation); | 168 memory_allocation_changed_callback_.Run(allocation); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void CommandBufferProxyImpl::OnSignalSyncPointAck(uint32 id) { | 171 void CommandBufferProxyImpl::OnSignalSyncPointAck(uint32 id) { |
| 172 SignalTaskMap::iterator it = signal_tasks_.find(id); | 172 base::Closure callback; |
| 173 DCHECK(it != signal_tasks_.end()); | 173 { |
| 174 base::Closure callback = it->second; | 174 base::AutoLock lock(signal_lock_); |
|
reveman
2014/10/22 22:42:47
Alternatively, we can make sure to only access sig
| |
| 175 signal_tasks_.erase(it); | 175 SignalTaskMap::iterator it = signal_tasks_.find(id); |
| 176 DCHECK(it != signal_tasks_.end()); | |
| 177 callback = it->second; | |
| 178 signal_tasks_.erase(it); | |
| 179 } | |
| 176 callback.Run(); | 180 callback.Run(); |
| 177 } | 181 } |
| 178 | 182 |
| 179 void CommandBufferProxyImpl::SetChannelErrorCallback( | 183 void CommandBufferProxyImpl::SetChannelErrorCallback( |
| 180 const base::Closure& callback) { | 184 const base::Closure& callback) { |
| 181 channel_error_callback_ = callback; | 185 channel_error_callback_ = callback; |
| 182 } | 186 } |
| 183 | 187 |
| 184 bool CommandBufferProxyImpl::Initialize() { | 188 bool CommandBufferProxyImpl::Initialize() { |
| 185 TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize"); | 189 TRACE_EVENT0("gpu", "CommandBufferProxyImpl::Initialize"); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 const std::vector<ui::LatencyInfo>& latency_info) { | 256 const std::vector<ui::LatencyInfo>& latency_info) { |
| 253 for (size_t i = 0; i < latency_info.size(); i++) | 257 for (size_t i = 0; i < latency_info.size(); i++) |
| 254 latency_info_.push_back(latency_info[i]); | 258 latency_info_.push_back(latency_info[i]); |
| 255 } | 259 } |
| 256 | 260 |
| 257 void CommandBufferProxyImpl::SetSwapBuffersCompletionCallback( | 261 void CommandBufferProxyImpl::SetSwapBuffersCompletionCallback( |
| 258 const SwapBuffersCompletionCallback& callback) { | 262 const SwapBuffersCompletionCallback& callback) { |
| 259 swap_buffers_completion_callback_ = callback; | 263 swap_buffers_completion_callback_ = callback; |
| 260 } | 264 } |
| 261 | 265 |
| 266 void CommandBufferProxyImpl::WaitForPendingGpuMemoryBufferUsageToComplete( | |
| 267 const base::Closure& callback) { | |
| 268 uint32 sync_point = InsertSyncPoint(); | |
| 269 SignalSyncPoint( | |
| 270 sync_point, | |
| 271 base::Bind(&CommandBufferProxyImpl::GpuMemoryBufferSyncPointSignalled, | |
| 272 base::Unretained(this), | |
| 273 sync_point)); | |
| 274 | |
| 275 base::AutoLock lock(gpu_memory_buffer_task_lock_); | |
| 276 gpu_memory_buffer_tasks_.insert(std::make_pair(sync_point, callback)); | |
|
alexst (slow to review)
2014/10/22 20:05:01
Forgot to add, these are to be called in the destr
reveman
2014/10/22 22:42:47
Will the dtor be called on the same thread that ca
| |
| 277 } | |
| 278 | |
| 279 void CommandBufferProxyImpl::GpuMemoryBufferSyncPointSignalled( | |
| 280 uint32 sync_point) { | |
| 281 base::Closure callback; | |
| 282 { | |
| 283 base::AutoLock lock(gpu_memory_buffer_task_lock_); | |
| 284 SignalTaskMap::iterator it = gpu_memory_buffer_tasks_.find(sync_point); | |
| 285 DCHECK(it != gpu_memory_buffer_tasks_.end()); | |
| 286 callback = it->second; | |
| 287 signal_tasks_.erase(it); | |
| 288 } | |
| 289 callback.Run(); | |
| 290 } | |
| 291 | |
| 292 uint32 CommandBufferProxyImpl::GetNextSignalId() { | |
| 293 base::AutoLock lock(signal_lock_); | |
| 294 return next_signal_id_++; | |
| 295 } | |
| 296 | |
| 262 void CommandBufferProxyImpl::WaitForTokenInRange(int32 start, int32 end) { | 297 void CommandBufferProxyImpl::WaitForTokenInRange(int32 start, int32 end) { |
| 263 TRACE_EVENT2("gpu", | 298 TRACE_EVENT2("gpu", |
| 264 "CommandBufferProxyImpl::WaitForToken", | 299 "CommandBufferProxyImpl::WaitForToken", |
| 265 "start", | 300 "start", |
| 266 start, | 301 start, |
| 267 "end", | 302 "end", |
| 268 end); | 303 end); |
| 269 TryUpdateState(); | 304 TryUpdateState(); |
| 270 if (!InRange(start, end, last_state_.token) && | 305 if (!InRange(start, end, last_state_.token) && |
| 271 last_state_.error == gpu::error::kNoError) { | 306 last_state_.error == gpu::error::kNoError) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 return; | 491 return; |
| 457 | 492 |
| 458 Send(new GpuCommandBufferMsg_RetireSyncPoint(route_id_, sync_point)); | 493 Send(new GpuCommandBufferMsg_RetireSyncPoint(route_id_, sync_point)); |
| 459 } | 494 } |
| 460 | 495 |
| 461 void CommandBufferProxyImpl::SignalSyncPoint(uint32 sync_point, | 496 void CommandBufferProxyImpl::SignalSyncPoint(uint32 sync_point, |
| 462 const base::Closure& callback) { | 497 const base::Closure& callback) { |
| 463 if (last_state_.error != gpu::error::kNoError) | 498 if (last_state_.error != gpu::error::kNoError) |
| 464 return; | 499 return; |
| 465 | 500 |
| 466 uint32 signal_id = next_signal_id_++; | 501 uint32 signal_id = GetNextSignalId(); |
| 467 if (!Send(new GpuCommandBufferMsg_SignalSyncPoint(route_id_, | 502 if (!Send(new GpuCommandBufferMsg_SignalSyncPoint(route_id_, |
| 468 sync_point, | 503 sync_point, |
| 469 signal_id))) { | 504 signal_id))) { |
| 470 return; | 505 return; |
| 471 } | 506 } |
| 472 | 507 |
| 508 base::AutoLock lock(signal_lock_); | |
| 473 signal_tasks_.insert(std::make_pair(signal_id, callback)); | 509 signal_tasks_.insert(std::make_pair(signal_id, callback)); |
| 474 } | 510 } |
| 475 | 511 |
| 476 void CommandBufferProxyImpl::SignalQuery(uint32 query, | 512 void CommandBufferProxyImpl::SignalQuery(uint32 query, |
| 477 const base::Closure& callback) { | 513 const base::Closure& callback) { |
| 478 if (last_state_.error != gpu::error::kNoError) | 514 if (last_state_.error != gpu::error::kNoError) |
| 479 return; | 515 return; |
| 480 | 516 |
| 481 // Signal identifiers are hidden, so nobody outside of this class will see | 517 // Signal identifiers are hidden, so nobody outside of this class will see |
| 482 // them. (And thus, they cannot save them.) The IDs themselves only last | 518 // them. (And thus, they cannot save them.) The IDs themselves only last |
| 483 // until the callback is invoked, which will happen as soon as the GPU | 519 // until the callback is invoked, which will happen as soon as the GPU |
| 484 // catches upwith the command buffer. | 520 // catches upwith the command buffer. |
| 485 // A malicious caller trying to create a collision by making next_signal_id | 521 // A malicious caller trying to create a collision by making next_signal_id |
| 486 // would have to make calls at an astounding rate (300B/s) and even if they | 522 // would have to make calls at an astounding rate (300B/s) and even if they |
| 487 // could do that, all they would do is to prevent some callbacks from getting | 523 // could do that, all they would do is to prevent some callbacks from getting |
| 488 // called, leading to stalled threads and/or memory leaks. | 524 // called, leading to stalled threads and/or memory leaks. |
| 489 uint32 signal_id = next_signal_id_++; | 525 uint32 signal_id = GetNextSignalId(); |
| 490 if (!Send(new GpuCommandBufferMsg_SignalQuery(route_id_, | 526 if (!Send(new GpuCommandBufferMsg_SignalQuery(route_id_, |
| 491 query, | 527 query, |
| 492 signal_id))) { | 528 signal_id))) { |
| 493 return; | 529 return; |
| 494 } | 530 } |
| 495 | 531 |
| 532 base::AutoLock lock(signal_lock_); | |
| 496 signal_tasks_.insert(std::make_pair(signal_id, callback)); | 533 signal_tasks_.insert(std::make_pair(signal_id, callback)); |
| 497 } | 534 } |
| 498 | 535 |
| 499 void CommandBufferProxyImpl::SetSurfaceVisible(bool visible) { | 536 void CommandBufferProxyImpl::SetSurfaceVisible(bool visible) { |
| 500 if (last_state_.error != gpu::error::kNoError) | 537 if (last_state_.error != gpu::error::kNoError) |
| 501 return; | 538 return; |
| 502 | 539 |
| 503 Send(new GpuCommandBufferMsg_SetSurfaceVisible(route_id_, visible)); | 540 Send(new GpuCommandBufferMsg_SetSurfaceVisible(route_id_, visible)); |
| 504 } | 541 } |
| 505 | 542 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 if (!ui::LatencyInfo::Verify( | 619 if (!ui::LatencyInfo::Verify( |
| 583 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { | 620 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { |
| 584 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>()); | 621 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>()); |
| 585 return; | 622 return; |
| 586 } | 623 } |
| 587 swap_buffers_completion_callback_.Run(latency_info); | 624 swap_buffers_completion_callback_.Run(latency_info); |
| 588 } | 625 } |
| 589 } | 626 } |
| 590 | 627 |
| 591 } // namespace content | 628 } // namespace content |
| OLD | NEW |