| OLD | NEW |
| 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(nullptr, dummyRootTransform
(), dummyRootClip(), 1.0, CompositorFilterOperations()))); |
| 50 return rootEffect; |
| 51 } |
| 31 | 52 |
| 32 static const int kCanvasWidth = 800; | 53 static const int kCanvasWidth = 800; |
| 33 static const int kCanvasHeight = 600; | 54 static const int kCanvasHeight = 600; |
| 34 | 55 |
| 35 class MockCanvas : public SkCanvas { | 56 class MockCanvas : public SkCanvas { |
| 36 public: | 57 public: |
| 37 MockCanvas(int width, int height) : SkCanvas(width, height) {} | 58 MockCanvas(int width, int height) : SkCanvas(width, height) {} |
| 38 | 59 |
| 39 MOCK_METHOD3(onDrawRect, void(const SkRect&, const SkPaint&, MockCanvas*)); | 60 MOCK_METHOD3(onDrawRect, void(const SkRect&, const SkPaint&, MockCanvas*)); |
| 40 MOCK_METHOD2(willSaveLayer, void(unsigned alpha, MockCanvas*)); | 61 MOCK_METHOD2(willSaveLayer, void(unsigned alpha, MockCanvas*)); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 onDrawRect(SkRect::MakeWH(300, 200), | 162 onDrawRect(SkRect::MakeWH(300, 200), |
| 142 Property(&SkPaint::getColor, SK_ColorRED), _)); | 163 Property(&SkPaint::getColor, SK_ColorRED), _)); |
| 143 EXPECT_CALL(canvas, willSaveLayer(expectedSecondOpacity, _)); | 164 EXPECT_CALL(canvas, willSaveLayer(expectedSecondOpacity, _)); |
| 144 EXPECT_CALL(canvas, | 165 EXPECT_CALL(canvas, |
| 145 onDrawRect(SkRect::MakeWH(300, 200), | 166 onDrawRect(SkRect::MakeWH(300, 200), |
| 146 Property(&SkPaint::getColor, SK_ColorBLUE), _)); | 167 Property(&SkPaint::getColor, SK_ColorBLUE), _)); |
| 147 } | 168 } |
| 148 | 169 |
| 149 // Build an opacity effect tree. | 170 // Build an opacity effect tree. |
| 150 RefPtr<EffectPaintPropertyNode> opacityEffect1 = | 171 RefPtr<EffectPaintPropertyNode> opacityEffect1 = |
| 151 EffectPaintPropertyNode::create(nullptr, 0.5); | 172 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(), d
ummyRootClip(), 0.5, CompositorFilterOperations()); |
| 152 RefPtr<EffectPaintPropertyNode> opacityEffect2 = | 173 RefPtr<EffectPaintPropertyNode> opacityEffect2 = |
| 153 EffectPaintPropertyNode::create(opacityEffect1, 0.25); | 174 EffectPaintPropertyNode::create(opacityEffect1, dummyRootTransform(), dumm
yRootClip(), 0.25, CompositorFilterOperations()); |
| 154 | 175 |
| 155 TestPaintArtifact artifact; | 176 TestPaintArtifact artifact; |
| 156 artifact.chunk(nullptr, nullptr, opacityEffect1.get()) | 177 artifact.chunk(nullptr, nullptr, opacityEffect1.get()) |
| 157 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); | 178 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); |
| 158 artifact.chunk(nullptr, nullptr, opacityEffect2.get()) | 179 artifact.chunk(nullptr, nullptr, opacityEffect2.get()) |
| 159 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); | 180 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); |
| 160 paintArtifactToSkCanvas(artifact.build(), &canvas); | 181 paintArtifactToSkCanvas(artifact.build(), &canvas); |
| 161 } | 182 } |
| 162 | 183 |
| 163 TEST_F(PaintArtifactToSkCanvasTest, ChangingOpacityEffects) { | 184 TEST_F(PaintArtifactToSkCanvasTest, ChangingOpacityEffects) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 180 Property(&SkPaint::getColor, SK_ColorBLUE), _)); | 201 Property(&SkPaint::getColor, SK_ColorBLUE), _)); |
| 181 } | 202 } |
| 182 | 203 |
| 183 // Build an opacity effect tree with the following structure: | 204 // Build an opacity effect tree with the following structure: |
| 184 // _root_ | 205 // _root_ |
| 185 // | | | 206 // | | |
| 186 // 0.1 a c 0.3 | 207 // 0.1 a c 0.3 |
| 187 // | | | 208 // | | |
| 188 // 0.2 b d 0.4 | 209 // 0.2 b d 0.4 |
| 189 RefPtr<EffectPaintPropertyNode> opacityEffectA = | 210 RefPtr<EffectPaintPropertyNode> opacityEffectA = |
| 190 EffectPaintPropertyNode::create(nullptr, 0.1); | 211 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(), d
ummyRootClip(), 0.1, CompositorFilterOperations()); |
| 191 RefPtr<EffectPaintPropertyNode> opacityEffectB = | 212 RefPtr<EffectPaintPropertyNode> opacityEffectB = |
| 192 EffectPaintPropertyNode::create(opacityEffectA, 0.2); | 213 EffectPaintPropertyNode::create(opacityEffectA, dummyRootTransform(), dumm
yRootClip(), 0.2, CompositorFilterOperations()); |
| 193 RefPtr<EffectPaintPropertyNode> opacityEffectC = | 214 RefPtr<EffectPaintPropertyNode> opacityEffectC = |
| 194 EffectPaintPropertyNode::create(nullptr, 0.3); | 215 EffectPaintPropertyNode::create(dummyRootEffect(), dummyRootTransform(), d
ummyRootClip(), 0.3, CompositorFilterOperations()); |
| 195 RefPtr<EffectPaintPropertyNode> opacityEffectD = | 216 RefPtr<EffectPaintPropertyNode> opacityEffectD = |
| 196 EffectPaintPropertyNode::create(opacityEffectC, 0.4); | 217 EffectPaintPropertyNode::create(opacityEffectC, dummyRootTransform(), dumm
yRootClip(), 0.4, CompositorFilterOperations()); |
| 197 | 218 |
| 198 // Build a two-chunk artifact directly. | 219 // Build a two-chunk artifact directly. |
| 199 // chunk1 references opacity node b, chunk2 references opacity node d. | 220 // chunk1 references opacity node b, chunk2 references opacity node d. |
| 200 TestPaintArtifact artifact; | 221 TestPaintArtifact artifact; |
| 201 artifact.chunk(nullptr, nullptr, opacityEffectB.get()) | 222 artifact.chunk(nullptr, nullptr, opacityEffectB.get()) |
| 202 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); | 223 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); |
| 203 artifact.chunk(nullptr, nullptr, opacityEffectD.get()) | 224 artifact.chunk(nullptr, nullptr, opacityEffectD.get()) |
| 204 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); | 225 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorBLUE); |
| 205 paintArtifactToSkCanvas(artifact.build(), &canvas); | 226 paintArtifactToSkCanvas(artifact.build(), &canvas); |
| 206 } | 227 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 ResultOf(&getCanvasClipAsRegion, Eq(totalClip)))); | 270 ResultOf(&getCanvasClipAsRegion, Eq(totalClip)))); |
| 250 | 271 |
| 251 TestPaintArtifact artifact; | 272 TestPaintArtifact artifact; |
| 252 artifact.chunk(nullptr, clip2.get(), nullptr) | 273 artifact.chunk(nullptr, clip2.get(), nullptr) |
| 253 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); | 274 .rectDrawing(FloatRect(0, 0, 300, 200), SK_ColorRED); |
| 254 paintArtifactToSkCanvas(artifact.build(), &canvas); | 275 paintArtifactToSkCanvas(artifact.build(), &canvas); |
| 255 } | 276 } |
| 256 | 277 |
| 257 } // namespace | 278 } // namespace |
| 258 } // namespace blink | 279 } // namespace blink |
| OLD | NEW |