Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
tests
RecordPatternTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2015 Google Inc.
3
*
4
* Use of this source code is governed by a BSD-style license that can be
5
* found in the LICENSE file.
6
*/
7
8
#include "
include/core/SkCanvas.h
"
9
#include "
include/core/SkPaint.h
"
10
#include "
include/core/SkRect.h
"
11
#include "
src/core/SkRecord.h
"
12
#include "
src/core/SkRecordPattern.h
"
13
#include "
src/core/SkRecorder.h
"
14
#include "
src/core/SkRecords.h
"
15
#include "
tests/Test.h
"
16
17
using namespace
SkRecords
;
18
typedef
Pattern<Is<Save>
,
19
Is<ClipRect>
,
20
Is<Restore>
>
21
SaveClipRectRestore
;
22
23
DEF_TEST
(RecordPattern_Simple, r) {
24
SaveClipRectRestore
pattern;
25
26
SkRecord
record;
27
REPORTER_ASSERT
(r, !pattern.match(&record, 0));
28
29
SkRecorder
recorder(&record, 1920, 1200);
30
31
// Build up a save-clip-restore block. The pattern will match only it's complete.
32
recorder.
save
();
33
REPORTER_ASSERT
(r, !pattern.match(&record, 0));
34
35
recorder.
clipRect
(
SkRect::MakeWH
(300, 200));
36
REPORTER_ASSERT
(r, !pattern.match(&record, 0));
37
38
recorder.
restore
();
39
REPORTER_ASSERT
(r, pattern.match(&record, 0));
40
REPORTER_ASSERT
(r, pattern.first<Save>() !=
nullptr
);
41
REPORTER_ASSERT
(r, pattern.second<
ClipRect
>() !=
nullptr
);
42
REPORTER_ASSERT
(r, pattern.third<Restore>() !=
nullptr
);
43
}
44
45
DEF_TEST
(RecordPattern_StartingIndex, r) {
46
SaveClipRectRestore
pattern;
47
48
SkRecord
record;
49
SkRecorder
recorder(&record, 1920, 1200);
50
51
// There will be two save-clipRect-restore blocks [0,3) and [3,6).
52
for
(
int
i = 0; i < 2; i++) {
53
recorder.
save
();
54
recorder.
clipRect
(
SkRect::MakeWH
(300, 200));
55
recorder.
restore
();
56
}
57
58
// We should match only at 0 and 3. Going over the length should fail gracefully.
59
for
(
int
i = 0; i < 8; i++) {
60
if
(i == 0 || i == 3) {
61
REPORTER_ASSERT
(r, pattern.match(&record, i) == i + 3);
62
}
else
{
63
REPORTER_ASSERT
(r, !pattern.match(&record, i));
64
}
65
}
66
}
67
68
DEF_TEST
(RecordPattern_DontMatchSubsequences, r) {
69
SaveClipRectRestore
pattern;
70
71
SkRecord
record;
72
SkRecorder
recorder(&record, 1920, 1200);
73
74
recorder.
save
();
75
recorder.
clipRect
(
SkRect::MakeWH
(300, 200));
76
recorder.
drawRect
(
SkRect::MakeWH
(600, 300),
SkPaint
());
77
recorder.
restore
();
78
79
REPORTER_ASSERT
(r, !pattern.match(&record, 0));
80
}
81
82
DEF_TEST
(RecordPattern_Greedy, r) {
83
Pattern<Is<Save>
,
Greedy<Is<ClipRect>
>,
Is<Restore>
> pattern;
84
85
SkRecord
record;
86
SkRecorder
recorder(&record, 1920, 1200);
87
int
index = 0;
88
89
recorder.
save
();
90
recorder.
clipRect
(
SkRect::MakeWH
(300, 200));
91
recorder.
restore
();
92
REPORTER_ASSERT
(r, pattern.match(&record, index));
93
index += 3;
94
95
recorder.
save
();
96
recorder.
clipRect
(
SkRect::MakeWH
(300, 200));
97
recorder.
clipRect
(
SkRect::MakeWH
(100, 100));
98
recorder.
restore
();
99
REPORTER_ASSERT
(r, pattern.match(&record, index));
100
}
101
102
DEF_TEST
(RecordPattern_Complex, r) {
103
Pattern<Is<Save>
,
104
Greedy<Not<Or<Is<Save>
,
105
Is<Restore>
,
106
IsDraw
>>>,
107
Is<Restore>
> pattern;
108
109
SkRecord
record;
110
SkRecorder
recorder(&record, 1920, 1200);
111
int
start
,
begin
,
end
;
112
113
start
= record.
count
();
114
recorder.
save
();
115
recorder.
clipRect
(
SkRect::MakeWH
(300, 200));
116
recorder.
restore
();
117
REPORTER_ASSERT
(r, pattern.match(&record, 0) == record.
count
());
118
end
=
start
;
119
REPORTER_ASSERT
(r, pattern.search(&record, &
begin
, &
end
));
120
REPORTER_ASSERT
(r,
begin
==
start
);
121
REPORTER_ASSERT
(r,
end
== record.
count
());
122
123
start
= record.
count
();
124
recorder.
save
();
125
recorder.
clipRect
(
SkRect::MakeWH
(300, 200));
126
recorder.
drawRect
(
SkRect::MakeWH
(100, 3000),
SkPaint
());
127
recorder.
restore
();
128
REPORTER_ASSERT
(r, !pattern.match(&record,
start
));
129
end
=
start
;
130
REPORTER_ASSERT
(r, !pattern.search(&record, &
begin
, &
end
));
131
132
start
= record.
count
();
133
recorder.
save
();
134
recorder.
clipRect
(
SkRect::MakeWH
(300, 200));
135
recorder.
clipRect
(
SkRect::MakeWH
(100, 400));
136
recorder.
restore
();
137
REPORTER_ASSERT
(r, pattern.match(&record,
start
) == record.
count
());
138
end
=
start
;
139
REPORTER_ASSERT
(r, pattern.search(&record, &
begin
, &
end
));
140
REPORTER_ASSERT
(r,
begin
==
start
);
141
REPORTER_ASSERT
(r,
end
== record.
count
());
142
143
REPORTER_ASSERT
(r, !pattern.search(&record, &
begin
, &
end
));
144
}
145
146
DEF_TEST
(RecordPattern_SaveLayerIsNotADraw, r) {
147
Pattern<IsDraw>
pattern;
148
149
SkRecord
record;
150
SkRecorder
recorder(&record, 1920, 1200);
151
recorder.
saveLayer
(
nullptr
,
nullptr
);
152
153
REPORTER_ASSERT
(r, !pattern.match(&record, 0));
154
}
SaveClipRectRestore
Pattern< Is< Save >, Is< ClipRect >, Is< Restore > > SaveClipRectRestore
Definition
RecordPatternTest.cpp:21
SkCanvas.h
SkPaint.h
SkRecordPattern.h
SkRecord.h
SkRecorder.h
SkRecords.h
SkRect.h
Test.h
DEF_TEST
#define DEF_TEST(name, reporter)
Definition
Test.h:312
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition
Test.h:286
SkCanvas::saveLayer
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition
SkCanvas.cpp:500
SkCanvas::drawRect
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition
SkCanvas.cpp:1997
SkCanvas::clipRect
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition
SkCanvas.cpp:1685
SkCanvas::restore
void restore()
Definition
SkCanvas.cpp:465
SkCanvas::save
int save()
Definition
SkCanvas.cpp:451
SkPaint
Definition
SkPaint.h:44
SkRecord
Definition
SkRecord.h:32
SkRecord::count
int count() const
Definition
SkRecord.h:38
SkRecorder
Definition
SkRecorder.h:77
SkRecords::IsDraw
Definition
SkRecordPattern.h:44
SkRecords::Is
Definition
SkRecordPattern.h:21
SkRecords::Pattern
Definition
SkRecordPattern.h:150
begin
static const char * begin(const StringSlice &s)
Definition
editor.cpp:252
start
glong start
Definition
fl_accessible_text_field.cc:39
end
glong glong end
Definition
fl_accessible_text_field.cc:40
SkRecords
Definition
SkCanvas.h:82
ClipRect
Definition
SkCanvasStateUtils.cpp:57
SkRecords::Greedy
Definition
SkRecordPattern.h:139
SkRect::MakeWH
static constexpr SkRect MakeWH(float w, float h)
Definition
SkRect.h:609
Generated on Fri Apr 26 2024 06:18:00 for Flutter Engine by
1.9.8