Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
flutter::testing::DisplayListTestBase< BaseT > Class Template Reference
Inheritance diagram for flutter::testing::DisplayListTestBase< BaseT >:

Public Types

typedef const std::function< void(DlCanvas &)> DlSetup
 
typedef const std::function< void(DlCanvas &, DlPaint &, SkRect &rect)> DlRenderer
 

Public Member Functions

 DisplayListTestBase ()=default
 

Static Public Member Functions

static DlOpReceiverToReceiver (DisplayListBuilder &builder)
 
static sk_sp< DisplayListBuild (DisplayListInvocation &invocation)
 
static sk_sp< DisplayListBuild (size_t g_index, size_t v_index)
 
static void check_defaults (DisplayListBuilder &builder, const SkRect &cull_rect=DisplayListBuilder::kMaxCullRect)
 
static void verify_inverted_bounds (DlSetup &setup, DlRenderer &renderer, DlPaint paint, SkRect render_rect, SkRect expected_bounds, const std::string &desc)
 
static void check_inverted_bounds (DlRenderer &renderer, const std::string &desc)
 

Detailed Description

template<typename BaseT>
class flutter::testing::DisplayListTestBase< BaseT >

Definition at line 50 of file display_list_unittests.cc.

Member Typedef Documentation

◆ DlRenderer

template<typename BaseT >
typedef const std::function<void(DlCanvas&, DlPaint&, SkRect& rect)> flutter::testing::DisplayListTestBase< BaseT >::DlRenderer

Definition at line 138 of file display_list_unittests.cc.

◆ DlSetup

template<typename BaseT >
typedef const std::function<void(DlCanvas&)> flutter::testing::DisplayListTestBase< BaseT >::DlSetup

Definition at line 136 of file display_list_unittests.cc.

Constructor & Destructor Documentation

◆ DisplayListTestBase()

template<typename BaseT >
flutter::testing::DisplayListTestBase< BaseT >::DisplayListTestBase ( )
default

Member Function Documentation

◆ Build() [1/2]

template<typename BaseT >
static sk_sp< DisplayList > flutter::testing::DisplayListTestBase< BaseT >::Build ( DisplayListInvocation invocation)
inlinestatic

Definition at line 58 of file display_list_unittests.cc.

58 {
59 DisplayListBuilder builder;
60 invocation.Invoke(ToReceiver(builder));
61 return builder.Build();
62 }
static DlOpReceiver & ToReceiver(DisplayListBuilder &builder)

◆ Build() [2/2]

template<typename BaseT >
static sk_sp< DisplayList > flutter::testing::DisplayListTestBase< BaseT >::Build ( size_t  g_index,
size_t  v_index 
)
inlinestatic

Definition at line 64 of file display_list_unittests.cc.

64 {
65 DisplayListBuilder builder;
66 DlOpReceiver& receiver =
68 uint32_t op_count = 0u;
69 size_t byte_count = 0u;
70 uint32_t depth = 0u;
71 uint32_t render_op_depth_cost = 1u;
72 for (size_t i = 0; i < allGroups.size(); i++) {
73 DisplayListInvocationGroup& group = allGroups[i];
74 size_t j = (i == g_index ? v_index : 0);
75 if (j >= group.variants.size()) {
76 continue;
77 }
78 DisplayListInvocation& invocation = group.variants[j];
79 op_count += invocation.op_count();
80 byte_count += invocation.raw_byte_count();
81 depth += invocation.depth_accumulated(render_op_depth_cost);
82 invocation.Invoke(receiver);
83 render_op_depth_cost =
84 invocation.adjust_render_op_depth_cost(render_op_depth_cost);
85 }
86 sk_sp<DisplayList> dl = builder.Build();
87 std::string name;
88 if (g_index >= allGroups.size()) {
89 name = "Default";
90 } else {
91 name = allGroups[g_index].op_name;
92 if (v_index >= allGroups[g_index].variants.size()) {
93 name += " skipped";
94 } else {
95 name += " variant " + std::to_string(v_index + 1);
96 }
97 }
98 EXPECT_EQ(dl->op_count(false), op_count) << name;
99 EXPECT_EQ(dl->bytes(false), byte_count + sizeof(DisplayList)) << name;
100 EXPECT_EQ(dl->total_depth(), depth) << name;
101 return dl;
102 }
static std::vector< testing::DisplayListInvocationGroup > allGroups
DEF_SWITCHES_START aot vmservice shared library name
Definition switches.h:32

◆ check_defaults()

