5#include "flutter/display_list/benchmarking/dl_complexity.h"
6#include "flutter/display_list/benchmarking/dl_complexity_gl.h"
7#include "flutter/display_list/benchmarking/dl_complexity_metal.h"
8#include "flutter/display_list/display_list.h"
9#include "flutter/display_list/dl_builder.h"
10#include "flutter/display_list/dl_sampling_options.h"
11#include "flutter/display_list/testing/dl_test_snippets.h"
12#include "flutter/testing/testing.h"
23std::vector<DisplayListComplexityCalculator*> Calculators() {
29std::vector<DisplayListComplexityCalculator*> AccumulatorCalculators() {
35 std::vector<SkPoint>
points;
47TEST(DisplayListComplexity, EmptyDisplayList) {
50 auto calculators = Calculators();
51 for (
auto calculator : calculators) {
52 ASSERT_EQ(calculator->Compute(display_list.get()), 0u);
56TEST(DisplayListComplexity, DisplayListCeiling) {
59 auto calculators = AccumulatorCalculators();
60 for (
auto calculator : calculators) {
61 calculator->SetComplexityCeiling(10u);
62 ASSERT_EQ(calculator->Compute(display_list.get()), 10u);
67TEST(DisplayListComplexity, NestedDisplayList) {
70 auto calculators = Calculators();
71 for (
auto calculator : calculators) {
76 ASSERT_GT(calculator->Compute(display_list.get()), 1u);
80TEST(DisplayListComplexity, AntiAliasing) {
84 auto display_list_no_aa = builder_no_aa.
Build();
89 auto display_list_aa = builder_aa.
Build();
91 auto calculators = AccumulatorCalculators();
92 for (
auto calculator : calculators) {
93 ASSERT_NE(calculator->Compute(display_list_no_aa.get()),
94 calculator->Compute(display_list_aa.get()));
98TEST(DisplayListComplexity, StrokeWidth) {
101 DlPaint().setStrokeWidth(0.0f));
102 auto display_list_stroke_0 = builder_stroke_0.
Build();
106 DlPaint().setStrokeWidth(1.0f));
107 auto display_list_stroke_1 = builder_stroke_1.
Build();
109 auto calculators = AccumulatorCalculators();
110 for (
auto calculator : calculators) {
111 ASSERT_NE(calculator->Compute(display_list_stroke_0.get()),
112 calculator->Compute(display_list_stroke_1.get()));
116TEST(DisplayListComplexity, Style) {
120 auto display_list_filled = builder_filled.
Build();
125 auto display_list_stroked = builder_stroked.
Build();
127 auto calculators = AccumulatorCalculators();
128 for (
auto calculator : calculators) {
129 ASSERT_NE(calculator->Compute(display_list_filled.get()),
130 calculator->Compute(display_list_stroked.get()));
134TEST(DisplayListComplexity, SaveLayers) {
136 builder.SaveLayer(
nullptr,
nullptr);
137 auto display_list =
builder.Build();
139 auto calculators = AccumulatorCalculators();
140 for (
auto calculator : calculators) {
141 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
145TEST(DisplayListComplexity, DrawPath) {
152 auto display_list_line = builder_line.
Build();
160 auto display_list_quad = builder_quad.
Build();
168 auto display_list_conic = builder_conic.
Build();
176 auto display_list_cubic = builder_cubic.
Build();
178 auto calculators = AccumulatorCalculators();
179 for (
auto calculator : calculators) {
180 ASSERT_NE(calculator->Compute(display_list_line.get()), 0u);
181 ASSERT_NE(calculator->Compute(display_list_quad.get()), 0u);
182 ASSERT_NE(calculator->Compute(display_list_conic.get()), 0u);
183 ASSERT_NE(calculator->Compute(display_list_cubic.get()), 0u);
187TEST(DisplayListComplexity, DrawShadow) {
194 auto display_list_line = builder_line.
Build();
202 auto display_list_quad = builder_quad.
Build();
211 auto display_list_conic = builder_conic.
Build();
220 auto display_list_cubic = builder_cubic.
Build();
222 auto calculators = AccumulatorCalculators();
223 for (
auto calculator : calculators) {
224 ASSERT_NE(calculator->Compute(display_list_line.get()), 0u);
225 ASSERT_NE(calculator->Compute(display_list_quad.get()), 0u);
226 ASSERT_NE(calculator->Compute(display_list_conic.get()), 0u);
227 ASSERT_NE(calculator->Compute(display_list_cubic.get()), 0u);
231TEST(DisplayListComplexity, DrawOval) {
234 auto display_list =
builder.Build();
236 auto calculators = AccumulatorCalculators();
237 for (
auto calculator : calculators) {
238 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
242TEST(DisplayListComplexity, DrawCircle) {
245 auto display_list =
builder.Build();
247 auto calculators = AccumulatorCalculators();
248 for (
auto calculator : calculators) {
249 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
253TEST(DisplayListComplexity, DrawRRect) {
258 auto display_list =
builder.Build();
260 auto calculators = AccumulatorCalculators();
261 for (
auto calculator : calculators) {
262 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
266TEST(DisplayListComplexity, DrawDRRect) {
273 auto display_list =
builder.Build();
275 auto calculators = AccumulatorCalculators();
276 for (
auto calculator : calculators) {
277 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
281TEST(DisplayListComplexity, DrawArc) {
285 auto display_list =
builder.Build();
287 auto calculators = AccumulatorCalculators();
288 for (
auto calculator : calculators) {
289 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
293TEST(DisplayListComplexity, DrawVertices) {
296 points.data(),
nullptr,
nullptr);
299 auto display_list =
builder.Build();
301 auto calculators = AccumulatorCalculators();
302 for (
auto calculator : calculators) {
303 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
307TEST(DisplayListComplexity, DrawTextBlob) {
313 auto display_list =
builder.Build();
318 auto display_list_multiple = builder_multiple.
Build();
320 auto calculators = AccumulatorCalculators();
321 for (
auto calculator : calculators) {
322 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
323 ASSERT_GT(calculator->Compute(display_list_multiple.get()),
324 calculator->Compute(display_list.get()));
328TEST(DisplayListComplexity, DrawPoints) {
333 auto display_list_lines = builder_lines.
Build();
338 auto display_list_points = builder_points.
Build();
343 auto display_list_polygon = builder_polygon.
Build();
345 auto calculators = AccumulatorCalculators();
346 for (
auto calculator : calculators) {
347 ASSERT_NE(calculator->Compute(display_list_lines.get()), 0u);
348 ASSERT_NE(calculator->Compute(display_list_points.get()), 0u);
349 ASSERT_NE(calculator->Compute(display_list_polygon.get()), 0u);
364 auto display_list =
builder.Build();
366 auto calculators = AccumulatorCalculators();
367 for (
auto calculator : calculators) {
368 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
372TEST(DisplayListComplexity, DrawImageNine) {
386 auto display_list =
builder.Build();
388 auto calculators = AccumulatorCalculators();
389 for (
auto calculator : calculators) {
390 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
408 auto display_list =
builder.Build();
410 auto calculators = AccumulatorCalculators();
411 for (
auto calculator : calculators) {
412 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
424 std::vector<SkRect> rects;
425 std::vector<SkRSXform>
xforms;
426 for (
int i = 0;
i < 10;
i++) {
435 auto display_list =
builder.Build();
437 auto calculators = AccumulatorCalculators();
438 for (
auto calculator : calculators) {
439 ASSERT_NE(calculator->Compute(display_list.get()), 0u);
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
static const int points[]
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
constexpr SkColor SK_ColorRED
SkPath & moveTo(SkScalar x, SkScalar y)
SkPath & lineTo(SkScalar x, SkScalar y)
SkPath & quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
SkPath & conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
static sk_sp< SkTextBlob > MakeFromString(const char *string, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
void DrawLine(const SkPoint &p0, const SkPoint &p1, const DlPaint &paint) override
void DrawRect(const SkRect &rect, const DlPaint &paint) override
void DrawPath(const SkPath &path, const DlPaint &paint) override
void DrawPoints(PointMode mode, uint32_t count, const SkPoint pts[], const DlPaint &paint) override
void DrawTextBlob(const sk_sp< SkTextBlob > &blob, SkScalar x, SkScalar y, const DlPaint &paint) override
void DrawShadow(const SkPath &path, const DlColor color, const SkScalar elevation, bool transparent_occluder, SkScalar dpr) override
sk_sp< DisplayList > Build()
static DisplayListGLComplexityCalculator * GetInstance()
static DisplayListComplexityCalculator * GetInstance()
@ kLines
draw each separate pair of points as a line segment
@ kPolygon
draw each pair of overlapping points as a line segment
@ kPoints
draw each point separately
static sk_sp< DlImage > Make(const SkImage *image)
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.
static float max(float r, float g, float b)
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
sk_sp< const SkImage > image
PODArray< SkRSXform > xforms
void DrawImage(SkCanvas *canvas, const SkImage *image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
SK_API void DrawImageRect(SkCanvas *canvas, const SkImage *image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
SkFont CreateTestFontOfSize(SkScalar scalar)
sk_sp< DisplayList > GetSampleDisplayList()
std::vector< SkPoint > GetTestPoints(size_t count, SkISize canvas_size)
sk_sp< DisplayList > GetSampleNestedDisplayList()
TEST(DisplayListComplexity, EmptyDisplayList)
@ kTriangles
The vertices are taken 3 at a time to form a triangle.
@ kStroke
strokes boundary of shapes
@ kFill
fills interior of shapes
skgpu::graphite::DrawAtlas DrawAtlas
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkPoint Make(float x, float y)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)