| Flutter Impeller |

skia_conversions_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
5 #include "display_list/dl_blend_mode.h"
6 #include "display_list/dl_color.h"
7 #include "display_list/dl_tile_mode.h"
8 #include "flutter/testing/testing.h"
9 #include "impeller/core/formats.h"
10 #include "impeller/display_list/skia_conversions.h"
11 #include "impeller/geometry/color.h"
12 #include "impeller/geometry/scalar.h"
13
14 namespace impeller {
15 namespace testing {
16
17 TEST(SkiaConversionTest, ToSamplerDescriptor) {
18 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
19 flutter::DlImageSampling::kNearestNeighbor)
20 .min_filter,
21 impeller::MinMagFilter::kNearest);
22 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
23 flutter::DlImageSampling::kNearestNeighbor)
24 .mip_filter,
25 impeller::MipFilter::kBase);
26
27 EXPECT_EQ(
28 skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
29 .min_filter,
30 impeller::MinMagFilter::kLinear);
31 EXPECT_EQ(
32 skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
33 .mip_filter,
34 impeller::MipFilter::kBase);
35
36 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
37 flutter::DlImageSampling::kMipmapLinear)
38 .min_filter,
39 impeller::MinMagFilter::kLinear);
40 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
41 flutter::DlImageSampling::kMipmapLinear)
42 .mip_filter,
43 impeller::MipFilter::kLinear);
44 }
45
46 TEST(SkiaConversionsTest, ToColor) {
47 // Create a color with alpha, red, green, and blue values that are all
48 // trivially divisible by 255 so that we can test the conversion results in
49 // correct scalar values.
50 // AARRGGBB
51 const flutter::DlColor color = flutter::DlColor(0x8040C020);
52 auto converted_color = skia_conversions::ToColor(color);
53
54 ASSERT_TRUE(ScalarNearlyEqual(converted_color.alpha, 0x80 * (1.0f / 255)));
55 ASSERT_TRUE(ScalarNearlyEqual(converted_color.red, 0x40 * (1.0f / 255)));
56 ASSERT_TRUE(ScalarNearlyEqual(converted_color.green, 0xC0 * (1.0f / 255)));
57 ASSERT_TRUE(ScalarNearlyEqual(converted_color.blue, 0x20 * (1.0f / 255)));
58 }
59
60 } // namespace testing
61 } // namespace impeller
color.h
formats.h
impeller::skia_conversions::ToSamplerDescriptor
impeller::SamplerDescriptor ToSamplerDescriptor(const flutter::DlImageSampling options)
Definition: skia_conversions.cc:24
impeller::skia_conversions::ToColor
Color ToColor(const flutter::DlColor &color)
Definition: skia_conversions.cc:13
impeller::testing::TEST
TEST(AllocationSizeTest, CanCreateTypedAllocations)
Definition: allocation_size_unittests.cc:10
impeller
Definition: allocation.cc:12
impeller::MipFilter::kLinear
@ kLinear
Sample from the two nearest mip levels and linearly interpolate.
impeller::MipFilter::kBase
@ kBase
The texture is sampled as if it only had a single mipmap level.
impeller::ToSamplerDescriptor
static impeller::SamplerDescriptor ToSamplerDescriptor(const flutter::DlFilterMode options)
Definition: dl_dispatcher.cc:122
impeller::ScalarNearlyEqual
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:36
impeller::MinMagFilter::kLinear
@ kLinear
impeller::MinMagFilter::kNearest
@ kNearest
Select nearest to the sample point. Most widely supported.
scalar.h
skia_conversions.h