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"
13 #include "include/core/SkMatrix.h"
14 #include "include/core/SkRRect.h"
15 
16 namespace impeller {
17 namespace testing {
18 
19 TEST(SkiaConversionTest, ToSamplerDescriptor) {
21  flutter::DlImageSampling::kNearestNeighbor)
22  .min_filter,
25  flutter::DlImageSampling::kNearestNeighbor)
26  .mip_filter,
28 
29  EXPECT_EQ(
30  skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
31  .min_filter,
33  EXPECT_EQ(
34  skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
35  .mip_filter,
37 
39  flutter::DlImageSampling::kMipmapLinear)
40  .min_filter,
43  flutter::DlImageSampling::kMipmapLinear)
44  .mip_filter,
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
impeller::SamplerDescriptor ToSamplerDescriptor(const flutter::DlImageSampling options)
Color ToColor(const flutter::DlColor &color)
TEST(AllocationSizeTest, CanCreateTypedAllocations)
@ kLinear
Sample from the two nearest mip levels and linearly interpolate.
@ kBase
The texture is sampled as if it only had a single mipmap level.
static impeller::SamplerDescriptor ToSamplerDescriptor(const flutter::DlFilterMode options)
constexpr bool ScalarNearlyEqual(Scalar x, Scalar y, Scalar tolerance=kEhCloseEnough)
Definition: scalar.h:35
@ kNearest
Select nearest to the sample point. Most widely supported.