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

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

Issue 1599673002: compositor-worker: Remove code from cc_blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix blink_platform_unittests Created 4 years, 11 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
new file mode 100644
index 0000000000000000000000000000000000000000..1b4d2a92052a70b99871476936ab4d98fe3a8cc2
--- /dev/null
+++ b/third_party/WebKit/Source/platform/graphics/CompositorMutableStateTest.cpp
@@ -0,0 +1,159 @@
+// Copyright 2016 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 "platform/graphics/CompositorMutableState.h"
+
+#include "base/message_loop/message_loop.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/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/CompositorMutableProperties.h"
+#include "platform/graphics/CompositorMutableStateProvider.h"
+#include "platform/graphics/CompositorMutation.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/OwnPtr.h"
+
+namespace blink {
+
+using cc::FakeImplTaskRunnerProvider;
+using cc::FakeLayerTreeHostImpl;
+using cc::FakeOutputSurface;
+using cc::LayerImpl;
+using cc::LayerTreeSettings;
+using cc::OutputSurface;
+using cc::TestTaskGraphRunner;
+using cc::TestSharedBitmapManager;
+
+class CompositorMutableStateTest : public testing::Test {
+public:
+ CompositorMutableStateTest()
+ : m_outputSurface(FakeOutputSurface::Create3d())
+ {
+ LayerTreeSettings settings;
+ settings.layer_transforms_should_scale_layer_contents = true;
+ settings.verify_property_trees = true;
+ m_hostImpl.reset(new FakeLayerTreeHostImpl(settings, &m_taskRunnerProvider, &m_sharedBitmapManager, &m_taskGraphRunner));
+ m_hostImpl->SetVisible(true);
+ EXPECT_TRUE(m_hostImpl->InitializeRenderer(m_outputSurface.get()));
+ }
+
+ void SetLayerPropertiesForTesting(LayerImpl* layer)
+ {
+ layer->SetTransform(gfx::Transform());
+ layer->SetTransformOrigin(gfx::Point3F());
+ layer->SetPosition(gfx::PointF());
+ layer->SetBounds(gfx::Size(100, 100));
+ layer->SetShouldFlattenTransform(true);
+ layer->Set3dSortingContextId(0);
+ layer->SetForceRenderSurface(true);
+ layer->SetDrawsContent(true);
+ }
+
+ FakeLayerTreeHostImpl& hostImpl() { return *m_hostImpl; }
+
+ LayerImpl* rootLayer() { return m_hostImpl->active_tree()->root_layer(); }
+
+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;
+ TestSharedBitmapManager m_sharedBitmapManager;
+ TestTaskGraphRunner m_taskGraphRunner;
+ FakeImplTaskRunnerProvider m_taskRunnerProvider;
+ scoped_ptr<OutputSurface> m_outputSurface;
+ scoped_ptr<FakeLayerTreeHostImpl> m_hostImpl;
+};
+
+TEST_F(CompositorMutableStateTest, 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(hostImpl().active_tree(), 42);
+ SetLayerPropertiesForTesting(root.get());
+
+ hostImpl().SetViewportSize(root->bounds());
+ hostImpl().active_tree()->SetRootLayer(std::move(root));
+ hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
+
+ CompositorMutations mutations;
+ CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations);
+ OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42));
+ EXPECT_FALSE(state);
+}
+
+TEST_F(CompositorMutableStateTest, 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(hostImpl().active_tree(), 42);
+ SetLayerPropertiesForTesting(root.get());
+ root->SetElementId(42);
+
+ hostImpl().SetViewportSize(root->bounds());
+ hostImpl().active_tree()->SetRootLayer(std::move(root));
+ hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
+
+ CompositorMutations mutations;
+ CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations);
+ OwnPtr<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.
+ scoped_ptr<LayerImpl> root = LayerImpl::Create(hostImpl().active_tree(), 42);
+ SetLayerPropertiesForTesting(root.get());
+ root->SetElementId(42);
+ root->SetMutableProperties(CompositorMutableProperty::kOpacity | CompositorMutableProperty::kTransform | CompositorMutableProperty::kScrollLeft | CompositorMutableProperty::kScrollTop);
+
+ hostImpl().SetViewportSize(root->bounds());
+ hostImpl().active_tree()->SetRootLayer(std::move(root));
+ hostImpl().UpdateNumChildrenAndDrawPropertiesForActiveTree();
+
+ CompositorMutations mutations;
+ CompositorMutableStateProvider provider(hostImpl().active_tree(), &mutations);
+
+ OwnPtr<CompositorMutableState> state(provider.getMutableStateFor(42));
+ EXPECT_TRUE(state.get());
+
+ EXPECT_EQ(1.0, rootLayer()->opacity());
+ EXPECT_EQ(gfx::Transform().ToString(), rootLayer()->transform().ToString());
+ EXPECT_EQ(0.0, rootLayer()->CurrentScrollOffset().x());
+ EXPECT_EQ(0.0, rootLayer()->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, rootLayer()->opacity());
+ EXPECT_EQ(zero.ToString(), rootLayer()->transform().ToString());
+ EXPECT_EQ(1.0, rootLayer()->CurrentScrollOffset().x());
+ EXPECT_EQ(1.0, rootLayer()->CurrentScrollOffset().y());
+
+ // The corresponding mutation should reflect the changed values.
+ EXPECT_EQ(1ul, mutations.map.size());
+
+ const CompositorMutation& mutation = *mutations.map.find(42)->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());
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698