5 #include "display_list/dl_sampling_options.h"
6 #include "display_list/dl_types.h"
7 #include "display_list/effects/dl_color_filter.h"
8 #include "display_list/effects/image_filters/dl_matrix_image_filter.h"
9 #include "display_list/geometry/dl_geometry_types.h"
12 #include "flutter/display_list/dl_blend_mode.h"
13 #include "flutter/display_list/dl_builder.h"
14 #include "flutter/display_list/dl_color.h"
15 #include "flutter/display_list/dl_paint.h"
16 #include "flutter/testing/testing.h"
34 std::tuple<std::vector<DlRect>,
35 std::vector<RSTransform>,
36 sk_sp<DlImageImpeller>>
37 CreateTestData(
const AiksTest* test) {
41 auto size = atlas->impeller_texture()->GetSize();
43 Scalar half_width = size.width / 2;
44 Scalar half_height = size.height / 2;
45 std::vector<DlRect> texture_coordinates = {
46 DlRect::MakeLTRB(0, 0, half_width, half_height),
47 DlRect::MakeLTRB(half_width, 0, size.width, half_height),
48 DlRect::MakeLTRB(0, half_height, half_width, size.height),
49 DlRect::MakeLTRB(half_width, half_height, size.width, size.height)};
51 std::vector<RSTransform> transforms = {
52 MakeTranslation(0, 0), MakeTranslation(half_width, 0),
53 MakeTranslation(0, half_height),
54 MakeTranslation(half_width, half_height)};
55 return std::make_tuple(texture_coordinates, transforms, atlas);
61 DisplayListBuilder builder;
62 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
64 builder.Scale(GetContentScale().
x, GetContentScale().y);
65 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
66 nullptr, 4, DlBlendMode::kSrcOver,
67 DlImageSampling::kNearestNeighbor,
nullptr);
69 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
73 DisplayListBuilder builder;
74 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
76 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
77 DlColor::kBlue(), DlColor::kYellow()};
79 builder.Scale(GetContentScale().
x, GetContentScale().y);
80 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
81 colors.data(), 4, DlBlendMode::kModulate,
82 DlImageSampling::kNearestNeighbor,
nullptr);
84 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
88 DisplayListBuilder builder;
90 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
92 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
93 DlColor::kBlue(), DlColor::kYellow()};
95 builder.Scale(GetContentScale().
x, GetContentScale().y);
96 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
97 colors.data(), 4, DlBlendMode::kSrcATop,
98 DlImageSampling::kNearestNeighbor,
nullptr);
100 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
104 DisplayListBuilder builder;
107 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
111 builder.Scale(GetContentScale().
x, GetContentScale().y);
112 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
113 nullptr, 4, DlBlendMode::kSrcOver,
114 DlImageSampling::kNearestNeighbor,
nullptr,
117 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
122 auto size = atlas->impeller_texture()->GetSize();
123 std::vector<DlRect> texture_coordinates = {
124 DlRect::MakeLTRB(0, 0, size.width, size.height)};
125 std::vector<RSTransform> transforms = {MakeTranslation(0, 0)};
127 DisplayListBuilder builder;
128 builder.Scale(GetContentScale().
x, GetContentScale().y);
129 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
130 nullptr, 1, DlBlendMode::kSrcOver,
131 DlImageSampling::kNearestNeighbor,
nullptr);
133 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
138 DisplayListBuilder builder;
140 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
142 builder.Scale(0.25, 0.25);
143 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
144 nullptr, 4, DlBlendMode::kModulate,
145 DlImageSampling::kNearestNeighbor,
nullptr);
147 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
152 DisplayListBuilder builder;
154 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
155 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
156 DlColor::kBlue(), DlColor::kYellow()};
158 builder.Scale(0.25, 0.25);
159 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
160 colors.data(), 4, DlBlendMode::kModulate,
161 DlImageSampling::kNearestNeighbor,
nullptr);
163 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
167 DisplayListBuilder builder;
168 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
172 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
173 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
174 DlColor::kBlue(), DlColor::kYellow()};
176 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
177 colors.data(), 4, DlBlendMode::kPlus,
178 DlImageSampling::kNearestNeighbor,
nullptr);
180 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
184 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
187 texture_coordinates.data(),
nullptr, transforms.size(),
198 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
202 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
204 std::vector<DlColor> colors;
205 colors.reserve(texture_coordinates.size());
206 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
207 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
210 atlas->impeller_texture(), transforms.data(), texture_coordinates.data(),
221 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
225 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
227 std::vector<DlColor> colors;
228 colors.reserve(texture_coordinates.size());
229 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
230 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
233 texture_coordinates.data(), colors.data(),
242 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
244 std::vector<DlColor> colors;
245 colors.reserve(texture_coordinates.size());
246 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
247 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
250 texture_coordinates.data(), colors.data(),
256 sk_sp<DlImageImpeller> texture =
259 DisplayListBuilder builder;
260 DlPaint paint = DlPaint().setColorFilter(DlColorFilter::MakeBlend(
261 DlColor::kRed().withAlphaF(0.4), DlBlendMode::kSrcOver));
263 DlMatrix filter_matrix = DlMatrix();
264 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
265 flutter::DlImageSampling::kLinear);
266 DlPaint paint_with_filter = paint;
267 paint_with_filter.setImageFilter(&filter);
270 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
272 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
273 DlRect::MakeLTRB(0, 0, 500, 500), {},
277 builder.Translate(600, 0);
278 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
279 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
281 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
285 sk_sp<DlImageImpeller> texture =
288 DisplayListBuilder builder;
294 1.0, 1.0, 1.0, 1.0, 0
296 DlPaint paint = DlPaint().setColorFilter(
299 DlMatrix filter_matrix = DlMatrix();
300 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
301 flutter::DlImageSampling::kLinear);
302 DlPaint paint_with_filter = paint;
303 paint_with_filter.setImageFilter(&filter);
306 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
308 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
309 DlRect::MakeLTRB(0, 0, 500, 500), {},
313 builder.Translate(600, 0);
314 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
315 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
317 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
A wrapper around data provided by a drawAtlas call.
VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const override
bool ShouldUseBlend() const override
Whether the blend shader should be used.
bool ShouldSkip() const override
VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const override
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
TEST_P(AiksTest, DrawAtlasNoColor)
@ kNone
Does not use the index buffer.
static constexpr const ColorMatrix kColorInversion
A color matrix which inverts colors.