7#include "absl/status/statusor.h"
20#include "third_party/abseil-cpp/absl/status/status_matchers.h"
28absl::StatusOr<std::shared_ptr<DlColorSource>> MakeRuntimeEffect(
30 std::string_view
name,
31 const std::shared_ptr<std::vector<uint8_t>>& uniform_data = {},
32 const std::vector<std::shared_ptr<DlColorSource>>& samplers = {}) {
33 auto runtime_stages_result = test->OpenAssetAsRuntimeStage(
name.data());
34 if (!runtime_stages_result.ok()) {
35 return runtime_stages_result.status();
37 std::shared_ptr<RuntimeStage> runtime_stage =
38 runtime_stages_result.
value()[test->GetRuntimeStageBackend()];
40 return absl::InternalError(
"Runtime stage not found for backend.");
42 if (!runtime_stage->IsDirty()) {
43 return absl::InternalError(
"Runtime stage is not dirty.");
64 } frag_uniforms = {.iResolution =
Vector2(400, 400), .iTime = 100.0};
65 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
66 uniform_data->resize(
sizeof(FragUniforms));
67 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
71 MakeRuntimeEffect(
this,
"runtime_stage_example.frag.iplr", uniform_data);
72 ABSL_ASSERT_OK(effect);
79 DlClipOp::kIntersect);
83 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
90 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
91 uniform_data->resize(
sizeof(FragUniforms));
92 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
95 auto effect = MakeRuntimeEffect(
this,
"gradient.frag.iplr", uniform_data);
96 ABSL_ASSERT_OK(effect);
101 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
105 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
109 auto runtime_stages_result =
110 OpenAssetAsRuntimeStage(
"runtime_stage_filter_example.frag.iplr");
111 ABSL_ASSERT_OK(runtime_stages_result);
112 std::shared_ptr<RuntimeStage> runtime_stage =
113 runtime_stages_result.value()[GetRuntimeStageBackend()];
114 ASSERT_TRUE(runtime_stage);
115 ASSERT_TRUE(runtime_stage->IsDirty());
117 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
120 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
121 uniform_data->resize(
sizeof(
Vector2));
132 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
141 const float stops[2] = {0.0, 1.0};
143 2, colors.data(), stops,
145 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
149 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
150 uniform_data->resize(
sizeof(
Vector2));
154 MakeRuntimeEffect(
this,
"runtime_stage_filter_example.frag.iplr",
155 uniform_data, sampler_inputs);
156 ABSL_ASSERT_OK(effect);
162 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
179 std::shared_ptr<DlImageFilter> color_filter =
182 auto runtime_stages_result =
183 OpenAssetAsRuntimeStage(
"runtime_stage_filter_warp.frag.iplr");
184 ABSL_ASSERT_OK(runtime_stages_result);
185 std::shared_ptr<RuntimeStage> runtime_stage =
186 runtime_stages_result.value()[GetRuntimeStageBackend()];
187 ASSERT_TRUE(runtime_stage);
188 ASSERT_TRUE(runtime_stage->IsDirty());
190 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
193 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
194 uniform_data->resize(
sizeof(
Vector2));
201 builder.
Scale(0.7, 0.7);
207 DlImageSampling::kNearestNeighbor, &paint);
211 builder.
DrawLine({100, 100}, {200, 100}, green);
212 builder.
DrawLine({100, 100}, {100, 200}, green);
214 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
218 auto runtime_stages_result =
219 OpenAssetAsRuntimeStage(
"runtime_stage_filter_warp.frag.iplr");
220 ABSL_ASSERT_OK(runtime_stages_result);
221 std::shared_ptr<RuntimeStage> runtime_stage =
222 runtime_stages_result.value()[GetRuntimeStageBackend()];
223 ASSERT_TRUE(runtime_stage);
224 ASSERT_TRUE(runtime_stage->IsDirty());
229 bool compare =
false;
231 auto callback = [&]() -> sk_sp<DisplayList> {
232 if (IsPlaygroundEnabled()) {
233 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
234 ImGui::SliderFloat(
"xoffset", &xoffset, -50, 50);
235 ImGui::SliderFloat(
"yoffset", &yoffset, -50, 50);
236 ImGui::SliderFloat(
"xscale", &xscale, 0, 1);
237 ImGui::SliderFloat(
"yscale", &yscale, 0, 1);
238 ImGui::Checkbox(
"compare", &compare);
254 std::shared_ptr<DlImageFilter> color_filter =
257 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
260 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
261 uniform_data->resize(
sizeof(
Vector2));
268 builder.
Scale(xscale, yscale);
274 DlImageSampling::kNearestNeighbor, &paint);
280 DlImageSampling::kNearestNeighbor, &paint);
284 DlImageSampling::kNearestNeighbor, &paint);
289 builder.
DrawLine({100, 100}, {200, 100}, green);
290 builder.
DrawLine({100, 100}, {100, 200}, green);
292 builder.
DrawLine({800, 100}, {900, 100}, green);
293 builder.
DrawLine({800, 100}, {800, 200}, green);
294 builder.
DrawLine({100, 800}, {200, 800}, green);
295 builder.
DrawLine({100, 800}, {100, 900}, green);
298 return builder.
Build();
301 ASSERT_TRUE(OpenPlaygroundHere(
callback));
305 auto runtime_stages_result =
306 OpenAssetAsRuntimeStage(
"runtime_stage_filter_circle.frag.iplr");
307 ABSL_ASSERT_OK(runtime_stages_result);
308 std::shared_ptr<RuntimeStage> runtime_stage =
309 runtime_stages_result.value()[GetRuntimeStageBackend()];
310 ASSERT_TRUE(runtime_stage);
311 ASSERT_TRUE(runtime_stage->IsDirty());
314 auto callback = [&]() -> sk_sp<DisplayList> {
315 if (IsPlaygroundEnabled()) {
316 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
317 ImGui::SliderFloat(
"sigma", &sigma, 0, 20);
328 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
332 struct FragUniforms {
335 } frag_uniforms = {.size =
Vector2(1, 1), .origin =
Vector2(30.f, 30.f)};
336 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
337 uniform_data->resize(
sizeof(FragUniforms));
338 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
350 DlImageSampling::kNearestNeighbor, &paint);
354 builder.
SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
359 builder.
DrawLine({100, 100}, {200, 100}, green);
360 builder.
DrawLine({100, 100}, {100, 200}, green);
362 return builder.
Build();
365 ASSERT_TRUE(OpenPlaygroundHere(
callback));
369 auto runtime_stages_result =
370 OpenAssetAsRuntimeStage(
"runtime_stage_filter_circle.frag.iplr");
371 ABSL_ASSERT_OK(runtime_stages_result);
372 std::shared_ptr<RuntimeStage> runtime_stage =
373 runtime_stages_result.value()[GetRuntimeStageBackend()];
374 ASSERT_TRUE(runtime_stage);
375 ASSERT_TRUE(runtime_stage->IsDirty());
378 auto callback = [&]() -> sk_sp<DisplayList> {
379 if (IsPlaygroundEnabled()) {
380 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
381 ImGui::SliderFloat(
"sigma", &sigma, 0, 20);
392 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
395 struct FragUniforms {
398 } frag_uniforms = {.size =
Vector2(1, 1), .origin =
Vector2(30.f, 30.f)};
399 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
400 uniform_data->resize(
sizeof(FragUniforms));
401 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
413 DlImageSampling::kNearestNeighbor, &paint);
417 builder.
SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
422 builder.
DrawLine({100, 100}, {200, 100}, green);
423 builder.
DrawLine({100, 100}, {100, 200}, green);
425 return builder.
Build();
428 ASSERT_TRUE(OpenPlaygroundHere(
callback));
432 auto runtime_stages_result =
433 OpenAssetAsRuntimeStage(
"runtime_stage_filter_circle.frag.iplr");
434 ABSL_ASSERT_OK(runtime_stages_result);
435 std::shared_ptr<RuntimeStage> runtime_stage =
436 runtime_stages_result.value()[GetRuntimeStageBackend()];
437 ASSERT_TRUE(runtime_stage);
438 ASSERT_TRUE(runtime_stage->IsDirty());
444 auto callback = [&]() -> sk_sp<DisplayList> {
445 if (IsPlaygroundEnabled()) {
446 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
447 ImGui::SliderFloat(
"sigma", &sigma, 0, 20);
448 ImGui::SliderFloat(
"clip_x", &clip_origin.
x, 0, 2048.f);
449 ImGui::SliderFloat(
"clip_y", &clip_origin.
y, 0, 1536.f);
450 ImGui::SliderFloat(
"clip_width", &clip_size.
x, 0, 2048.f);
451 ImGui::SliderFloat(
"clip_height", &clip_size.
y, 0, 1536.f);
452 ImGui::SliderFloat(
"circle_x", &circle_origin.
x, 0.f, 2048.f);
453 ImGui::SliderFloat(
"circle_y", &circle_origin.
y, 0.f, 1536.f);
464 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
467 struct FragUniforms {
470 } frag_uniforms = {.size =
Vector2(1, 1), .origin = circle_origin};
471 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
472 uniform_data->resize(
sizeof(FragUniforms));
473 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
488 DlImageSampling::kNearestNeighbor, &paint);
492 builder.
SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
497 builder.
DrawLine({100, 100}, {200, 100}, green);
498 builder.
DrawLine({100, 100}, {100, 200}, green);
500 return builder.
Build();
503 ASSERT_TRUE(OpenPlaygroundHere(
callback));
507 struct FragUniforms {
509 } frag_uniforms = {.uSize =
Vector2(400, 400)};
510 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
511 uniform_data->resize(
sizeof(FragUniforms));
512 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
514 auto runtime_stages_result =
515 OpenAssetAsRuntimeStage(
"runtime_stage_border.frag.iplr");
516 ABSL_ASSERT_OK(runtime_stages_result);
517 std::shared_ptr<RuntimeStage> runtime_stage =
518 runtime_stages_result.value()[GetRuntimeStageBackend()];
519 ASSERT_TRUE(runtime_stage);
520 ASSERT_TRUE(runtime_stage->IsDirty());
522 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
553 builder.
SaveLayer(std::nullopt, &save_paint, runtime_filter.get());
561 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
566 auto size =
image->GetBounds().GetSize();
568 struct FragUniforms {
570 } frag_uniforms = {.size =
Size(
size.width,
size.height)};
571 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
572 uniform_data->resize(
sizeof(FragUniforms));
573 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
575 auto runtime_stages_result = OpenAssetAsRuntimeStage(
"gradient.frag.iplr");
576 ABSL_ASSERT_OK(runtime_stages_result);
577 std::shared_ptr<RuntimeStage> runtime_stage =
578 runtime_stages_result.value()[GetRuntimeStageBackend()];
579 ASSERT_TRUE(runtime_stage);
580 ASSERT_TRUE(runtime_stage->IsDirty());
582 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
592 auto callback = [&]() -> sk_sp<DisplayList> {
593 if (IsPlaygroundEnabled()) {
594 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
595 ImGui::SliderFloat(
"rotation", &rotation, 0, 360);
606 DlImageSampling::kNearestNeighbor, &paint);
608 return builder.
Build();
611 ASSERT_TRUE(OpenPlaygroundHere(
callback));
615 constexpr float kDimension = 400.0f;
616 struct FragUniforms {
619 } frag_uniforms = {.iResolution =
Vector2(kDimension, kDimension),
620 .iValues =
Vector4(0.25, 0.50, 0.75, 1.0)};
621 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
622 uniform_data->resize(
sizeof(FragUniforms));
623 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
626 auto effect = MakeRuntimeEffect(
this,
"runtime_stage_vector_array.frag.iplr",
628 ABSL_ASSERT_OK(effect);
634 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
void ClipRect(const DlRect &rect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override
void DrawImage(const sk_sp< DlImage > &image, const DlPoint &point, DlImageSampling sampling, const DlPaint *paint=nullptr) override
void SaveLayer(const std::optional< DlRect > &bounds, const DlPaint *paint=nullptr, const DlImageFilter *backdrop=nullptr, std::optional< int64_t > backdrop_id=std::nullopt) override
void DrawLine(const DlPoint &p0, const DlPoint &p1, const DlPaint &paint) override
void ClipRoundRect(const DlRoundRect &rrect, DlClipOp clip_op=DlClipOp::kIntersect, bool is_aa=false) override
void Rotate(DlScalar degrees) override
void Scale(DlScalar sx, DlScalar sy) override
void Translate(DlScalar tx, DlScalar ty) override
void DrawPaint(const DlPaint &paint) override
sk_sp< DisplayList > Build()
void DrawRect(const DlRect &rect, const DlPaint &paint) override
static std::shared_ptr< const DlColorFilter > MakeMatrix(const float matrix[20])
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 > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)
static std::shared_ptr< DlImageFilter > MakeBlur(DlScalar sigma_x, DlScalar sigma_y, DlTileMode tile_mode)
static std::shared_ptr< DlImageFilter > MakeRuntimeEffect(sk_sp< DlRuntimeEffect > runtime_effect, std::vector< std::shared_ptr< DlColorSource > > samplers, std::shared_ptr< std::vector< uint8_t > > uniform_data)
static std::shared_ptr< DlImageFilter > MakeColorFilter(const std::shared_ptr< const DlColorFilter > &filter)
static std::shared_ptr< DlImageFilter > MakeCompose(const std::shared_ptr< DlImageFilter > &outer, const std::shared_ptr< DlImageFilter > &inner)
DlPaint & setColor(DlColor color)
DlPaint & setBlendMode(DlBlendMode mode)
DlPaint & setImageFilter(std::nullptr_t filter)
DlPaint & setColorSource(std::nullptr_t source)
static sk_sp< DlRuntimeEffect > Make(std::shared_ptr< impeller::RuntimeStage > runtime_stage)
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
FlutterVulkanImage * image
FlutterDesktopBinaryReply callback
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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
DEF_SWITCHES_START aot vmservice shared library name
TEST_P(AiksTest, DrawAtlasNoColor)
AiksPlaygroundWithGoldens AiksTest
static constexpr DlColor kWhite()
static constexpr DlColor kBlue()
static constexpr DlColor kAqua()
static constexpr DlColor kRed()
static constexpr DlColor kGreen()
static RoundRect MakeRectXY(const Rect &rect, Scalar x_radius, Scalar y_radius)
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TSize MakeWH(Type width, Type height)