Flutter Impeller
aiks_dl_runtime_effect_unittests.cc
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 #include <memory>
6 
7 #include "display_list/effects/dl_color_source.h"
9 
10 #include "flutter/display_list/dl_builder.h"
11 #include "flutter/display_list/dl_paint.h"
12 
13 #include "include/core/SkPath.h"
14 #include "include/core/SkRRect.h"
15 
16 namespace impeller {
17 namespace testing {
18 
19 using namespace flutter;
20 
21 namespace {
22 std::shared_ptr<DlRuntimeEffectColorSource> MakeRuntimeEffect(
23  AiksTest* test,
24  std::string_view name,
25  const std::shared_ptr<std::vector<uint8_t>>& uniform_data = {},
26  const std::vector<std::shared_ptr<DlColorSource>>& samplers = {}) {
27  auto runtime_stages = test->OpenAssetAsRuntimeStage(name.data());
28  auto runtime_stage = runtime_stages[PlaygroundBackendToRuntimeStageBackend(
29  test->GetBackend())];
30  FML_CHECK(runtime_stage);
31  FML_CHECK(runtime_stage->IsDirty());
32 
33  auto dl_runtime_effect = DlRuntimeEffect::MakeImpeller(runtime_stage);
34 
35  return std::make_shared<DlRuntimeEffectColorSource>(dl_runtime_effect,
36  samplers, uniform_data);
37 }
38 } // namespace
39 
40 // Regression test for https://github.com/flutter/flutter/issues/126701 .
41 TEST_P(AiksTest, CanRenderClippedRuntimeEffects) {
42  struct FragUniforms {
43  Vector2 iResolution;
44  Scalar iTime;
45  } frag_uniforms = {.iResolution = Vector2(400, 400), .iTime = 100.0};
46  auto uniform_data = std::make_shared<std::vector<uint8_t>>();
47  uniform_data->resize(sizeof(FragUniforms));
48  memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
49 
50  DlPaint paint;
51  paint.setColorSource(
52  MakeRuntimeEffect(this, "runtime_stage_example.frag.iplr", uniform_data));
53 
54  DisplayListBuilder builder;
55  builder.Save();
56  builder.ClipRRect(
57  SkRRect::MakeRectXY(SkRect::MakeXYWH(0, 0, 400, 400), 10.0, 10.0),
58  DlCanvas::ClipOp::kIntersect);
59  builder.DrawRect(SkRect::MakeXYWH(0, 0, 400, 400), paint);
60  builder.Restore();
61 
62  ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
63 }
64 
65 TEST_P(AiksTest, DrawPaintTransformsBounds) {
66  struct FragUniforms {
67  Size size;
68  } frag_uniforms = {.size = Size::MakeWH(400, 400)};
69  auto uniform_data = std::make_shared<std::vector<uint8_t>>();
70  uniform_data->resize(sizeof(FragUniforms));
71  memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
72 
73  DlPaint paint;
74  paint.setColorSource(
75  MakeRuntimeEffect(this, "gradient.frag.iplr", uniform_data));
76 
77  DisplayListBuilder builder;
78  builder.Save();
79  builder.Scale(GetContentScale().x, GetContentScale().y);
80  builder.DrawPaint(paint);
81  builder.Restore();
82 
83  ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
84 }
85 
86 } // namespace testing
87 } // namespace impeller
impeller::AiksPlayground
Definition: aiks_playground.h:16
impeller::Scalar
float Scalar
Definition: scalar.h:18
aiks_unittests.h
impeller::testing::AiksTest
AiksPlayground AiksTest
Definition: aiks_unittests.h:17
impeller::Vector2
Point Vector2
Definition: point.h:331
impeller::PlaygroundBackendToRuntimeStageBackend
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
Definition: playground.h:32
impeller::TSize< Scalar >
flutter
Definition: dl_golden_blur_unittests.cc:15
impeller::testing::TEST_P
TEST_P(AiksTest, DrawAtlasNoColor)
Definition: aiks_dl_atlas_unittests.cc:78
impeller::TPoint< Scalar >
impeller::TSize< Scalar >::MakeWH
static constexpr TSize MakeWH(Type width, Type height)
Definition: size.h:34
impeller
Definition: allocation.cc:12