5 #include "display_list/dl_sampling_options.h"
8 #include "flutter/display_list/dl_blend_mode.h"
9 #include "flutter/display_list/dl_builder.h"
10 #include "flutter/display_list/dl_color.h"
11 #include "flutter/display_list/dl_paint.h"
12 #include "flutter/testing/testing.h"
19 #include "include/core/SkRefCnt.h"
31 std::tuple<std::vector<DlRect>,
32 std::vector<RSTransform>,
33 sk_sp<DlImageImpeller>>
34 CreateTestData(
const AiksTest* test) {
38 auto size = atlas->impeller_texture()->GetSize();
40 Scalar half_width = size.width / 2;
41 Scalar half_height = size.height / 2;
42 std::vector<DlRect> texture_coordinates = {
43 DlRect::MakeLTRB(0, 0, half_width, half_height),
44 DlRect::MakeLTRB(half_width, 0, size.width, half_height),
45 DlRect::MakeLTRB(0, half_height, half_width, size.height),
46 DlRect::MakeLTRB(half_width, half_height, size.width, size.height)};
48 std::vector<RSTransform> transforms = {
49 MakeTranslation(0, 0), MakeTranslation(half_width, 0),
50 MakeTranslation(0, half_height),
51 MakeTranslation(half_width, half_height)};
52 return std::make_tuple(texture_coordinates, transforms, atlas);
58 DisplayListBuilder builder;
59 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
61 builder.Scale(GetContentScale().
x, GetContentScale().y);
62 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
63 nullptr, 4, DlBlendMode::kSrcOver,
64 DlImageSampling::kNearestNeighbor,
nullptr);
66 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
70 DisplayListBuilder builder;
71 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
73 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
74 DlColor::kBlue(), DlColor::kYellow()};
76 builder.Scale(GetContentScale().
x, GetContentScale().y);
77 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
78 colors.data(), 4, DlBlendMode::kModulate,
79 DlImageSampling::kNearestNeighbor,
nullptr);
81 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
85 DisplayListBuilder builder;
87 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
89 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
90 DlColor::kBlue(), DlColor::kYellow()};
92 builder.Scale(GetContentScale().
x, GetContentScale().y);
93 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
94 colors.data(), 4, DlBlendMode::kSrcATop,
95 DlImageSampling::kNearestNeighbor,
nullptr);
97 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
101 DisplayListBuilder builder;
104 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
108 builder.Scale(GetContentScale().
x, GetContentScale().y);
109 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
110 nullptr, 4, DlBlendMode::kSrcOver,
111 DlImageSampling::kNearestNeighbor,
nullptr,
114 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
119 auto size = atlas->impeller_texture()->GetSize();
120 std::vector<DlRect> texture_coordinates = {
121 DlRect::MakeLTRB(0, 0, size.width, size.height)};
122 std::vector<RSTransform> transforms = {MakeTranslation(0, 0)};
124 DisplayListBuilder builder;
125 builder.Scale(GetContentScale().
x, GetContentScale().y);
126 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
127 nullptr, 1, DlBlendMode::kSrcOver,
128 DlImageSampling::kNearestNeighbor,
nullptr);
130 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
135 DisplayListBuilder builder;
137 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
139 builder.Scale(0.25, 0.25);
140 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
141 nullptr, 4, DlBlendMode::kModulate,
142 DlImageSampling::kNearestNeighbor,
nullptr);
144 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
149 DisplayListBuilder builder;
151 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
152 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
153 DlColor::kBlue(), DlColor::kYellow()};
155 builder.Scale(0.25, 0.25);
156 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
157 colors.data(), 4, DlBlendMode::kModulate,
158 DlImageSampling::kNearestNeighbor,
nullptr);
160 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
164 DisplayListBuilder builder;
165 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
169 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
170 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
171 DlColor::kBlue(), DlColor::kYellow()};
173 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
174 colors.data(), 4, DlBlendMode::kPlus,
175 DlImageSampling::kNearestNeighbor,
nullptr);
177 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
181 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
184 texture_coordinates.data(),
nullptr, transforms.size(),
195 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
199 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
201 std::vector<DlColor> colors;
202 colors.reserve(texture_coordinates.size());
203 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
204 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
207 texture_coordinates.data(), colors.data(),
219 EXPECT_EQ(vertex_buffer.vertex_count, texture_coordinates.size() * 6);
223 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
225 std::vector<DlColor> colors;
226 colors.reserve(texture_coordinates.size());
227 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
228 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
231 texture_coordinates.data(), colors.data(),
240 auto [texture_coordinates, transforms, atlas] = CreateTestData(
this);
242 std::vector<DlColor> colors;
243 colors.reserve(texture_coordinates.size());
244 for (
auto i = 0u; i < texture_coordinates.size(); i++) {
245 colors.push_back(DlColor::ARGB(0.5, 1, 1, 1));
248 texture_coordinates.data(), colors.data(),
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.