diff options
author | miletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-29 00:01:22 +0000 |
---|---|---|
committer | miletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-29 00:01:22 +0000 |
commit | 580ec6b79c40a7e58e896e4f0063ad9eca5d16a3 (patch) | |
tree | cb376ccd50dabd9e5a63ade75acdc70532109171 /cc | |
parent | 4b7718ac366ed68a86b710dd74486e4c487c6492 (diff) | |
download | chromium_src-580ec6b79c40a7e58e896e4f0063ad9eca5d16a3.zip chromium_src-580ec6b79c40a7e58e896e4f0063ad9eca5d16a3.tar.gz chromium_src-580ec6b79c40a7e58e896e4f0063ad9eca5d16a3.tar.bz2 |
Use LatencyInfoSwapPromise to track LatencyInfo through compositor
Originally we cache LatencyInfo directly in compositor. Now that
with the support of SwapPromise, we can use LatencyInfoSwapPromise
to track the LatencyInfo.
BUG=246034
TEST=Input LatencyInfo are still correctly passed to output surface
through LatencyInfoSwapPromise.
Review URL: https://codereview.chromium.org/81533002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237848 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/base/latency_info_swap_promise.cc | 50 | ||||
-rw-r--r-- | cc/base/latency_info_swap_promise.h | 28 | ||||
-rw-r--r-- | cc/base/swap_promise.h | 12 | ||||
-rw-r--r-- | cc/cc.gyp | 2 | ||||
-rw-r--r-- | cc/cc_tests.gyp | 1 | ||||
-rw-r--r-- | cc/trees/layer_tree_host.cc | 9 | ||||
-rw-r--r-- | cc/trees/layer_tree_host.h | 4 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 9 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl_unittest.cc | 39 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_unittest.cc | 2 | ||||
-rw-r--r-- | cc/trees/layer_tree_impl.cc | 21 | ||||
-rw-r--r-- | cc/trees/layer_tree_impl.h | 9 |
12 files changed, 136 insertions, 50 deletions
diff --git a/cc/base/latency_info_swap_promise.cc b/cc/base/latency_info_swap_promise.cc new file mode 100644 index 0000000..41c0e997 --- /dev/null +++ b/cc/base/latency_info_swap_promise.cc @@ -0,0 +1,50 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/base/latency_info_swap_promise.h" + +#include "base/logging.h" + +namespace { + ui::LatencyComponentType DidNotSwapReasonToLatencyComponentType( + cc::SwapPromise::DidNotSwapReason reason) { + switch (reason) { + case cc::SwapPromise::DID_NOT_SWAP_UNKNOWN: + case cc::SwapPromise::SWAP_FAILS: + return ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT; + case cc::SwapPromise::COMMIT_FAILS: + return ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT; + case cc::SwapPromise::SWAP_PROMISE_LIST_OVERFLOW: + return ui::LATENCY_INFO_LIST_TERMINATED_OVERFLOW_COMPONENT; + } + NOTREACHED() << "Unhandled DidNotSwapReason."; + return ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT; + } +} // namespace + +namespace cc { + +LatencyInfoSwapPromise::LatencyInfoSwapPromise(const ui::LatencyInfo& latency) + : latency_(latency) { +} + +LatencyInfoSwapPromise::~LatencyInfoSwapPromise() { +} + +void LatencyInfoSwapPromise::DidSwap(CompositorFrameMetadata* metadata) { + DCHECK(!latency_.terminated); + // TODO(miletus): Append the |latency_| into metadata's LatencyInfo list + // once we remove LatencyInfo merge in GPU side. + metadata->latency_info.MergeWith(latency_); +} + +void LatencyInfoSwapPromise::DidNotSwap(DidNotSwapReason reason) { + latency_.AddLatencyNumber(DidNotSwapReasonToLatencyComponentType(reason), + 0, 0); + // TODO(miletus): Turn this back on once per-event LatencyInfo tracking + // is enabled in GPU side. + // DCHECK(latency_.terminated); +} + +} // namespace cc diff --git a/cc/base/latency_info_swap_promise.h b/cc/base/latency_info_swap_promise.h new file mode 100644 index 0000000..1a2b1d6 --- /dev/null +++ b/cc/base/latency_info_swap_promise.h @@ -0,0 +1,28 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_BASE_LATENCY_INFO_SWAP_PROMISE_H_ +#define CC_BASE_LATENCY_INFO_SWAP_PROMISE_H_ + +#include "base/compiler_specific.h" +#include "cc/base/swap_promise.h" +#include "ui/events/latency_info.h" + +namespace cc { + +class CC_EXPORT LatencyInfoSwapPromise : public SwapPromise { + public: + explicit LatencyInfoSwapPromise(const ui::LatencyInfo& latency_info); + virtual ~LatencyInfoSwapPromise(); + + virtual void DidSwap(CompositorFrameMetadata* metadata) OVERRIDE; + virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE; + + private: + ui::LatencyInfo latency_; +}; + +} // namespace cc + +#endif // CC_BASE_LATENCY_INFO_SWAP_PROMISE_H_ diff --git a/cc/base/swap_promise.h b/cc/base/swap_promise.h index 90bf6af..36a5b13 100644 --- a/cc/base/swap_promise.h +++ b/cc/base/swap_promise.h @@ -5,6 +5,8 @@ #ifndef CC_BASE_SWAP_PROMISE_H_ #define CC_BASE_SWAP_PROMISE_H_ +#include "cc/output/compositor_frame_metadata.h" + namespace cc { const unsigned int kMaxQueuedSwapPromiseNumber = 100; @@ -27,11 +29,8 @@ const unsigned int kMaxQueuedSwapPromiseNumber = 100; // DidNotSwap() are called at a particular thread. It is better to let the // subclass carry thread-safe member data and operate on that member data in // DidSwap() and DidNotSwap(). -class SwapPromise { +class CC_EXPORT SwapPromise { public: - SwapPromise() {} - virtual ~SwapPromise() {} - enum DidNotSwapReason { DID_NOT_SWAP_UNKNOWN, SWAP_FAILS, @@ -39,7 +38,10 @@ class SwapPromise { SWAP_PROMISE_LIST_OVERFLOW, }; - virtual void DidSwap() = 0; + SwapPromise() {} + virtual ~SwapPromise() {} + + virtual void DidSwap(CompositorFrameMetadata* metadata) = 0; virtual void DidNotSwap(DidNotSwapReason reason) = 0; }; @@ -58,6 +58,8 @@ 'base/completion_event.h', 'base/invalidation_region.cc', 'base/invalidation_region.h', + 'base/latency_info_swap_promise.cc', + 'base/latency_info_swap_promise.h', 'base/math_util.cc', 'base/math_util.h', 'base/ref_counted_managed.h', diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index 5b318fa27..a3666ec 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -218,6 +218,7 @@ '../skia/skia.gyp:skia', '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', + '../ui/events/events.gyp:events_base', '../ui/gfx/gfx.gyp:gfx', '../webkit/common/gpu/webkit_gpu.gyp:webkit_gpu', 'cc.gyp:cc', diff --git a/cc/trees/layer_tree_host.cc b/cc/trees/layer_tree_host.cc index ac471c3..b5c368b 100644 --- a/cc/trees/layer_tree_host.cc +++ b/cc/trees/layer_tree_host.cc @@ -382,8 +382,6 @@ void LayerTreeHost::FinishCommitOnImplThread(LayerTreeHostImpl* host_impl) { min_page_scale_factor_, max_page_scale_factor_); sync_tree->SetPageScaleDelta(page_scale_delta / sent_page_scale_delta); - sync_tree->SetLatencyInfo(latency_info_); - latency_info_.Clear(); sync_tree->PassSwapPromises(&swap_promise_list_); @@ -705,10 +703,6 @@ void LayerTreeHost::SetVisible(bool visible) { proxy_->SetVisible(visible); } -void LayerTreeHost::SetLatencyInfo(const ui::LatencyInfo& latency_info) { - latency_info_.MergeWith(latency_info); -} - void LayerTreeHost::StartPageScaleAnimation(gfx::Vector2d target_offset, bool use_anchor, float scale, @@ -1271,9 +1265,6 @@ bool LayerTreeHost::ScheduleMicroBenchmark( } void LayerTreeHost::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) { - if (proxy_->HasImplThread()) { - DCHECK(proxy_->CommitRequested() || proxy_->BeginMainFrameRequested()); - } DCHECK(swap_promise); if (swap_promise_list_.size() > kMaxQueuedSwapPromiseNumber) BreakSwapPromises(SwapPromise::SWAP_PROMISE_LIST_OVERFLOW); diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h index 47bfa11..adc559f 100644 --- a/cc/trees/layer_tree_host.h +++ b/cc/trees/layer_tree_host.h @@ -37,7 +37,6 @@ #include "cc/trees/occlusion_tracker.h" #include "cc/trees/proxy.h" #include "third_party/skia/include/core/SkColor.h" -#include "ui/events/latency_info.h" #include "ui/gfx/rect.h" namespace cc { @@ -233,7 +232,6 @@ class CC_EXPORT LayerTreeHost { void ApplyScrollAndScale(const ScrollAndScaleSet& info); void SetImplTransform(const gfx::Transform& transform); - void SetLatencyInfo(const ui::LatencyInfo& latency_info); // Virtual for tests. virtual void StartRateLimiter(); @@ -415,8 +413,6 @@ class CC_EXPORT LayerTreeHost { bool in_paint_layer_contents_; - ui::LatencyInfo latency_info_; - static const int kTotalFramesToUseForLCDTextMetrics = 50; int total_frames_used_for_lcd_text_metrics_; diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 21d71cf..67b7a1a 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -15,6 +15,7 @@ #include "base/strings/stringprintf.h" #include "cc/animation/scrollbar_animation_controller.h" #include "cc/animation/timing_function.h" +#include "cc/base/latency_info_swap_promise.h" #include "cc/base/math_util.h" #include "cc/base/util.h" #include "cc/debug/benchmark_instrumentation.h" @@ -474,7 +475,9 @@ bool LayerTreeHostImpl::HaveTouchEventHandlersAt(gfx::Point viewport_point) { void LayerTreeHostImpl::SetLatencyInfoForInputEvent( const ui::LatencyInfo& latency_info) { - active_tree()->SetLatencyInfo(latency_info); + scoped_ptr<SwapPromise> swap_promise( + new LatencyInfoSwapPromise(latency_info)); + active_tree()->QueueSwapPromise(swap_promise.Pass()); } void LayerTreeHostImpl::TrackDamageForAllSurfaces( @@ -1269,7 +1272,6 @@ CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { metadata.root_layer_size = active_tree_->ScrollableSize(); metadata.min_page_scale_factor = active_tree_->min_page_scale_factor(); metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); - metadata.latency_info = active_tree_->GetLatencyInfo(); if (top_controls_manager_) { metadata.location_bar_offset = gfx::Vector2dF(0.f, top_controls_manager_->controls_top_offset()); @@ -1428,9 +1430,8 @@ bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { return false; } CompositorFrameMetadata metadata = MakeCompositorFrameMetadata(); + active_tree()->FinishSwapPromises(&metadata); renderer_->SwapBuffers(metadata); - active_tree_->ClearLatencyInfo(); - active_tree()->FinishSwapPromises(); return true; } diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc index 4439ff3..e8bd22a1 100644 --- a/cc/trees/layer_tree_host_impl_unittest.cc +++ b/cc/trees/layer_tree_host_impl_unittest.cc @@ -5335,5 +5335,44 @@ TEST_F(LayerTreeHostImplTest, WheelFlingShouldBubble) { } } +// Make sure LatencyInfo carried by LatencyInfoSwapPromise are passed +// to CompositorFrameMetadata after SwapBuffers(); +TEST_F(LayerTreeHostImplTest, LatencyInfoPassedToCompositorFrameMetadata) { + scoped_ptr<SolidColorLayerImpl> root = + SolidColorLayerImpl::Create(host_impl_->active_tree(), 1); + root->SetAnchorPoint(gfx::PointF()); + root->SetPosition(gfx::PointF()); + root->SetBounds(gfx::Size(10, 10)); + root->SetContentBounds(gfx::Size(10, 10)); + root->SetDrawsContent(true); + + host_impl_->active_tree()->SetRootLayer(root.PassAs<LayerImpl>()); + + FakeOutputSurface* fake_output_surface = + static_cast<FakeOutputSurface*>(host_impl_->output_surface()); + + const ui::LatencyInfo& metadata_latency_before = + fake_output_surface->last_sent_frame().metadata.latency_info; + EXPECT_FALSE(metadata_latency_before.FindLatency( + ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, NULL)); + + ui::LatencyInfo latency_info; + latency_info.AddLatencyNumber( + ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, 0); + host_impl_->SetLatencyInfoForInputEvent(latency_info); + + gfx::Rect full_frame_damage(host_impl_->DrawViewportSize()); + LayerTreeHostImpl::FrameData frame; + EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); + host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); + host_impl_->DidDrawAllLayers(frame); + EXPECT_TRUE(host_impl_->SwapBuffers(frame)); + + const ui::LatencyInfo& metadata_latency_after = + fake_output_surface->last_sent_frame().metadata.latency_info; + EXPECT_TRUE(metadata_latency_after.FindLatency( + ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, NULL)); +} + } // namespace } // namespace cc diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index e7dfa97..fa70d95 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -5241,7 +5241,7 @@ class TestSwapPromise : public SwapPromise { result_->dtor_called = true; } - virtual void DidSwap() OVERRIDE { + virtual void DidSwap(CompositorFrameMetadata* metadata) OVERRIDE { base::AutoLock lock(result_->lock); EXPECT_FALSE(result_->did_swap_called); EXPECT_FALSE(result_->did_not_swap_called); diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc index ea3218d..eb1d471 100644 --- a/cc/trees/layer_tree_impl.cc +++ b/cc/trees/layer_tree_impl.cc @@ -120,9 +120,6 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { next_activation_forces_redraw_ = false; } - target_tree->SetLatencyInfo(latency_info_); - latency_info_.Clear(); - target_tree->PassSwapPromises(&swap_promise_list_); target_tree->SetPageScaleFactorAndLimits( @@ -464,8 +461,6 @@ void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { pending_tree->SetCurrentlyScrollingLayer( LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); - pending_tree->SetLatencyInfo(latency_info_); - latency_info_.Clear(); } static void DidBecomeActiveRecursive(LayerImpl* layer) { @@ -699,18 +694,6 @@ void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() { scrollable_viewport_size - original_viewport_size); } -void LayerTreeImpl::SetLatencyInfo(const ui::LatencyInfo& latency_info) { - latency_info_.MergeWith(latency_info); -} - -const ui::LatencyInfo& LayerTreeImpl::GetLatencyInfo() { - return latency_info_; -} - -void LayerTreeImpl::ClearLatencyInfo() { - latency_info_.Clear(); -} - void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) { DCHECK(swap_promise); if (swap_promise_list_.size() > kMaxQueuedSwapPromiseNumber) @@ -725,9 +708,9 @@ void LayerTreeImpl::PassSwapPromises( new_swap_promise->clear(); } -void LayerTreeImpl::FinishSwapPromises() { +void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) { for (size_t i = 0; i < swap_promise_list_.size(); i++) - swap_promise_list_[i]->DidSwap(); + swap_promise_list_[i]->DidSwap(metadata); swap_promise_list_.clear(); } diff --git a/cc/trees/layer_tree_impl.h b/cc/trees/layer_tree_impl.h index 63d01ef..d27cd6d 100644 --- a/cc/trees/layer_tree_impl.h +++ b/cc/trees/layer_tree_impl.h @@ -15,7 +15,6 @@ #include "cc/base/swap_promise.h" #include "cc/layers/layer_impl.h" #include "cc/resources/ui_resource_client.h" -#include "ui/events/latency_info.h" #if defined(COMPILER_GCC) namespace BASE_HASH_NAMESPACE { @@ -207,17 +206,13 @@ class CC_EXPORT LayerTreeImpl { void SetRootLayerScrollOffsetDelegate( LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate); - void SetLatencyInfo(const ui::LatencyInfo& latency_info); - const ui::LatencyInfo& GetLatencyInfo(); - void ClearLatencyInfo(); - // Call this function when you expect there to be a swap buffer. // See swap_promise.h for how to use SwapPromise. void QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise); // Take the |new_swap_promise| and append it to |swap_promise_list_|. void PassSwapPromises(ScopedPtrVector<SwapPromise>* new_swap_promise); - void FinishSwapPromises(); + void FinishSwapPromises(CompositorFrameMetadata* metadata); void BreakSwapPromises(SwapPromise::DidNotSwapReason reason); void DidModifyTilePriorities(); @@ -280,8 +275,6 @@ class CC_EXPORT LayerTreeImpl { bool next_activation_forces_redraw_; - ui::LatencyInfo latency_info_; - ScopedPtrVector<SwapPromise> swap_promise_list_; UIResourceRequestQueue ui_resource_request_queue_; |