xref: /aosp_15_r20/external/skia/modules/skottie/src/Camera.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #ifndef SkottieCamera_DEFINED
9 #define SkottieCamera_DEFINED
10 
11 #include "include/core/SkM44.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkSize.h"
14 #include "modules/skottie/src/SkottieValue.h"
15 #include "modules/skottie/src/Transform.h"
16 
17 namespace skjson {
18 class ObjectValue;
19 }
20 namespace sksg {
21 class Transform;
22 }
23 
24 namespace skottie {
25 namespace internal {
26 class AnimationBuilder;
27 
28 class CameraAdaper final : public TransformAdapter3D {
29 public:
30     CameraAdaper(const skjson::ObjectValue& jlayer,
31                  const skjson::ObjectValue& jtransform,
32                  const AnimationBuilder& abuilder,
33                  const SkSize& viewport_size);
34     ~CameraAdaper() override;
35 
36     // Used in the absence of an explicit camera layer.
37     static sk_sp<sksg::Transform> DefaultCameraTransform(const SkSize& viewport_size);
38 
39     SkM44 totalMatrix() const override;
40 
41 private:
42     enum class CameraType {
43         kOneNode, // implicitly facing forward (decreasing z), does not auto-orient
44         kTwoNode, // explicitly facing a POI (the anchor point), auto-orients
45     };
46 
47     SkV3 poi(const SkV3& pos) const;
48 
49     const SkSize     fViewportSize;
50     const CameraType fType;
51 
52     ScalarValue fZoom = 0;
53 
54     using INHERITED = TransformAdapter3D;
55 };
56 
57 } // namespace internal
58 } // namespace skottie
59 
60 #endif // SkottieCamera_DEFINED
61