| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/testing/PictureMatchers.h" | 5 #include "platform/testing/PictureMatchers.h" |
| 6 | 6 |
| 7 #include "platform/geometry/FloatQuad.h" | 7 #include "platform/geometry/FloatQuad.h" |
| 8 #include "platform/geometry/FloatRect.h" | 8 #include "platform/geometry/FloatRect.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkPicture.h" | 10 #include "skia/ext/cdl_canvas.h" |
| 11 #include "skia/ext/cdl_paint.h" |
| 12 #include "skia/ext/cdl_picture.h" |
| 11 #include "wtf/Vector.h" | 13 #include "wtf/Vector.h" |
| 12 #include "wtf/text/WTFString.h" | 14 #include "wtf/text/WTFString.h" |
| 13 #include <utility> | 15 #include <utility> |
| 14 | 16 |
| 15 namespace blink { | 17 namespace blink { |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 class DrawsRectangleCanvas : public SkCanvas { | 21 class DrawsRectangleCanvas : public CdlCanvas { |
| 20 public: | 22 public: |
| 21 DrawsRectangleCanvas() : SkCanvas(800, 600) {} | 23 DrawsRectangleCanvas() : CdlCanvas(800, 600) {} |
| 22 const Vector<std::pair<FloatQuad, Color>>& quads() const { return m_quads; } | 24 const Vector<std::pair<FloatQuad, Color>>& quads() const { return m_quads; } |
| 23 void onDrawRect(const SkRect& rect, const SkPaint& paint) override { | 25 void onDrawRect(const SkRect& rect, const CdlPaint& paint) override { |
| 24 SkPoint quad[4]; | 26 SkPoint quad[4]; |
| 25 getTotalMatrix().mapRectToQuad(quad, rect); | 27 getTotalMatrix().mapRectToQuad(quad, rect); |
| 26 FloatQuad floatQuad(quad); | 28 FloatQuad floatQuad(quad); |
| 27 m_quads.append(std::make_pair(floatQuad, Color(paint.getColor()))); | 29 m_quads.append(std::make_pair(floatQuad, Color(paint.getColor()))); |
| 28 SkCanvas::onDrawRect(rect, paint); | 30 CdlCanvas::onDrawRect(rect, paint); |
| 29 } | 31 } |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 Vector<std::pair<FloatQuad, Color>> m_quads; | 34 Vector<std::pair<FloatQuad, Color>> m_quads; |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 class DrawsRectangleMatcher | 37 class DrawsRectangleMatcher |
| 36 : public ::testing::MatcherInterface<const SkPicture&> { | 38 : public ::testing::MatcherInterface<const CdlPicture&> { |
| 37 public: | 39 public: |
| 38 DrawsRectangleMatcher(const FloatRect& rect, Color color) | 40 DrawsRectangleMatcher(const FloatRect& rect, Color color) |
| 39 : m_rect(rect), m_color(color) {} | 41 : m_rect(rect), m_color(color) {} |
| 40 | 42 |
| 41 bool MatchAndExplain( | 43 bool MatchAndExplain( |
| 42 const SkPicture& picture, | 44 const CdlPicture& picture, |
| 43 ::testing::MatchResultListener* listener) const override { | 45 ::testing::MatchResultListener* listener) const override { |
| 44 DrawsRectangleCanvas canvas; | 46 DrawsRectangleCanvas canvas; |
| 45 picture.playback(&canvas); | 47 picture.playback(&canvas); |
| 46 const auto& quads = canvas.quads(); | 48 const auto& quads = canvas.quads(); |
| 47 | 49 |
| 48 if (quads.size() != 1) { | 50 if (quads.size() != 1) { |
| 49 *listener << "which draws " << quads.size() << " quads"; | 51 *listener << "which draws " << quads.size() << " quads"; |
| 50 return false; | 52 return false; |
| 51 } | 53 } |
| 52 | 54 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 81 *os << " with color " << m_color.serialized().ascii().data(); | 83 *os << " with color " << m_color.serialized().ascii().data(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 private: | 86 private: |
| 85 const FloatRect m_rect; | 87 const FloatRect m_rect; |
| 86 const Color m_color; | 88 const Color m_color; |
| 87 }; | 89 }; |
| 88 | 90 |
| 89 } // namespace | 91 } // namespace |
| 90 | 92 |
| 91 ::testing::Matcher<const SkPicture&> drawsRectangle(const FloatRect& rect, | 93 ::testing::Matcher<const CdlPicture&> drawsRectangle(const FloatRect& rect, |
| 92 Color color) { | 94 Color color) { |
| 93 return ::testing::MakeMatcher(new DrawsRectangleMatcher(rect, color)); | 95 return ::testing::MakeMatcher(new DrawsRectangleMatcher(rect, color)); |
| 94 } | 96 } |
| 95 | 97 |
| 96 } // namespace blink | 98 } // namespace blink |
| OLD | NEW |