| 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 |
|
| 8 |
#include "include/core/SkPaint.h" |
| 9 |
#include "include/core/SkRefCnt.h" |
| 10 |
#include "include/private/base/SkTPin.h" |
| 11 |
#include "modules/jsonreader/SkJSONReader.h" |
| 12 |
#include "modules/skottie/src/Adapter.h" |
| 13 |
#include "modules/skottie/src/SkottieJson.h" |
| 14 |
#include "modules/skottie/src/SkottiePriv.h" |
| 15 |
#include "modules/skottie/src/SkottieValue.h" |
| 16 |
#include "modules/skottie/src/layers/shapelayer/ShapeLayer.h" |
| 17 |
#include "modules/sksg/include/SkSGGeometryEffect.h" |
| 18 |
#include "modules/sksg/include/SkSGGeometryNode.h" |
| 19 |
|
| 20 |
#include <utility> |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
namespace skottie::internal { |
| 24 |
|
| 25 |
namespace { |
| 26 |
|
| 27 |
class OffsetPathsAdapter final : public DiscardableAdapterBase<OffsetPathsAdapter, |
| 28 |
sksg::OffsetEffect> { |
| 29 |
public: |
| 30 |
OffsetPathsAdapter(const skjson::ObjectValue& joffset, |
| 31 |
const AnimationBuilder& abuilder, |
| 32 |
sk_sp<sksg::GeometryNode> child) |
| 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 |
|
| 47 |
private: |
| 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 |
|
| 61 |
std::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 |