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 =
41 return absl::InternalError(
"Runtime stage not found for backend.");
43 if (!runtime_stage->IsDirty()) {
44 return absl::InternalError(
"Runtime stage is not dirty.");
59 } frag_uniforms = {.iResolution =
Vector2(400, 400), .iTime = 100.0};
60 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
61 uniform_data->resize(
sizeof(FragUniforms));
62 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
66 MakeRuntimeEffect(
this,
"runtime_stage_example.frag.iplr", uniform_data);
67 ABSL_ASSERT_OK(effect);
74 DlClipOp::kIntersect);
78 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
85 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
86 uniform_data->resize(
sizeof(FragUniforms));
87 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
90 auto effect = MakeRuntimeEffect(
this,
"gradient.frag.iplr", uniform_data);
91 ABSL_ASSERT_OK(effect);
96 builder.
Scale(GetContentScale().
x, GetContentScale().
y);
100 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
104 auto runtime_stages_result =
105 OpenAssetAsRuntimeStage(
"runtime_stage_filter_example.frag.iplr");
106 ABSL_ASSERT_OK(runtime_stages_result);
107 std::shared_ptr<RuntimeStage> runtime_stage =
108 runtime_stages_result
110 ASSERT_TRUE(runtime_stage);
111 ASSERT_TRUE(runtime_stage->IsDirty());
113 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
116 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
117 uniform_data->resize(
sizeof(
Vector2));
128 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
137 const float stops[2] = {0.0, 1.0};
139 2, colors.data(), stops,
141 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
145 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
146 uniform_data->resize(
sizeof(
Vector2));
150 MakeRuntimeEffect(
this,
"runtime_stage_filter_example.frag.iplr",
151 uniform_data, sampler_inputs);
152 ABSL_ASSERT_OK(effect);
158 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
175 std::shared_ptr<DlImageFilter> color_filter =
178 auto runtime_stages_result =
179 OpenAssetAsRuntimeStage(
"runtime_stage_filter_warp.frag.iplr");
180 ABSL_ASSERT_OK(runtime_stages_result);
181 std::shared_ptr<RuntimeStage> runtime_stage =
182 runtime_stages_result
184 ASSERT_TRUE(runtime_stage);
185 ASSERT_TRUE(runtime_stage->IsDirty());
187 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
190 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
191 uniform_data->resize(
sizeof(
Vector2));
198 builder.
Scale(0.7, 0.7);
204 DlImageSampling::kNearestNeighbor, &paint);
208 builder.
DrawLine({100, 100}, {200, 100}, green);
209 builder.
DrawLine({100, 100}, {100, 200}, green);
211 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
215 auto runtime_stages_result =
216 OpenAssetAsRuntimeStage(
"runtime_stage_filter_warp.frag.iplr");
217 ABSL_ASSERT_OK(runtime_stages_result);
218 std::shared_ptr<RuntimeStage> runtime_stage =
219 runtime_stages_result
221 ASSERT_TRUE(runtime_stage);
222 ASSERT_TRUE(runtime_stage->IsDirty());
227 bool compare =
false;
229 auto callback = [&]() -> sk_sp<DisplayList> {
231 ImGuiWindowFlags_AlwaysAutoResize)) {
232 ImGui::SliderFloat(
"xoffset", &xoffset, -50, 50);
233 ImGui::SliderFloat(
"yoffset", &yoffset, -50, 50);
234 ImGui::SliderFloat(
"xscale", &xscale, 0, 1);
235 ImGui::SliderFloat(
"yscale", &yscale, 0, 1);
236 ImGui::Checkbox(
"compare", &compare);
252 std::shared_ptr<DlImageFilter> color_filter =
255 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
258 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
259 uniform_data->resize(
sizeof(
Vector2));
266 builder.
Scale(xscale, yscale);
272 DlImageSampling::kNearestNeighbor, &paint);
278 DlImageSampling::kNearestNeighbor, &paint);
282 DlImageSampling::kNearestNeighbor, &paint);
287 builder.
DrawLine({100, 100}, {200, 100}, green);
288 builder.
DrawLine({100, 100}, {100, 200}, green);
290 builder.
DrawLine({800, 100}, {900, 100}, green);
291 builder.
DrawLine({800, 100}, {800, 200}, green);
292 builder.
DrawLine({100, 800}, {200, 800}, green);
293 builder.
DrawLine({100, 800}, {100, 900}, green);
296 return builder.
Build();
299 ASSERT_TRUE(OpenPlaygroundHere(
callback));
303 auto runtime_stages_result =
304 OpenAssetAsRuntimeStage(
"runtime_stage_filter_circle.frag.iplr");
305 ABSL_ASSERT_OK(runtime_stages_result);
306 std::shared_ptr<RuntimeStage> runtime_stage =
307 runtime_stages_result
309 ASSERT_TRUE(runtime_stage);
310 ASSERT_TRUE(runtime_stage->IsDirty());
313 auto callback = [&]() -> sk_sp<DisplayList> {
315 ImGuiWindowFlags_AlwaysAutoResize)) {
316 ImGui::SliderFloat(
"sigma", &sigma, 0, 20);
327 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
331 struct FragUniforms {
334 } frag_uniforms = {.size =
Vector2(1, 1), .origin =
Vector2(30.f, 30.f)};
335 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
336 uniform_data->resize(
sizeof(FragUniforms));
337 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
349 DlImageSampling::kNearestNeighbor, &paint);
353 builder.
SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
358 builder.
DrawLine({100, 100}, {200, 100}, green);
359 builder.
DrawLine({100, 100}, {100, 200}, green);
361 return builder.
Build();
364 ASSERT_TRUE(OpenPlaygroundHere(
callback));
368 auto runtime_stages_result =
369 OpenAssetAsRuntimeStage(
"runtime_stage_filter_circle.frag.iplr");
370 ABSL_ASSERT_OK(runtime_stages_result);
371 std::shared_ptr<RuntimeStage> runtime_stage =
372 runtime_stages_result
374 ASSERT_TRUE(runtime_stage);
375 ASSERT_TRUE(runtime_stage->IsDirty());
378 auto callback = [&]() -> sk_sp<DisplayList> {
380 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
438 ASSERT_TRUE(runtime_stage);
439 ASSERT_TRUE(runtime_stage->IsDirty());
445 auto callback = [&]() -> sk_sp<DisplayList> {
447 ImGuiWindowFlags_AlwaysAutoResize)) {
448 ImGui::SliderFloat(
"sigma", &sigma, 0, 20);
449 ImGui::SliderFloat(
"clip_x", &clip_origin.
x, 0, 2048.f);
450 ImGui::SliderFloat(
"clip_y", &clip_origin.
y, 0, 1536.f);
451 ImGui::SliderFloat(
"clip_width", &clip_size.
x, 0, 2048.f);
452 ImGui::SliderFloat(
"clip_height", &clip_size.
y, 0, 1536.f);
453 ImGui::SliderFloat(
"circle_x", &circle_origin.
x, 0.f, 2048.f);
454 ImGui::SliderFloat(
"circle_y", &circle_origin.
y, 0.f, 1536.f);
465 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
468 struct FragUniforms {
471 } frag_uniforms = {.size =
Vector2(1, 1), .origin = circle_origin};
472 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
473 uniform_data->resize(
sizeof(FragUniforms));
474 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
489 DlImageSampling::kNearestNeighbor, &paint);
493 builder.
SaveLayer(std::nullopt, &save_paint, backdrop_filter.get());
498 builder.
DrawLine({100, 100}, {200, 100}, green);
499 builder.
DrawLine({100, 100}, {100, 200}, green);
501 return builder.
Build();
504 ASSERT_TRUE(OpenPlaygroundHere(
callback));
508 struct FragUniforms {
510 } frag_uniforms = {.uSize =
Vector2(400, 400)};
511 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
512 uniform_data->resize(
sizeof(FragUniforms));
513 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
515 auto runtime_stages_result =
516 OpenAssetAsRuntimeStage(
"runtime_stage_border.frag.iplr");
517 ABSL_ASSERT_OK(runtime_stages_result);
518 std::shared_ptr<RuntimeStage> runtime_stage =
519 runtime_stages_result
521 ASSERT_TRUE(runtime_stage);
522 ASSERT_TRUE(runtime_stage->IsDirty());
524 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
555 builder.
SaveLayer(std::nullopt, &save_paint, runtime_filter.get());
563 ASSERT_TRUE(OpenPlaygroundHere(builder.
Build()));
568 auto size =
image->GetBounds().GetSize();
570 struct FragUniforms {
572 } frag_uniforms = {.size =
Size(
size.width,
size.height)};
573 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
574 uniform_data->resize(
sizeof(FragUniforms));
575 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
577 auto runtime_stages_result = OpenAssetAsRuntimeStage(
"gradient.frag.iplr");
578 ABSL_ASSERT_OK(runtime_stages_result);
579 std::shared_ptr<RuntimeStage> runtime_stage =
580 runtime_stages_result
582 ASSERT_TRUE(runtime_stage);
583 ASSERT_TRUE(runtime_stage->IsDirty());
585 std::vector<std::shared_ptr<DlColorSource>> sampler_inputs = {
595 auto callback = [&]() -> sk_sp<DisplayList> {
597 ImGuiWindowFlags_AlwaysAutoResize)) {
598 ImGui::SliderFloat(
"rotation", &rotation, 0, 360);
609 DlImageSampling::kNearestNeighbor, &paint);
611 return builder.
Build();
614 ASSERT_TRUE(OpenPlaygroundHere(
callback));
618 constexpr float kDimension = 400.0f;
619 struct FragUniforms {
622 } frag_uniforms = {.iResolution =
Vector2(kDimension, kDimension),
623 .iValues =
Vector4(0.25, 0.50, 0.75, 1.0)};
624 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
625 uniform_data->resize(
sizeof(FragUniforms));
626 memcpy(uniform_data->data(), &frag_uniforms,
sizeof(FragUniforms));
629 auto effect = MakeRuntimeEffect(
this,
"runtime_stage_vector_array.frag.iplr",
631 ABSL_ASSERT_OK(effect);
637 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 bool ImGuiBegin(const char *name, bool *p_open, ImGuiWindowFlags flags)
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)
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
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)