| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 int32 route_id, | 39 int32 route_id, |
| 40 int32 stream_id) | 40 int32 stream_id) |
| 41 : lock_(nullptr), | 41 : lock_(nullptr), |
| 42 channel_(channel), | 42 channel_(channel), |
| 43 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)), | 43 command_buffer_id_(CommandBufferProxyID(channel->channel_id(), route_id)), |
| 44 route_id_(route_id), | 44 route_id_(route_id), |
| 45 stream_id_(stream_id), | 45 stream_id_(stream_id), |
| 46 flush_count_(0), | 46 flush_count_(0), |
| 47 last_put_offset_(-1), | 47 last_put_offset_(-1), |
| 48 last_barrier_put_offset_(-1), | 48 last_barrier_put_offset_(-1), |
| 49 next_fence_sync_release_(1), |
| 50 flushed_fence_sync_release_(0), |
| 51 verified_fence_sync_release_(0), |
| 49 next_signal_id_(0) { | 52 next_signal_id_(0) { |
| 50 DCHECK(channel); | 53 DCHECK(channel); |
| 51 } | 54 } |
| 52 | 55 |
| 53 CommandBufferProxyImpl::~CommandBufferProxyImpl() { | 56 CommandBufferProxyImpl::~CommandBufferProxyImpl() { |
| 54 FOR_EACH_OBSERVER(DeletionObserver, | 57 FOR_EACH_OBSERVER(DeletionObserver, |
| 55 deletion_observers_, | 58 deletion_observers_, |
| 56 OnWillDeleteImpl()); | 59 OnWillDeleteImpl()); |
| 57 if (channel_) { | 60 if (channel_) { |
| 58 channel_->DestroyCommandBuffer(this); | 61 channel_->DestroyCommandBuffer(this); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 TRACE_EVENT1("gpu", | 208 TRACE_EVENT1("gpu", |
| 206 "CommandBufferProxyImpl::Flush", | 209 "CommandBufferProxyImpl::Flush", |
| 207 "put_offset", | 210 "put_offset", |
| 208 put_offset); | 211 put_offset); |
| 209 | 212 |
| 210 bool put_offset_changed = last_put_offset_ != put_offset; | 213 bool put_offset_changed = last_put_offset_ != put_offset; |
| 211 last_put_offset_ = put_offset; | 214 last_put_offset_ = put_offset; |
| 212 last_barrier_put_offset_ = put_offset; | 215 last_barrier_put_offset_ = put_offset; |
| 213 | 216 |
| 214 if (channel_) { | 217 if (channel_) { |
| 215 channel_->OrderingBarrier(route_id_, stream_id_, put_offset, ++flush_count_, | 218 const uint32_t flush_id = channel_->OrderingBarrier( |
| 216 latency_info_, put_offset_changed, true); | 219 route_id_, stream_id_, put_offset, ++flush_count_, latency_info_, |
| 220 put_offset_changed, true); |
| 221 if (put_offset_changed) { |
| 222 DCHECK(flush_id); |
| 223 const uint64_t fence_sync_release = next_fence_sync_release_ - 1; |
| 224 if (fence_sync_release > flushed_fence_sync_release_) { |
| 225 flushed_fence_sync_release_ = fence_sync_release; |
| 226 flushed_release_flush_id_.push( |
| 227 std::make_pair(fence_sync_release, flush_id)); |
| 228 } |
| 229 } |
| 217 } | 230 } |
| 218 | 231 |
| 219 if (put_offset_changed) | 232 if (put_offset_changed) |
| 220 latency_info_.clear(); | 233 latency_info_.clear(); |
| 221 } | 234 } |
| 222 | 235 |
| 223 void CommandBufferProxyImpl::OrderingBarrier(int32 put_offset) { | 236 void CommandBufferProxyImpl::OrderingBarrier(int32 put_offset) { |
| 224 if (last_state_.error != gpu::error::kNoError) | 237 if (last_state_.error != gpu::error::kNoError) |
| 225 return; | 238 return; |
| 226 | 239 |
| 227 TRACE_EVENT1("gpu", "CommandBufferProxyImpl::OrderingBarrier", "put_offset", | 240 TRACE_EVENT1("gpu", "CommandBufferProxyImpl::OrderingBarrier", "put_offset", |
| 228 put_offset); | 241 put_offset); |
| 229 | 242 |
| 230 bool put_offset_changed = last_barrier_put_offset_ != put_offset; | 243 bool put_offset_changed = last_barrier_put_offset_ != put_offset; |
| 231 last_barrier_put_offset_ = put_offset; | 244 last_barrier_put_offset_ = put_offset; |
| 232 | 245 |
| 233 if (channel_) { | 246 if (channel_) { |
| 234 channel_->OrderingBarrier(route_id_, stream_id_, put_offset, ++flush_count_, | 247 const uint32_t flush_id = channel_->OrderingBarrier( |
| 235 latency_info_, put_offset_changed, false); | 248 route_id_, stream_id_, put_offset, ++flush_count_, latency_info_, |
| 249 put_offset_changed, false); |
| 250 if (put_offset_changed) { |
| 251 DCHECK(flush_id); |
| 252 const uint64_t fence_sync_release = next_fence_sync_release_ - 1; |
| 253 if (fence_sync_release > flushed_fence_sync_release_) { |
| 254 flushed_fence_sync_release_ = fence_sync_release; |
| 255 flushed_release_flush_id_.push( |
| 256 std::make_pair(fence_sync_release, flush_id)); |
| 257 } |
| 258 } |
| 236 } | 259 } |
| 237 | 260 |
| 238 if (put_offset_changed) | 261 if (put_offset_changed) |
| 239 latency_info_.clear(); | 262 latency_info_.clear(); |
| 240 } | 263 } |
| 241 | 264 |
| 242 void CommandBufferProxyImpl::SetLatencyInfo( | 265 void CommandBufferProxyImpl::SetLatencyInfo( |
| 243 const std::vector<ui::LatencyInfo>& latency_info) { | 266 const std::vector<ui::LatencyInfo>& latency_info) { |
| 244 CheckLock(); | 267 CheckLock(); |
| 245 for (size_t i = 0; i < latency_info.size(); i++) | 268 for (size_t i = 0; i < latency_info.size(); i++) |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 489 } |
| 467 | 490 |
| 468 gpu::CommandBufferNamespace CommandBufferProxyImpl::GetNamespaceID() const { | 491 gpu::CommandBufferNamespace CommandBufferProxyImpl::GetNamespaceID() const { |
| 469 return gpu::CommandBufferNamespace::GPU_IO; | 492 return gpu::CommandBufferNamespace::GPU_IO; |
| 470 } | 493 } |
| 471 | 494 |
| 472 uint64_t CommandBufferProxyImpl::GetCommandBufferID() const { | 495 uint64_t CommandBufferProxyImpl::GetCommandBufferID() const { |
| 473 return command_buffer_id_; | 496 return command_buffer_id_; |
| 474 } | 497 } |
| 475 | 498 |
| 499 uint64_t CommandBufferProxyImpl::GenerateFenceSyncRelease() { |
| 500 return next_fence_sync_release_++; |
| 501 } |
| 502 |
| 503 bool CommandBufferProxyImpl::IsFenceSyncRelease(uint64_t release) { |
| 504 return release != 0 && release < next_fence_sync_release_; |
| 505 } |
| 506 |
| 507 bool CommandBufferProxyImpl::IsFenceSyncFlushed(uint64_t release) { |
| 508 CheckLock(); |
| 509 if (last_state_.error != gpu::error::kNoError) |
| 510 return false; |
| 511 |
| 512 if (release <= verified_fence_sync_release_) |
| 513 return true; |
| 514 |
| 515 // Check if we have actually flushed the fence sync release. |
| 516 if (release <= flushed_fence_sync_release_) { |
| 517 DCHECK(!flushed_release_flush_id_.empty()); |
| 518 // Check if it has already been validated by another context. |
| 519 UpdateVerifiedReleases(channel_->GetHighestValidatedFlushID(stream_id_)); |
| 520 if (release <= verified_fence_sync_release_) |
| 521 return true; |
| 522 |
| 523 // Has not been validated, validate it now. |
| 524 UpdateVerifiedReleases(channel_->ValidateFlushIDReachedServer(stream_id_)); |
| 525 return release <= verified_fence_sync_release_; |
| 526 } |
| 527 |
| 528 return false; |
| 529 } |
| 530 |
| 476 uint32 CommandBufferProxyImpl::InsertSyncPoint() { | 531 uint32 CommandBufferProxyImpl::InsertSyncPoint() { |
| 477 CheckLock(); | 532 CheckLock(); |
| 478 if (last_state_.error != gpu::error::kNoError) | 533 if (last_state_.error != gpu::error::kNoError) |
| 479 return 0; | 534 return 0; |
| 480 | 535 |
| 481 uint32 sync_point = 0; | 536 uint32 sync_point = 0; |
| 482 Send(new GpuCommandBufferMsg_InsertSyncPoint(route_id_, true, &sync_point)); | 537 Send(new GpuCommandBufferMsg_InsertSyncPoint(route_id_, true, &sync_point)); |
| 483 return sync_point; | 538 return sync_point; |
| 484 } | 539 } |
| 485 | 540 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 const GpuConsoleMessageCallback& callback) { | 667 const GpuConsoleMessageCallback& callback) { |
| 613 CheckLock(); | 668 CheckLock(); |
| 614 console_message_callback_ = callback; | 669 console_message_callback_ = callback; |
| 615 } | 670 } |
| 616 | 671 |
| 617 void CommandBufferProxyImpl::TryUpdateState() { | 672 void CommandBufferProxyImpl::TryUpdateState() { |
| 618 if (last_state_.error == gpu::error::kNoError) | 673 if (last_state_.error == gpu::error::kNoError) |
| 619 shared_state()->Read(&last_state_); | 674 shared_state()->Read(&last_state_); |
| 620 } | 675 } |
| 621 | 676 |
| 677 void CommandBufferProxyImpl::UpdateVerifiedReleases(uint32_t verified_flush) { |
| 678 while (!flushed_release_flush_id_.empty()) { |
| 679 const std::pair<uint64_t, uint32_t>& front_item = |
| 680 flushed_release_flush_id_.front(); |
| 681 if (front_item.second > verified_flush) |
| 682 break; |
| 683 verified_fence_sync_release_ = front_item.first; |
| 684 flushed_release_flush_id_.pop(); |
| 685 } |
| 686 } |
| 687 |
| 622 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { | 688 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { |
| 623 return reinterpret_cast<gpu::CommandBufferSharedState*>( | 689 return reinterpret_cast<gpu::CommandBufferSharedState*>( |
| 624 shared_state_shm_->memory()); | 690 shared_state_shm_->memory()); |
| 625 } | 691 } |
| 626 | 692 |
| 627 void CommandBufferProxyImpl::OnSwapBuffersCompleted( | 693 void CommandBufferProxyImpl::OnSwapBuffersCompleted( |
| 628 const std::vector<ui::LatencyInfo>& latency_info, | 694 const std::vector<ui::LatencyInfo>& latency_info, |
| 629 gfx::SwapResult result) { | 695 gfx::SwapResult result) { |
| 630 if (!swap_buffers_completion_callback_.is_null()) { | 696 if (!swap_buffers_completion_callback_.is_null()) { |
| 631 if (!ui::LatencyInfo::Verify( | 697 if (!ui::LatencyInfo::Verify( |
| 632 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { | 698 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { |
| 633 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>(), | 699 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>(), |
| 634 result); | 700 result); |
| 635 return; | 701 return; |
| 636 } | 702 } |
| 637 swap_buffers_completion_callback_.Run(latency_info, result); | 703 swap_buffers_completion_callback_.Run(latency_info, result); |
| 638 } | 704 } |
| 639 } | 705 } |
| 640 | 706 |
| 641 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, | 707 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 642 base::TimeDelta interval) { | 708 base::TimeDelta interval) { |
| 643 if (!update_vsync_parameters_completion_callback_.is_null()) | 709 if (!update_vsync_parameters_completion_callback_.is_null()) |
| 644 update_vsync_parameters_completion_callback_.Run(timebase, interval); | 710 update_vsync_parameters_completion_callback_.Run(timebase, interval); |
| 645 } | 711 } |
| 646 | 712 |
| 647 } // namespace content | 713 } // namespace content |
| OLD | NEW |