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 
14 namespace impeller {
15 namespace testing {
16 
17 TEST(SkiaConversionTest, ToSamplerDescriptor) {
19  flutter::DlImageSampling::kNearestNeighbor)
20  .min_filter,
23  flutter::DlImageSampling::kNearestNeighbor)
24  .mip_filter,
26 
27  EXPECT_EQ(
28  skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
29  .min_filter,
31  EXPECT_EQ(
32  skia_conversions::ToSamplerDescriptor(flutter::DlImageSampling::kLinear)
33  .mip_filter,
35 
37  flutter::DlImageSampling::kMipmapLinear)
38  .min_filter,
41  flutter::DlImageSampling::kMipmapLinear)
42  .mip_filter,
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
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:36
@ kNearest
Select nearest to the sample point. Most widely supported.