template<typename BaseT >
static void flutter::testing::DisplayListTestBase< BaseT >::check_defaults ( DisplayListBuilder builder,
const SkRect cull_rect = DisplayListBuilder::kMaxCullRect 
)
inlinestatic

Definition at line 104 of file display_list_unittests.cc.

106 {
107 DlPaint builder_paint = DisplayListBuilderTestingAttributes(builder);
108 DlPaint defaults;
109
110 EXPECT_EQ(builder_paint.isAntiAlias(), defaults.isAntiAlias());
111 EXPECT_EQ(builder_paint.isInvertColors(), defaults.isInvertColors());
112 EXPECT_EQ(builder_paint.getColor(), defaults.getColor());
113 EXPECT_EQ(builder_paint.getBlendMode(), defaults.getBlendMode());
114 EXPECT_EQ(builder_paint.getDrawStyle(), defaults.getDrawStyle());
115 EXPECT_EQ(builder_paint.getStrokeWidth(), defaults.getStrokeWidth());
116 EXPECT_EQ(builder_paint.getStrokeMiter(), defaults.getStrokeMiter());
117 EXPECT_EQ(builder_paint.getStrokeCap(), defaults.getStrokeCap());
118 EXPECT_EQ(builder_paint.getStrokeJoin(), defaults.getStrokeJoin());
119 EXPECT_EQ(builder_paint.getColorSource(), defaults.getColorSource());
120 EXPECT_EQ(builder_paint.getColorFilter(), defaults.getColorFilter());
121 EXPECT_EQ(builder_paint.getImageFilter(), defaults.getImageFilter());
122 EXPECT_EQ(builder_paint.getMaskFilter(), defaults.getMaskFilter());
123 EXPECT_EQ(builder_paint.getPathEffect(), defaults.getPathEffect());
124 EXPECT_EQ(builder_paint, defaults);
125 EXPECT_TRUE(builder_paint.isDefault());
126
127 EXPECT_EQ(builder.GetTransform(), SkMatrix());
128 EXPECT_EQ(builder.GetTransformFullPerspective(), SkM44());
129
130 EXPECT_EQ(builder.GetLocalClipBounds(), cull_rect);
131 EXPECT_EQ(builder.GetDestinationClipBounds(), cull_rect);
132
133 EXPECT_EQ(builder.GetSaveCount(), 1);
134 }
Definition SkM44.h:150
DlPaint DisplayListBuilderTestingAttributes(DisplayListBuilder &builder)
#define EXPECT_TRUE(handle)
Definition unit_test.h:685

◆ check_inverted_bounds()

template<typename BaseT >
static void flutter::testing::DisplayListTestBase< BaseT >::check_inverted_bounds ( DlRenderer renderer,
const std::string &  desc 
)
inlinestatic

Definition at line 154 of file display_list_unittests.cc.

