7 #include "flutter/fml/make_copyable.h"
8 #include "flutter/testing/testing.h"
9 #include "gmock/gmock.h"
14 #include "impeller/entity/runtime_effect.vert.h"
29 const std::shared_ptr<fml::Mapping> fixture =
30 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
32 ASSERT_GT(fixture->GetSize(), 0u);
35 ASSERT_TRUE(stage->IsValid());
41 const std::shared_ptr<fml::Mapping> fixture =
42 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
44 auto junk_allocation = std::make_shared<Allocation>();
45 ASSERT_TRUE(junk_allocation->Truncate(fixture->GetSize(),
false));
48 ::memset(junk_allocation->GetBuffer(), 127, junk_allocation->GetLength());
55 const std::shared_ptr<fml::Mapping> fixture =
56 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
58 ASSERT_GT(fixture->GetSize(), 0u);
62 ASSERT_TRUE(stage->IsValid());
63 switch (GetBackend()) {
66 ASSERT_EQ(stage->GetUniforms().size(), 17u);
68 auto uni = stage->GetUniform(
"u_color");
69 ASSERT_NE(uni,
nullptr);
70 EXPECT_EQ(uni->dimensions.rows, 4u);
71 EXPECT_EQ(uni->dimensions.cols, 1u);
72 EXPECT_EQ(uni->location, 0u);
76 auto uni = stage->GetUniform(
"u_alpha");
77 ASSERT_NE(uni,
nullptr);
78 EXPECT_EQ(uni->dimensions.rows, 1u);
79 EXPECT_EQ(uni->dimensions.cols, 1u);
80 EXPECT_EQ(uni->location, 1u);
84 auto uni = stage->GetUniform(
"u_sparkle_color");
85 ASSERT_NE(uni,
nullptr);
86 EXPECT_EQ(uni->dimensions.rows, 4u);
87 EXPECT_EQ(uni->dimensions.cols, 1u);
88 EXPECT_EQ(uni->location, 2u);
92 auto uni = stage->GetUniform(
"u_sparkle_alpha");
93 ASSERT_NE(uni,
nullptr);
94 EXPECT_EQ(uni->dimensions.rows, 1u);
95 EXPECT_EQ(uni->dimensions.cols, 1u);
96 EXPECT_EQ(uni->location, 3u);
100 auto uni = stage->GetUniform(
"u_blur");
101 ASSERT_NE(uni,
nullptr);
102 EXPECT_EQ(uni->dimensions.rows, 1u);
103 EXPECT_EQ(uni->dimensions.cols, 1u);
104 EXPECT_EQ(uni->location, 4u);
108 auto uni = stage->GetUniform(
"u_radius_scale");
109 ASSERT_NE(uni,
nullptr);
110 EXPECT_EQ(uni->dimensions.rows, 1u);
111 EXPECT_EQ(uni->dimensions.cols, 1u);
112 EXPECT_EQ(uni->location, 6u);
116 auto uni = stage->GetUniform(
"u_max_radius");
117 ASSERT_NE(uni,
nullptr);
118 EXPECT_EQ(uni->dimensions.rows, 1u);
119 EXPECT_EQ(uni->dimensions.cols, 1u);
120 EXPECT_EQ(uni->location, 7u);
124 auto uni = stage->GetUniform(
"u_resolution_scale");
125 ASSERT_NE(uni,
nullptr);
126 EXPECT_EQ(uni->dimensions.rows, 2u);
127 EXPECT_EQ(uni->dimensions.cols, 1u);
128 EXPECT_EQ(uni->location, 8u);
132 auto uni = stage->GetUniform(
"u_noise_scale");
133 ASSERT_NE(uni,
nullptr);
134 EXPECT_EQ(uni->dimensions.rows, 2u);
135 EXPECT_EQ(uni->dimensions.cols, 1u);
136 EXPECT_EQ(uni->location, 9u);
140 auto uni = stage->GetUniform(
"u_noise_phase");
141 ASSERT_NE(uni,
nullptr);
142 EXPECT_EQ(uni->dimensions.rows, 1u);
143 EXPECT_EQ(uni->dimensions.cols, 1u);
144 EXPECT_EQ(uni->location, 10u);
149 auto uni = stage->GetUniform(
"u_circle1");
150 ASSERT_NE(uni,
nullptr);
151 EXPECT_EQ(uni->dimensions.rows, 2u);
152 EXPECT_EQ(uni->dimensions.cols, 1u);
153 EXPECT_EQ(uni->location, 11u);
157 auto uni = stage->GetUniform(
"u_circle2");
158 ASSERT_NE(uni,
nullptr);
159 EXPECT_EQ(uni->dimensions.rows, 2u);
160 EXPECT_EQ(uni->dimensions.cols, 1u);
161 EXPECT_EQ(uni->location, 12u);
165 auto uni = stage->GetUniform(
"u_circle3");
166 ASSERT_NE(uni,
nullptr);
167 EXPECT_EQ(uni->dimensions.rows, 2u);
168 EXPECT_EQ(uni->dimensions.cols, 1u);
169 EXPECT_EQ(uni->location, 13u);
173 auto uni = stage->GetUniform(
"u_rotation1");
174 ASSERT_NE(uni,
nullptr);
175 EXPECT_EQ(uni->dimensions.rows, 2u);
176 EXPECT_EQ(uni->dimensions.cols, 1u);
177 EXPECT_EQ(uni->location, 14u);
181 auto uni = stage->GetUniform(
"u_rotation2");
182 ASSERT_NE(uni,
nullptr);
183 EXPECT_EQ(uni->dimensions.rows, 2u);
184 EXPECT_EQ(uni->dimensions.cols, 1u);
185 EXPECT_EQ(uni->location, 15u);
189 auto uni = stage->GetUniform(
"u_rotation3");
190 ASSERT_NE(uni,
nullptr);
191 EXPECT_EQ(uni->dimensions.rows, 2u);
192 EXPECT_EQ(uni->dimensions.cols, 1u);
193 EXPECT_EQ(uni->location, 16u);
199 EXPECT_EQ(stage->GetUniforms().size(), 1u);
203 EXPECT_EQ(uni->struct_float_count, 32u);
214 EXPECT_EQ(uni->GetSize(), 144u);
215 std::vector<uint8_t> layout(uni->GetSize() /
sizeof(
float), 1);
221 EXPECT_THAT(uni->struct_layout, ::testing::ElementsAreArray(layout));
228 const std::shared_ptr<fml::Mapping> fixture =
229 flutter::testing::OpenFixtureAsMapping(
"ink_sparkle.frag.iplr");
230 ASSERT_TRUE(fixture);
231 ASSERT_GT(fixture->GetSize(), 0u);
234 ASSERT_TRUE(stage->IsValid());
235 std::promise<bool> registration;
236 auto future = registration.get_future();
237 auto library = GetContext()->GetShaderLibrary();
238 library->RegisterFunction(
239 stage->GetEntrypoint(),
241 stage->GetCodeMapping(),
242 fml::MakeCopyable([reg = std::move(registration)](
bool result)
mutable {
243 reg.set_value(result);
245 ASSERT_TRUE(future.get());
249 ASSERT_NE(
function,
nullptr);
258 ASSERT_EQ(
function,
nullptr);
263 auto stages = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
267 ASSERT_NE(stage,
nullptr);
268 ASSERT_TRUE(RegisterStage(*stage));
269 auto library = GetContext()->GetShaderLibrary();
270 using VS = RuntimeEffectVertexShader;
272 desc.
SetLabel(
"Runtime Stage InkSparkle");
277 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
278 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
279 VS::kInterleavedBufferLayout);
281 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
282 VS::kDescriptorSetLayouts[0],
289 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
293 color0.
format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
298 const auto stencil_fmt =
299 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
301 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
302 ASSERT_NE(pipeline,
nullptr);
306 auto stages = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");