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

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: remove DCHECK(layer) Created 4 years, 1 month 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); 152 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE);
130 paintArtifactToSkCanvas(artifact.build(), &canvas); 153 paintArtifactToSkCanvas(artifact.build(), &canvas);
131 } 154 }
132 155
133 TEST_F(PaintArtifactToSkCanvasTest, OpacityEffectsCombining) { 156 TEST_F(PaintArtifactToSkCanvasTest, OpacityEffectsCombining) {
134 unsigned expectedFirstOpacity = 127; // floor(0.5 * 255) 157 unsigned expectedFirstOpacity = 127; // floor(0.5 * 255)
135 unsigned expectedSecondOpacity = 63; // floor(0.25 * 255) 158 unsigned expectedSecondOpacity = 63; // floor(0.25 * 255)
136 MockCanvas canvas(kCanvasWidth, kCanvasHeight); 159 MockCanvas canvas(kCanvasWidth, kCanvasHeight);
137 { 160 {
138 testing::InSequence sequence; 161 testing::InSequence sequence;
162 EXPECT_CALL(canvas, willSaveLayer(255, _));
139 EXPECT_CALL(canvas, willSaveLayer(expectedFirstOpacity, _)); 163 EXPECT_CALL(canvas, willSaveLayer(expectedFirstOpacity, _));
140 EXPECT_CALL(canvas, 164 EXPECT_CALL(canvas,
141 onDrawRect(SkRect::MakeWH(300, 200), 165 onDrawRect(SkRect::MakeWH(300, 200),
142 Property(&SkPaint::getColor, SK_ColorRED), _)); 166 Property(&SkPaint::getColor, SK_ColorRED), _));
143 EXPECT_CALL(canvas, willSaveLayer(expectedSecondOpacity, _)); 167 EXPECT_CALL(canvas, willSaveLayer(expectedSecondOpacity, _));
144 EXPECT_CALL(canvas, 168 EXPECT_CALL(canvas,
145 onDrawRect(SkRect::MakeWH(300, 200), 169 onDrawRect(SkRect::MakeWH(300, 200),
146 Property(&SkPaint::getColor, SK_ColorBLUE), _)); 170 Property(&SkPaint::getColor, SK_ColorBLUE), _));
147 } 171 }
148 172
149 // Build an opacity effect tree. 173 // Build an opacity effect tree.
150 RefPtr<EffectPaintPropertyNode> opacityEffect1 = 174 RefPtr<EffectPaintPropertyNode> opacityEffect1 =
151 EffectPaintPropertyNode::create(nullptr, 0.5); 175 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(),
176 dummyRootClip(),
177 CompositorFilterOperations(), 0.5);
152 RefPtr<EffectPaintPropertyNode> opacityEffect2 = 178 RefPtr<EffectPaintPropertyNode> opacityEffect2 =
153 EffectPaintPropertyNode::create(opacityEffect1, 0.25); 179 EffectPaintPropertyNode::create(opacityEffect1, dummyRootTransform(),
180 dummyRootClip(),
181 CompositorFilterOperations(), 0.25);
154 182
155 TestPaintArtifact artifact; 183 TestPaintArtifact artifact;
156 artifact.chunk(nullptr, nullptr, opacityEffect1.get()) 184 artifact.chunk(dummyRootTransform(), dummyRootClip(), opacityEffect1.get())
157 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); 185 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED);
158 artifact.chunk(nullptr, nullptr, opacityEffect2.get()) 186 artifact.chunk(dummyRootTransform(), dummyRootClip(), opacityEffect2.get())
159 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); 187 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE);
160 paintArtifactToSkCanvas(artifact.build(), &canvas); 188 paintArtifactToSkCanvas(artifact.build(), &canvas);
161 } 189 }
162 190
163 TEST_F(PaintArtifactToSkCanvasTest, ChangingOpacityEffects) { 191 TEST_F(PaintArtifactToSkCanvasTest, ChangingOpacityEffects) {
164 unsigned expectedAOpacity = 25; // floor(0.1 * 255) 192 unsigned expectedAOpacity = 25; // floor(0.1 * 255)
165 unsigned expectedBOpacity = 51; // floor(0.2 * 255) 193 unsigned expectedBOpacity = 51; // floor(0.2 * 255)
166 unsigned expectedCOpacity = 76; // floor(0.3 * 255) 194 unsigned expectedCOpacity = 76; // floor(0.3 * 255)
167 unsigned expectedDOpacity = 102; // floor(0.4 * 255) 195 unsigned expectedDOpacity = 102; // floor(0.4 * 255)
168 MockCanvas canvas(kCanvasWidth, kCanvasHeight); 196 MockCanvas canvas(kCanvasWidth, kCanvasHeight);
169 { 197 {
170 testing::InSequence sequence; 198 testing::InSequence sequence;
199 EXPECT_CALL(canvas, willSaveLayer(255, _));
171 EXPECT_CALL(canvas, willSaveLayer(expectedAOpacity, _)); 200 EXPECT_CALL(canvas, willSaveLayer(expectedAOpacity, _));
172 EXPECT_CALL(canvas, willSaveLayer(expectedBOpacity, _)); 201 EXPECT_CALL(canvas, willSaveLayer(expectedBOpacity, _));
173 EXPECT_CALL(canvas, 202 EXPECT_CALL(canvas,
174 onDrawRect(SkRect::MakeWH(300, 200), 203 onDrawRect(SkRect::MakeWH(300, 200),
175 Property(&SkPaint::getColor, SK_ColorRED), _)); 204 Property(&SkPaint::getColor, SK_ColorRED), _));
176 EXPECT_CALL(canvas, willSaveLayer(expectedCOpacity, _)); 205 EXPECT_CALL(canvas, willSaveLayer(expectedCOpacity, _));
177 EXPECT_CALL(canvas, willSaveLayer(expectedDOpacity, _)); 206 EXPECT_CALL(canvas, willSaveLayer(expectedDOpacity, _));
178 EXPECT_CALL(canvas, 207 EXPECT_CALL(canvas,
179 onDrawRect(SkRect::MakeWH(300, 200), 208 onDrawRect(SkRect::MakeWH(300, 200),
180 Property(&SkPaint::getColor, SK_ColorBLUE), _)); 209 Property(&SkPaint::getColor, SK_ColorBLUE), _));
181 } 210 }
182 211
183 // Build an opacity effect tree with the following structure: 212 // Build an opacity effect tree with the following structure:
184 // _root_ 213 // _root_
185 // | | 214 // | |
186 // 0.1 a c 0.3 215 // 0.1 a c 0.3
187 // | | 216 // | |
188 // 0.2 b d 0.4 217 // 0.2 b d 0.4
189 RefPtr<EffectPaintPropertyNode> opacityEffectA = 218 RefPtr<EffectPaintPropertyNode> opacityEffectA =
190 EffectPaintPropertyNode::create(nullptr, 0.1); 219 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(),
220 dummyRootClip(),
221 CompositorFilterOperations(), 0.1);
191 RefPtr<EffectPaintPropertyNode> opacityEffectB = 222 RefPtr<EffectPaintPropertyNode> opacityEffectB =
192 EffectPaintPropertyNode::create(opacityEffectA, 0.2); 223 EffectPaintPropertyNode::create(opacityEffectA, dummyRootTransform(),
224 dummyRootClip(),
225 CompositorFilterOperations(), 0.2);
193 RefPtr<EffectPaintPropertyNode> opacityEffectC = 226 RefPtr<EffectPaintPropertyNode> opacityEffectC =
194 EffectPaintPropertyNode::create(nullptr, 0.3); 227 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(),
228 dummyRootClip(),
229 CompositorFilterOperations(), 0.3);
195 RefPtr<EffectPaintPropertyNode> opacityEffectD = 230 RefPtr<EffectPaintPropertyNode> opacityEffectD =
196 EffectPaintPropertyNode::create(opacityEffectC, 0.4); 231 EffectPaintPropertyNode::create(opacityEffectC, dummyRootTransform(),
232 dummyRootClip(),
233 CompositorFilterOperations(), 0.4);
197 234
198 // Build a two-chunk artifact directly. 235 // Build a two-chunk artifact directly.
199 // chunk1 references opacity node b, chunk2 references opacity node d. 236 // chunk1 references opacity node b, chunk2 references opacity node d.
200 TestPaintArtifact artifact; 237 TestPaintArtifact artifact;
201 artifact.chunk(nullptr, nullptr, opacityEffectB.get()) 238 artifact.chunk(dummyRootTransform(), dummyRootClip(), opacityEffectB.get())
202 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); 239 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED);
203 artifact.chunk(nullptr, nullptr, opacityEffectD.get()) 240 artifact.chunk(dummyRootTransform(), dummyRootClip(), opacityEffectD.get())
204 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); 241 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE);
205 paintArtifactToSkCanvas(artifact.build(), &canvas); 242 paintArtifactToSkCanvas(artifact.build(), &canvas);
206 } 243 }
207 244
208 static SkRegion getCanvasClipAsRegion(SkCanvas* canvas) { 245 static SkRegion getCanvasClipAsRegion(SkCanvas* canvas) {
209 SkIRect clipRect; 246 SkIRect clipRect;
210 canvas->getClipDeviceBounds(&clipRect); 247 canvas->getClipDeviceBounds(&clipRect);
211 248
212 SkRegion clipRegion; 249 SkRegion clipRegion;
213 clipRegion.setRect(clipRect); 250 clipRegion.setRect(clipRect);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 ResultOf(&getCanvasClipAsRegion, Eq(totalClip)))); 286 ResultOf(&getCanvasClipAsRegion, Eq(totalClip))));
250 287
251 TestPaintArtifact artifact; 288 TestPaintArtifact artifact;
252 artifact.chunk(nullptr, clip2.get(), nullptr) 289 artifact.chunk(nullptr, clip2.get(), nullptr)
253 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); 290 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED);
254 paintArtifactToSkCanvas(artifact.build(), &canvas); 291 paintArtifactToSkCanvas(artifact.build(), &canvas);
255 } 292 }
256 293
257 } // namespace 294 } // namespace
258 } // namespace blink 295 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698