Commit 54689895 authored by trchen's avatar trchen Committed by Commit bot

[SPv2] Add createOpacityOnlyEffect test helper

This CL adds a test helper header platform/testing/PaintPropertyTestHelpers.h
for common operations that are used in SPv2-related tests.

createOpacityOnlyEffect is added to create effect nodes with only opacity,
other optional effects are assigned a no-op value, and local transform space
and clip are inherited from parent.

As a side change, rootPaintChunkProperties is also moved to the helper header
and renamed to defaultPaintChunkProperties.
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2565903002
Cr-Commit-Position: refs/heads/master@{#437994}
parent d798a7a8
...@@ -1606,6 +1606,7 @@ static_library("test_support") { ...@@ -1606,6 +1606,7 @@ static_library("test_support") {
"testing/MessageLoopForMojo.h", "testing/MessageLoopForMojo.h",
"testing/PaintPrinters.cpp", "testing/PaintPrinters.cpp",
"testing/PaintPrinters.h", "testing/PaintPrinters.h",
"testing/PaintPropertyTestHelpers.h",
"testing/PictureMatchers.cpp", "testing/PictureMatchers.cpp",
"testing/PictureMatchers.h", "testing/PictureMatchers.h",
"testing/PlatformTestPrinters.cpp", "testing/PlatformTestPrinters.cpp",
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "platform/graphics/paint/EffectPaintPropertyNode.h" #include "platform/graphics/paint/EffectPaintPropertyNode.h"
#include "platform/graphics/paint/PaintArtifact.h" #include "platform/graphics/paint/PaintArtifact.h"
#include "platform/graphics/paint/ScrollPaintPropertyNode.h" #include "platform/graphics/paint/ScrollPaintPropertyNode.h"
#include "platform/testing/PaintPropertyTestHelpers.h"
#include "platform/testing/PictureMatchers.h" #include "platform/testing/PictureMatchers.h"
#include "platform/testing/TestPaintArtifact.h" #include "platform/testing/TestPaintArtifact.h"
#include "platform/testing/WebLayerTreeViewImplForTesting.h" #include "platform/testing/WebLayerTreeViewImplForTesting.h"
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
namespace blink { namespace blink {
namespace { namespace {
using ::blink::testing::createOpacityOnlyEffect;
using ::testing::Pointee; using ::testing::Pointee;
PaintChunkProperties defaultPaintChunkProperties() { PaintChunkProperties defaultPaintChunkProperties() {
...@@ -569,15 +571,12 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ...@@ -569,15 +571,12 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees,
} }
TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) { TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) {
RefPtr<EffectPaintPropertyNode> effect1 = EffectPaintPropertyNode::create( RefPtr<EffectPaintPropertyNode> effect1 =
EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.5);
ClipPaintPropertyNode::root(), CompositorFilterOperations(), 0.5); RefPtr<EffectPaintPropertyNode> effect2 =
RefPtr<EffectPaintPropertyNode> effect2 = EffectPaintPropertyNode::create( createOpacityOnlyEffect(effect1, 0.3);
effect1, TransformPaintPropertyNode::root(), RefPtr<EffectPaintPropertyNode> effect3 =
ClipPaintPropertyNode::root(), CompositorFilterOperations(), 0.3); createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.2);
RefPtr<EffectPaintPropertyNode> effect3 = EffectPaintPropertyNode::create(
EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
ClipPaintPropertyNode::root(), CompositorFilterOperations(), 0.2);
TestPaintArtifact artifact; TestPaintArtifact artifact;
artifact artifact
...@@ -661,9 +660,8 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneScrollNode) { ...@@ -661,9 +660,8 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneScrollNode) {
} }
TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedScrollNodes) { TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedScrollNodes) {
RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( RefPtr<EffectPaintPropertyNode> effect =
EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.5);
ClipPaintPropertyNode::root(), CompositorFilterOperations(), 0.5);
RefPtr<TransformPaintPropertyNode> scrollTranslationA = RefPtr<TransformPaintPropertyNode> scrollTranslationA =
TransformPaintPropertyNode::create( TransformPaintPropertyNode::create(
......
...@@ -10,22 +10,19 @@ ...@@ -10,22 +10,19 @@
#include "platform/graphics/paint/EffectPaintPropertyNode.h" #include "platform/graphics/paint/EffectPaintPropertyNode.h"
#include "platform/graphics/paint/ScrollPaintPropertyNode.h" #include "platform/graphics/paint/ScrollPaintPropertyNode.h"
#include "platform/graphics/paint/TransformPaintPropertyNode.h" #include "platform/graphics/paint/TransformPaintPropertyNode.h"
#include "platform/testing/PaintPropertyTestHelpers.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace blink { namespace blink {
class GeometryMapperTest : public ::testing::Test { class GeometryMapperTest : public ::testing::Test {
public: public:
RefPtr<TransformPaintPropertyNode> rootTransformNode;
RefPtr<ClipPaintPropertyNode> rootClipNode;
RefPtr<EffectPaintPropertyNode> rootEffectNode;
RefPtr<ScrollPaintPropertyNode> rootScrollNode;
std::unique_ptr<GeometryMapper> geometryMapper; std::unique_ptr<GeometryMapper> geometryMapper;
PropertyTreeState rootPropertyTreeState() { PropertyTreeState rootPropertyTreeState() {
PropertyTreeState state(rootTransformNode.get(), rootClipNode.get(), PropertyTreeState state(
rootEffectNode.get(), rootScrollNode.get()); TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(),
EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root());
return state; return state;
} }
...@@ -42,16 +39,6 @@ class GeometryMapperTest : public ::testing::Test { ...@@ -42,16 +39,6 @@ class GeometryMapperTest : public ::testing::Test {
private: private:
void SetUp() override { void SetUp() override {
rootTransformNode = TransformPaintPropertyNode::create(
nullptr, TransformationMatrix(), FloatPoint3D());
rootClipNode = ClipPaintPropertyNode::create(
nullptr, rootTransformNode,
FloatRoundedRect(LayoutRect::infiniteIntRect()));
rootEffectNode = EffectPaintPropertyNode::create(
nullptr, rootTransformNode, rootClipNode, CompositorFilterOperations(),
1.0);
rootScrollNode = ScrollPaintPropertyNode::create(
nullptr, rootTransformNode, IntSize(), IntSize(), false, false, 0);
geometryMapper = WTF::makeUnique<GeometryMapper>(); geometryMapper = WTF::makeUnique<GeometryMapper>();
} }
...@@ -116,9 +103,10 @@ const static float kTestEpsilon = 1e-6; ...@@ -116,9 +103,10 @@ const static float kTestEpsilon = 1e-6;
TEST_F(GeometryMapperTest, Root) { TEST_F(GeometryMapperTest, Root) {
FloatRect input(0, 0, 100, 100); FloatRect input(0, 0, 100, 100);
CHECK_MAPPINGS(input, input, input, rootTransformNode->matrix(), CHECK_MAPPINGS(input, input, input,
rootClipNode->clipRect().rect(), rootPropertyTreeState(), TransformPaintPropertyNode::root()->matrix(),
rootPropertyTreeState()); ClipPaintPropertyNode::root()->clipRect().rect(),
rootPropertyTreeState(), rootPropertyTreeState());
} }
TEST_F(GeometryMapperTest, IdentityTransform) { TEST_F(GeometryMapperTest, IdentityTransform) {
...@@ -132,7 +120,7 @@ TEST_F(GeometryMapperTest, IdentityTransform) { ...@@ -132,7 +120,7 @@ TEST_F(GeometryMapperTest, IdentityTransform) {
FloatRect input(0, 0, 100, 100); FloatRect input(0, 0, 100, 100);
CHECK_MAPPINGS(input, input, input, transform->matrix(), CHECK_MAPPINGS(input, input, input, transform->matrix(),
rootClipNode->clipRect().rect(), localState, ClipPaintPropertyNode::root()->clipRect().rect(), localState,
rootPropertyTreeState()); rootPropertyTreeState());
} }
...@@ -149,7 +137,7 @@ TEST_F(GeometryMapperTest, TranslationTransform) { ...@@ -149,7 +137,7 @@ TEST_F(GeometryMapperTest, TranslationTransform) {
FloatRect output = transformMatrix.mapRect(input); FloatRect output = transformMatrix.mapRect(input);
CHECK_MAPPINGS(input, output, output, transform->matrix(), CHECK_MAPPINGS(input, output, output, transform->matrix(),
rootClipNode->clipRect().rect(), localState, ClipPaintPropertyNode::root()->clipRect().rect(), localState,
rootPropertyTreeState()); rootPropertyTreeState());
bool success = false; bool success = false;
...@@ -174,7 +162,7 @@ TEST_F(GeometryMapperTest, RotationAndScaleTransform) { ...@@ -174,7 +162,7 @@ TEST_F(GeometryMapperTest, RotationAndScaleTransform) {
FloatRect output = transformMatrix.mapRect(input); FloatRect output = transformMatrix.mapRect(input);
CHECK_MAPPINGS(input, output, output, transformMatrix, CHECK_MAPPINGS(input, output, output, transformMatrix,
rootClipNode->clipRect().rect(), localState, ClipPaintPropertyNode::root()->clipRect().rect(), localState,
rootPropertyTreeState()); rootPropertyTreeState());
} }
...@@ -194,7 +182,7 @@ TEST_F(GeometryMapperTest, RotationAndScaleTransformWithTransformOrigin) { ...@@ -194,7 +182,7 @@ TEST_F(GeometryMapperTest, RotationAndScaleTransformWithTransformOrigin) {
FloatRect output = transformMatrix.mapRect(input); FloatRect output = transformMatrix.mapRect(input);
CHECK_MAPPINGS(input, output, output, transformMatrix, CHECK_MAPPINGS(input, output, output, transformMatrix,
rootClipNode->clipRect().rect(), localState, ClipPaintPropertyNode::root()->clipRect().rect(), localState,
rootPropertyTreeState()); rootPropertyTreeState());
} }
...@@ -218,8 +206,9 @@ TEST_F(GeometryMapperTest, NestedTransforms) { ...@@ -218,8 +206,9 @@ TEST_F(GeometryMapperTest, NestedTransforms) {
TransformationMatrix final = rotateTransform * scaleTransform; TransformationMatrix final = rotateTransform * scaleTransform;
FloatRect output = final.mapRect(input); FloatRect output = final.mapRect(input);
CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect(), CHECK_MAPPINGS(input, output, output, final,
localState, rootPropertyTreeState()); ClipPaintPropertyNode::root()->clipRect().rect(), localState,
rootPropertyTreeState());
// Check the cached matrix for the intermediate transform. // Check the cached matrix for the intermediate transform.
EXPECT_EQ(rotateTransform, EXPECT_EQ(rotateTransform,
...@@ -249,8 +238,9 @@ TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) { ...@@ -249,8 +238,9 @@ TEST_F(GeometryMapperTest, NestedTransformsScaleAndTranslation) {
TransformationMatrix final = scaleTransform * translateTransform; TransformationMatrix final = scaleTransform * translateTransform;
FloatRect output = final.mapRect(input); FloatRect output = final.mapRect(input);
CHECK_MAPPINGS(input, output, output, final, rootClipNode->clipRect().rect(), CHECK_MAPPINGS(input, output, output, final,
localState, rootPropertyTreeState()); ClipPaintPropertyNode::root()->clipRect().rect(), localState,
rootPropertyTreeState());
// Check the cached matrix for the intermediate transform. // Check the cached matrix for the intermediate transform.
EXPECT_EQ(scaleTransform, EXPECT_EQ(scaleTransform,
...@@ -281,13 +271,14 @@ TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) { ...@@ -281,13 +271,14 @@ TEST_F(GeometryMapperTest, NestedTransformsIntermediateDestination) {
FloatRect output = scaleTransform.mapRect(input); FloatRect output = scaleTransform.mapRect(input);
CHECK_MAPPINGS(input, output, output, scaleTransform, CHECK_MAPPINGS(input, output, output, scaleTransform,
rootClipNode->clipRect().rect(), localState, ClipPaintPropertyNode::root()->clipRect().rect(), localState,
intermediateState); intermediateState);
} }
TEST_F(GeometryMapperTest, SimpleClip) { TEST_F(GeometryMapperTest, SimpleClip) {
RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
rootClipNode, rootTransformNode, FloatRoundedRect(10, 10, 50, 50)); ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
FloatRoundedRect(10, 10, 50, 50));
PropertyTreeState localState = rootPropertyTreeState(); PropertyTreeState localState = rootPropertyTreeState();
localState.setClip(clip.get()); localState.setClip(clip.get());
...@@ -295,13 +286,14 @@ TEST_F(GeometryMapperTest, SimpleClip) { ...@@ -295,13 +286,14 @@ TEST_F(GeometryMapperTest, SimpleClip) {
FloatRect input(0, 0, 100, 100); FloatRect input(0, 0, 100, 100);
FloatRect output(10, 10, 50, 50); FloatRect output(10, 10, 50, 50);
CHECK_MAPPINGS( CHECK_MAPPINGS(input, // Input
input, // Input output, // Visual rect
output, // Visual rect input, // Transformed rect (not clipped).
input, // Transformed rect (not clipped). TransformPaintPropertyNode::root()
rootTransformNode->matrix(), // Transform matrix to ancestor space ->matrix(), // Transform matrix to ancestor space
clip->clipRect().rect(), // Clip rect in ancestor space clip->clipRect().rect(), // Clip rect in ancestor space
localState, rootPropertyTreeState()); localState,
rootPropertyTreeState());
} }
TEST_F(GeometryMapperTest, ClipBeforeTransform) { TEST_F(GeometryMapperTest, ClipBeforeTransform) {
...@@ -312,7 +304,8 @@ TEST_F(GeometryMapperTest, ClipBeforeTransform) { ...@@ -312,7 +304,8 @@ TEST_F(GeometryMapperTest, ClipBeforeTransform) {
rotateTransform, FloatPoint3D()); rotateTransform, FloatPoint3D());
RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
rootClipNode, transform.get(), FloatRoundedRect(10, 10, 50, 50)); ClipPaintPropertyNode::root(), transform.get(),
FloatRoundedRect(10, 10, 50, 50));
PropertyTreeState localState = rootPropertyTreeState(); PropertyTreeState localState = rootPropertyTreeState();
localState.setClip(clip.get()); localState.setClip(clip.get());
...@@ -341,9 +334,9 @@ TEST_F(GeometryMapperTest, ClipAfterTransform) { ...@@ -341,9 +334,9 @@ TEST_F(GeometryMapperTest, ClipAfterTransform) {
TransformPaintPropertyNode::create(rootPropertyTreeState().transform(), TransformPaintPropertyNode::create(rootPropertyTreeState().transform(),
rotateTransform, FloatPoint3D()); rotateTransform, FloatPoint3D());
RefPtr<ClipPaintPropertyNode> clip = RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create(
ClipPaintPropertyNode::create(rootClipNode, rootTransformNode.get(), ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
FloatRoundedRect(10, 10, 200, 200)); FloatRoundedRect(10, 10, 200, 200));
PropertyTreeState localState = rootPropertyTreeState(); PropertyTreeState localState = rootPropertyTreeState();
localState.setClip(clip.get()); localState.setClip(clip.get());
...@@ -364,9 +357,9 @@ TEST_F(GeometryMapperTest, ClipAfterTransform) { ...@@ -364,9 +357,9 @@ TEST_F(GeometryMapperTest, ClipAfterTransform) {
} }
TEST_F(GeometryMapperTest, TwoClipsWithTransformBetween) { TEST_F(GeometryMapperTest, TwoClipsWithTransformBetween) {
RefPtr<ClipPaintPropertyNode> clip1 = RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create(
ClipPaintPropertyNode::create(rootClipNode, rootTransformNode.get(), ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(),
FloatRoundedRect(10, 10, 200, 200)); FloatRoundedRect(10, 10, 200, 200));
TransformationMatrix rotateTransform; TransformationMatrix rotateTransform;
rotateTransform.rotate(45); rotateTransform.rotate(45);
......
// 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/paint/ClipPaintPropertyNode.h"
#include "platform/graphics/paint/EffectPaintPropertyNode.h"
#include "platform/graphics/paint/PaintChunkProperties.h"
#include "platform/graphics/paint/ScrollPaintPropertyNode.h"
#include "platform/graphics/paint/TransformPaintPropertyNode.h"
namespace blink {
namespace testing {
static inline PassRefPtr<EffectPaintPropertyNode> createOpacityOnlyEffect(
PassRefPtr<const EffectPaintPropertyNode> parent,
float opacity) {
RefPtr<TransformPaintPropertyNode> localTransformSpace =
const_cast<TransformPaintPropertyNode*>(parent->localTransformSpace());
RefPtr<ClipPaintPropertyNode> outputClip =
const_cast<ClipPaintPropertyNode*>(parent->outputClip());
return EffectPaintPropertyNode::create(
std::move(parent), std::move(localTransformSpace), std::move(outputClip),
CompositorFilterOperations(), opacity);
}
static inline PaintChunkProperties defaultPaintChunkProperties() {
PaintChunkProperties defaultProperties;
defaultProperties.transform = TransformPaintPropertyNode::root();
defaultProperties.clip = ClipPaintPropertyNode::root();
defaultProperties.effect = EffectPaintPropertyNode::root();
defaultProperties.scroll = ScrollPaintPropertyNode::root();
return defaultProperties;
}
} // namespace testing
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment