ink_drop_mask_unittest.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/views/animation/ink_drop_mask.h"
  5. #include <algorithm>
  6. #include <memory>
  7. #include "cc/paint/display_item_list.h"
  8. #include "cc/paint/paint_op_buffer.h"
  9. #include "cc/paint/paint_record.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. #include "third_party/skia/include/core/SkPath.h"
  12. #include "third_party/skia/include/core/SkPoint.h"
  13. #include "ui/compositor/paint_context.h"
  14. namespace views {
  15. TEST(InkDropMaskTest, PathInkDropMaskPaintsTriangle) {
  16. gfx::Size layer_size(10, 10);
  17. SkPath path;
  18. SkPoint p1 = SkPoint::Make(3, 3);
  19. SkPoint p2 = SkPoint::Make(5, 6);
  20. SkPoint p3 = SkPoint::Make(8, 1);
  21. path.moveTo(p1.x(), p1.y());
  22. path.lineTo(p2.x(), p2.y());
  23. path.lineTo(p3.x(), p3.y());
  24. path.close();
  25. PathInkDropMask mask(layer_size, path);
  26. auto list = base::MakeRefCounted<cc::DisplayItemList>();
  27. mask.OnPaintLayer(
  28. ui::PaintContext(list.get(), 1.f, gfx::Rect(layer_size), false));
  29. EXPECT_EQ(1u, list->num_paint_ops()) << list->ToString();
  30. sk_sp<cc::PaintRecord> record = list->ReleaseAsRecord();
  31. const auto* draw_op = record->GetOpAtForTesting<cc::DrawPathOp>(0);
  32. ASSERT_NE(nullptr, draw_op);
  33. ASSERT_EQ(3, draw_op->path.countPoints());
  34. SkPoint points[3];
  35. ASSERT_EQ(3, draw_op->path.getPoints(points, 3));
  36. std::sort(points, points + 3,
  37. [](const SkPoint& a, const SkPoint& b) { return a.x() < b.x(); });
  38. EXPECT_EQ(p1, points[0]);
  39. EXPECT_EQ(p2, points[1]);
  40. EXPECT_EQ(p3, points[2]);
  41. }
  42. } // namespace views