Flutter Engine
The Flutter Engine
aiks_dl_atlas_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6#include "flutter/impeller/aiks/aiks_unittests.h"
7
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"
17
18namespace impeller {
19namespace testing {
20
21using namespace flutter;
22
23namespace {
24SkRSXform MakeTranslation(Scalar tx, Scalar ty) {
25 return SkRSXform::Make(1, 0, tx, ty);
26}
27
28std::tuple<std::vector<SkRect>, std::vector<SkRSXform>, sk_sp<DlImageImpeller>>
29CreateTestData(const AiksTest* test) {
30 // Draws the image as four squares stiched together.
31 auto atlas =
32 DlImageImpeller::Make(test->CreateTextureForFixture("bay_bridge.jpg"));
33 auto size = atlas->impeller_texture()->GetSize();
34 // Divide image into four quadrants.
35 Scalar half_width = size.width / 2;
36 Scalar half_height = size.height / 2;
37 std::vector<SkRect> texture_coordinates = {
38 SkRect::MakeLTRB(0, 0, half_width, half_height),
39 SkRect::MakeLTRB(half_width, 0, size.width, half_height),
40 SkRect::MakeLTRB(0, half_height, half_width, size.height),
41 SkRect::MakeLTRB(half_width, half_height, size.width, size.height)};
42 // Position quadrants adjacent to eachother.
43 std::vector<SkRSXform> transforms = {
44 MakeTranslation(0, 0), MakeTranslation(half_width, 0),
45 MakeTranslation(0, half_height),
46 MakeTranslation(half_width, half_height)};
47 return std::make_tuple(texture_coordinates, transforms, atlas);
48}
49
50} // namespace
51
52TEST_P(AiksTest, DrawAtlasNoColor) {
54 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
55
56 builder.Scale(GetContentScale().x, GetContentScale().y);
57 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
58 /*colors=*/nullptr, /*count=*/4, DlBlendMode::kSrcOver,
60
61 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
62}
63
64TEST_P(AiksTest, DrawAtlasWithColorAdvanced) {
66 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
67
68 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
70
71 builder.Scale(GetContentScale().x, GetContentScale().y);
72 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
73 colors.data(), /*count=*/4, DlBlendMode::kModulate,
74 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
75
76 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
77}
78
79TEST_P(AiksTest, DrawAtlasWithColorSimple) {
81 // Draws the image as four squares stiched together.
82 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
83
84 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
86
87 builder.Scale(GetContentScale().x, GetContentScale().y);
88 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
89 colors.data(), /*count=*/4, DlBlendMode::kSrcATop,
90 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
91
92 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
93}
94
95TEST_P(AiksTest, DrawAtlasWithOpacity) {
97 // Draws the image as four squares stiched together slightly
98 // opaque
99 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
100
102 paint.setAlpha(128);
103 builder.Scale(GetContentScale().x, GetContentScale().y);
104 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
105 /*colors=*/nullptr, 4, DlBlendMode::kSrcOver,
106 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr,
107 &paint);
108
109 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
110}
111
112TEST_P(AiksTest, DrawAtlasNoColorFullSize) {
113 auto atlas = DlImageImpeller::Make(CreateTextureForFixture("bay_bridge.jpg"));
114 auto size = atlas->impeller_texture()->GetSize();
115 std::vector<SkRect> texture_coordinates = {
116 SkRect::MakeLTRB(0, 0, size.width, size.height)};
117 std::vector<SkRSXform> transforms = {MakeTranslation(0, 0)};
118
120 builder.Scale(GetContentScale().x, GetContentScale().y);
121 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
122 /*colors=*/nullptr, /*count=*/1, DlBlendMode::kSrcOver,
123 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
124
125 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
126}
127
128// Regression test for https://github.com/flutter/flutter/issues/127374.
129TEST_P(AiksTest, DrawAtlasAdvancedAndTransform) {
131 // Draws the image as four squares stiched together.
132 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
133
134 builder.Scale(0.25, 0.25);
135 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
136 /*colors=*/nullptr, /*count=*/4, DlBlendMode::kModulate,
137 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
138
139 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
140}
141
142// Regression test for https://github.com/flutter/flutter/issues/127374.
143TEST_P(AiksTest, DrawAtlasWithColorAdvancedAndTransform) {
145 // Draws the image as four squares stiched together.
146 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
147 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
149
150 builder.Scale(0.25, 0.25);
151 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
152 colors.data(), /*count=*/4, DlBlendMode::kModulate,
153 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
154
155 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
156}
157
158TEST_P(AiksTest, DrawAtlasPlusWideGamut) {
160 EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
162
163 // Draws the image as four squares stiched together.
164 auto [texture_coordinates, transforms, atlas] = CreateTestData(this);
165 std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kGreen(),
167
168 builder.DrawAtlas(atlas, transforms.data(), texture_coordinates.data(),
169 colors.data(), /*count=*/4, DlBlendMode::kPlus,
170 DlImageSampling::kNearestNeighbor, /*cullRect=*/nullptr);
171
172 ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
173}
174
175} // namespace testing
176} // namespace impeller
static sk_sp< DlImageImpeller > Make(std::shared_ptr< Texture > texture, OwningContext owning_context=OwningContext::kIO)
const Paint & paint
Definition: color_source.cc:38
double y
double x
SK_API GrDirectContext * GetContext(const SkImage *src)
sk_sp< const SkImage > atlas
Definition: SkRecords.h:331
PODArray< SkColor > colors
Definition: SkRecords.h:276
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
AiksPlayground AiksTest
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
float Scalar
Definition: scalar.h:18
static SkRSXform Make(SkScalar scos, SkScalar ssin, SkScalar tx, SkScalar ty)
Definition: SkRSXform.h:24
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
static constexpr DlColor kBlue()
Definition: dl_color.h:26
static constexpr DlColor kYellow()
Definition: dl_color.h:29
static constexpr DlColor kRed()
Definition: dl_color.h:24
static constexpr DlColor kGreen()
Definition: dl_color.h:25