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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <SkPath.h>
#include <SkRegion.h>
#include "ClipArea.h"
#include "Matrix.h"
#include "Rect.h"
#include "utils/LinearAllocator.h"
namespace android {
namespace uirenderer {
static Rect kViewportBounds(0, 0, 2048, 2048);
static ClipArea createClipArea() {
ClipArea area;
area.setViewportDimensions(kViewportBounds.getWidth(), kViewportBounds.getHeight());
return area;
}
TEST(TransformedRectangle, basics) {
Rect r(0, 0, 100, 100);
Matrix4 minus90;
minus90.loadRotate(-90);
minus90.mapRect(r);
Rect r2(20, 40, 120, 60);
Matrix4 m90;
m90.loadRotate(90);
TransformedRectangle tr(r, m90);
EXPECT_TRUE(tr.canSimplyIntersectWith(tr));
Matrix4 m0;
TransformedRectangle tr0(r2, m0);
EXPECT_FALSE(tr.canSimplyIntersectWith(tr0));
Matrix4 m45;
m45.loadRotate(45);
TransformedRectangle tr2(r, m45);
EXPECT_FALSE(tr2.canSimplyIntersectWith(tr));
}
TEST(RectangleList, basics) {
RectangleList list;
EXPECT_TRUE(list.isEmpty());
Rect r(0, 0, 100, 100);
Matrix4 m45;
m45.loadRotate(45);
list.set(r, m45);
EXPECT_FALSE(list.isEmpty());
Rect r2(20, 20, 200, 200);
list.intersectWith(r2, m45);
EXPECT_FALSE(list.isEmpty());
EXPECT_EQ(1, list.getTransformedRectanglesCount());
Rect r3(20, 20, 200, 200);
Matrix4 m30;
m30.loadRotate(30);
list.intersectWith(r2, m30);
EXPECT_FALSE(list.isEmpty());
EXPECT_EQ(2, list.getTransformedRectanglesCount());
SkRegion clip;
clip.setRect(0, 0, 2000, 2000);
SkRegion rgn(list.convertToRegion(clip));
EXPECT_FALSE(rgn.isEmpty());
}
TEST(ClipArea, basics) {
ClipArea area(createClipArea());
EXPECT_FALSE(area.isEmpty());
}
TEST(ClipArea, paths) {
ClipArea area(createClipArea());
Matrix4 transform;
transform.loadIdentity();
SkPath path;
SkScalar r = 100;
path.addCircle(r, r, r);
area.clipPathWithTransform(path, &transform, SkRegion::kIntersect_Op);
EXPECT_FALSE(area.isEmpty());
EXPECT_FALSE(area.isSimple());
EXPECT_FALSE(area.isRectangleList());
Rect clipRect(area.getClipRect());
clipRect.dump("clipRect");
Rect expected(0, 0, r * 2, r * 2);
expected.dump("expected");
EXPECT_EQ(expected, clipRect);
SkRegion clipRegion(area.getClipRegion());
auto skRect(clipRegion.getBounds());
Rect regionBounds;
regionBounds.set(skRect);
EXPECT_EQ(expected, regionBounds);
}
}
}
|