155 {
156 SkRect rect = SkRect::MakeLTRB(0.0f, 0.0f, 10.0f, 10.0f);
157 SkRect invertedLR = SkRect::MakeLTRB(rect.fRight, rect.fTop, //
158 rect.fLeft, rect.fBottom);
159 SkRect invertedTB = SkRect::MakeLTRB(rect.fLeft, rect.fBottom, //
160 rect.fRight, rect.fTop);
161 SkRect invertedLTRB = SkRect::MakeLTRB(rect.fRight, rect.fBottom, //
162 rect.fLeft, rect.fTop);
163 auto empty_setup = [](DlCanvas&) {};
164
165 ASSERT_TRUE(rect.fLeft < rect.fRight);
166 ASSERT_TRUE(rect.fTop < rect.fBottom);
167 ASSERT_FALSE(rect.isEmpty());
168 ASSERT_TRUE(invertedLR.fLeft > invertedLR.fRight);
169 ASSERT_TRUE(invertedLR.isEmpty());
170 ASSERT_TRUE(invertedTB.fTop > invertedTB.fBottom);
171 ASSERT_TRUE(invertedTB.isEmpty());
172 ASSERT_TRUE(invertedLTRB.fLeft > invertedLTRB.fRight);
173 ASSERT_TRUE(invertedLTRB.fTop > invertedLTRB.fBottom);
174 ASSERT_TRUE(invertedLTRB.isEmpty());
175
176 DlPaint ref_paint = DlPaint();
177 SkRect ref_bounds = rect;
178 verify_inverted_bounds(empty_setup, renderer, ref_paint, invertedLR,
179 ref_bounds, desc + " LR swapped");
180 verify_inverted_bounds(empty_setup, renderer, ref_paint, invertedTB,
181 ref_bounds, desc + " TB swapped");
182 verify_inverted_bounds(empty_setup, renderer, ref_paint, invertedLTRB,
183 ref_bounds, desc + " LR&TB swapped");
184
185 // Round joins are used because miter joins greatly pad the bounds,
186 // but only on paths. So we use round joins for consistency there.
187 // We aren't fully testing all stroke-related bounds computations here,
188 // those are more fully tested in the render tests. We are simply
189 // checking that they are applied to the ordered bounds.
190 DlPaint stroke_paint = DlPaint() //
191 .setDrawStyle(DlDrawStyle::kStroke) //
192 .setStrokeJoin(DlStrokeJoin::kRound) //
193 .setStrokeWidth(2.0f);
194 SkRect stroke_bounds = rect.makeOutset(1.0f, 1.0f);
195 verify_inverted_bounds(empty_setup, renderer, stroke_paint, invertedLR,
196 stroke_bounds, desc + " LR swapped, sw 2");
197 verify_inverted_bounds(empty_setup, renderer, stroke_paint, invertedTB,
198 stroke_bounds, desc + " TB swapped, sw 2");
199 verify_inverted_bounds(empty_setup, renderer, stroke_paint, invertedLTRB,
200 stroke_bounds, desc + " LR&TB swapped, sw 2");
201
202 DlBlurMaskFilter mask_filter(DlBlurStyle::kNormal, 2.0f);
203 DlPaint maskblur_paint = DlPaint() //
204 .setMaskFilter(&mask_filter);
205 SkRect maskblur_bounds = rect.makeOutset(6.0f, 6.0f);
206 verify_inverted_bounds(empty_setup, renderer, maskblur_paint, invertedLR,
207 maskblur_bounds, desc + " LR swapped, mask 2");
208 verify_inverted_bounds(empty_setup, renderer, maskblur_paint, invertedTB,
209 maskblur_bounds, desc + " TB swapped, mask 2");
210 verify_inverted_bounds(empty_setup, renderer, maskblur_paint, invertedLTRB,
211 maskblur_bounds, desc + " LR&TB swapped, mask 2");
212
213 DlErodeImageFilter erode_filter(2.0f, 2.0f);
214 DlPaint erode_paint = DlPaint() //
215 .setImageFilter(&erode_filter);
216 SkRect erode_bounds = rect.makeInset(2.0f, 2.0f);
217 verify_inverted_bounds(empty_setup, renderer, erode_paint, invertedLR,
218 erode_bounds, desc + " LR swapped, erode 2");
219 verify_inverted_bounds(empty_setup, renderer, erode_paint, invertedTB,
220 erode_bounds, desc + " TB swapped, erode 2");
221 verify_inverted_bounds(empty_setup, renderer, erode_paint, invertedLTRB,
222 erode_bounds, desc + " LR&TB swapped, erode 2");
223 }
static void verify_inverted_bounds(DlSetup &setup, DlRenderer &renderer, DlPaint paint, SkRect render_rect, SkRect expected_bounds, const std::string &desc)
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
@ kStroke
strokes boundary of shapes
@ kNormal
fuzzy inside and outside
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
bool isEmpty() const
Definition SkRect.h:693
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15

◆ ToReceiver()

template<typename BaseT >
static DlOpReceiver & flutter::testing::DisplayListTestBase< BaseT >::ToReceiver ( DisplayListBuilder builder)
inlinestatic

Definition at line 54 of file display_list_unittests.cc.

54 {
56 }
DlOpReceiver & DisplayListBuilderTestingAccessor(DisplayListBuilder &builder)

◆ verify_inverted_bounds()

template<typename BaseT >
static void flutter::testing::DisplayListTestBase< BaseT >::verify_inverted_bounds ( DlSetup setup,
DlRenderer renderer,
DlPaint  paint,
SkRect  render_rect,
SkRect  expected_bounds,
const std::string &  desc 
)
inlinestatic

Definition at line 140 of file display_list_unittests.cc.

145 {
146 DisplayListBuilder builder;
147 setup(builder);
148 renderer(builder, paint, render_rect);
149 auto dl = builder.Build();
150 EXPECT_EQ(dl->op_count(), 1u) << desc;
151 EXPECT_EQ(dl->bounds(), expected_bounds) << desc;
152 }
const Paint & paint
Definition setup.py:1

The documentation for this class was generated from the following file: