1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/animation/ink_drop_mask.h"
#include <algorithm>
#include <memory>
#include <vector>
#include "cc/paint/display_item_list.h"
#include "cc/paint/paint_op_buffer_iterator.h"
#include "cc/paint/paint_record.h"
#include "cc/test/paint_op_matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "ui/compositor/paint_context.h"
namespace views {
using ::cc::PaintOpIs;
using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::ExplainMatchResult;
using ::testing::ResultOf;
using ::testing::UnorderedElementsAreArray;
MATCHER_P(PointsAre, expected, "") {
int expected_size = expected.size();
if (arg.countPoints() != expected_size) {
*result_listener << "Expected path to have " << expected_size
<< " points, but had " << arg.countPoints() << ".";
return false;
}
std::vector<SkPoint> actual(expected_size);
if (arg.getPoints(&actual.front(), expected_size) != expected_size) {
*result_listener << "Failed extracting " << expected.size()
<< " points from path.";
return false;
}
return ExplainMatchResult(UnorderedElementsAreArray(expected), actual,
result_listener);
}
TEST(InkDropMaskTest, PathInkDropMaskPaintsTriangle) {
gfx::Size layer_size(10, 10);
SkPath path;
std::vector<SkPoint> points = {SkPoint::Make(3, 3), SkPoint::Make(5, 6),
SkPoint::Make(8, 1)};
path.moveTo(points[0].x(), points[0].y());
path.lineTo(points[1].x(), points[1].y());
path.lineTo(points[2].x(), points[2].y());
path.close();
PathInkDropMask mask(layer_size, path);
auto list = base::MakeRefCounted<cc::DisplayItemList>();
mask.OnPaintLayer(
ui::PaintContext(list.get(), 1.f, gfx::Rect(layer_size), false));
EXPECT_EQ(1u, list->num_paint_ops()) << list->ToString();
cc::PaintRecord record = list->FinalizeAndReleaseAsRecordForTesting();
EXPECT_THAT(
record,
ElementsAre(AllOf(
PaintOpIs<cc::DrawRecordOp>(),
ResultOf(
[](const cc::PaintOp& op) {
return static_cast<const cc::DrawRecordOp&>(op).record;
},
ElementsAre(AllOf(
PaintOpIs<cc::DrawPathOp>(),
ResultOf(
[](const cc::PaintOp& op) {
return static_cast<const cc::DrawPathOp&>(op).path;
},
PointsAre(points))))))));
}
} // namespace views
|