5 #include "display_list/dl_sampling_options.h"
6 #include "display_list/dl_tile_mode.h"
7 #include "display_list/dl_vertices.h"
8 #include "display_list/effects/dl_mask_filter.h"
11 #include "flutter/display_list/dl_blend_mode.h"
12 #include "flutter/display_list/dl_builder.h"
13 #include "flutter/display_list/dl_color.h"
14 #include "flutter/display_list/dl_paint.h"
15 #include "flutter/testing/testing.h"
19 #include "third_party/abseil-cpp/absl/status/status_matchers.h"
27 std::shared_ptr<DlVertices> MakeVertices(
29 std::vector<DlPoint> vertices,
30 std::vector<uint16_t> indices,
31 std::vector<DlPoint> texture_coordinates,
32 std::vector<DlColor> colors) {
33 DlVertices::Builder::Flags flags(
34 {{texture_coordinates.size() > 0, colors.size() > 0}});
35 DlVertices::Builder builder(mode, vertices.size(), flags, indices.size());
36 if (colors.size() > 0) {
37 builder.store_colors(colors.data());
39 if (texture_coordinates.size() > 0) {
40 builder.store_texture_coordinates(texture_coordinates.data());
42 if (indices.size() > 0) {
43 builder.store_indices(indices.data());
45 builder.store_vertices(vertices.data());
46 return builder.build();
52 DisplayListBuilder builder;
56 auto size = image->impeller_texture()->GetSize();
59 DlColorSource::MakeImage(image, DlTileMode::kClamp, DlTileMode::kClamp));
61 std::vector<DlPoint> vertex_coordinates = {
66 auto vertices = MakeVertices(DlVertexMode::kTriangleStrip, vertex_coordinates,
69 builder.DrawVertices(vertices, DlBlendMode::kSrcOver, paint);
70 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
75 DisplayListBuilder builder;
79 auto size = image->impeller_texture()->GetSize();
81 DlMatrix matrix = DlMatrix::MakeTranslation({100, 100});
83 DlColorSource::MakeImage(image, DlTileMode::kClamp, DlTileMode::kClamp,
84 DlImageSampling::kLinear, &matrix));
86 std::vector<DlPoint> positions = {
92 MakeVertices(DlVertexMode::kTriangleStrip, positions, {0, 1, 2}, {}, {});
94 builder.DrawVertices(vertices, DlBlendMode::kSrcOver, paint);
95 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
100 DisplayListBuilder builder;
104 auto size = image->impeller_texture()->GetSize();
106 paint.setColorSource(
107 DlColorSource::MakeImage(image, DlTileMode::kClamp, DlTileMode::kClamp));
109 std::vector<DlPoint> positions = {
114 std::vector<DlColor> colors = {
115 DlColor::kRed().withAlpha(128), DlColor::kBlue().withAlpha(128),
116 DlColor::kGreen().withAlpha(128), DlColor::kRed().withAlpha(128),
117 DlColor::kBlue().withAlpha(128), DlColor::kGreen().withAlpha(128),
121 MakeVertices(DlVertexMode::kTriangles, positions, {}, {}, colors);
123 builder.DrawVertices(vertices, DlBlendMode::kDstOver, paint);
124 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
128 DisplayListBuilder builder;
132 auto size = image->impeller_texture()->GetSize();
134 paint.setColorSource(
135 DlColorSource::MakeImage(image, DlTileMode::kClamp, DlTileMode::kClamp));
137 std::vector<DlPoint> positions = {
142 std::vector<DlColor> colors = {
143 DlColor::kRed().modulateOpacity(0.5),
144 DlColor::kBlue().modulateOpacity(0.5),
145 DlColor::kGreen().modulateOpacity(0.5),
146 DlColor::kRed().modulateOpacity(0.5),
147 DlColor::kBlue().modulateOpacity(0.5),
148 DlColor::kGreen().modulateOpacity(0.5),
152 MakeVertices(DlVertexMode::kTriangles, positions, {}, {}, colors);
154 builder.DrawVertices(vertices, DlBlendMode::kColorBurn, paint);
155 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
160 constexpr
Scalar hexagon_radius = 125;
161 auto hex_start =
Point(200.0, -hexagon_radius + 200.0);
162 auto center_to_flat = 1.73 / 2 * hexagon_radius;
165 std::vector<DlPoint> vertices = {
166 DlPoint(hex_start.x, hex_start.y),
167 DlPoint(hex_start.x + center_to_flat, hex_start.y + 0.5 * hexagon_radius),
168 DlPoint(hex_start.x + center_to_flat, hex_start.y + 1.5 * hexagon_radius),
169 DlPoint(hex_start.x + center_to_flat, hex_start.y + 1.5 * hexagon_radius),
170 DlPoint(hex_start.x, hex_start.y + 2 * hexagon_radius),
171 DlPoint(hex_start.x, hex_start.y + 2 * hexagon_radius),
172 DlPoint(hex_start.x - center_to_flat, hex_start.y + 1.5 * hexagon_radius),
173 DlPoint(hex_start.x - center_to_flat, hex_start.y + 1.5 * hexagon_radius),
174 DlPoint(hex_start.x - center_to_flat, hex_start.y + 0.5 * hexagon_radius)
177 auto paint = flutter::DlPaint(flutter::DlColor::kDarkGrey());
178 auto dl_vertices = flutter::DlVertices::Make(
179 flutter::DlVertexMode::kTriangleFan, vertices.size(), vertices.data(),
181 flutter::DisplayListBuilder builder;
182 builder.DrawVertices(dl_vertices, flutter::DlBlendMode::kSrcOver, paint);
183 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
189 std::vector<DlPoint> positions = {
194 std::vector<flutter::DlColor> colors = {flutter::DlColor::kWhite(),
195 flutter::DlColor::kGreen(),
196 flutter::DlColor::kWhite()};
198 auto vertices = flutter::DlVertices::Make(
199 flutter::DlVertexMode::kTriangles, 3, positions.data(),
200 nullptr, colors.data());
202 flutter::DisplayListBuilder builder;
203 flutter::DlPaint paint;
205 paint.setColor(flutter::DlColor::kRed().modulateOpacity(0.5));
206 builder.Scale(-1, -1);
207 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
209 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
213 std::vector<DlPoint> positions = {
219 auto vertices = flutter::DlVertices::Make(
220 flutter::DlVertexMode::kTriangles, 3, positions.data(),
223 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
224 flutter::DlColor::kRed()};
225 const float stops[2] = {0.0, 1.0};
227 auto linear = flutter::DlColorSource::MakeLinear(
228 {100.0, 100.0}, {300.0, 300.0}, 2, colors.data(), stops,
229 flutter::DlTileMode::kRepeat);
231 flutter::DisplayListBuilder builder;
232 flutter::DlPaint paint;
234 paint.setColorSource(linear);
235 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
237 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
241 std::vector<DlPoint> positions = {
246 std::vector<DlPoint> texture_coordinates = {
252 auto vertices = flutter::DlVertices::Make(
253 flutter::DlVertexMode::kTriangles, 3, positions.data(),
254 texture_coordinates.data(),
nullptr);
256 std::vector<flutter::DlColor> colors = {flutter::DlColor::kBlue(),
257 flutter::DlColor::kRed()};
258 const float stops[2] = {0.0, 1.0};
260 auto linear = flutter::DlColorSource::MakeLinear(
261 {100.0, 100.0}, {300.0, 300.0}, 2, colors.data(), stops,
262 flutter::DlTileMode::kRepeat);
264 flutter::DisplayListBuilder builder;
265 flutter::DlPaint paint;
267 paint.setColorSource(linear);
268 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
270 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
274 auto texture = CreateTextureForFixture(
"embarcadero.jpg");
276 std::vector<DlPoint> positions = {
281 std::vector<DlPoint> texture_coordinates = {
287 auto vertices = flutter::DlVertices::Make(
288 flutter::DlVertexMode::kTriangles, 3, positions.data(),
289 texture_coordinates.data(),
nullptr);
291 flutter::DisplayListBuilder builder;
292 flutter::DlPaint paint;
294 auto image_source = flutter::DlColorSource::MakeImage(
295 dl_image, flutter::DlTileMode::kRepeat, flutter::DlTileMode::kRepeat);
297 paint.setColorSource(image_source);
298 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
300 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
304 DrawVerticesImageSourceWithTextureCoordinatesAndColorBlending) {
305 auto texture = CreateTextureForFixture(
"embarcadero.jpg");
307 std::vector<DlPoint> positions = {
312 std::vector<flutter::DlColor> colors = {flutter::DlColor::kWhite(),
313 flutter::DlColor::kGreen(),
314 flutter::DlColor::kWhite()};
315 std::vector<DlPoint> texture_coordinates = {
321 auto vertices = flutter::DlVertices::Make(
322 flutter::DlVertexMode::kTriangles, 3, positions.data(),
323 texture_coordinates.data(), colors.data());
325 flutter::DisplayListBuilder builder;
326 flutter::DlPaint paint;
328 auto image_source = flutter::DlColorSource::MakeImage(
329 dl_image, flutter::DlTileMode::kRepeat, flutter::DlTileMode::kRepeat);
331 paint.setColorSource(image_source);
332 builder.DrawVertices(vertices, flutter::DlBlendMode::kModulate, paint);
334 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
338 std::vector<DlPoint> positions = {
344 std::vector<uint16_t> indices = {0, 1, 2, 0, 2, 3};
346 auto vertices = flutter::DlVertices::Make(
347 flutter::DlVertexMode::kTriangles, positions.size(), positions.data(),
348 nullptr,
nullptr, indices.size(),
351 flutter::DisplayListBuilder builder;
352 flutter::DlPaint paint;
354 paint.setColor(flutter::DlColor::kRed());
355 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
357 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
361 std::vector<DlPoint> positions = {
367 auto color = flutter::DlColor::kBlue().withAlpha(0x99);
368 std::vector<uint16_t> indices = {0, 1, 2, 0, 2, 3};
369 std::vector<flutter::DlColor> colors = {color, color, color, color};
371 auto vertices = flutter::DlVertices::Make(
372 flutter::DlVertexMode::kTriangles, positions.size(), positions.data(),
373 nullptr, colors.data(), indices.size(),
376 flutter::DisplayListBuilder builder;
377 flutter::DlPaint paint;
378 paint.setBlendMode(flutter::DlBlendMode::kSrcOver);
379 paint.setColor(flutter::DlColor::kRed());
381 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
382 builder.DrawVertices(vertices, flutter::DlBlendMode::kDst, paint);
384 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
388 std::vector<DlPoint> positions = {
394 std::vector<uint16_t> indices = {0, 1, 2, 0, 2, 3, 99, 100, 101};
396 auto vertices = flutter::DlVertices::Make(
397 flutter::DlVertexMode::kTriangles, positions.size(), positions.data(),
398 nullptr,
nullptr, indices.size(),
401 EXPECT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(100, 100, 300, 500));
403 flutter::DisplayListBuilder builder;
404 flutter::DlPaint paint;
405 paint.setBlendMode(flutter::DlBlendMode::kSrcOver);
406 paint.setColor(flutter::DlColor::kRed());
408 builder.DrawRect(DlRect::MakeLTRB(0, 0, 400, 400), paint);
409 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrc, paint);
412 std::shared_ptr<Texture> image =
420 std::vector<DlPoint> positions_lt = {
427 auto vertices_lt = flutter::DlVertices::Make(
428 flutter::DlVertexMode::kTriangleStrip, positions_lt.size(),
430 positions_lt.data(),
nullptr,
434 std::vector<DlPoint> positions_rt = {
441 auto vertices_rt = flutter::DlVertices::Make(
442 flutter::DlVertexMode::kTriangleStrip, positions_rt.size(),
444 positions_rt.data(),
nullptr,
448 std::vector<DlPoint> positions_lb = {
455 auto vertices_lb = flutter::DlVertices::Make(
456 flutter::DlVertexMode::kTriangleStrip, positions_lb.size(),
458 positions_lb.data(),
nullptr,
462 std::vector<DlPoint> positions_rb = {
469 auto vertices_rb = flutter::DlVertices::Make(
470 flutter::DlVertexMode::kTriangleStrip, positions_rb.size(),
472 positions_rb.data(),
nullptr,
476 flutter::DisplayListBuilder builder;
477 flutter::DlPaint paint;
478 flutter::DlPaint rect_paint;
479 rect_paint.setColor(DlColor::kBlue());
481 auto runtime_stages_result =
482 OpenAssetAsRuntimeStage(
"runtime_stage_simple.frag.iplr");
483 ABSL_ASSERT_OK(runtime_stages_result);
484 std::shared_ptr<RuntimeStage> runtime_stage =
485 runtime_stages_result
487 ASSERT_TRUE(runtime_stage);
490 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
491 auto color_source = flutter::DlColorSource::MakeRuntimeEffect(
492 runtime_effect, {}, uniform_data);
494 paint.setColorSource(color_source);
496 builder.Scale(GetContentScale().
x, GetContentScale().y);
498 builder.DrawRect(DlRect::MakeLTRB(0, 0, 100, 100), rect_paint);
499 builder.DrawVertices(vertices_lt, flutter::DlBlendMode::kSrcOver, paint);
500 builder.DrawVertices(vertices_rt, flutter::DlBlendMode::kSrcOver, paint);
501 builder.DrawVertices(vertices_lb, flutter::DlBlendMode::kSrcOver, paint);
502 builder.DrawVertices(vertices_rb, flutter::DlBlendMode::kSrcOver, paint);
505 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
511 DrawVerticesTextureCoordinatesWithFragmentShaderNonZeroOrigin) {
512 std::vector<DlPoint> positions_lt = {
519 auto vertices = flutter::DlVertices::Make(
520 flutter::DlVertexMode::kTriangleStrip, positions_lt.size(),
522 positions_lt.data(),
nullptr,
526 flutter::DisplayListBuilder builder;
527 flutter::DlPaint paint;
528 flutter::DlPaint rect_paint;
529 rect_paint.setColor(DlColor::kBlue());
531 auto runtime_stages_result =
532 OpenAssetAsRuntimeStage(
"runtime_stage_position.frag.iplr");
533 ABSL_ASSERT_OK(runtime_stages_result);
534 std::shared_ptr<RuntimeStage> runtime_stage =
535 runtime_stages_result
537 ASSERT_TRUE(runtime_stage);
540 auto rect_data = std::vector<Rect>{
Rect::MakeLTRB(200, 200, 250, 250)};
542 auto uniform_data = std::make_shared<std::vector<uint8_t>>();
543 uniform_data->resize(rect_data.size() *
sizeof(
Rect));
544 memcpy(uniform_data->data(), rect_data.data(), uniform_data->size());
546 auto color_source = flutter::DlColorSource::MakeRuntimeEffect(
547 runtime_effect, {}, uniform_data);
549 paint.setColorSource(color_source);
551 builder.Scale(GetContentScale().
x, GetContentScale().y);
552 builder.DrawRect(DlRect::MakeLTRB(200, 200, 250, 250), rect_paint);
553 builder.DrawVertices(vertices, flutter::DlBlendMode::kSrcOver, paint);
555 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
560 DisplayListBuilder builder;
562 paint.setMaskFilter(DlBlurMaskFilter::Make(DlBlurStyle::kNormal, 10));
564 std::vector<DlPoint> vertex_coordinates = {
569 auto vertices = MakeVertices(DlVertexMode::kTriangleStrip, vertex_coordinates,
572 builder.DrawVertices(vertices, DlBlendMode::kSrcOver, paint);
573 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
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)
TEST_P(AiksTest, DrawAtlasNoColor)
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips, std::optional< PixelFormat > target_pixel_format)
Render the provided display list to a texture with the given size.
constexpr RuntimeStageBackend PlaygroundBackendToRuntimeStageBackend(PlaygroundBackend backend)
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)