Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
void attachDiscardableAdapter(sk_sp< T > adapter) const
static sk_sp< TransformEffect > Make(sk_sp< RenderNode > child, sk_sp< Transform > transform)
dst
Definition cp.py:12
SkV2 Vec2Value
Definition Skottie.h:32
Definition SkMD5.cpp:134
SkScalar width() const
Definition SkSize.h:76
SkScalar height() const
Definition SkSize.h:77