2017-12-19 17:21:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSGTransform_DEFINED
|
|
|
|
#define SkSGTransform_DEFINED
|
|
|
|
|
|
|
|
#include "SkSGEffectNode.h"
|
|
|
|
|
|
|
|
#include "SkMatrix.h"
|
2019-01-09 20:37:57 +00:00
|
|
|
#include "SkMatrix44.h"
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
/**
|
2019-01-09 20:37:57 +00:00
|
|
|
* Transformations base class.
|
2018-01-05 02:11:55 +00:00
|
|
|
*/
|
2019-01-09 20:37:57 +00:00
|
|
|
class Transform : public Node {
|
2018-01-05 02:11:55 +00:00
|
|
|
public:
|
2019-01-09 20:37:57 +00:00
|
|
|
// Compose T = A x B
|
|
|
|
static sk_sp<Transform> MakeConcat(sk_sp<Transform> a, sk_sp<Transform> b);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Transform();
|
|
|
|
|
2019-01-10 16:27:13 +00:00
|
|
|
virtual SkMatrix asMatrix () const = 0;
|
|
|
|
virtual SkMatrix44 asMatrix44() const = 0;
|
|
|
|
|
2019-01-09 20:37:57 +00:00
|
|
|
private:
|
2019-01-10 16:27:13 +00:00
|
|
|
friend class TransformPriv;
|
|
|
|
|
2019-01-09 20:37:57 +00:00
|
|
|
using INHERITED = Node;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete, SkMatrix-backed transformation.
|
|
|
|
*/
|
|
|
|
class Matrix final : public Transform {
|
|
|
|
public:
|
|
|
|
static sk_sp<Matrix> Make(const SkMatrix& m);
|
2018-01-05 02:11:55 +00:00
|
|
|
|
2018-09-12 14:15:34 +00:00
|
|
|
SG_ATTRIBUTE(Matrix, SkMatrix, fMatrix)
|
2018-01-05 02:11:55 +00:00
|
|
|
|
|
|
|
protected:
|
2018-09-12 14:15:34 +00:00
|
|
|
explicit Matrix(const SkMatrix&);
|
2018-01-05 02:11:55 +00:00
|
|
|
|
2018-01-05 16:32:31 +00:00
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
2018-01-05 02:11:55 +00:00
|
|
|
|
2019-01-10 16:27:13 +00:00
|
|
|
SkMatrix asMatrix () const override;
|
|
|
|
SkMatrix44 asMatrix44() const override;
|
|
|
|
|
2018-01-05 02:11:55 +00:00
|
|
|
private:
|
2018-09-12 14:15:34 +00:00
|
|
|
SkMatrix fMatrix;
|
2018-01-05 02:11:55 +00:00
|
|
|
|
2019-01-09 20:37:57 +00:00
|
|
|
using INHERITED = Transform;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete, SkMatrix44-backed transformation.
|
|
|
|
*/
|
|
|
|
class Matrix44 final : public Transform {
|
|
|
|
public:
|
|
|
|
static sk_sp<Matrix44> Make(const SkMatrix44& m);
|
|
|
|
|
|
|
|
SG_ATTRIBUTE(Matrix, SkMatrix44, fMatrix)
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit Matrix44(const SkMatrix44&);
|
|
|
|
|
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
|
|
|
|
2019-01-10 16:27:13 +00:00
|
|
|
SkMatrix asMatrix () const override;
|
|
|
|
SkMatrix44 asMatrix44() const override;
|
|
|
|
|
2019-01-09 20:37:57 +00:00
|
|
|
private:
|
|
|
|
SkMatrix44 fMatrix;
|
|
|
|
|
|
|
|
using INHERITED = Transform;
|
2018-01-05 02:11:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-01-09 20:37:57 +00:00
|
|
|
* Concrete Effect node, binding a Transform to a RenderNode.
|
2017-12-19 17:21:02 +00:00
|
|
|
*/
|
2019-01-09 20:37:57 +00:00
|
|
|
class TransformEffect final : public EffectNode {
|
2017-12-19 17:21:02 +00:00
|
|
|
public:
|
2019-01-09 20:37:57 +00:00
|
|
|
static sk_sp<TransformEffect> Make(sk_sp<RenderNode> child, sk_sp<Transform> transform) {
|
|
|
|
return child && transform
|
|
|
|
? sk_sp<TransformEffect>(new TransformEffect(std::move(child), std::move(transform)))
|
2018-01-05 02:11:55 +00:00
|
|
|
: nullptr;
|
2017-12-19 17:21:02 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 20:37:57 +00:00
|
|
|
static sk_sp<TransformEffect> Make(sk_sp<RenderNode> child, const SkMatrix& m) {
|
2018-01-05 02:11:55 +00:00
|
|
|
return Make(std::move(child), Matrix::Make(m));
|
|
|
|
}
|
|
|
|
|
2019-01-09 20:37:57 +00:00
|
|
|
~TransformEffect() override;
|
2018-01-05 02:11:55 +00:00
|
|
|
|
2019-01-09 20:37:57 +00:00
|
|
|
const sk_sp<Transform>& getTransform() const { return fTransform; }
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
protected:
|
2018-08-09 11:40:01 +00:00
|
|
|
void onRender(SkCanvas*, const RenderContext*) const override;
|
2017-12-19 17:21:02 +00:00
|
|
|
|
2018-01-05 16:32:31 +00:00
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
private:
|
2019-01-09 20:37:57 +00:00
|
|
|
TransformEffect(sk_sp<RenderNode>, sk_sp<Transform>);
|
2018-01-19 20:07:29 +00:00
|
|
|
|
2019-01-09 20:37:57 +00:00
|
|
|
const sk_sp<Transform> fTransform;
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
typedef EffectNode INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sksg
|
|
|
|
|
|
|
|
#endif // SkSGTransform_DEFINED
|