Flutter Engine
The Flutter Engine
TrimPaths.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
19#include "src/utils/SkJSON.h"
20
21#include <algorithm>
22#include <cstddef>
23#include <utility>
24#include <vector>
25
26namespace skottie {
27namespace internal {
28
29namespace {
30
31class TrimEffectAdapter final : public DiscardableAdapterBase<TrimEffectAdapter, sksg::TrimEffect> {
32public:
33 TrimEffectAdapter(const skjson::ObjectValue& jtrim,
34 const AnimationBuilder& abuilder,
36 : INHERITED(sksg::TrimEffect::Make(std::move(child))) {
37 this->bind(abuilder, jtrim["s"], &fStart);
38 this->bind(abuilder, jtrim["e"], &fEnd);
39 this->bind(abuilder, jtrim["o"], &fOffset);
40 }
41
42private:
43 void onSync() override {
44 // BM semantics: start/end are percentages, offset is "degrees" (?!).
45 const auto start = fStart / 100,
46 end = fEnd / 100,
47 offset = fOffset / 360;
48
49 auto startT = std::min(start, end) + offset,
50 stopT = std::max(start, end) + offset;
52
53 if (stopT - startT < 1) {
54 startT -= SkScalarFloorToScalar(startT);
55 stopT -= SkScalarFloorToScalar(stopT);
56
57 if (startT > stopT) {
58 using std::swap;
59 swap(startT, stopT);
61 }
62 } else {
63 startT = 0;
64 stopT = 1;
65 }
66
67 this->node()->setStart(startT);
68 this->node()->setStop(stopT);
69 this->node()->setMode(mode);
70 }
71
72 ScalarValue fStart = 0,
73 fEnd = 100,
74 fOffset = 0;
75
76 using INHERITED = DiscardableAdapterBase<TrimEffectAdapter, sksg::TrimEffect>;
77};
78
79} // namespace
80
81std::vector<sk_sp<sksg::GeometryNode>> ShapeBuilder::AttachTrimGeometryEffect(
82 const skjson::ObjectValue& jtrim,
83 const AnimationBuilder* abuilder,
84 std::vector<sk_sp<sksg::GeometryNode>>&& geos) {
85
86 enum class Mode {
87 kParallel, // "m": 1 (Trim Multiple Shapes: Simultaneously)
88 kSerial, // "m": 2 (Trim Multiple Shapes: Individually)
89 } gModes[] = { Mode::kParallel, Mode::kSerial};
90
91 const auto mode = gModes[std::min<size_t>(ParseDefault<size_t>(jtrim["m"], 1) - 1,
92 std::size(gModes) - 1)];
93
94 std::vector<sk_sp<sksg::GeometryNode>> inputs;
95 if (mode == Mode::kSerial) {
97 } else {
98 inputs = std::move(geos);
99 }
100
101 std::vector<sk_sp<sksg::GeometryNode>> trimmed;
102 trimmed.reserve(inputs.size());
103
104 for (const auto& i : inputs) {
105 trimmed.push_back(
106 abuilder->attachDiscardableAdapter<TrimEffectAdapter>(jtrim, *abuilder, i));
107 }
108
109 return trimmed;
110}
111
112} // namespace internal
113} // namespace skottie
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
#define SkScalarFloorToScalar(x)
Definition: SkScalar.h:30
constexpr SkBlendMode gModes[]
Definition: aarectmodes.cpp:73
void attachDiscardableAdapter(sk_sp< T > adapter) const
Definition: SkottiePriv.h:139
static sk_sp< sksg::Merge > MergeGeometry(std::vector< sk_sp< sksg::GeometryNode > > &&, sksg::Merge::Mode)
Definition: MergePaths.cpp:24
static std::vector< sk_sp< sksg::GeometryNode > > AttachTrimGeometryEffect(const skjson::ObjectValue &, const AnimationBuilder *, std::vector< sk_sp< sksg::GeometryNode > > &&)
Definition: TrimPaths.cpp:81
glong glong end
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
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 mode
Definition: switches.h:228
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
SkScalar ScalarValue
Definition: SkottieValue.h:22
Definition: Skottie.h:32
Definition: ref_ptr.h:256
SeparatedVector2 offset