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>> CreateTestData(
const AiksTest* test) {
40 auto size = atlas->impeller_texture()->GetSize();
42 Scalar half_width = size.width / 2;
43 Scalar half_height = size.height / 2;
44 std::vector<DlRect> texture_coordinates = {
45 DlRect::MakeLTRB(0, 0, half_width, half_height),
46 DlRect::MakeLTRB(half_width, 0, size.width, half_height),
47 DlRect::MakeLTRB(0, half_height, half_width, size.height),
48 DlRect::MakeLTRB(half_width, half_height, size.width, size.height)};
50 std::vector<RSTransform> transforms = {
51 MakeTranslation(0, 0), MakeTranslation(half_width, 0),
52 MakeTranslation(0, half_height),
53 MakeTranslation(half_width, half_height)};
54 return std::make_tuple(texture_coordinates, transforms, atlas);
60 DisplayListBuilder builder;
61 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
63 builder.Scale(GetContentScale().
x, GetContentScale().y);
64 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
65 nullptr, 4, DlBlendMode::kSrcOver,
66 DlImageSampling::kNearestNeighbor,
nullptr);
68 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
72 DisplayListBuilder builder;
73 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
75 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
76 DlColor::kBlue(), DlColor::kYellow()};
78 builder.Scale(GetContentScale().
x, GetContentScale().y);
79 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
80 colors.data(), 4, DlBlendMode::kModulate,
81 DlImageSampling::kNearestNeighbor,
nullptr);
83 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
87 DisplayListBuilder builder;
89 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
91 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
92 DlColor::kBlue(), DlColor::kYellow()};
94 builder.Scale(GetContentScale().
x, GetContentScale().y);
95 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
96 colors.data(), 4, DlBlendMode::kSrcATop,
97 DlImageSampling::kNearestNeighbor,
nullptr);
99 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
103 DisplayListBuilder builder;
106 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
110 builder.Scale(GetContentScale().
x, GetContentScale().y);
111 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
112 nullptr, 4, DlBlendMode::kSrcOver,
113 DlImageSampling::kNearestNeighbor,
nullptr,
116 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
121 auto size = atlas->impeller_texture()->GetSize();
122 std::vector<DlRect> texture_coordinates = {
123 DlRect::MakeLTRB(0, 0, size.width, size.height)};
124 std::vector<RSTransform> transforms = {MakeTranslation(0, 0)};
126 DisplayListBuilder builder;
127 builder.Scale(GetContentScale().
x, GetContentScale().y);
128 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
129 nullptr, 1, DlBlendMode::kSrcOver,
130 DlImageSampling::kNearestNeighbor,
nullptr);
132 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
137 DisplayListBuilder builder;
139 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
141 builder.Scale(0.25, 0.25);
142 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
143 nullptr, 4, DlBlendMode::kModulate,
144 DlImageSampling::kNearestNeighbor,
nullptr);
146 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
151 DisplayListBuilder builder;
153 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
154 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
155 DlColor::kBlue(), DlColor::kYellow()};
157 builder.Scale(0.25, 0.25);
158 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
159 colors.data(), 4, DlBlendMode::kModulate,
160 DlImageSampling::kNearestNeighbor,
nullptr);
162 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
166 DisplayListBuilder builder;
167 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
171 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
172 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
173 DlColor::kBlue(), DlColor::kYellow()};
175 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
176 colors.data(), 4, DlBlendMode::kPlus,
177 DlImageSampling::kNearestNeighbor,
nullptr);
179 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
183 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
186 texture_coordinates.data(),
nullptr, transforms.size(),
197 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
201 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
203 std::vector<DlColor> colors;
204 colors.reserve(texture_coordinates.size());
205 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
206 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
209 atlas->impeller_texture(), transforms.data(), texture_coordinates.data(),
220 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
224 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
226 std::vector<DlColor> colors;
227 colors.reserve(texture_coordinates.size());
228 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
229 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
232 texture_coordinates.data(), colors.data(),
241 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
243 std::vector<DlColor> colors;
244 colors.reserve(texture_coordinates.size());
245 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
246 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
249 texture_coordinates.data(), colors.data(),
255 sk_sp<DlImageImpeller> texture =
258 DisplayListBuilder builder;
259 DlPaint paint = DlPaint().setColorFilter(DlColorFilter::MakeBlend(
260 DlColor::kRed().withAlphaF(0.4), DlBlendMode::kSrcOver));
262 DlMatrix filter_matrix = DlMatrix();
263 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
264 flutter::DlImageSampling::kLinear);
265 DlPaint paint_with_filter = paint;
266 paint_with_filter.setImageFilter(&filter);
269 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
271 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
272 DlRect::MakeLTRB(0, 0, 500, 500), {},
276 builder.Translate(600, 0);
277 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
278 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
280 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
284 sk_sp<DlImageImpeller> texture =
287 DisplayListBuilder builder;
293 1.0, 1.0, 1.0, 1.0, 0
295 DlPaint paint = DlPaint().setColorFilter(
298 DlMatrix filter_matrix = DlMatrix();
299 auto filter = flutter::DlMatrixImageFilter(filter_matrix,
300 flutter::DlImageSampling::kLinear);
301 DlPaint paint_with_filter = paint;
302 paint_with_filter.setImageFilter(&filter);
305 builder.DrawPaint(DlPaint().setColor(DlColor::kWhite()));
307 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
308 DlRect::MakeLTRB(0, 0, 500, 500), {},
312 builder.Translate(600, 0);
313 builder.DrawImageRect(texture, DlRect::MakeSize(texture->GetSize()),
314 DlRect::MakeLTRB(0, 0, 500, 500), {}, &paint);
316 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
320 DisplayListBuilder builder;
321 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
323 std::vector<DlColor> colors = {DlColor::kDarkGrey(), DlColor::kBlack(),
324 DlColor::kLightGrey(), DlColor::kWhite()};
326 builder.Scale(GetContentScale().
x, GetContentScale().y);
327 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
328 colors.data(), 4, DlBlendMode::kColorBurn,
329 DlImageSampling::kNearestNeighbor,
nullptr);
331 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
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.