diff options
author | vollick <vollick@chromium.org> | 2016-01-07 20:36:38 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-08 04:37:46 +0000 |
commit | 9c7f6d0e46a46605801d143c04b86f5e4445cd37 (patch) | |
tree | 964f50059ee17492e4111901ed1e55de3c143bd4 | |
parent | 8b876b75f69ae160847db39840784b3805c504a9 (diff) | |
download | chromium_src-9c7f6d0e46a46605801d143c04b86f5e4445cd37.zip chromium_src-9c7f6d0e46a46605801d143c04b86f5e4445cd37.tar.gz chromium_src-9c7f6d0e46a46605801d143c04b86f5e4445cd37.tar.bz2 |
compositor-worker: Introduce WebCompositorMutableState
This change introduces a wrapper around compositer-owned state that may
be mutated by a compositor worker.
This depends on crrev.com/1405993008
BUG=430155
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1447893002
Cr-Commit-Position: refs/heads/master@{#368273}
-rw-r--r-- | cc/animation/layer_tree_mutation.h | 63 | ||||
-rw-r--r-- | cc/blink/BUILD.gn | 5 | ||||
-rw-r--r-- | cc/blink/cc_blink.gyp | 4 | ||||
-rw-r--r-- | cc/blink/cc_blink_tests.gyp | 1 | ||||
-rw-r--r-- | cc/blink/web_compositor_mutable_state_impl.cc | 72 | ||||
-rw-r--r-- | cc/blink/web_compositor_mutable_state_impl.h | 46 | ||||
-rw-r--r-- | cc/blink/web_compositor_mutable_state_impl_unittest.cc | 172 | ||||
-rw-r--r-- | cc/blink/web_compositor_mutable_state_provider_impl.cc | 34 | ||||
-rw-r--r-- | cc/blink/web_compositor_mutable_state_provider_impl.h | 44 | ||||
-rw-r--r-- | cc/layers/layer_impl.cc | 9 | ||||
-rw-r--r-- | cc/trees/layer_tree_impl.cc | 58 | ||||
-rw-r--r-- | cc/trees/layer_tree_impl.h | 15 | ||||
-rw-r--r-- | third_party/WebKit/public/platform/WebCompositorMutableState.h | 34 | ||||
-rw-r--r-- | third_party/WebKit/public/platform/WebCompositorMutableStateProvider.h | 28 | ||||
-rw-r--r-- | third_party/WebKit/public/platform/WebPassOwnPtr.h | 9 | ||||
-rw-r--r-- | ui/gfx/transform.h | 1 |
16 files changed, 592 insertions, 3 deletions
diff --git a/cc/animation/layer_tree_mutation.h b/cc/animation/layer_tree_mutation.h new file mode 100644 index 0000000..0fdd592 --- /dev/null +++ b/cc/animation/layer_tree_mutation.h @@ -0,0 +1,63 @@ +// Copyright 2015 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_ANIMATION_LAYER_TREE_MUTATION_H_ +#define CC_ANIMATION_LAYER_TREE_MUTATION_H_ + +#include "base/containers/hash_tables.h" +#include "cc/animation/mutable_properties.h" +#include "third_party/skia/include/utils/SkMatrix44.h" + +namespace cc { + +class LayerTreeMutation { + public: + void SetOpacity(float opacity) { + mutated_flags_ |= kMutablePropertyOpacity; + opacity_ = opacity; + } + void SetScrollLeft(float scroll_left) { + mutated_flags_ |= kMutablePropertyScrollLeft; + scroll_left_ = scroll_left; + } + void SetScrollTop(float scroll_top) { + mutated_flags_ |= kMutablePropertyScrollTop; + scroll_top_ = scroll_top; + } + void SetTransform(const SkMatrix44& transform) { + mutated_flags_ |= kMutablePropertyTransform; + transform_ = transform; + } + + bool is_opacity_mutated() const { + return !!(mutated_flags_ & kMutablePropertyOpacity); + } + bool is_scroll_left_mutated() const { + return !!(mutated_flags_ & kMutablePropertyScrollLeft); + } + bool is_scroll_top_mutated() const { + return !!(mutated_flags_ & kMutablePropertyScrollTop); + } + bool is_transform_mutated() const { + return !!(mutated_flags_ & kMutablePropertyTransform); + } + + float opacity() const { return opacity_; } + float scroll_left() const { return scroll_left_; } + float scroll_top() const { return scroll_top_; } + SkMatrix44 transform() const { return transform_; } + + private: + uint32_t mutated_flags_ = 0; + float opacity_ = 0; + float scroll_left_ = 0; + float scroll_top_ = 0; + SkMatrix44 transform_; +}; + +typedef base::hash_map<uint64_t, LayerTreeMutation> LayerTreeMutationMap; + +} // namespace cc + +#endif // CC_ANIMATION_LAYER_TREE_MUTATION_H_ diff --git a/cc/blink/BUILD.gn b/cc/blink/BUILD.gn index 93915b0..cbdeef8 100644 --- a/cc/blink/BUILD.gn +++ b/cc/blink/BUILD.gn @@ -21,6 +21,10 @@ component("blink") { "web_compositor_animation_player_impl.h", "web_compositor_animation_timeline_impl.cc", "web_compositor_animation_timeline_impl.h", + "web_compositor_mutable_state_impl.cc", + "web_compositor_mutable_state_impl.h", + "web_compositor_mutable_state_provider_impl.cc", + "web_compositor_mutable_state_provider_impl.h", "web_compositor_support_impl.cc", "web_compositor_support_impl.h", "web_content_layer_impl.cc", @@ -79,6 +83,7 @@ if (!is_mac) { sources = [ "web_animation_unittest.cc", "web_compositor_animation_player_unittest.cc", + "web_compositor_mutable_state_impl_unittest.cc", "web_float_animation_curve_unittest.cc", "web_layer_impl_fixed_bounds_unittest.cc", diff --git a/cc/blink/cc_blink.gyp b/cc/blink/cc_blink.gyp index dc01cae..995af72 100644 --- a/cc/blink/cc_blink.gyp +++ b/cc/blink/cc_blink.gyp @@ -37,6 +37,10 @@ 'web_compositor_animation_player_impl.h', 'web_compositor_animation_timeline_impl.cc', 'web_compositor_animation_timeline_impl.h', + 'web_compositor_mutable_state_impl.cc', + 'web_compositor_mutable_state_impl.h', + 'web_compositor_mutable_state_provider_impl.cc', + 'web_compositor_mutable_state_provider_impl.h', 'web_compositor_support_impl.cc', 'web_compositor_support_impl.h', 'web_content_layer_impl.cc', diff --git a/cc/blink/cc_blink_tests.gyp b/cc/blink/cc_blink_tests.gyp index f72a5db..edcd118 100644 --- a/cc/blink/cc_blink_tests.gyp +++ b/cc/blink/cc_blink_tests.gyp @@ -28,6 +28,7 @@ 'web_compositor_animation_player_unittest.cc', 'web_float_animation_curve_unittest.cc', 'web_layer_impl_fixed_bounds_unittest.cc', + 'web_compositor_mutable_state_impl_unittest.cc', ], } ], diff --git a/cc/blink/web_compositor_mutable_state_impl.cc b/cc/blink/web_compositor_mutable_state_impl.cc new file mode 100644 index 0000000..b0421e8 --- /dev/null +++ b/cc/blink/web_compositor_mutable_state_impl.cc @@ -0,0 +1,72 @@ +// Copyright 2015 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/blink/web_compositor_mutable_state_impl.h" + +#include "cc/animation/layer_tree_mutation.h" +#include "cc/layers/layer_impl.h" +#include "cc/trees/layer_tree_impl.h" + +namespace cc_blink { + +WebCompositorMutableStateImpl::WebCompositorMutableStateImpl( + cc::LayerTreeMutation* mutation, + cc::LayerImpl* main_layer, + cc::LayerImpl* scroll_layer) + : mutation_(mutation), + main_layer_(main_layer), + scroll_layer_(scroll_layer) {} + +WebCompositorMutableStateImpl::~WebCompositorMutableStateImpl() {} + +double WebCompositorMutableStateImpl::opacity() const { + return main_layer_->opacity(); +} + +void WebCompositorMutableStateImpl::setOpacity(double opacity) { + if (!main_layer_) + return; + main_layer_->OnOpacityAnimated(opacity); + mutation_->SetOpacity(opacity); +} + +const SkMatrix44& WebCompositorMutableStateImpl::transform() const { + static SkMatrix44 identity; + return main_layer_ ? main_layer_->transform().matrix() : identity; +} + +void WebCompositorMutableStateImpl::setTransform(const SkMatrix44& matrix) { + if (!main_layer_) + return; + main_layer_->OnTransformAnimated(gfx::Transform(matrix)); + mutation_->SetTransform(matrix); +} + +double WebCompositorMutableStateImpl::scrollLeft() const { + return scroll_layer_ ? scroll_layer_->CurrentScrollOffset().x() : 0.0; +} + +void WebCompositorMutableStateImpl::setScrollLeft(double scroll_left) { + if (!scroll_layer_) + return; + gfx::ScrollOffset offset = scroll_layer_->CurrentScrollOffset(); + offset.set_x(scroll_left); + scroll_layer_->OnScrollOffsetAnimated(offset); + mutation_->SetScrollLeft(scroll_left); +} + +double WebCompositorMutableStateImpl::scrollTop() const { + return scroll_layer_ ? scroll_layer_->CurrentScrollOffset().y() : 0.0; +} + +void WebCompositorMutableStateImpl::setScrollTop(double scroll_top) { + if (!scroll_layer_) + return; + gfx::ScrollOffset offset = scroll_layer_->CurrentScrollOffset(); + offset.set_y(scroll_top); + scroll_layer_->OnScrollOffsetAnimated(offset); + mutation_->SetScrollTop(scroll_top); +} + +} // namespace cc_blink diff --git a/cc/blink/web_compositor_mutable_state_impl.h b/cc/blink/web_compositor_mutable_state_impl.h new file mode 100644 index 0000000..b052eca --- /dev/null +++ b/cc/blink/web_compositor_mutable_state_impl.h @@ -0,0 +1,46 @@ +// Copyright 2015 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_BLINK_WEB_COMPOSITOR_MUTABLE_STATE_IMPL_H_ +#define CC_BLINK_WEB_COMPOSITOR_MUTABLE_STATE_IMPL_H_ + +#include "cc/blink/cc_blink_export.h" + +#include "third_party/WebKit/public/platform/WebCompositorMutableState.h" + +namespace cc { +class LayerImpl; +class LayerTreeMutation; +} + +namespace cc_blink { + +class WebCompositorMutableStateImpl : public blink::WebCompositorMutableState { + public: + WebCompositorMutableStateImpl(cc::LayerTreeMutation* mutation, + cc::LayerImpl* main_layer, + cc::LayerImpl* scroll_layer); + ~WebCompositorMutableStateImpl() override; + + double opacity() const override; + void setOpacity(double opacity) override; + + const SkMatrix44& transform() const override; + void setTransform(const SkMatrix44& transform) override; + + double scrollLeft() const override; + void setScrollLeft(double scroll_left) override; + + double scrollTop() const override; + void setScrollTop(double scroll_top) override; + + private: + cc::LayerTreeMutation* mutation_; + cc::LayerImpl* main_layer_; + cc::LayerImpl* scroll_layer_; +}; + +} // namespace cc_blink + +#endif // CC_BLINK_WEB_COMPOSITOR_MUTABLE_STATE_IMPL_H_ diff --git a/cc/blink/web_compositor_mutable_state_impl_unittest.cc b/cc/blink/web_compositor_mutable_state_impl_unittest.cc new file mode 100644 index 0000000..d2dc7df --- /dev/null +++ b/cc/blink/web_compositor_mutable_state_impl_unittest.cc @@ -0,0 +1,172 @@ +// Copyright 2015 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/blink/web_compositor_mutable_state_impl.h" + +#include "cc/animation/layer_tree_mutation.h" +#include "cc/blink/web_compositor_mutable_state_provider_impl.h" +#include "cc/test/fake_impl_task_runner_provider.h" +#include "cc/test/fake_layer_tree_host_impl.h" +#include "cc/test/fake_output_surface.h" +#include "cc/test/layer_tree_host_common_test.h" +#include "cc/test/test_shared_bitmap_manager.h" +#include "cc/test/test_task_graph_runner.h" +#include "cc/trees/layer_tree_host_impl.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace cc_blink { +namespace { + +using cc::FakeImplTaskRunnerProvider; +using cc::FakeLayerTreeHostImpl; +using cc::FakeOutputSurface; +using cc::LayerImpl; +using cc::LayerImplList; +using cc::LayerTreeHostCommonTest; +using cc::LayerTreeMutation; +using cc::LayerTreeMutationMap; +using cc::LayerTreeSettings; +using cc::OutputSurface; +using cc::TestTaskGraphRunner; +using cc::TestSharedBitmapManager; + +using blink::WebCompositorMutableState; + +class WebCompositorMutableStateTest : public LayerTreeHostCommonTest { + public: + WebCompositorMutableStateTest() + : output_surface_(FakeOutputSurface::Create3d()) { + LayerTreeSettings settings; + settings.layer_transforms_should_scale_layer_contents = true; + settings.verify_property_trees = true; + host_impl_.reset(new FakeLayerTreeHostImpl(settings, &task_runner_provider_, + &shared_bitmap_manager_, + &task_graph_runner_)); + host_impl_->SetVisible(true); + EXPECT_TRUE(host_impl_->InitializeRenderer(output_surface_.get())); + } + + FakeLayerTreeHostImpl& host_impl() { return *host_impl_; } + + LayerImpl* root_layer() { return host_impl_->active_tree()->root_layer(); } + + private: + TestSharedBitmapManager shared_bitmap_manager_; + TestTaskGraphRunner task_graph_runner_; + FakeImplTaskRunnerProvider task_runner_provider_; + scoped_ptr<OutputSurface> output_surface_; + scoped_ptr<FakeLayerTreeHostImpl> host_impl_; +}; + +TEST_F(WebCompositorMutableStateTest, NoMutableState) { + // In this test, there are no layers with either an element id or mutable + // properties. We should not be able to get any mutable state. + scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42); + + gfx::Transform identity_matrix; + gfx::Point3F transform_origin; + gfx::PointF position; + gfx::Size bounds(100, 100); + SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, + position, bounds, true, false, true); + root->SetDrawsContent(true); + + host_impl().SetViewportSize(root->bounds()); + host_impl().active_tree()->SetRootLayer(std::move(root)); + host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); + + LayerTreeMutationMap mutations; + WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(), + &mutations); + scoped_ptr<WebCompositorMutableState> state(provider.getMutableStateFor(42)); + EXPECT_FALSE(state); +} + +TEST_F(WebCompositorMutableStateTest, MutableStateNoMutableProperties) { + // In this test, there is a layer with an element id, but no mutable + // properties. This should behave just as if we'd had no element id. + scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42); + + gfx::Transform identity_matrix; + gfx::Point3F transform_origin; + gfx::PointF position; + gfx::Size bounds(100, 100); + SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, + position, bounds, true, false, true); + root->SetDrawsContent(true); + root->SetElementId(42); + + host_impl().SetViewportSize(root->bounds()); + host_impl().active_tree()->SetRootLayer(std::move(root)); + host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); + + LayerTreeMutationMap mutations; + WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(), + &mutations); + scoped_ptr<WebCompositorMutableState> state(provider.getMutableStateFor(42)); + EXPECT_FALSE(state); +} + +TEST_F(WebCompositorMutableStateTest, MutableStateMutableProperties) { + // In this test, there is a layer with an element id and mutable properties. + // In this case, we should get a valid mutable state for this element id that + // has a real effect on the corresponding layer. + scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl().active_tree(), 42); + + gfx::Transform identity_matrix; + gfx::Point3F transform_origin; + gfx::PointF position; + gfx::Size bounds(100, 100); + SetLayerPropertiesForTesting(root.get(), identity_matrix, transform_origin, + position, bounds, true, false, true); + root->SetDrawsContent(true); + root->SetElementId(42); + root->SetMutableProperties( + cc::kMutablePropertyOpacity | cc::kMutablePropertyTransform | + cc::kMutablePropertyScrollLeft | cc::kMutablePropertyScrollTop); + + host_impl().SetViewportSize(root->bounds()); + host_impl().active_tree()->SetRootLayer(std::move(root)); + host_impl().UpdateNumChildrenAndDrawPropertiesForActiveTree(); + + LayerTreeMutationMap mutations; + WebCompositorMutableStateProviderImpl provider(host_impl().active_tree(), + &mutations); + + scoped_ptr<WebCompositorMutableState> state(provider.getMutableStateFor(42)); + EXPECT_TRUE(state.get()); + + EXPECT_EQ(1.0, root_layer()->opacity()); + EXPECT_EQ(identity_matrix.ToString(), root_layer()->transform().ToString()); + EXPECT_EQ(0.0, root_layer()->CurrentScrollOffset().x()); + EXPECT_EQ(0.0, root_layer()->CurrentScrollOffset().y()); + + gfx::Transform zero(0, 0, 0, 0, 0, 0); + state->setOpacity(0.5); + state->setTransform(zero.matrix()); + state->setScrollLeft(1.0); + state->setScrollTop(1.0); + + EXPECT_EQ(0.5, root_layer()->opacity()); + EXPECT_EQ(zero.ToString(), root_layer()->transform().ToString()); + EXPECT_EQ(1.0, root_layer()->CurrentScrollOffset().x()); + EXPECT_EQ(1.0, root_layer()->CurrentScrollOffset().y()); + + // The corresponding mutation should reflect the changed values. + EXPECT_EQ(1ul, mutations.size()); + + const LayerTreeMutation& mutation = mutations[42]; + EXPECT_TRUE(mutation.is_opacity_mutated()); + EXPECT_TRUE(mutation.is_transform_mutated()); + EXPECT_TRUE(mutation.is_scroll_left_mutated()); + EXPECT_TRUE(mutation.is_scroll_top_mutated()); + + EXPECT_EQ(0.5, mutation.opacity()); + EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString()); + EXPECT_EQ(1.0, mutation.scroll_left()); + EXPECT_EQ(1.0, mutation.scroll_top()); +} + +} // namespace +} // namespace cc_blink diff --git a/cc/blink/web_compositor_mutable_state_provider_impl.cc b/cc/blink/web_compositor_mutable_state_provider_impl.cc new file mode 100644 index 0000000..713a542 --- /dev/null +++ b/cc/blink/web_compositor_mutable_state_provider_impl.cc @@ -0,0 +1,34 @@ +// Copyright 2015 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/blink/web_compositor_mutable_state_provider_impl.h" + +#include "cc/blink/web_compositor_mutable_state_impl.h" +#include "cc/layers/layer_impl.h" +#include "cc/trees/layer_tree_impl.h" + +namespace cc_blink { + +WebCompositorMutableStateProviderImpl::WebCompositorMutableStateProviderImpl( + cc::LayerTreeImpl* state, + cc::LayerTreeMutationMap* mutations) + : state_(state), mutations_(mutations) {} + +WebCompositorMutableStateProviderImpl:: + ~WebCompositorMutableStateProviderImpl() {} + +blink::WebPassOwnPtr<blink::WebCompositorMutableState> +WebCompositorMutableStateProviderImpl::getMutableStateFor(uint64_t element_id) { + cc::LayerTreeImpl::ElementLayers layers = + state_->GetMutableLayers(element_id); + + if (!layers.main && !layers.scroll) + return nullptr; + + return blink::adoptWebPtr<blink::WebCompositorMutableState>( + new WebCompositorMutableStateImpl(&(*mutations_)[element_id], layers.main, + layers.scroll)); +} + +} // namespace cc_blink diff --git a/cc/blink/web_compositor_mutable_state_provider_impl.h b/cc/blink/web_compositor_mutable_state_provider_impl.h new file mode 100644 index 0000000..138103d --- /dev/null +++ b/cc/blink/web_compositor_mutable_state_provider_impl.h @@ -0,0 +1,44 @@ +// Copyright 2015 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_BLINK_WEB_COMPOSITOR_MUTABLE_STATE_PROVIDER_IMPL_H_ +#define CC_BLINK_WEB_COMPOSITOR_MUTABLE_STATE_PROVIDER_IMPL_H_ + +#include "base/compiler_specific.h" +#include "base/containers/hash_tables.h" +#include "cc/animation/layer_tree_mutation.h" +#include "cc/blink/cc_blink_export.h" + +#include "third_party/WebKit/public/platform/WebCompositorMutableStateProvider.h" + +namespace cc { +class LayerTreeImpl; +} // namespace cc + +namespace cc_blink { + +class WebCompositorMutableStateProviderImpl + : public blink::WebCompositorMutableStateProvider { + public: + // TODO(vollick): after slimming paint v2, this will need to operate on + // property trees, not the layer tree impl. + // + // The LayerTreeImpl and the LayerTreeMutationMap are both owned by caller. + CC_BLINK_EXPORT WebCompositorMutableStateProviderImpl( + cc::LayerTreeImpl* state, + cc::LayerTreeMutationMap* mutations); + + CC_BLINK_EXPORT ~WebCompositorMutableStateProviderImpl() override; + + CC_BLINK_EXPORT blink::WebPassOwnPtr<blink::WebCompositorMutableState> + getMutableStateFor(uint64_t element_id) override WARN_UNUSED_RESULT; + + private: + cc::LayerTreeImpl* state_; + cc::LayerTreeMutationMap* mutations_; +}; + +} // namespace cc_blink + +#endif // CC_BLINK_WEB_COMPOSITOR_MUTABLE_STATE_PROVIDER_IMPL_H_ diff --git a/cc/layers/layer_impl.cc b/cc/layers/layer_impl.cc index f36215d..93d45a9 100644 --- a/cc/layers/layer_impl.cc +++ b/cc/layers/layer_impl.cc @@ -115,6 +115,9 @@ LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, layer_animation_controller_->set_layer_animation_delegate(this); } } + + layer_tree_impl_->AddToElementMap(this); + SetNeedsPushProperties(); } @@ -132,6 +135,8 @@ LayerImpl::~LayerImpl() { layer_tree_impl_->UnregisterScrollLayer(this); layer_tree_impl_->UnregisterLayer(this); + layer_tree_impl_->RemoveFromElementMap(this); + TRACE_EVENT_OBJECT_DELETED_WITH_ID( TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); } @@ -1249,7 +1254,9 @@ void LayerImpl::SetElementId(uint64_t element_id) { TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "LayerImpl::SetElementId", "id", element_id); + layer_tree_impl_->RemoveFromElementMap(this); element_id_ = element_id; + layer_tree_impl_->AddToElementMap(this); SetNeedsPushProperties(); } @@ -1261,6 +1268,8 @@ void LayerImpl::SetMutableProperties(uint32_t properties) { "LayerImpl::SetMutableProperties", "properties", properties); mutable_properties_ = properties; + // If this layer is already in the element map, update its properties. + layer_tree_impl_->AddToElementMap(this); SetNeedsPushProperties(); } diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc index 86be523..3834f74 100644 --- a/cc/trees/layer_tree_impl.cc +++ b/cc/trees/layer_tree_impl.cc @@ -17,6 +17,7 @@ #include "base/trace_event/trace_event_argument.h" #include "cc/animation/animation_host.h" #include "cc/animation/keyframed_animation_curve.h" +#include "cc/animation/mutable_properties.h" #include "cc/animation/scrollbar_animation_controller.h" #include "cc/animation/scrollbar_animation_controller_linear_fade.h" #include "cc/animation/scrollbar_animation_controller_thinning.h" @@ -46,6 +47,15 @@ namespace cc { +namespace { + +const uint32_t kMainLayerFlags = + kMutablePropertyOpacity | kMutablePropertyTransform; +const uint32_t kScrollLayerFlags = + kMutablePropertyScrollLeft | kMutablePropertyScrollTop; + +} // namespace + LayerTreeImpl::LayerTreeImpl( LayerTreeHostImpl* layer_tree_host_impl, scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, @@ -359,6 +369,54 @@ void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { target_tree->has_ever_been_drawn_ = false; } +void LayerTreeImpl::AddToElementMap(LayerImpl* layer) { + if (!layer->element_id()) + return; + + TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), + "LayerTreeImpl::AddToElementMap", "element_id", + layer->element_id(), "layer_id", layer->id()); + + ElementLayers& layers = element_layers_map_[layer->element_id()]; + if (layer->mutable_properties() & kMainLayerFlags) { + if (!layers.main || layer->IsActive()) + layers.main = layer; + } + if (layer->mutable_properties() & kScrollLayerFlags) { + if (!layers.scroll || layer->IsActive()) { + TRACE_EVENT2("compositor-worker", "LayerTreeImpl::AddToElementMap scroll", + "element_id", layer->element_id(), "layer_id", layer->id()); + layers.scroll = layer; + } + } +} + +void LayerTreeImpl::RemoveFromElementMap(LayerImpl* layer) { + if (!layer->element_id()) + return; + + TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), + "LayerTreeImpl::RemoveFromElementMap", "element_id", + layer->element_id(), "layer_id", layer->id()); + + ElementLayers& layers = element_layers_map_[layer->element_id()]; + if (layer->mutable_properties() & kMainLayerFlags) + layers.main = nullptr; + if (layer->mutable_properties() & kScrollLayerFlags) + layers.scroll = nullptr; + + if (!layers.main && !layers.scroll) + element_layers_map_.erase(layer->element_id()); +} + +LayerTreeImpl::ElementLayers LayerTreeImpl::GetMutableLayers( + uint64_t element_id) { + auto iter = element_layers_map_.find(element_id); + if (iter == element_layers_map_.end()) + return ElementLayers(); + + return iter->second; +} LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { return InnerViewportScrollLayer() diff --git a/cc/trees/layer_tree_impl.h b/cc/trees/layer_tree_impl.h index d80eeca..16a1bb9 100644 --- a/cc/trees/layer_tree_impl.h +++ b/cc/trees/layer_tree_impl.h @@ -5,9 +5,6 @@ #ifndef CC_TREES_LAYER_TREE_IMPL_H_ #define CC_TREES_LAYER_TREE_IMPL_H_ -#include <stddef.h> -#include <stdint.h> - #include <map> #include <set> #include <string> @@ -141,6 +138,16 @@ class CC_EXPORT LayerTreeImpl { void PushPropertiesTo(LayerTreeImpl* tree_impl); + struct CC_EXPORT ElementLayers { + // Transform and opacity mutations apply to this layer. + LayerImpl* main = nullptr; + // Scroll mutations apply to this layer. + LayerImpl* scroll = nullptr; + }; + + void AddToElementMap(LayerImpl* layer); + void RemoveFromElementMap(LayerImpl* layer); + ElementLayers GetMutableLayers(uint64_t element_id); int source_frame_number() const { return source_frame_number_; } void set_source_frame_number(int frame_number) { source_frame_number_ = frame_number; @@ -476,6 +483,8 @@ class CC_EXPORT LayerTreeImpl { typedef base::hash_map<int, LayerImpl*> LayerIdMap; LayerIdMap layer_id_map_; + base::hash_map<uint64_t, ElementLayers> element_layers_map_; + // Maps from clip layer ids to scroll layer ids. Note that this only includes // the subset of clip layers that act as scrolling containers. (This is // derived from LayerImpl::scroll_clip_layer_ and exists to avoid O(n) walks.) diff --git a/third_party/WebKit/public/platform/WebCompositorMutableState.h b/third_party/WebKit/public/platform/WebCompositorMutableState.h new file mode 100644 index 0000000..a4d57d2 --- /dev/null +++ b/third_party/WebKit/public/platform/WebCompositorMutableState.h @@ -0,0 +1,34 @@ +// Copyright 2015 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 WebCompositorMutableState_h +#define WebCompositorMutableState_h + +#include <cstdint> + +class SkMatrix44; + +namespace blink { + +// This class wraps the compositor-owned, mutable state for a single element. +class WebCompositorMutableState { +public: + virtual ~WebCompositorMutableState() { } + + virtual double opacity() const = 0; + virtual void setOpacity(double) = 0; + + virtual const SkMatrix44& transform() const = 0; + virtual void setTransform(const SkMatrix44&) = 0; + + virtual double scrollLeft() const = 0; + virtual void setScrollLeft(double) = 0; + + virtual double scrollTop() const = 0; + virtual void setScrollTop(double) = 0; +}; + +} // namespace blink + +#endif // WebCompositorMutableState_h diff --git a/third_party/WebKit/public/platform/WebCompositorMutableStateProvider.h b/third_party/WebKit/public/platform/WebCompositorMutableStateProvider.h new file mode 100644 index 0000000..c2dca7c --- /dev/null +++ b/third_party/WebKit/public/platform/WebCompositorMutableStateProvider.h @@ -0,0 +1,28 @@ +// Copyright 2015 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 WebCompositorMutableStateProvider_h +#define WebCompositorMutableStateProvider_h + +#include "public/platform/WebPassOwnPtr.h" + +#include <cstdint> + +namespace blink { + +class WebCompositorMutableState; + +// This class is a window onto compositor-owned state. It vends out wrappers +// around per-element bits of this state. +class WebCompositorMutableStateProvider { +public: + virtual ~WebCompositorMutableStateProvider() { } + + // The caller is expected to take ownership. + virtual WebPassOwnPtr<WebCompositorMutableState> getMutableStateFor(uint64_t elementId) = 0; +}; + +} // namespace blink + +#endif // WebCompositorMutableStateProvider_h diff --git a/third_party/WebKit/public/platform/WebPassOwnPtr.h b/third_party/WebKit/public/platform/WebPassOwnPtr.h index 217bd54..9b2d34f 100644 --- a/third_party/WebKit/public/platform/WebPassOwnPtr.h +++ b/third_party/WebKit/public/platform/WebPassOwnPtr.h @@ -10,6 +10,8 @@ #if INSIDE_BLINK #include "wtf/PassOwnPtr.h" +#else +#include <base/memory/scoped_ptr.h> #endif namespace blink { @@ -50,6 +52,13 @@ public: m_ptr = nullptr; return adoptPtr(ptr); } +#else + operator scoped_ptr<T>() + { + T* ptr = m_ptr; + m_ptr = nullptr; + return scoped_ptr<T>(ptr); + } #endif // INSIDE_BLINK template <typename U> friend class WebPassOwnPtr; diff --git a/ui/gfx/transform.h b/ui/gfx/transform.h index 26f7b9d..75c4797 100644 --- a/ui/gfx/transform.h +++ b/ui/gfx/transform.h @@ -40,6 +40,7 @@ class GFX_EXPORT Transform { // Initialize with the concatenation of lhs * rhs. Transform(const Transform& lhs, const Transform& rhs) : matrix_(lhs.matrix_, rhs.matrix_) {} + explicit Transform(const SkMatrix44& matrix) : matrix_(matrix) {} // Constructs a transform from explicit 16 matrix elements. Elements // should be given in row-major order. Transform(SkMScalar col1row1, |