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->GetImpellerTexture(test->GetContext())->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->GetImpellerTexture(GetContext())->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()));
169 if (!EnsureContextSupportsWideGamut()) {
170 GTEST_SKIP() <<
"This backend doesn't yet support wide gamut.";
173 DisplayListBuilder builder;
174 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
178 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
179 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
180 DlColor::kBlue(), DlColor::kYellow()};
182 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
183 colors.data(), 4, DlBlendMode::kPlus,
184 DlImageSampling::kNearestNeighbor,
nullptr);
186 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
190 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
193 transforms.data(), texture_coordinates.data(),
nullptr,
205 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
209 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
211 std::vector<DlColor> colors;
212 colors.reserve(texture_coordinates.size());
213 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
214 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
217 transforms.data(), texture_coordinates.data(),
229 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
233 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
235 std::vector<DlColor> colors;
236 colors.reserve(texture_coordinates.size());
237 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
238 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
241 transforms.data(), texture_coordinates.data(),
251 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
253 std::vector<DlColor> colors;
254 colors.reserve(texture_coordinates.size());
255 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
256 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
259 transforms.data(), texture_coordinates.data(),
266 sk_sp<DlImageImpeller> texture =
269 DisplayListBuilder builder;
270 DlPaint paint = DlPaint().setColorFilter(DlColorFilter::MakeBlend(
271 DlColor::kRed().withAlphaF(0.4), DlBlendMode::kSrcOver));
273 DlMatrix filter_matrix = DlMatrix();
274 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
275 flutter::DlImageSampling::kLinear);
276 DlPaint paint_with_filter = paint;
277 paint_with_filter.setImageFilter(&filter);
280 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
282 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
283 DlRect::MakeLTRB(0, 0, 500, 500), {},
287 builder.Translate(600, 0);
288 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
289 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
291 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
295 sk_sp<DlImageImpeller> texture =
298 DisplayListBuilder builder;
304 1.0, 1.0, 1.0, 1.0, 0
306 DlPaint paint = DlPaint().setColorFilter(
309 DlMatrix filter_matrix = DlMatrix();
310 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
311 flutter::DlImageSampling::kLinear);
312 DlPaint paint_with_filter = paint;
313 paint_with_filter.setImageFilter(&filter);
316 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
318 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
319 DlRect::MakeLTRB(0, 0, 500, 500), {},
323 builder.Translate(600, 0);
324 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
325 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
327 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
331 DisplayListBuilder builder;
332 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
334 std::vector<DlColor> colors = {DlColor::kDarkGrey(), DlColor::kBlack(),
335 DlColor::kLightGrey(), DlColor::kWhite()};
337 builder.Scale(GetContentScale().
x, GetContentScale().y);
338 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
339 colors.data(), 4, DlBlendMode::kColorBurn,
340 DlImageSampling::kNearestNeighbor,
nullptr);
342 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
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.
std::shared_ptr< ContextGLES > context