Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1266)

Unified Diff: third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp

Issue 2765053002: Avoid exposing cc::Layer tree to CompositorProxy (Closed)
Patch Set: Minor changes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp b/third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp
index 95ad341795d5e073184585b32d26b3e8a5a8ab20..8589afd596a45813909ed225b8c9ce6ad4728031 100644
--- a/third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp
+++ b/third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp
@@ -5,14 +5,6 @@
#include "platform/graphics/CompositorMutableState.h"
#include "base/message_loop/message_loop.h"
-#include "cc/test/fake_compositor_frame_sink.h"
-#include "cc/test/fake_impl_task_runner_provider.h"
-#include "cc/test/fake_layer_tree_host_impl.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 "cc/trees/layer_tree_impl.h"
-#include "platform/graphics/CompositorElementId.h"
#include "platform/graphics/CompositorMutableProperties.h"
#include "platform/graphics/CompositorMutableStateProvider.h"
#include "platform/graphics/CompositorMutation.h"
@@ -21,135 +13,67 @@
namespace blink {
-using cc::FakeImplTaskRunnerProvider;
-using cc::FakeLayerTreeHostImpl;
-using cc::FakeCompositorFrameSink;
-using cc::LayerImpl;
-using cc::LayerTreeSettings;
-using cc::TestTaskGraphRunner;
-using cc::TestSharedBitmapManager;
-
-class CompositorMutableStateTest : public testing::Test {
- public:
- CompositorMutableStateTest()
- : m_compositorFrameSink(FakeCompositorFrameSink::Create3d()) {
- LayerTreeSettings settings;
- settings.layer_transforms_should_scale_layer_contents = true;
- m_hostImpl.reset(new FakeLayerTreeHostImpl(settings, &m_taskRunnerProvider,
- &m_taskGraphRunner));
- m_hostImpl->SetVisible(true);
- EXPECT_TRUE(m_hostImpl->InitializeRenderer(m_compositorFrameSink.get()));
- }
-
- void SetLayerPropertiesForTesting(LayerImpl* layer) {
- layer->test_properties()->transform = gfx::Transform();
- layer->SetPosition(gfx::PointF());
- layer->SetBounds(gfx::Size(100, 100));
- layer->SetDrawsContent(true);
- }
-
- FakeLayerTreeHostImpl& hostImpl() { return *m_hostImpl; }
-
- LayerImpl* rootLayer() {
- return m_hostImpl->active_tree()->root_layer_for_testing();
- }
-
- private:
- // The cc testing machinery has fairly deep dependency on having a main
- // message loop (one example is the task runner provider). We construct one
- // here so that it's installed in TLA and can be found by other cc classes.
- base::MessageLoop m_messageLoop;
- TestTaskGraphRunner m_taskGraphRunner;
- FakeImplTaskRunnerProvider m_taskRunnerProvider;
- std::unique_ptr<FakeCompositorFrameSink> m_compositorFrameSink;
- std::unique_ptr<FakeLayerTreeHostImpl> m_hostImpl;
-};
-
-TEST_F(CompositorMutableStateTest, NoMutableState) {
- // In this test, there are no layers with either an element id or mutable
+TEST(CompositorMutableStateTest, NoMutableState) {
+ // In this test, there are no proxies with either an element id or mutable
// properties. We should not be able to get any mutable state.
- std::unique_ptr<LayerImpl> root =
- LayerImpl::Create(hostImpl().active_tree(), 42);
- SetLayerPropertiesForTesting(root.get());
-
- hostImpl().SetViewportSize(root->bounds());
- hostImpl().active_tree()->SetRootLayerForTesting(std::move(root));
- hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
-
+ ProxyCompositorMutablePropertiesMap emptyMap;
CompositorMutations mutations;
- CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations);
+ CompositorMutableStateProvider provider(&emptyMap, &mutations);
std::unique_ptr<CompositorMutableState> state(
provider.getMutableStateFor(42));
EXPECT_FALSE(state);
}
-TEST_F(CompositorMutableStateTest, 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.
- std::unique_ptr<LayerImpl> root =
- LayerImpl::Create(hostImpl().active_tree(), 42);
-
- std::unique_ptr<LayerImpl> scopedLayer =
- LayerImpl::Create(hostImpl().active_tree(), 11);
- LayerImpl* layer = scopedLayer.get();
- layer->SetScrollClipLayer(root->id());
-
- root->test_properties()->AddChild(std::move(scopedLayer));
-
- SetLayerPropertiesForTesting(layer);
-
- int primaryId = 12;
- root->SetElementId(
- createCompositorElementId(primaryId, CompositorSubElementId::Primary));
- layer->SetElementId(
- createCompositorElementId(primaryId, CompositorSubElementId::Scroll));
-
- root->SetMutableProperties(CompositorMutableProperty::kOpacity |
- CompositorMutableProperty::kTransform);
- layer->SetMutableProperties(CompositorMutableProperty::kScrollLeft |
- CompositorMutableProperty::kScrollTop);
+TEST(CompositorMutableStateTest, MutableStateMutableProperties) {
+ // In this test, there is a proxy with an element id and mutable properties.
+ // In this case, we should get a valid mutable state for this element id and
+ // mutations should be updated accordingly.
+ int proxyId = 12;
+ int elementId = 15;
- hostImpl().SetViewportSize(layer->bounds());
- hostImpl().active_tree()->SetRootLayerForTesting(std::move(root));
- hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
+ ProxyCompositorMutablePropertiesMap inputProperties;
+ inputProperties[proxyId].elementId = elementId;
+ inputProperties[proxyId].opacity = 1.0;
+ inputProperties[proxyId].transform = SkMatrix44::I();
+ inputProperties[proxyId].scrollLeft = 0;
+ inputProperties[proxyId].scrollTop = 0;
CompositorMutations mutations;
- CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations);
+ CompositorMutableStateProvider provider(&inputProperties, &mutations);
std::unique_ptr<CompositorMutableState> state(
- provider.getMutableStateFor(primaryId));
+ provider.getMutableStateFor(proxyId));
EXPECT_TRUE(state.get());
- EXPECT_EQ(1.0, rootLayer()->Opacity());
- EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->Transform().ToString());
- EXPECT_EQ(0.0, layer->CurrentScrollOffset().x());
- EXPECT_EQ(0.0, layer->CurrentScrollOffset().y());
+ EXPECT_EQ(1.0, state->opacity());
+ EXPECT_EQ(SkMatrix44::I(), state->transform());
+ EXPECT_EQ(0.0, state->scrollTop());
+ EXPECT_EQ(0.0, state->scrollLeft());
- gfx::Transform zero(0, 0, 0, 0, 0, 0);
+ SkMatrix44 zero;
state->setOpacity(0.5);
- state->setTransform(zero.matrix());
- state->setScrollLeft(1.0);
- state->setScrollTop(1.0);
+ state->setTransform(zero);
+ state->setScrollLeft(0.75);
+ state->setScrollTop(0.25);
- EXPECT_EQ(0.5, rootLayer()->Opacity());
- EXPECT_EQ(zero.ToString(), rootLayer()->Transform().ToString());
- EXPECT_EQ(1.0, layer->CurrentScrollOffset().x());
- EXPECT_EQ(1.0, layer->CurrentScrollOffset().y());
+ EXPECT_EQ(0.5, state->opacity());
+ EXPECT_EQ(zero, state->transform());
+ EXPECT_EQ(0.25, state->scrollTop());
+ EXPECT_EQ(0.75, state->scrollLeft());
// The corresponding mutation should reflect the changed values.
EXPECT_EQ(1ul, mutations.map.size());
- const CompositorMutation& mutation = *mutations.map.find(primaryId)->value;
+ const CompositorMutation& mutation = *mutations.map.find(elementId)->value;
EXPECT_TRUE(mutation.isOpacityMutated());
EXPECT_TRUE(mutation.isTransformMutated());
EXPECT_TRUE(mutation.isScrollLeftMutated());
EXPECT_TRUE(mutation.isScrollTopMutated());
EXPECT_EQ(0.5, mutation.opacity());
- EXPECT_EQ(zero.ToString(), gfx::Transform(mutation.transform()).ToString());
- EXPECT_EQ(1.0, mutation.scrollLeft());
- EXPECT_EQ(1.0, mutation.scrollTop());
+ EXPECT_EQ(zero, mutation.transform());
+ EXPECT_EQ(0.75, mutation.scrollLeft());
+ EXPECT_EQ(0.25, mutation.scrollTop());
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698