Flutter Engine
The 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
8#include "flutter/display_list/display_list.h"
9#include "flutter/display_list/dl_builder.h"
10#include "flutter/testing/testing.h"
11
17
18namespace flutter {
19namespace testing {
20
24
25typedef const std::function<void(DlOpReceiver&)> DlInvoker;
26
27constexpr SkPoint kEndPoints[] = {
28 {0, 0},
29 {100, 100},
30};
36constexpr float kStops[] = {
37 0.0,
38 0.5,
39 1.0,
40};
41
42// clang-format off
43constexpr float kRotateColorMatrix[20] = {
44 0, 1, 0, 0, 0,
45 0, 0, 1, 0, 0,
46 1, 0, 0, 0, 0,
47 0, 0, 0, 1, 0,
48};
49constexpr float kInvertColorMatrix[20] = {
50 -1.0, 0, 0, 1.0, 0,
51 0, -1.0, 0, 1.0, 0,
52 0, 0, -1.0, 1.0, 0,
53 1.0, 1.0, 1.0, 1.0, 0,
54};
55// clang-format on
56
57const SkScalar kTestDashes1[] = {4.0, 2.0};
58const SkScalar kTestDashes2[] = {1.0, 1.5};
59
60constexpr SkPoint kTestPoints[] = {
61 {10, 10},
62 {20, 20},
63 {10, 20},
64 {20, 10},
65};
66#define TestPointCount sizeof(kTestPoints) / (sizeof(kTestPoints[0]))
67
70
71static sk_sp<DlImage> MakeTestImage(int w, int h, int checker_size) {
74 SkCanvas* canvas = surface->getCanvas();
75 SkPaint p0, p1;
80 p1.setAlpha(128);
81 for (int y = 0; y < w; y += checker_size) {
82 for (int x = 0; x < h; x += checker_size) {
83 SkPaint& cellp = ((x + y) & 1) == 0 ? p0 : p1;
84 canvas->drawRect(SkRect::MakeXYWH(x, y, checker_size, checker_size),
85 cellp);
86 }
87 }
88 return DlImage::Make(surface->makeImageSnapshot());
89}
90
91static auto TestImage1 = MakeTestImage(40, 40, 5);
92static auto TestImage2 = MakeTestImage(50, 50, 5);
93static auto TestSkImage = MakeTestImage(30, 30, 5)->skia_image();
94
99static const std::shared_ptr<DlColorSource> kTestSource2 =
101 kEndPoints[1],
102 3,
103 kColors,
104 kStops,
106static const std::shared_ptr<DlColorSource> kTestSource3 =
108 10.0,
109 3,
110 kColors,
111 kStops,
113static const std::shared_ptr<DlColorSource> kTestSource4 =
115 10.0,
116 kEndPoints[1],
117 200.0,
118 3,
119 kColors,
120 kStops,
122static const std::shared_ptr<DlColorSource> kTestSource5 =
124 0.0,
125 360.0,
126 3,
127 kColors,
128 kStops,
139 5.0,
142 5.0,
145 6.0,
148 5.0,
178static const std::shared_ptr<DlPathEffect> kTestPathEffect1 =
180static const std::shared_ptr<DlPathEffect> kTestPathEffect2 =
187constexpr SkRect kTestBounds = SkRect::MakeLTRB(10, 10, 50, 60);
194static const SkPath kTestPath1 =
195 SkPath::Polygon({{0, 0}, {10, 10}, {10, 0}, {0, 10}}, true);
196static const SkPath kTestPath2 =
197 SkPath::Polygon({{0, 0}, {10, 10}, {0, 10}, {10, 0}}, true);
198static const SkPath kTestPath3 =
199 SkPath::Polygon({{0, 0}, {10, 10}, {10, 0}, {0, 10}}, false);
202
203static std::shared_ptr<const DlVertices> TestVertices1 =
205 3,
207 nullptr,
208 kColors);
209static std::shared_ptr<const DlVertices> TestVertices2 =
211 3,
213 nullptr,
214 kColors);
215
217 DisplayListBuilder builder;
218 builder.DrawRect(SkRect::MakeWH(w, h), DlPaint(DlColor(color)));
219 return builder.Build();
220}
225
227
229
231 // ----------------------------------
232 // Required fields for initialization
233 uint32_t op_count_;
235
237
239 // ----------------------------------
240
241 // ----------------------------------
242 // Optional fields for initialization
243 uint32_t additional_depth_ = 0u;
245 // ----------------------------------
246
247 bool is_empty() { return byte_count_ == 0; }
248
249 uint32_t op_count() { return op_count_; }
250 // byte count for the individual ops, no DisplayList overhead
251 size_t raw_byte_count() { return byte_count_; }
252 // byte count for the ops with DisplayList overhead, comparable
253 // to |DisplayList.byte_count().
254 size_t byte_count() { return sizeof(DisplayList) + byte_count_; }
255
256 uint32_t depth_accumulated(uint32_t depth_scale = 1u) {
257 return depth_op_count_ * depth_scale + additional_depth_;
258 }
259 uint32_t depth_op_count() { return depth_op_count_; }
260 uint32_t additional_depth() { return additional_depth_; }
261 uint32_t adjust_render_op_depth_cost(uint32_t previous_cost) {
262 return render_op_cost_override_ == 0u //
263 ? previous_cost
265 }
266
267 void Invoke(DlOpReceiver& builder) { invoker_(builder); }
268};
269
271 std::string op_name;
272 std::vector<DisplayListInvocation> variants;
273};
274
275std::vector<DisplayListInvocationGroup> CreateAllRenderingOps();
276std::vector<DisplayListInvocationGroup> CreateAllGroups();
277
278} // namespace testing
279} // namespace flutter
280
281#endif // FLUTTER_DISPLAY_LIST_TESTING_DL_TEST_SNIPPETS_H_
SkColor4f color
SkPathOp ops[]
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
void drawRect(const SkRect &rect, const SkPaint &paint)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
static SkMatrix RotateDeg(SkScalar deg)
Definition SkMatrix.h:104
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
void setAlpha(U8CPU a)
Definition SkPaint.h:279
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
Definition SkPath.cpp:3518
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
Definition SkPath.cpp:3522
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition SkPath.cpp:3546
static SkRRect MakeRect(const SkRect &r)
Definition SkRRect.h:149
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.h:180
static std::shared_ptr< DlConicalGradientColorSource > MakeConical(SkPoint start_center, SkScalar start_radius, SkPoint end_center, SkScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static std::shared_ptr< DlLinearGradientColorSource > MakeLinear(const SkPoint start_point, const SkPoint end_point, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static std::shared_ptr< DlSweepGradientColorSource > MakeSweep(SkPoint center, SkScalar start, SkScalar end, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static std::shared_ptr< DlRadialGradientColorSource > MakeRadial(SkPoint center, SkScalar radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const SkMatrix *matrix=nullptr)
static std::shared_ptr< DlPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
static sk_sp< DlImage > Make(const SkImage *image)
Definition dl_image.cc:11
Internal API for rendering recorded display lists to backends.
static std::shared_ptr< DlVertices > Make(DlVertexMode mode, int vertex_count, const SkPoint vertices[], const SkPoint texture_coordinates[], const DlColor colors[], int index_count=0, const uint16_t indices[]=nullptr)
Constructs a DlVector with compact inline storage for all of its required and optional lists of data.
VkSurfaceKHR surface
Definition main.cc:49
float SkScalar
Definition extension.cpp:12
double y
double x
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static const DlComposeImageFilter kTestComposeImageFilter2(kTestBlurImageFilter2, kTestMatrixImageFilter1)
static const DlDilateImageFilter kTestDilateImageFilter2(6.0, 5.0)
static const std::shared_ptr< DlColorSource > kTestSource3
constexpr SkRect kTestBounds
constexpr float kStops[]
static auto TestSkImage
const std::function< void(DlOpReceiver &)> DlInvoker
static const DlMatrixImageFilter kTestMatrixImageFilter1(SkMatrix::RotateDeg(45), kNearestSampling)
const SkScalar kTestDashes2[]
SkFont CreateTestFontOfSize(SkScalar scalar)
static const DlBlurMaskFilter kTestMaskFilter1(DlBlurStyle::kNormal, 3.0)
static const std::shared_ptr< DlPathEffect > kTestPathEffect2
static const std::shared_ptr< DlColorSource > kTestSource4
static const SkRRect kTestInnerRRect
static const DlBlurMaskFilter kTestMaskFilter4(DlBlurStyle::kInner, 3.0)
static const SkPath kTestPath1
static const DlComposeImageFilter kTestComposeImageFilter1(kTestBlurImageFilter1, kTestMatrixImageFilter1)
static std::shared_ptr< const DlVertices > TestVertices2
static const DlColorFilterImageFilter kTestCFImageFilter2(kTestBlendColorFilter2)
constexpr float kRotateColorMatrix[20]
static const DlErodeImageFilter kTestErodeImageFilter2(4.0, 3.0)
constexpr SkPoint kEndPoints[]
const SkScalar kTestDashes1[]
static const DlMatrixColorFilter kTestMatrixColorFilter2(kInvertColorMatrix)
static const DlBlurMaskFilter kTestMaskFilter3(DlBlurStyle::kSolid, 3.0)
static const DlImageColorSource kTestSource1(TestImage1, DlTileMode::kClamp, DlTileMode::kMirror, kLinearSampling)
static const DlBlurImageFilter kTestBlurImageFilter4(5.0, 5.0, DlTileMode::kDecal)
static const DlErodeImageFilter kTestErodeImageFilter3(3.0, 4.0)
static const SkMatrix kTestMatrix2
static const DlMatrixImageFilter kTestMatrixImageFilter3(SkMatrix::RotateDeg(45), kLinearSampling)
static const DlColorFilterImageFilter kTestCFImageFilter1(kTestBlendColorFilter1)
static constexpr SkPoint kTestPoints[2]
static const std::shared_ptr< DlColorSource > kTestSource5
constexpr float kInvertColorMatrix[20]
static const DlErodeImageFilter kTestErodeImageFilter1(4.0, 4.0)
static const SkRRect kTestRRect
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 DlBlendColorFilter kTestBlendColorFilter2(DlColor::kBlue(), DlBlendMode::kDstATop)
static const SkMatrix kTestMatrix1
static const DlBlendColorFilter kTestBlendColorFilter1(DlColor::kRed(), DlBlendMode::kDstATop)
static auto TestImage1
static const std::shared_ptr< DlPathEffect > kTestPathEffect1
static const DlMatrixColorFilter kTestMatrixColorFilter1(kRotateColorMatrix)
static const DlBlendColorFilter kTestBlendColorFilter3(DlColor::kRed(), DlBlendMode::kDstIn)
static DlImageSampling kLinearSampling
static sk_sp< DisplayList > TestDisplayList2
static const DlMatrixImageFilter kTestMatrixImageFilter2(SkMatrix::RotateDeg(85), kNearestSampling)
static std::shared_ptr< const DlVertices > TestVertices1
static const SkPath kTestPath2
static const DlBlurImageFilter kTestBlurImageFilter3(5.0, 6.0, DlTileMode::kClamp)
std::vector< DisplayListInvocationGroup > CreateAllRenderingOps()
static const SkPath kTestPathRect
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< DlImage > MakeTestImage(int w, int h, SkColor color)
static sk_sp< DisplayList > MakeTestDisplayList(int w, int h, SkColor color)
static const DlBlurImageFilter kTestBlurImageFilter1(5.0, 5.0, DlTileMode::kClamp)
static auto TestImage2
static const SkPath kTestPathOval
std::vector< DisplayListInvocationGroup > CreateAllGroups()
static const DlComposeImageFilter kTestComposeImageFilter3(kTestBlurImageFilter1, kTestMatrixImageFilter2)
static const SkPath kTestPath3
const DlColor kColors[]
static sk_sp< DisplayList > TestDisplayList1
@ 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 switches.h:59
@ kDstATop
r = d*sa + s*(1-da)
SkScalar w
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
SkRect makeInset(float dx, float dy) const
Definition SkRect.h:987
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646
static constexpr DlColor kBlue()
Definition dl_color.h:26
static constexpr DlColor kYellow()
Definition dl_color.h:29
static constexpr DlColor kRed()
Definition dl_color.h:24
static constexpr DlColor kGreen()
Definition dl_color.h:25
std::vector< DisplayListInvocation > variants
uint32_t adjust_render_op_depth_cost(uint32_t previous_cost)
uint32_t depth_accumulated(uint32_t depth_scale=1u)