Skia
2D Graphics Library
SkSGTransform.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 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 SkSGTransform_DEFINED
9 #define SkSGTransform_DEFINED
10 
12 
13 class SkM44;
14 class SkMatrix;
15 
16 namespace sksg {
17 
21 class Transform : public Node {
22 public:
23  // Compose T' = A x B
25 
26  // T' = Inv(T)
28 
29 protected:
31 
32  virtual bool is44() const = 0;
33 
34  virtual SkMatrix asMatrix() const = 0;
35  virtual SkM44 asM44 () const = 0;
36 
37 private:
38  friend class TransformPriv;
39 
40  using INHERITED = Node;
41 };
42 
55 template <typename T>
56 class Matrix final : public Transform {
57 public:
58  template <typename = std::enable_if<std::is_same<T, SkMatrix>::value ||
59  std::is_same<T, SkM44 >::value>>
60  static sk_sp<Matrix> Make(const T& m) { return sk_sp<Matrix>(new Matrix(m)); }
61 
62  SG_ATTRIBUTE(Matrix, T, fMatrix)
63 
64 protected:
65  explicit Matrix(const T& m) : fMatrix(m) {}
66 
68  return SkRect::MakeEmpty();
69  }
70 
71  bool is44() const override { return std::is_same<T, SkM44>::value; }
72 
73  SkMatrix asMatrix() const override;
74  SkM44 asM44 () const override;
75 
76 private:
77  T fMatrix;
78 
79  using INHERITED = Transform;
80 };
81 
85 class TransformEffect final : public EffectNode {
86 public:
88  return child && transform
89  ? sk_sp<TransformEffect>(new TransformEffect(std::move(child), std::move(transform)))
90  : nullptr;
91  }
92 
94  return Make(std::move(child), Matrix<SkMatrix>::Make(m));
95  }
96 
97  ~TransformEffect() override;
98 
99  const sk_sp<Transform>& getTransform() const { return fTransform; }
100 
101 protected:
102  void onRender(SkCanvas*, const RenderContext*) const override;
103  const RenderNode* onNodeAt(const SkPoint&) const override;
104 
106 
107 private:
109 
110  const sk_sp<Transform> fTransform;
111 
112  using INHERITED = EffectNode;
113 };
114 
115 } // namespace sksg
116 
117 #endif // SkSGTransform_DEFINED
#define SG_ATTRIBUTE(attr_name, attr_type, attr_container)
Definition: SkSGNode.h:99
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
4x4 matrix used by SkCanvas and other parts of Skia.
Definition: SkM44.h:150
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
Definition: SkRefCnt.h:119
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:220
Base class for nodes which apply some transformation when rendering their descendants.
Definition: SkSGEffectNode.h:21
EffectNode(sk_sp< RenderNode >, uint32_t inval_traits=0)
Receiver for invalidation events.
Definition: SkSGInvalidationController.h:25
Concrete, matrix-backed Transform.
Definition: SkSGTransform.h:56
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition: SkSGTransform.h:67
Matrix(const T &m)
Definition: SkSGTransform.h:65
static sk_sp< Matrix > Make(const T &m)
Definition: SkSGTransform.h:60
SkMatrix asMatrix() const override
bool is44() const override
Definition: SkSGTransform.h:71
SkM44 asM44() const override
Base class for all scene graph nodes.
Definition: SkSGNode.h:32
Node(uint32_t invalTraits)
Base class for nodes which can render to a canvas.
Definition: SkSGRenderNode.h:27
Concrete Effect node, binding a Transform to a RenderNode.
Definition: SkSGTransform.h:85
const RenderNode * onNodeAt(const SkPoint &) const override
static sk_sp< TransformEffect > Make(sk_sp< RenderNode > child, const SkMatrix &m)
Definition: SkSGTransform.h:93
~TransformEffect() override
const sk_sp< Transform > & getTransform() const
Definition: SkSGTransform.h:99
static sk_sp< TransformEffect > Make(sk_sp< RenderNode > child, sk_sp< Transform > transform)
Definition: SkSGTransform.h:87
void onRender(SkCanvas *, const RenderContext *) const override
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Transformations base class.
Definition: SkSGTransform.h:21
virtual SkM44 asM44() const =0
friend class TransformPriv
Definition: SkSGTransform.h:38
static sk_sp< Transform > MakeInverse(sk_sp< Transform > t)
static sk_sp< Transform > MakeConcat(sk_sp< Transform > a, sk_sp< Transform > b)
virtual bool is44() const =0
virtual SkMatrix asMatrix() const =0
Definition: Skottie.h:30
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
static constexpr SkRect MakeEmpty()
Returns constructed SkRect set to (0, 0, 0, 0).
Definition: SkRect.h:595
Definition: SkSGRenderNode.h:53