Flutter Engine
The Flutter Engine
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 54 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 141 of file display_list_unittests.cc.

◆ DlSetup

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

Definition at line 139 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 62 of file display_list_unittests.cc.

62 {
63 DisplayListBuilder builder;
64 invocation.Invoke(ToReceiver(builder));
65 return builder.Build();
66 }
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 68 of file display_list_unittests.cc.

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

◆ 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 108 of file display_list_unittests.cc.

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

◆ 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 157 of file display_list_unittests.cc.

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

58 {
60 }
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 143 of file display_list_unittests.cc.

148 {
149 DisplayListBuilder builder;
150 setup(builder);
151 renderer(builder, paint, render_rect);
152 auto dl = builder.Build();
153 EXPECT_EQ(dl->op_count(), 1u) << desc;
154 EXPECT_EQ(dl->bounds(), expected_bounds) << desc;
155 }
const Paint & paint
Definition: color_source.cc:38
static void setup(SkCanvas *canvas, SkPaint *paint, const SkBitmap &bm, SkFilterMode fm, SkTileMode tmx, SkTileMode tmy)
Definition: tilemodes.cpp:52

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