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"
|
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
/**
|
2018-01-05 02:11:55 +00:00
|
|
|
* Concrete node, wrapping an SkMatrix, with an optional parent Matrix (to allow chaining):
|
|
|
|
*
|
|
|
|
* M' = parent x M
|
|
|
|
*/
|
|
|
|
class Matrix : public Node {
|
|
|
|
public:
|
|
|
|
static sk_sp<Matrix> Make(const SkMatrix& m, sk_sp<Matrix> parent = nullptr) {
|
|
|
|
return sk_sp<Matrix>(new Matrix(m, std::move(parent)));
|
|
|
|
}
|
|
|
|
|
|
|
|
~Matrix() override;
|
|
|
|
|
|
|
|
SG_ATTRIBUTE(Matrix, SkMatrix, fLocalMatrix)
|
|
|
|
|
|
|
|
const SkMatrix& getTotalMatrix() const { return fTotalMatrix; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit Matrix(const SkMatrix&, sk_sp<Matrix>);
|
|
|
|
|
|
|
|
RevalidationResult onRevalidate(InvalidationController*, const SkMatrix&) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
sk_sp<Matrix> fParent;
|
|
|
|
SkMatrix fLocalMatrix,
|
|
|
|
fTotalMatrix; // cached during revalidation
|
|
|
|
|
|
|
|
typedef Node INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Concrete Effect node, binding a Matrix to a RenderNode.
|
2017-12-19 17:21:02 +00:00
|
|
|
*/
|
|
|
|
class Transform : public EffectNode {
|
|
|
|
public:
|
2018-01-05 02:11:55 +00:00
|
|
|
static sk_sp<Transform> Make(sk_sp<RenderNode> child, sk_sp<Matrix> matrix) {
|
|
|
|
return child && matrix
|
|
|
|
? sk_sp<Transform>(new Transform(std::move(child), std::move(matrix)))
|
|
|
|
: nullptr;
|
2017-12-19 17:21:02 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 02:11:55 +00:00
|
|
|
static sk_sp<Transform> Make(sk_sp<RenderNode> child, const SkMatrix& m) {
|
|
|
|
return Make(std::move(child), Matrix::Make(m));
|
|
|
|
}
|
|
|
|
|
|
|
|
~Transform() override;
|
|
|
|
|
|
|
|
const sk_sp<Matrix>& getMatrix() const { return fMatrix; }
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
protected:
|
2018-01-05 02:11:55 +00:00
|
|
|
Transform(sk_sp<RenderNode>, sk_sp<Matrix>);
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
void onRender(SkCanvas*) const override;
|
|
|
|
|
2018-01-05 00:21:58 +00:00
|
|
|
RevalidationResult onRevalidate(InvalidationController*, const SkMatrix&) override;
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
private:
|
2018-01-05 02:11:55 +00:00
|
|
|
sk_sp<Matrix> fMatrix;
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
typedef EffectNode INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sksg
|
|
|
|
|
|
|
|
#endif // SkSGTransform_DEFINED
|