Flutter Engine
The Flutter Engine
CornerPinEffect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
11#include "include/core/SkSize.h"
18
19#include <array>
20#include <cstddef>
21#include <utility>
22
23namespace skjson {
24class ArrayValue;
25}
26
27namespace skottie::internal {
28
29namespace {
30
31class CornerPinAdapter final : public AnimatablePropertyContainer {
32public:
34 const AnimationBuilder& abuilder,
35 const SkSize& layer_size) {
36 return sk_sp<CornerPinAdapter>(new CornerPinAdapter(jprops, abuilder, layer_size));
37 }
38
39 auto& node() const { return fMatrixNode; }
40
41private:
42 CornerPinAdapter(const skjson::ArrayValue& jprops,
43 const AnimationBuilder& abuilder,
44 const SkSize& layer_size)
45 : fMatrixNode(sksg::Matrix<SkMatrix>::Make(SkMatrix::I()))
46 , fLayerSize(layer_size) {
47 enum : size_t {
48 kUpperLeft_Index = 0,
49 kUpperRight_Index = 1,
50 kLowerLeft_Index = 2,
51 kLowerRight_Index = 3,
52 };
53
54 EffectBinder(jprops, abuilder, this)
55 .bind( kUpperLeft_Index, fUL)
56 .bind(kUpperRight_Index, fUR)
57 .bind( kLowerLeft_Index, fLL)
58 .bind(kLowerRight_Index, fLR);
59 }
60
61 void onSync() override {
62 const SkPoint src[] = {{ 0, 0},
63 {fLayerSize.width(), 0},
64 {fLayerSize.width(), fLayerSize.height()},
65 { 0, fLayerSize.height()}},
66
67 dst[] = {{ fUL.x, fUL.y},
68 { fUR.x, fUR.y},
69 { fLR.x, fLR.y},
70 { fLL.x, fLL.y}};
71 static_assert(std::size(src) == std::size(dst));
72
73 SkMatrix m;
74 if (m.setPolyToPoly(src, dst, std::size(src))) {
75 fMatrixNode->setMatrix(m);
76 }
77 }
78
79 const sk_sp<sksg::Matrix<SkMatrix>> fMatrixNode;
80 const SkSize fLayerSize;
81
82 Vec2Value fUL,
83 fLL,
84 fUR,
85 fLR;
86};
87
88} // namespace
89
90sk_sp<sksg::RenderNode> EffectBuilder::attachCornerPinEffect(const skjson::ArrayValue& jprops,
91 sk_sp<sksg::RenderNode> layer) const {
92 sk_sp<sksg::Matrix<SkMatrix>> matrix_node =
93 fBuilder->attachDiscardableAdapter<CornerPinAdapter>(jprops, *fBuilder, fLayerSize);
94
95 return sksg::TransformEffect::Make(std::move(layer), std::move(matrix_node));
96}
97
98} // namespace skottie::internal
void attachDiscardableAdapter(sk_sp< T > adapter) const
Definition: SkottiePriv.h:139
static sk_sp< TransformEffect > Make(sk_sp< RenderNode > child, sk_sp< Transform > transform)
Definition: SkSGTransform.h:97
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
dst
Definition: cp.py:12
SK_API sk_sp< PrecompileColorFilter > Matrix()
SkV2 Vec2Value
Definition: SkottieValue.h:23
Definition: Skottie.h:32
Definition: SkMD5.cpp:134
Definition: SkSize.h:52
SkScalar width() const
Definition: SkSize.h:76
SkScalar height() const
Definition: SkSize.h:77