Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
dl_sk_conversions_unittests.cc File Reference
#include "flutter/display_list/dl_blend_mode.h"
#include "flutter/display_list/dl_paint.h"
#include "flutter/display_list/dl_sampling_options.h"
#include "flutter/display_list/dl_tile_mode.h"
#include "flutter/display_list/dl_vertices.h"
#include "flutter/display_list/effects/dl_color_source.h"
#include "flutter/display_list/skia/dl_sk_conversions.h"
#include "gtest/gtest.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/core/SkSamplingOptions.h"
#include "third_party/skia/include/core/SkTileMode.h"

Go to the source code of this file.

Namespaces

namespace  flutter
 
namespace  flutter::testing
 

Macros

#define FOR_EACH_BLEND_MODE_ENUM(FUNC)
 
#define CHECK_TO_SKENUM(V)   ASSERT_EQ(ToSk(DlBlendMode::V), SkBlendMode::V);
 
#define TEST_MODE(V)   test_mode(DlBlendMode::V);
 

Functions

 flutter::testing::TEST (DisplayListImageFilter, LocalImageSkiaNull)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkColor)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkTileMode)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkBlurStyle)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkDrawStyle)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkStrokeCap)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkStrokeJoin)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkVertexMode)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkFilterMode)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkSrcRectConstraint)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkSamplingOptions)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkBlendMode)
 
 flutter::testing::TEST (DisplayListSkConversions, BlendColorFilterModifiesTransparency)
 
 flutter::testing::TEST (DisplayListSkConversions, ConvertWithZeroAndNegativeVerticesAndIndices)
 
 flutter::testing::TEST (DisplayListVertices, ConvertWithZeroAndNegativeVerticesAndIndices)
 
 flutter::testing::TEST (DisplayListColorSource, ConvertRuntimeEffect)
 
 flutter::testing::TEST (DisplayListColorSource, ConvertRuntimeEffectWithNullSampler)
 
 flutter::testing::TEST (DisplayListSkConversions, MatrixColorFilterModifiesTransparency)
 
 flutter::testing::TEST (DisplayListSkConversions, ToSkDitheringEnabledForGradients)
 

Macro Definition Documentation

◆ CHECK_TO_SKENUM

#define CHECK_TO_SKENUM (   V)    ASSERT_EQ(ToSk(DlBlendMode::V), SkBlendMode::V);

◆ FOR_EACH_BLEND_MODE_ENUM

#define FOR_EACH_BLEND_MODE_ENUM (   FUNC)

Definition at line 111 of file dl_sk_conversions_unittests.cc.

