Flutter Engine
 
Loading...
Searching...
No Matches
dl_test_snippets.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SNIPPETS_H_
6#define FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SNIPPETS_H_
7
15
16#include "third_party/skia/include/core/SkPath.h"
17#include "third_party/skia/include/core/SkRRect.h"
18#include "third_party/skia/include/core/SkSurface.h"
19#include "third_party/skia/include/effects/SkGradientShader.h"
20#include "third_party/skia/include/effects/SkImageFilters.h"
21#include "third_party/skia/include/effects/SkRuntimeEffect.h"
22
23namespace flutter {
24namespace testing {
25
26sk_sp<DisplayList> GetSampleDisplayList();
27sk_sp<DisplayList> GetSampleDisplayList(int ops);
28sk_sp<DisplayList> GetSampleNestedDisplayList();
29sk_sp<DlImage> MakeTestImage(int w, int h, int checker_size);
30sk_sp<DlImage> MakeTestImage(int w, int h, DlColor color);
31
32typedef const std::function<void(DlOpReceiver&)> DlInvoker;
33
34constexpr DlPoint kEndPoints[] = {
35 {0, 0},
36 {100, 100},
37};
43constexpr float kStops[] = {
44 0.0,
45 0.5,
46 1.0,
47};
48
49// clang-format off
50constexpr float kRotateColorMatrix[20] = {
51 0, 1, 0, 0, 0,
52 0, 0, 1, 0, 0,
53 1, 0, 0, 0, 0,
54 0, 0, 0, 1, 0,
55};
56constexpr float kInvertColorMatrix[20] = {
57 -1.0, 0, 0, 1.0, 0,
58 0, -1.0, 0, 1.0, 0,
59 0, 0, -1.0, 1.0, 0,
60 1.0, 1.0, 1.0, 1.0, 0,
61};
62// clang-format on
63
64constexpr DlPoint kTestPoints[] = {
65 {10, 10},
66 {20, 20},
67 {10, 20},
68 {20, 10},
69};
70#define TestPointCount sizeof(kTestPoints) / (sizeof(kTestPoints[0]))
71
74
75static auto kTestImage1 = MakeTestImage(40, 40, 5);
76static auto kTestImage2 = MakeTestImage(50, 50, 5);
77static auto kTestSkImage = MakeTestImage(30, 30, 5)->skia_image();
78
79static const std::shared_ptr<DlColorSource> kTestSource1 =
84static const std::shared_ptr<DlColorSource> kTestSource2 =
86 kEndPoints[1],
87 3,
88 kColors,
89 kStops,
91static const std::shared_ptr<DlColorSource> kTestSource3 =
93 10.0,
94 3,
95 kColors,
96 kStops,
98static const std::shared_ptr<DlColorSource> kTestSource4 =
100 10.0,
101 kEndPoints[1],
102 200.0,
103 3,
104 kColors,
105 kStops,
107static const std::shared_ptr<DlColorSource> kTestSource5 =
109 0.0,
110 360.0,
111 3,
112 kColors,
113 kStops,
115
116static const auto kTestBlendColorFilter1 =
117 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kDstATop);
118static const auto kTestBlendColorFilter2 =
119 DlColorFilter::MakeBlend(DlColor::kBlue(), DlBlendMode::kDstATop);
120static const auto kTestBlendColorFilter3 =
121 DlColorFilter::MakeBlend(DlColor::kRed(), DlBlendMode::kDstOver);
122static const auto kTestMatrixColorFilter1 =
124static const auto kTestMatrixColorFilter2 =
126
128 5.0,
131 5.0,
134 6.0,
137 5.0,
172constexpr DlRect kTestBounds = DlRect::MakeLTRB(10, 10, 50, 60);
173constexpr SkRect kTestSkBounds = SkRect::MakeLTRB(10, 10, 50, 60);
178static const SkRRect kTestSkRRect = SkRRect::MakeRectXY(kTestSkBounds, 5, 5);
179static const SkRRect kTestRRectRect = SkRRect::MakeRect(kTestSkBounds);
182static const SkRRect kTestSkInnerRRect =
183 SkRRect::MakeRectXY(kTestSkBounds.makeInset(5, 5), 2, 2);
187static const DlPath kTestPath1 =
188 DlPath(SkPath::Polygon({{0, 0}, {10, 10}, {10, 0}, {0, 10}}, true));
189static const DlPath kTestPath2 =
190 DlPath(SkPath::Polygon({{0, 0}, {10, 10}, {0, 10}, {10, 0}}, true));
191static const DlPath kTestPath3 =
192 DlPath(SkPath::Polygon({{0, 0}, {10, 10}, {10, 0}, {0, 10}}, false));
193
194static const std::shared_ptr<DlVertices> kTestVertices1 =
196 3,
198 nullptr,
199 kColors);
200static const std::shared_ptr<DlVertices> kTestVertices2 =
202 3,
204 nullptr,
205 kColors);
206
207static sk_sp<DisplayList> MakeTestDisplayList(int w, int h, SkColor color) {
208 DisplayListBuilder builder;
209 builder.DrawRect(DlRect::MakeWH(w, h), DlPaint(DlColor(color)));
210 return builder.Build();
211}
212static sk_sp<DisplayList> TestDisplayList1 =
213 MakeTestDisplayList(20, 20, SK_ColorGREEN);
214static sk_sp<DisplayList> TestDisplayList2 =
215 MakeTestDisplayList(25, 25, SK_ColorBLUE);
216
217static const sk_sp<DlRuntimeEffect> kTestRuntimeEffect1 =
219 SkRuntimeEffect::MakeForShader(
220 SkString("vec4 main(vec2 p) { return vec4(0); }"))
221 .effect);
222static const sk_sp<DlRuntimeEffect> kTestRuntimeEffect2 =
224 SkRuntimeEffect::MakeForShader(
225 SkString("vec4 main(vec2 p) { return vec4(1); }"))
226 .effect);
227
228SkFont CreateTestFontOfSize(DlScalar scalar);
229
230sk_sp<SkTextBlob> GetTestTextBlob(const std::string& str,
231 DlScalar font_size = 20.0f);
232sk_sp<SkTextBlob> GetTestTextBlob(int index);
233#if IMPELLER_SUPPORTS_RENDERING
234std::shared_ptr<impeller::TextFrame> GetTestTextFrame(int index);
235#endif
236
238 // ----------------------------------
239 // Required fields for initialization
240 uint32_t op_count_;
242
244
246 // ----------------------------------
247
248 // ----------------------------------
249 // Optional fields for initialization
250 uint32_t additional_depth_ = 0u;
252 // ----------------------------------
253
254 bool is_empty() { return byte_count_ == 0; }
255
256 uint32_t op_count() { return op_count_; }
257 // byte count for the individual ops, no DisplayList overhead
258 size_t raw_byte_count() { return byte_count_; }
259 // byte count for the ops with DisplayList overhead, comparable
260 // to |DisplayList.byte_count().
261 size_t byte_count() { return sizeof(DisplayList) + byte_count_; }
262
263 uint32_t depth_accumulated(uint32_t depth_scale = 1u) {
264 return depth_op_count_ * depth_scale + additional_depth_;
265 }
266 uint32_t depth_op_count() { return depth_op_count_; }
267 uint32_t additional_depth() { return additional_depth_; }
268 uint32_t adjust_render_op_depth_cost(uint32_t previous_cost) {
269 return render_op_cost_override_ == 0u //
270 ? previous_cost
272 }
273
274 void Invoke(DlOpReceiver& builder) { invoker_(builder); }
275};
276
278 std::string op_name;
279 std::vector<DisplayListInvocation> variants;
280};
281
282std::vector<DisplayListInvocationGroup> CreateAllRenderingOps();
283std::vector<DisplayListInvocationGroup> CreateAllGroups();
284
285} // namespace testing
286} // namespace flutter
287
288#endif // FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SNIPPETS_H_
sk_sp< DisplayList > Build()
Definition dl_builder.cc:66
void DrawRect(const DlRect &rect, const DlPaint &paint) override
static std::shared_ptr< const DlColorFilter > MakeBlend(DlColor color, DlBlendMode mode)
static std::shared_ptr< const DlColorFilter > MakeMatrix(const float matrix[20])
static std::shared_ptr< DlColorSource > MakeSweep(DlPoint center, DlScalar start, DlScalar end, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
static std::shared_ptr< DlColorSource > MakeImage(const sk_sp< const DlImage > &image, DlTileMode horizontal_tile_mode, DlTileMode vertical_tile_mode, DlImageSampling sampling=DlImageSampling::kLinear, const DlMatrix *matrix=nullptr)
static std::shared_ptr< DlColorSource > MakeLinear(const DlPoint start_point, const DlPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
static std::shared_ptr< DlColorSource > MakeConical(DlPoint start_center, DlScalar start_radius, DlPoint end_center, DlScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
static std::shared_ptr< DlColorSource > MakeRadial(DlPoint center, DlScalar radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
Internal API for rendering recorded display lists to backends.
static DlPath MakeRoundRect(const DlRoundRect &rrect)
Definition dl_path.cc:72
static DlPath MakeRect(const DlRect &rect)
Definition dl_path.cc:39
static DlPath MakeOval(const DlRect &bounds)
Definition dl_path.cc:57
static sk_sp< DlRuntimeEffect > Make(const sk_sp< SkRuntimeEffect > &runtime_effect)
static std::shared_ptr< DlVertices > Make(DlVertexMode mode, int vertex_count, const DlPoint vertices[], const DlPoint texture_coordinates[], const DlColor colors[], int index_count=0, const uint16_t indices[]=nullptr, const DlRect *bounds=nullptr)
Constructs a DlVector with compact inline storage for all of its required and optional lists of data.
static const DlComposeImageFilter kTestComposeImageFilter2(kTestBlurImageFilter2, kTestMatrixImageFilter1)
static const DlPath kTestPathOval
static const DlDilateImageFilter kTestDilateImageFilter2(6.0, 5.0)
static const std::shared_ptr< DlColorSource > kTestSource3
constexpr float kStops[]
const std::function< void(DlOpReceiver &)> DlInvoker
static const auto kTestMatrixColorFilter2
static auto kTestSkImage
static const sk_sp< DlRuntimeEffect > kTestRuntimeEffect1
static const DlBlurMaskFilter kTestMaskFilter1(DlBlurStyle::kNormal, 3.0)
static const DlPath kTestPathRect
SkFont CreateTestFontOfSize(DlScalar scalar)
static const std::shared_ptr< DlColorSource > kTestSource4
static const DlBlurMaskFilter kTestMaskFilter4(DlBlurStyle::kInner, 3.0)
static const DlComposeImageFilter kTestComposeImageFilter1(kTestBlurImageFilter1, kTestMatrixImageFilter1)
static const std::shared_ptr< DlVertices > kTestVertices2
constexpr SkRect kTestSkBounds
static const DlColorFilterImageFilter kTestCFImageFilter2(kTestBlendColorFilter2)
static const DlRoundRect kTestInnerRRect
constexpr DlPoint kTestPoints[]
constexpr float kRotateColorMatrix[20]
static const DlErodeImageFilter kTestErodeImageFilter2(4.0, 3.0)
static const auto kTestBlendColorFilter2
static const DlBlurMaskFilter kTestMaskFilter3(DlBlurStyle::kSolid, 3.0)
static const DlMatrixImageFilter kTestMatrixImageFilter2(DlMatrix::MakeRotationZ(DlDegrees(85)), kNearestSampling)
static const DlPath kTestPath2
static const DlBlurImageFilter kTestBlurImageFilter4(5.0, 5.0, DlTileMode::kDecal)
static const DlErodeImageFilter kTestErodeImageFilter3(3.0, 4.0)
static const DlRoundSuperellipse kTestRSuperellipse
static const DlMatrixImageFilter kTestMatrixImageFilter1(DlMatrix::MakeRotationZ(DlDegrees(45)), kNearestSampling)
static const auto kTestMatrixColorFilter1
static const std::shared_ptr< DlColorSource > kTestSource1
constexpr DlRect kTestBounds
static const DlPath kTestPath1
static const DlColorFilterImageFilter kTestCFImageFilter1(kTestBlendColorFilter1)
static const DlPath kTestPath3
static const std::shared_ptr< DlColorSource > kTestSource5
constexpr float kInvertColorMatrix[20]
sk_sp< DlImage > MakeTestImage(int w, int h, int checker_size)
static const sk_sp< DlRuntimeEffect > kTestRuntimeEffect2
static const DlErodeImageFilter kTestErodeImageFilter1(4.0, 4.0)
sk_sp< DisplayList > GetSampleDisplayList()
static const std::shared_ptr< DlColorSource > kTestSource2
static const DlBlurMaskFilter kTestMaskFilter2(DlBlurStyle::kNormal, 5.0)
static const DlBlurImageFilter kTestBlurImageFilter2(6.0, 5.0, DlTileMode::kClamp)
static const auto kTestBlendColorFilter3
static const DlPath kTestPathRRect
static auto kTestImage1
static DlImageSampling kLinearSampling
static const auto kTestBlendColorFilter1
static sk_sp< DisplayList > TestDisplayList2
static const SkRRect kTestSkInnerRRect
static const DlBlurImageFilter kTestBlurImageFilter3(5.0, 6.0, DlTileMode::kClamp)
static auto kTestImage2
std::vector< DisplayListInvocationGroup > CreateAllRenderingOps()
static const DlDilateImageFilter kTestDilateImageFilter1(5.0, 5.0)
static const SkRRect kTestRRectRect
sk_sp< DisplayList > GetSampleNestedDisplayList()
static DlImageSampling kNearestSampling
static const DlBlurMaskFilter kTestMaskFilter5(DlBlurStyle::kOuter, 3.0)
sk_sp< SkTextBlob > GetTestTextBlob(int index)
static const DlDilateImageFilter kTestDilateImageFilter3(5.0, 6.0)
static sk_sp< DisplayList > MakeTestDisplayList(int w, int h, SkColor color)
static const SkRRect kTestSkRRect
static const DlBlurImageFilter kTestBlurImageFilter1(5.0, 5.0, DlTileMode::kClamp)
constexpr DlPoint kEndPoints[]
std::vector< DisplayListInvocationGroup > CreateAllGroups()
static const DlComposeImageFilter kTestComposeImageFilter3(kTestBlurImageFilter1, kTestMatrixImageFilter2)
static const std::shared_ptr< DlVertices > kTestVertices1
const DlColor kColors[]
static const DlRoundRect kTestRRect
static sk_sp< DisplayList > TestDisplayList1
static const DlMatrixImageFilter kTestMatrixImageFilter3(DlMatrix::MakeRotationZ(DlDegrees(45)), kLinearSampling)
impeller::Scalar DlScalar
impeller::Degrees DlDegrees
@ kTriangles
The vertices are taken 3 at a time to form a triangle.
@ kNormal
fuzzy inside and outside
@ kOuter
nothing inside, fuzzy outside
@ kInner
fuzzy inside, nothing outside
@ kSolid
solid inside, fuzzy outside
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder h
Definition switch_defs.h:54
static constexpr DlColor kBlue()
Definition dl_color.h:73
static constexpr DlColor kYellow()
Definition dl_color.h:76
static constexpr DlColor kRed()
Definition dl_color.h:71
static constexpr DlColor kGreen()
Definition dl_color.h:72
std::vector< DisplayListInvocation > variants
uint32_t adjust_render_op_depth_cost(uint32_t previous_cost)
uint32_t depth_accumulated(uint32_t depth_scale=1u)
static Matrix MakeRotationZ(Radians r)
Definition matrix.h:223
static RoundRect MakeRectXY(const Rect &rect, Scalar x_radius, Scalar y_radius)
Definition round_rect.h:31
static RoundSuperellipse MakeRectXY(const Rect &rect, Scalar x_radius, Scalar y_radius)
static constexpr TRect MakeWH(Type width, Type height)
Definition rect.h:140
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition rect.h:618
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129
Scalar font_size