Coverage Report

Created: 2021-08-22 09:07

/src/skia/modules/skottie/src/layers/shapelayer/Ellipse.cpp
Line
Count
Source
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/SkRRect.h"
9
#include "modules/skottie/src/Adapter.h"
10
#include "modules/skottie/src/SkottieJson.h"
11
#include "modules/skottie/src/SkottiePriv.h"
12
#include "modules/skottie/src/SkottieValue.h"
13
#include "modules/skottie/src/layers/shapelayer/ShapeLayer.h"
14
#include "modules/sksg/include/SkSGRect.h"
15
16
namespace skottie {
17
namespace internal {
18
19
namespace  {
20
21
class EllipseGeometryAdapter final :
22
        public DiscardableAdapterBase<EllipseGeometryAdapter, sksg::RRect> {
23
public:
24
    EllipseGeometryAdapter(const skjson::ObjectValue& jellipse,
25
97.6k
                           const AnimationBuilder* abuilder) {
26
80
        this->node()->setDirection(ParseDefault(jellipse["d"], -1) == 3 ? SkPathDirection::kCCW
27
97.5k
                                                                        : SkPathDirection::kCW);
28
97.6k
        this->node()->setInitialPointIndex(1); // starting point: (Center, Top)
29
30
97.6k
        this->bind(*abuilder, jellipse["s"], fSize);
31
97.6k
        this->bind(*abuilder, jellipse["p"], fPosition);
32
97.6k
    }
33
34
private:
35
96.8k
    void onSync() override {
36
96.8k
        const auto bounds = SkRect::MakeXYWH(fPosition.x - fSize.x / 2,
37
96.8k
                                             fPosition.y - fSize.y / 2,
38
96.8k
                                             fSize.x, fSize.y);
39
40
96.8k
        this->node()->setRRect(SkRRect::MakeOval(bounds));
41
96.8k
    }
42
43
    Vec2Value fSize     = {0,0},
44
              fPosition = {0,0}; // center
45
};
46
47
} // namespace
48
49
sk_sp<sksg::GeometryNode> ShapeBuilder::AttachEllipseGeometry(const skjson::ObjectValue& jellipse,
50
97.6k
                                                              const AnimationBuilder* abuilder) {
51
97.6k
    return abuilder->attachDiscardableAdapter<EllipseGeometryAdapter>(jellipse, abuilder);
52
97.6k
}
53
54
} // namespace internal
55
} // namespace skottie