11#include "flutter/impeller/aiks/aiks_unittests.h"
13#include "flutter/display_list/dl_builder.h"
14#include "flutter/display_list/dl_color.h"
15#include "flutter/display_list/dl_paint.h"
16#include "flutter/testing/testing.h"
42 std::vector<DlColor>
colors = {
45 std::vector<Scalar> stops = {0.0, 1.0};
48 {0, 0}, {200, 200}, 2,
colors.data(), stops.data(), tile_mode);
49 paint.setColorSource(gradient);
52 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(
builder.Build()));
87 std::vector<DlColor>
colors = {
90 std::vector<Scalar> stops = {0.0, 1.0};
98 DlBlendMode::kSrcOver));
101 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
107 builder.Translate(100.0, 100.0);
112 std::vector<Scalar> stops = {0.0, 1.0};
127 builder.Translate(100.0, 100.0);
132 std::vector<Scalar> stops = {0.0, 1.0};
148 builder.Translate(100.0, 100.0);
153 std::vector<Scalar> stops = {0.0, 1.0};
156 {100, 100}, 45, 135, 2,
colors.data(), stops.data(),
171 builder.Translate(100.0, 100.0);
176 std::vector<Scalar> stops = {0.0, 1.0};
179 colors.data(), stops.data(),
191void CanRenderLinearGradientWithOverlappingStops(
AiksTest* aiks_test,
195 builder.Translate(100.0, 100.0);
197 std::vector<DlColor>
colors = {
202 std::vector<Scalar> stops = {0.0, 0.5, 0.5, 1.0};
205 stops.size(),
colors.data(),
206 stops.data(), tile_mode));
210 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(
builder.Build()));
220void CanRenderLinearGradientManyColors(
AiksTest* aiks_test,
223 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
227 std::vector<DlColor>
colors = {
229 DlColor(
Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0}.ToARGB()),
230 DlColor(
Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0}.ToARGB()),
231 DlColor(
Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0}.ToARGB()),
232 DlColor(
Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0}.ToARGB()),
233 DlColor(
Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0}.ToARGB()),
234 DlColor(
Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}.ToARGB())};
235 std::vector<Scalar> stops = {
246 stops.size(),
colors.data(),
247 stops.data(), tile_mode));
252 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(
builder.Build()));
270void CanRenderLinearGradientWayManyColors(
AiksTest* aiks_test,
274 builder.Translate(100.0, 100.0);
276 std::vector<DlColor>
colors;
277 std::vector<Scalar> stops;
278 auto current_stop = 0.0;
279 for (
int i = 0;
i < 2000;
i++) {
281 stops.push_back(current_stop);
282 current_stop += 1 / 2000.0;
284 stops[2000 - 1] = 1.0;
287 stops.size(),
colors.data(),
288 stops.data(), tile_mode));
291 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(
builder.Build()));
302 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
306 static int selected_tile_mode = 0;
309 ImGuiWindowFlags_AlwaysAutoResize)) {
310 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
311 sizeof(tile_mode_names) /
sizeof(
char*));
312 std::string label =
"##1";
313 for (
int i = 0;
i < 4;
i++) {
314 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
315 &(
matrix.vec[
i]), 4, NULL, NULL,
"%.2f", 0);
323 builder.Translate(100.0, 100.0);
324 auto tile_mode = tile_modes[selected_tile_mode];
326 std::vector<DlColor>
colors = {
334 std::vector<Scalar> stops = {
335 0.0, 2.0 / 62.0, 4.0 / 62.0, 8.0 / 62.0, 16.0 / 62.0, 32.0 / 62.0, 1.0,
339 stops.size(),
colors.data(),
340 stops.data(), tile_mode));
345 ASSERT_TRUE(OpenPlaygroundHere(
callback));
351 std::vector<DlColor>
colors = {
355 std::vector<Scalar> stops = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5,
356 0.6, 0.7, 0.8, 0.9, 1.0};
361 {200, 200}, {400, 400}, stops.size(),
colors.data(), stops.data(),
368 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
373 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
377 static int selected_tile_mode = 0;
380 ImGuiWindowFlags_AlwaysAutoResize)) {
381 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
382 sizeof(tile_mode_names) /
sizeof(
char*));
383 std::string label =
"##1";
384 for (
int i = 0;
i < 4;
i++) {
385 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
386 &(
matrix.vec[
i]), 4, NULL, NULL,
"%.2f", 0);
394 builder.Translate(100.0, 100.0);
395 auto tile_mode = tile_modes[selected_tile_mode];
397 std::vector<DlColor>
colors = {
400 std::vector<Scalar> stops = {0.0, 1.0};
403 {100, 100}, 100, 2,
colors.data(), stops.data(), tile_mode));
408 ASSERT_TRUE(OpenPlaygroundHere(
callback));
413 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
417 static int selected_tile_mode = 0;
425 ImGuiWindowFlags_AlwaysAutoResize)) {
426 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
427 sizeof(tile_mode_names) /
sizeof(
char*));
428 std::string label =
"##1";
429 for (
int i = 0;
i < 4;
i++) {
430 ImGui::InputScalarN(label.c_str(), ImGuiDataType_Float,
431 &(
matrix.vec[
i]), 4, NULL, NULL,
"%.2f", 0);
439 builder.Translate(100.0, 100.0);
440 auto tile_mode = tile_modes[selected_tile_mode];
442 std::vector<DlColor>
colors = {
450 std::vector<Scalar> stops = {
461 {100, 100}, 100, stops.size(),
colors.data(), stops.data(), tile_mode));
466 ASSERT_TRUE(OpenPlaygroundHere(
callback));
472 builder.Scale(aiks_test->GetContentScale().x, aiks_test->GetContentScale().y);
476 std::vector<DlColor>
colors = {
479 std::vector<Scalar> stops = {0.0, 1.0};
482 {100, 100}, 45, 135, 2,
colors.data(),
483 stops.data(), tile_mode));
486 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(
builder.Build()));
504void CanRenderSweepGradientManyColors(
AiksTest* aiks_test,
508 builder.Translate(100.0, 100.0);
510 std::vector<DlColor>
colors = {
512 DlColor(
Color{0x5b / 255.0, 0.0, 0x60 / 255.0, 1.0}.ToARGB()),
513 DlColor(
Color{0x87 / 255.0, 0x01 / 255.0, 0x60 / 255.0, 1.0}.ToARGB()),
514 DlColor(
Color{0xac / 255.0, 0x25 / 255.0, 0x53 / 255.0, 1.0}.ToARGB()),
515 DlColor(
Color{0xe1 / 255.0, 0x6b / 255.0, 0x5c / 255.0, 1.0}.ToARGB()),
516 DlColor(
Color{0xf3 / 255.0, 0x90 / 255.0, 0x60 / 255.0, 1.0}.ToARGB()),
517 DlColor(
Color{0xff / 255.0, 0xb5 / 255.0, 0x6b / 250.0, 1.0}.ToARGB())};
518 std::vector<Scalar> stops = {
529 stops.size(),
colors.data(),
530 stops.data(), tile_mode));
533 ASSERT_TRUE(aiks_test->OpenPlaygroundHere(
builder.Build()));
556 std::vector<DlColor>
colors = {
561 std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
562 std::array<std::tuple<SkPoint, float, SkPoint, float>, 8> array{
580 for (
int i = 0;
i < 8;
i++) {
584 std::get<2>(array[
i]), std::get<3>(array[
i]),
std::get<0>(array[
i]),
590 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
594 std::vector<DlColor>
colors = {
599 std::vector<Scalar> stops = {0.0, 1.f / 3.f, 2.f / 3.f, 1.0};
601 std::array<std::shared_ptr<DlColorSource>, 3> color_sources = {
614 for (
int i = 0;
i < 3;
i++) {
617 paint.setColorSource(color_sources[
i]);
621 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
627 static float scale = 3;
628 static bool add_circle_clip =
true;
629 const char* tile_mode_names[] = {
"Clamp",
"Repeat",
"Mirror",
"Decal"};
632 static int selected_tile_mode = 0;
633 static float alpha = 1;
636 ImGuiWindowFlags_AlwaysAutoResize)) {
637 ImGui::SliderFloat(
"Scale", &
scale, 0, 6);
638 ImGui::Checkbox(
"Circle clip", &add_circle_clip);
639 ImGui::SliderFloat(
"Alpha", &alpha, 0, 1);
640 ImGui::Combo(
"Tile mode", &selected_tile_mode, tile_mode_names,
641 sizeof(tile_mode_names) /
sizeof(
char*));
646 builder.Scale(GetContentScale().
x, GetContentScale().
y);
653 paint.setStrokeWidth(10);
654 auto tile_mode = tile_modes[selected_tile_mode];
656 std::vector<DlColor>
colors = {
659 std::vector<Scalar> stops = {0.0, 1.0};
662 stops.size(),
colors.data(),
663 stops.data(), tile_mode));
667 path.quadTo({60, 20}, {60, 60});
670 path.quadTo({60, 60}, {20, 60});
674 if (add_circle_clip) {
679 auto [handle_a, handle_b] =
683 if (!
builder.GetTransform().invert(&screen_to_canvas)) {
687 Point point_a = ip_matrix * handle_a * GetContentScale();
688 Point point_b = ip_matrix * handle_b * GetContentScale();
690 Point middle = (point_a + point_b) / 2;
691 auto radius = point_a.GetDistance(middle);
702 paint.setStrokeCap(cap);
712 ASSERT_TRUE(OpenPlaygroundHere(
callback));
723 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
726 colors.data(), stops.data(),
735 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
746 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
749 colors.data(), stops.data(),
758 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
769 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
772 colors.data(), stops.data(),
781 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
792 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
795 colors.data(), stops.data(),
804 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
814 std::vector<Scalar> stops = {0.0, 0.1, 1.0};
818 paint.setColorSource(
828 ASSERT_TRUE(OpenPlaygroundHere(
builder.Build()));
SkPath & addCircle(SkScalar x, SkScalar y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
static std::shared_ptr< DlColorFilter > Make(DlColor color, DlBlendMode mode)
static std::shared_ptr< DlMaskFilter > Make(DlBlurStyle style, SkScalar sigma, bool respect_ctm=true)
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)
bool OpenPlaygroundHere(Picture picture)
static bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
Point GetContentScale() const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
unsigned useCenter Optional< SkMatrix > matrix
PODArray< SkColor > colors
SK_API sk_sp< SkShader > Color(SkColor)
@ kMiter
extends to miter limit
@ kBevel
connects outside edges
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
@ kStroke
strokes boundary of shapes
@ kNormal
fuzzy inside and outside
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
static void CanRenderLinearGradientWithDithering(AiksTest *aiks_test)
static void CanRenderRadialGradientWithDithering(AiksTest *aiks_test)
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
static void CanRenderConicalGradientWithDithering(AiksTest *aiks_test)
static void CanRenderSweepGradientWithDithering(AiksTest *aiks_test)
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
static Matrix ToMatrix(const SkMatrix &m)
const myers::Point & get< 1 >(const myers::Segment &s)
const myers::Point & get< 0 >(const myers::Segment &s)
SK_API sk_sp< PrecompileColorFilter > Matrix()
static SkString join(const CommandLineFlags::StringArray &)
static constexpr SkPoint Make(float x, float y)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
static constexpr DlColor kWhite()
static constexpr DlColor kBlue()
static constexpr DlColor kRed()
static constexpr DlColor kGreen()
constexpr uint32_t ToARGB() const
Convert to ARGB 32 bit color.
static constexpr Color Red()
static constexpr Color MakeRGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
A 4x4 matrix using column-major storage.