c80ee456ad
This reverts commit 046c2b7d90
.
Reason for revert: need to update/guard flutter
Original change's description:
> move onto new factories for SkMatrix
>
> Just rename, no functional changes expected.
>
> Change-Id: Id77ab1cf6b1cab35087a7c56000750912cf47383
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290831
> Commit-Queue: Mike Reed <reed@google.com>
> Reviewed-by: Florin Malita <fmalita@chromium.org>
TBR=fmalita@chromium.org,reed@google.com
Change-Id: Ic74f177128913374b8c60b4df88f04cf72fbacb3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291359
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
118 lines
2.8 KiB
C++
118 lines
2.8 KiB
C++
/*
|
|
* 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 "modules/sksg/include/SkSGEffectNode.h"
|
|
|
|
class SkM44;
|
|
class SkMatrix;
|
|
|
|
namespace sksg {
|
|
|
|
/**
|
|
* Transformations base class.
|
|
*/
|
|
class Transform : public Node {
|
|
public:
|
|
// Compose T' = A x B
|
|
static sk_sp<Transform> MakeConcat(sk_sp<Transform> a, sk_sp<Transform> b);
|
|
|
|
// T' = Inv(T)
|
|
static sk_sp<Transform> MakeInverse(sk_sp<Transform> t);
|
|
|
|
protected:
|
|
Transform();
|
|
|
|
virtual bool is44() const = 0;
|
|
|
|
virtual SkMatrix asMatrix() const = 0;
|
|
virtual SkM44 asM44 () const = 0;
|
|
|
|
private:
|
|
friend class TransformPriv;
|
|
|
|
using INHERITED = Node;
|
|
};
|
|
|
|
/**
|
|
* Concrete, matrix-backed Transform.
|
|
*
|
|
* Supported instantiations: SkMatrix, SkM44.
|
|
*
|
|
* Sample use:
|
|
*
|
|
* auto m33 = Matrix<SkMatrix>::Make(SkMatrix::I());
|
|
* ...
|
|
* m33->setMatrix(SkMatrix::MakeTrans(10, 10));
|
|
*
|
|
*/
|
|
template <typename T>
|
|
class Matrix final : public Transform {
|
|
public:
|
|
template <typename = std::enable_if<std::is_same<T, SkMatrix>::value ||
|
|
std::is_same<T, SkM44 >::value>>
|
|
static sk_sp<Matrix> Make(const T& m) { return sk_sp<Matrix>(new Matrix(m)); }
|
|
|
|
SG_ATTRIBUTE(Matrix, T, fMatrix)
|
|
|
|
protected:
|
|
explicit Matrix(const T& m) : fMatrix(m) {}
|
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override {
|
|
return SkRect::MakeEmpty();
|
|
}
|
|
|
|
bool is44() const override { return std::is_same<T, SkM44>::value; }
|
|
|
|
SkMatrix asMatrix() const override;
|
|
SkM44 asM44 () const override;
|
|
|
|
private:
|
|
T fMatrix;
|
|
|
|
using INHERITED = Transform;
|
|
};
|
|
|
|
/**
|
|
* Concrete Effect node, binding a Transform to a RenderNode.
|
|
*/
|
|
class TransformEffect final : public EffectNode {
|
|
public:
|
|
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)))
|
|
: nullptr;
|
|
}
|
|
|
|
static sk_sp<TransformEffect> Make(sk_sp<RenderNode> child, const SkMatrix& m) {
|
|
return Make(std::move(child), Matrix<SkMatrix>::Make(m));
|
|
}
|
|
|
|
~TransformEffect() override;
|
|
|
|
const sk_sp<Transform>& getTransform() const { return fTransform; }
|
|
|
|
protected:
|
|
void onRender(SkCanvas*, const RenderContext*) const override;
|
|
const RenderNode* onNodeAt(const SkPoint&) const override;
|
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
|
|
|
private:
|
|
TransformEffect(sk_sp<RenderNode>, sk_sp<Transform>);
|
|
|
|
const sk_sp<Transform> fTransform;
|
|
|
|
typedef EffectNode INHERITED;
|
|
};
|
|
|
|
} // namespace sksg
|
|
|
|
#endif // SkSGTransform_DEFINED
|