| 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 #include "include/core/SkMatrix.h"
14 #include "include/core/SkRRect.h"
15
16 namespace impeller {
17 namespace testing {
18
19 TEST(SkiaConversionTest, ToSamplerDescriptor) {
20 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
21 flutter::DlImageSampling::kNearestNeighbor)
22 .min_filter,
23 impeller::MinMagFilter::kNearest);
24 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
25 flutter::DlImageSampling::kNearestNeighbor)
26 .mip_filter,
27 impeller::MipFilter::kBase);
28
29 EXPECT_EQ(
30 skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
31 .min_filter,
32 impeller::MinMagFilter::kLinear);
33 EXPECT_EQ(
34 skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
35 .mip_filter,
36 impeller::MipFilter::kBase);
37
38 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
39 flutter::DlImageSampling::kMipmapLinear)
40 .min_filter,
41 impeller::MinMagFilter::kLinear);
42 EXPECT_EQ(skia_conversions::ToSamplerDescriptor(
43 flutter::DlImageSampling::kMipmapLinear)
44 .mip_filter,
45 impeller::MipFilter::kLinear);
46 }
47
48 TEST(SkiaConversionsTest, ToColor) {
49 // Create a color with alpha, red, green, and blue values that are all
50 // trivially divisible by 255 so that we can test the conversion results in
51 // correct scalar values.
52 // AARRGGBB
53 const flutter::DlColor color = flutter::DlColor(0x8040C020);
54 auto converted_color = skia_conversions::ToColor(color);
55
56 ASSERT_TRUE(ScalarNearlyEqual(converted_color.alpha, 0x80 * (1.0f / 255)));
57 ASSERT_TRUE(ScalarNearlyEqual(converted_color.red, 0x40 * (1.0f / 255)));
58 ASSERT_TRUE(ScalarNearlyEqual(converted_color.green, 0xC0 * (1.0f / 255)));
59 ASSERT_TRUE(ScalarNearlyEqual(converted_color.blue, 0x20 * (1.0f / 255)));
60 }
61
62 } // namespace testing
63 } // 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:123
impeller::ScalarNearlyEqual
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:35
impeller::MinMagFilter::kLinear
@ kLinear
impeller::MinMagFilter::kNearest
@ kNearest
Select nearest to the sample point. Most widely supported.
scalar.h
skia_conversions.h