145 {
146#define CHECK_TO_SKENUM(V) ASSERT_EQ(ToSk(DlBlendMode::V), SkBlendMode::V);
148#undef CHECK_TO_SKENUM
149}
150
151TEST(DisplayListSkConversions, BlendColorFilterModifiesTransparency) {
152 auto test_mode_color = [](DlBlendMode mode, DlColor color) {
153 std::stringstream desc_str;
154 desc_str << "blend[" << static_cast<int>(mode) << ", " << color.argb()
155 << "]";
156 std::string desc = desc_str.str();
157 DlBlendColorFilter filter(color, mode);
158 auto srgb = SkColorSpace::MakeSRGB();
159 if (filter.modifies_transparent_black()) {
160 auto dl_filter = DlBlendColorFilter::Make(color, mode);
161 auto sk_filter = ToSk(filter);
162 ASSERT_NE(dl_filter, nullptr) << desc;
163 ASSERT_NE(sk_filter, nullptr) << desc;
164 ASSERT_TRUE(sk_filter->filterColor4f(SkColors::kTransparent, srgb.get(),
165 srgb.get()) !=
167 << desc;
168 } else {
169 auto dl_filter = DlBlendColorFilter::Make(color, mode);
170 auto sk_filter = ToSk(filter);
171 EXPECT_EQ(dl_filter == nullptr, sk_filter == nullptr) << desc;
172 ASSERT_TRUE(sk_filter == nullptr ||
173 sk_filter->filterColor4f(SkColors::kTransparent, srgb.get(),
174 srgb.get()) ==
176 << desc;
177 }
178 };
179
180 auto test_mode = [&test_mode_color](DlBlendMode mode) {
181 test_mode_color(mode, DlColor::kTransparent());
182 test_mode_color(mode, DlColor::kWhite());
183 test_mode_color(mode, DlColor::kWhite().modulateOpacity(0.5));
184 test_mode_color(mode, DlColor::kBlack());
185 test_mode_color(mode, DlColor::kBlack().modulateOpacity(0.5));
186 };
187
188#define TEST_MODE(V) test_mode(DlBlendMode::V);
190#undef TEST_MODE
191}
192
193#undef FOR_EACH_BLEND_MODE_ENUM
194
195TEST(DisplayListSkConversions, ConvertWithZeroAndNegativeVerticesAndIndices) {
196 std::shared_ptr<const DlVertices> vertices1 = DlVertices::Make(
197 DlVertexMode::kTriangles, 0, nullptr, nullptr, nullptr, 0, nullptr);
198 EXPECT_NE(vertices1, nullptr);
199 EXPECT_NE(ToSk(vertices1), nullptr);
200
201 std::shared_ptr<const DlVertices> vertices2 = DlVertices::Make(
202 DlVertexMode::kTriangles, -1, nullptr, nullptr, nullptr, -1, nullptr);
203 EXPECT_NE(vertices2, nullptr);
204 EXPECT_NE(ToSk(vertices2), nullptr);
205}
206
207TEST(DisplayListVertices, ConvertWithZeroAndNegativeVerticesAndIndices) {
208 DlVertices::Builder builder1(DlVertexMode::kTriangles, 0,
209 DlVertices::Builder::kNone, 0);
210 EXPECT_TRUE(builder1.is_valid());
211 std::shared_ptr<DlVertices> vertices1 = builder1.build();
212 EXPECT_NE(vertices1, nullptr);
213 EXPECT_NE(ToSk(vertices1), nullptr);
214
215 DlVertices::Builder builder2(DlVertexMode::kTriangles, -1,
216 DlVertices::Builder::kNone, -1);
217 EXPECT_TRUE(builder2.is_valid());
218 std::shared_ptr<DlVertices> vertices2 = builder2.build();
219 EXPECT_NE(vertices2, nullptr);
220 EXPECT_NE(ToSk(vertices2), nullptr);
221}
222
223TEST(DisplayListColorSource, ConvertRuntimeEffect) {
224 const sk_sp<DlRuntimeEffect> kTestRuntimeEffect1 = DlRuntimeEffect::MakeSkia(
226 SkString("vec4 main(vec2 p) { return vec4(0); }"))
227 .effect);
228 const sk_sp<DlRuntimeEffect> kTestRuntimeEffect2 = DlRuntimeEffect::MakeSkia(
230 SkString("vec4 main(vec2 p) { return vec4(1); }"))
231 .effect);
232 std::shared_ptr<DlRuntimeEffectColorSource> source1 =
233 DlColorSource::MakeRuntimeEffect(
234 kTestRuntimeEffect1, {}, std::make_shared<std::vector<uint8_t>>());
235 std::shared_ptr<DlRuntimeEffectColorSource> source2 =
236 DlColorSource::MakeRuntimeEffect(
237 kTestRuntimeEffect2, {}, std::make_shared<std::vector<uint8_t>>());
238 std::shared_ptr<DlRuntimeEffectColorSource> source3 =
239 DlColorSource::MakeRuntimeEffect(
240 nullptr, {}, std::make_shared<std::vector<uint8_t>>());
241
242 ASSERT_NE(ToSk(source1), nullptr);
243 ASSERT_NE(ToSk(source2), nullptr);
244 ASSERT_EQ(ToSk(source3), nullptr);
245}
246
247TEST(DisplayListColorSource, ConvertRuntimeEffectWithNullSampler) {
248 const sk_sp<DlRuntimeEffect> kTestRuntimeEffect1 = DlRuntimeEffect::MakeSkia(
250 SkString("vec4 main(vec2 p) { return vec4(0); }"))
251 .effect);
252 std::shared_ptr<DlRuntimeEffectColorSource> source1 =
253 DlColorSource::MakeRuntimeEffect(
254 kTestRuntimeEffect1, {nullptr},
255 std::make_shared<std::vector<uint8_t>>());
256
257 ASSERT_EQ(ToSk(source1), nullptr);
258}
259
260TEST(DisplayListSkConversions, MatrixColorFilterModifiesTransparency) {
261 auto test_matrix = [](int element, SkScalar value) {
262 // clang-format off
263 float matrix[] = {
264 1, 0, 0, 0, 0,
265 0, 1, 0, 0, 0,
266 0, 0, 1, 0, 0,
267 0, 0, 0, 1, 0,
268 };
269 // clang-format on
270 std::string desc =
271 "matrix[" + std::to_string(element) + "] = " + std::to_string(value);
272 matrix[element] = value;
273 DlMatrixColorFilter filter(matrix);
274 auto dl_filter = DlMatrixColorFilter::Make(matrix);
275 auto sk_filter = ToSk(filter);
276 auto srgb = SkColorSpace::MakeSRGB();
277 EXPECT_EQ(dl_filter == nullptr, sk_filter == nullptr);
278 EXPECT_EQ(filter.modifies_transparent_black(),
279 sk_filter && sk_filter->filterColor4f(SkColors::kTransparent,
280 srgb.get(), srgb.get()) !=
282 };
283
284 // Tests identity (matrix[0] already == 1 in an identity filter)
285 test_matrix(0, 1);
286 // test_matrix(19, 1);
287 for (int i = 0; i < 20; i++) {
288 test_matrix(i, -0.25);
289 test_matrix(i, 0);
290 test_matrix(i, 0.25);
291 test_matrix(i, 1);
292 test_matrix(i, 1.25);
296 }
297}
298
299TEST(DisplayListSkConversions, ToSkDitheringEnabledForGradients) {
300 // Test that when using the utility method "ToSk", the resulting SkPaint
301 // has "isDither" set to true, if the paint is a gradient, because it's
302 // a supported feature in the Impeller backend.
303
304 DlPaint dl_paint;
305
306 // Set the paint to be a gradient.
307 dl_paint.setColorSource(DlColorSource::MakeLinear(SkPoint::Make(0, 0),
308 SkPoint::Make(100, 100), 0,
309 0, 0, DlTileMode::kClamp));
310
311 {
312 SkPaint sk_paint = ToSk(dl_paint);
313 EXPECT_TRUE(sk_paint.isDither());
314 }
315
316 {
317 SkPaint sk_paint = ToStrokedSk(dl_paint);
318 EXPECT_TRUE(sk_paint.isDither());
319 }
320
321 {
322 SkPaint sk_paint = ToNonShaderSk(dl_paint);
323 EXPECT_FALSE(sk_paint.isDither());
324 }
325}
326
327} // namespace testing
328} // namespace flutter
#define TEST(S, s, D, expected)
SkColor4f color
static void test_matrix(skiatest::Reporter *reporter)
#define SK_ScalarNaN
Definition SkScalar.h:28
#define SK_ScalarInfinity
Definition SkScalar.h:26
static sk_sp< SkColorSpace > MakeSRGB()
bool isDither() const
Definition SkPaint.h:175
static Result MakeForShader(SkString sksl, const Options &)
#define CHECK_TO_SKENUM(V)
#define FOR_EACH_BLEND_MODE_ENUM(FUNC)
#define TEST_MODE(V)
float SkScalar
Definition extension.cpp:12
uint8_t value
constexpr SkColor4f kTransparent
Definition SkColor.h:434
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
SkPaint ToSk(const DlPaint &paint)
SkPaint ToStrokedSk(const DlPaint &paint)
SkPaint ToNonShaderSk(const DlPaint &paint)
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 mode
Definition switches.h:228
static constexpr SkPoint Make(float x, float y)
#define EXPECT_TRUE(handle)
Definition unit_test.h:685

◆ TEST_MODE

#define TEST_MODE (   V)    test_mode(DlBlendMode::V);