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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/PaintArtifactToSkCanvasTest.cpp

Issue 2428513004: [SPv2] Create effect nodes for CSS filter (Closed)
Patch Set: address pdr's comment Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/graphics/paint/PaintArtifactToSkCanvas.h" 5 #include "platform/graphics/paint/PaintArtifactToSkCanvas.h"
6 6
7 #include "platform/RuntimeEnabledFeatures.h" 7 #include "platform/RuntimeEnabledFeatures.h"
8 #include "platform/graphics/paint/DisplayItem.h" 8 #include "platform/graphics/paint/DisplayItem.h"
9 #include "platform/graphics/paint/DrawingDisplayItem.h" 9 #include "platform/graphics/paint/DrawingDisplayItem.h"
10 #include "platform/graphics/paint/PaintArtifact.h" 10 #include "platform/graphics/paint/PaintArtifact.h"
11 #include "platform/testing/TestPaintArtifact.h" 11 #include "platform/testing/TestPaintArtifact.h"
12 #include "platform/transforms/TransformationMatrix.h" 12 #include "platform/transforms/TransformationMatrix.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/skia/include/core/SkCanvas.h" 15 #include "third_party/skia/include/core/SkCanvas.h"
16 #include "third_party/skia/include/core/SkColor.h" 16 #include "third_party/skia/include/core/SkColor.h"
17 #include "third_party/skia/include/core/SkMatrix.h" 17 #include "third_party/skia/include/core/SkMatrix.h"
18 #include "third_party/skia/include/core/SkPaint.h" 18 #include "third_party/skia/include/core/SkPaint.h"
19 #include "third_party/skia/include/core/SkPicture.h" 19 #include "third_party/skia/include/core/SkPicture.h"
20 #include "third_party/skia/include/core/SkPictureRecorder.h" 20 #include "third_party/skia/include/core/SkPictureRecorder.h"
21 #include "third_party/skia/include/core/SkRect.h" 21 #include "third_party/skia/include/core/SkRect.h"
22 22
23 using testing::_; 23 using testing::_;
24 using testing::Eq; 24 using testing::Eq;
25 using testing::Pointee; 25 using testing::Pointee;
26 using testing::Property; 26 using testing::Property;
27 using testing::ResultOf; 27 using testing::ResultOf;
28 28
29 namespace blink { 29 namespace blink {
30
30 namespace { 31 namespace {
32 TransformPaintPropertyNode* dummyRootTransform() {
33 DEFINE_STATIC_REF(TransformPaintPropertyNode, rootTransform,
34 (TransformPaintPropertyNode::create(
35 nullptr, TransformationMatrix(), FloatPoint3D())));
36 return rootTransform;
37 }
38
39 ClipPaintPropertyNode* dummyRootClip() {
40 DEFINE_STATIC_REF(ClipPaintPropertyNode, rootClip,
41 (ClipPaintPropertyNode::create(
42 nullptr, dummyRootTransform(),
43 FloatRoundedRect(LayoutRect::infiniteIntRect()))));
44 return rootClip;
45 }
46
47 EffectPaintPropertyNode* dummyRootEffect() {
48 DEFINE_STATIC_REF(EffectPaintPropertyNode, rootEffect,
49 (EffectPaintPropertyNode::create(
50 nullptr, dummyRootTransform(), dummyRootClip(),
51 CompositorFilterOperations(), 1.0)));
52 return rootEffect;
53 }
31 54
32 static const int kCanvasWidth = 800; 55 static const int kCanvasWidth = 800;
33 static const int kCanvasHeight = 600; 56 static const int kCanvasHeight = 600;
34 57
35 class MockCanvas : public SkCanvas { 58 class MockCanvas : public SkCanvas {
36 public: 59 public:
37 MockCanvas(int width, int height) : SkCanvas(width, height) {} 60 MockCanvas(int width, int height) : SkCanvas(width, height) {}
38 61
39 MOCK_METHOD3(onDrawRect, void(const SkRect&, const SkPaint&, MockCanvas*)); 62 MOCK_METHOD3(onDrawRect, void(const SkRect&, const SkPaint&, MockCanvas*));
40 MOCK_METHOD2(willSaveLayer, void(unsigned alpha, MockCanvas*)); 63 MOCK_METHOD2(willSaveLayer, void(unsigned alpha, MockCanvas*));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 onDrawRect(SkRect::MakeWH(300, 200), 164 onDrawRect(SkRect::MakeWH(300, 200),
142 Property(&SkPaint::getColor, SK_ColorRED), _)); 165 Property(&SkPaint::getColor, SK_ColorRED), _));
143 EXPECT_CALL(canvas, willSaveLayer(expectedSecondOpacity, _)); 166 EXPECT_CALL(canvas, willSaveLayer(expectedSecondOpacity, _));
144 EXPECT_CALL(canvas, 167 EXPECT_CALL(canvas,
145 onDrawRect(SkRect::MakeWH(300, 200), 168 onDrawRect(SkRect::MakeWH(300, 200),
146 Property(&SkPaint::getColor, SK_ColorBLUE), _)); 169 Property(&SkPaint::getColor, SK_ColorBLUE), _));
147 } 170 }
148 171
149 // Build an opacity effect tree. 172 // Build an opacity effect tree.
150 RefPtr<EffectPaintPropertyNode> opacityEffect1 = 173 RefPtr<EffectPaintPropertyNode> opacityEffect1 =
151 EffectPaintPropertyNode::create(nullptr, 0.5); 174 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(),
175 dummyRootClip(),
176 CompositorFilterOperations(), 0.5);
152 RefPtr<EffectPaintPropertyNode> opacityEffect2 = 177 RefPtr<EffectPaintPropertyNode> opacityEffect2 =
153 EffectPaintPropertyNode::create(opacityEffect1, 0.25); 178 EffectPaintPropertyNode::create(opacityEffect1, dummyRootTransform(),
179 dummyRootClip(),
180 CompositorFilterOperations(), 0.25);
154 181
155 TestPaintArtifact artifact; 182 TestPaintArtifact artifact;
156 artifact.chunk(nullptr, nullptr, opacityEffect1.get()) 183 artifact.chunk(nullptr, nullptr, opacityEffect1.get())
157 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); 184 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED);
158 artifact.chunk(nullptr, nullptr, opacityEffect2.get()) 185 artifact.chunk(nullptr, nullptr, opacityEffect2.get())
159 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); 186 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE);
160 paintArtifactToSkCanvas(artifact.build(), &canvas); 187 paintArtifactToSkCanvas(artifact.build(), &canvas);
161 } 188 }
162 189
163 TEST_F(PaintArtifactToSkCanvasTest, ChangingOpacityEffects) { 190 TEST_F(PaintArtifactToSkCanvasTest, ChangingOpacityEffects) {
(...skipping 16 matching lines...) Expand all
180 Property(&SkPaint::getColor, SK_ColorBLUE), _)); 207 Property(&SkPaint::getColor, SK_ColorBLUE), _));
181 } 208 }
182 209
183 // Build an opacity effect tree with the following structure: 210 // Build an opacity effect tree with the following structure:
184 // _root_ 211 // _root_
185 // | | 212 // | |
186 // 0.1 a c 0.3 213 // 0.1 a c 0.3
187 // | | 214 // | |
188 // 0.2 b d 0.4 215 // 0.2 b d 0.4
189 RefPtr<EffectPaintPropertyNode> opacityEffectA = 216 RefPtr<EffectPaintPropertyNode> opacityEffectA =
190 EffectPaintPropertyNode::create(nullptr, 0.1); 217 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(),
218 dummyRootClip(),
219 CompositorFilterOperations(), 0.1);
191 RefPtr<EffectPaintPropertyNode> opacityEffectB = 220 RefPtr<EffectPaintPropertyNode> opacityEffectB =
192 EffectPaintPropertyNode::create(opacityEffectA, 0.2); 221 EffectPaintPropertyNode::create(opacityEffectA, dummyRootTransform(),
222 dummyRootClip(),
223 CompositorFilterOperations(), 0.2);
193 RefPtr<EffectPaintPropertyNode> opacityEffectC = 224 RefPtr<EffectPaintPropertyNode> opacityEffectC =
194 EffectPaintPropertyNode::create(nullptr, 0.3); 225 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(),
226 dummyRootClip(),
227 CompositorFilterOperations(), 0.3);
195 RefPtr<EffectPaintPropertyNode> opacityEffectD = 228 RefPtr<EffectPaintPropertyNode> opacityEffectD =
196 EffectPaintPropertyNode::create(opacityEffectC, 0.4); 229 EffectPaintPropertyNode::create(opacityEffectC, dummyRootTransform(),
230 dummyRootClip(),
231 CompositorFilterOperations(), 0.4);
197 232
198 // Build a two-chunk artifact directly. 233 // Build a two-chunk artifact directly.
199 // chunk1 references opacity node b, chunk2 references opacity node d. 234 // chunk1 references opacity node b, chunk2 references opacity node d.
200 TestPaintArtifact artifact; 235 TestPaintArtifact artifact;
201 artifact.chunk(nullptr, nullptr, opacityEffectB.get()) 236 artifact.chunk(nullptr, nullptr, opacityEffectB.get())
202 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); 237 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED);
203 artifact.chunk(nullptr, nullptr, opacityEffectD.get()) 238 artifact.chunk(nullptr, nullptr, opacityEffectD.get())
204 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); 239 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE);
205 paintArtifactToSkCanvas(artifact.build(), &canvas); 240 paintArtifactToSkCanvas(artifact.build(), &canvas);
206 } 241 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 ResultOf(&getCanvasClipAsRegion, Eq(totalClip)))); 284 ResultOf(&getCanvasClipAsRegion, Eq(totalClip))));
250 285
251 TestPaintArtifact artifact; 286 TestPaintArtifact artifact;
252 artifact.chunk(nullptr, clip2.get(), nullptr) 287 artifact.chunk(nullptr, clip2.get(), nullptr)
253 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); 288 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED);
254 paintArtifactToSkCanvas(artifact.build(), &canvas); 289 paintArtifactToSkCanvas(artifact.build(), &canvas);
255 } 290 }
256 291
257 } // namespace 292 } // namespace
258 } // namespace blink 293 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698