Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
OffsetPaths.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
18#include "src/utils/SkJSON.h"
19
20#include <utility>
21#include <vector>
22
23namespace skottie::internal {
24
25namespace {
26
27class OffsetPathsAdapter final : public DiscardableAdapterBase<OffsetPathsAdapter,
28 sksg::OffsetEffect> {
29public:
30 OffsetPathsAdapter(const skjson::ObjectValue& joffset,
31 const AnimationBuilder& abuilder,
33 : INHERITED(sksg::OffsetEffect::Make(std::move(child))) {
34 static constexpr SkPaint::Join gJoinMap[] = {
35 SkPaint::kMiter_Join, // 'lj': 1
36 SkPaint::kRound_Join, // 'lj': 2
37 SkPaint::kBevel_Join, // 'lj': 3
38 };
39
40 const auto join = ParseDefault<int>(joffset["lj"], 1) - 1;
41 this->node()->setJoin(gJoinMap[SkTPin<int>(join, 0, std::size(gJoinMap) - 1)]);
42
43 this->bind(abuilder, joffset["a" ], fAmount);
44 this->bind(abuilder, joffset["ml"], fMiterLimit);
45 }
46
47private:
48 void onSync() override {
49 this->node()->setOffset(fAmount);
50 this->node()->setMiterLimit(fMiterLimit);
51 }
52
53 ScalarValue fAmount = 0,
54 fMiterLimit = 0;
55
56 using INHERITED = DiscardableAdapterBase<OffsetPathsAdapter, sksg::OffsetEffect>;
57};
58
59} // namespace
60
61std::vector<sk_sp<sksg::GeometryNode>> ShapeBuilder::AttachOffsetGeometryEffect(
62 const skjson::ObjectValue& jround, const AnimationBuilder* abuilder,
63 std::vector<sk_sp<sksg::GeometryNode>>&& geos) {
64 std::vector<sk_sp<sksg::GeometryNode>> offsetted;
65 offsetted.reserve(geos.size());
66
67 for (auto& g : geos) {
68 offsetted.push_back(abuilder->attachDiscardableAdapter<OffsetPathsAdapter>
69 (jround, *abuilder, std::move(g)));
70 }
71
72 return offsetted;
73}
74
75} // namespace skottie::internal
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
#define INHERITED(method,...)
@ kRound_Join
adds circle
Definition SkPaint.h:360
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
@ kBevel_Join
connects outside edges
Definition SkPaint.h:361
void attachDiscardableAdapter(sk_sp< T > adapter) const
static std::vector< sk_sp< sksg::GeometryNode > > AttachOffsetGeometryEffect(const skjson::ObjectValue &, const AnimationBuilder *, std::vector< sk_sp< sksg::GeometryNode > > &&)
SkScalar ScalarValue
Definition Skottie.h:32
SINT Vec< 2 *N, T > join(const Vec< N, T > &lo, const Vec< N, T > &hi)
Definition SkVx.h:242
Definition ref_ptr.h:256