Flutter Engine
 
Loading...
Searching...
No Matches
dl_sk_canvas_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
6
8#include "flutter/third_party/skia/include/utils/SkShadowUtils.h"
9#include "gtest/gtest.h"
10
11namespace flutter {
12namespace testing {
13
14namespace {
15
16void TestShadowBounds(bool with_rotate, bool with_perspective) {
17 const SkVector3 light_position = SkVector3::Make(0.0f, -1.0f, 1.0f);
18 const DlScalar light_radius =
20
21 DlPath dl_path = DlPath::MakeRectLTRB(100, 100, 200, 200);
22 for (int dpr = 1; dpr <= 2; dpr++) {
23 for (int elevation = 1; elevation <= 5; elevation++) {
24 SkVector3 z_params = SkVector3::Make(0.0f, 0.0f, elevation * dpr);
25 for (int i = 1; i <= 10; i++) {
26 DlScalar xScale = static_cast<DlScalar>(i);
27 for (int j = 1; j <= 10; j++) {
28 DlScalar yScale = static_cast<DlScalar>(j);
29
30 DlMatrix matrix = DlMatrix::MakeTranslateScale({xScale, yScale, 1.0f},
31 {10.0f, 15.0f, 7.0f});
32 if (with_rotate) {
33 matrix = matrix * DlMatrix::MakeRotationZ(DlDegrees(45));
34 }
35 if (with_perspective) {
36 matrix.m[3] = 0.001f;
37 }
38 SkMatrix sk_matrix;
39 ASSERT_TRUE(ToSk(&matrix, sk_matrix) != nullptr);
40 SkMatrix sk_inverse = sk_matrix;
41 ASSERT_TRUE(sk_matrix.invert(&sk_inverse));
42
43 auto label = (std::stringstream()
44 << "Matrix: " << matrix << ", elevation = " << elevation
45 << ", dpr = " << dpr)
46 .str();
47
48 DlRect dl_bounds =
49 DlCanvas::ComputeShadowBounds(dl_path, elevation, dpr, matrix);
50 SkRect sk_bounds;
51 ASSERT_TRUE(SkShadowUtils::GetLocalBounds(
52 sk_matrix, dl_path.GetSkPath(), z_params, light_position,
53 light_radius, kDirectionalLight_ShadowFlag, &sk_bounds))
54 << label;
55 EXPECT_FLOAT_EQ(dl_bounds.GetLeft(), sk_bounds.fLeft) << label;
56 EXPECT_FLOAT_EQ(dl_bounds.GetTop(), sk_bounds.fTop) << label;
57 EXPECT_FLOAT_EQ(dl_bounds.GetRight(), sk_bounds.fRight) << label;
58 EXPECT_FLOAT_EQ(dl_bounds.GetBottom(), sk_bounds.fBottom) << label;
59 }
60 }
61 }
62 }
63}
64
65} // namespace
66
67TEST(DlSkCanvas, ShadowBoundsCompatibilityTranslateScale) {
68 TestShadowBounds(false, false);
69}
70
71TEST(DlSkCanvas, ShadowBoundsCompatibilityTranslateScaleRotate) {
72 TestShadowBounds(true, false);
73}
74
75TEST(DlSkCanvas, ShadowBoundsCompatibilityTranslateScalePerspective) {
76 TestShadowBounds(false, true);
77}
78
79} // namespace testing
80} // namespace flutter
static constexpr DlScalar kShadowLightHeight
Definition dl_canvas.h:215
static constexpr DlScalar kShadowLightRadius
Definition dl_canvas.h:216
static DlRect ComputeShadowBounds(const DlPath &path, float elevation, DlScalar dpr, const DlMatrix &ctm)
Compute the local coverage for a |DrawShadow| operation using the given parameters (excluding the col...
Definition dl_canvas.cc:125
static DlPath MakeRectLTRB(DlScalar left, DlScalar top, DlScalar right, DlScalar bottom)
Definition dl_path.cc:43
SkMatrix sk_matrix
TEST(NativeAssetsManagerTest, NoAvailableAssets)
impeller::Scalar DlScalar
SkPaint ToSk(const DlPaint &paint)
impeller::Matrix DlMatrix
impeller::Rect DlRect
impeller::Degrees DlDegrees
flutter::DlPath DlPath
static constexpr Matrix MakeTranslateScale(const Vector3 &s, const Vector3 &t)
Definition matrix.h:113
static Matrix MakeRotationZ(Radians r)
Definition matrix.h:223