| Index: cc/base/scale_translate2d.h
|
| diff --git a/cc/base/scale_translate2d.h b/cc/base/scale_translate2d.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e045f8cfd84446e8bad6eaf202ffcd9749517058
|
| --- /dev/null
|
| +++ b/cc/base/scale_translate2d.h
|
| @@ -0,0 +1,106 @@
|
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CC_BASE_SCALE_TRANSLATE2D_H_
|
| +#define CC_BASE_SCALE_TRANSLATE2D_H_
|
| +
|
| +#include "cc/base/base_export.h"
|
| +#include "ui/gfx/geometry/rect_f.h"
|
| +#include "ui/gfx/geometry/vector2d_f.h"
|
| +
|
| +class SkCanvas;
|
| +
|
| +namespace cc {
|
| +
|
| +class CC_BASE_EXPORT ScaleTranslate2d {
|
| + public:
|
| + constexpr ScaleTranslate2d() : scale_(1.f) {}
|
| + constexpr ScaleTranslate2d(float scale, const gfx::Vector2dF& translation)
|
| + : scale_(scale), translation_(translation) {}
|
| +
|
| + bool operator==(const ScaleTranslate2d& other) const {
|
| + return scale_ == other.scale_ && translation_ == other.translation_;
|
| + }
|
| + bool operator!=(const ScaleTranslate2d& other) const {
|
| + return !(*this == other);
|
| + }
|
| +
|
| + static ScaleTranslate2d PreScale(const ScaleTranslate2d& t, float scale) {
|
| + return ScaleTranslate2d(t.scale_ * scale, t.translation_);
|
| + }
|
| + void PreScale(float scale) { *this = PreScale(*this, scale); }
|
| +
|
| + static ScaleTranslate2d PostScale(const ScaleTranslate2d& t, float scale) {
|
| + return ScaleTranslate2d(t.scale_ * scale,
|
| + gfx::ScaleVector2d(t.translation_, scale));
|
| + }
|
| + void PostScale(float scale) { *this = PostScale(*this, scale); }
|
| +
|
| + static ScaleTranslate2d PreTranslate(const ScaleTranslate2d& t,
|
| + const gfx::Vector2dF& translation) {
|
| + return ScaleTranslate2d(
|
| + t.scale_, gfx::ScaleVector2d(translation, t.scale_) + t.translation_);
|
| + }
|
| + void PreTranslate(const gfx::Vector2dF& translation) {
|
| + *this = PreTranslate(*this, translation);
|
| + }
|
| +
|
| + static ScaleTranslate2d PostTranslate(const ScaleTranslate2d& t,
|
| + const gfx::Vector2dF& translation) {
|
| + return ScaleTranslate2d(t.scale_, t.translation_ + translation);
|
| + }
|
| + void PostTranslate(const gfx::Vector2dF& translation) {
|
| + *this = PostTranslate(*this, translation);
|
| + }
|
| +
|
| + static ScaleTranslate2d Concat(const ScaleTranslate2d& post,
|
| + const ScaleTranslate2d& pre) {
|
| + return ScaleTranslate2d(
|
| + pre.scale_ * post.scale_,
|
| + gfx::ScaleVector2d(pre.translation_, post.scale_) + post.translation_);
|
| + }
|
| + void PreConcat(const ScaleTranslate2d& other) {
|
| + *this = Concat(*this, other);
|
| + }
|
| + void PostConcat(const ScaleTranslate2d& other) {
|
| + *this = Concat(other, *this);
|
| + }
|
| +
|
| + static ScaleTranslate2d Inverse(const ScaleTranslate2d& t) {
|
| + return ScaleTranslate2d(1 / t.scale_,
|
| + gfx::ScaleVector2d(-t.translation_, 1 / t.scale_));
|
| + }
|
| + void Invert() { *this = Inverse(*this); }
|
| +
|
| + gfx::PointF TransformPoint(const gfx::PointF& p) const {
|
| + return gfx::ScalePoint(p, scale_) + translation_;
|
| + }
|
| + gfx::PointF TransformPointReverse(const gfx::PointF& p) const {
|
| + return gfx::ScalePoint(p - translation_, 1.f / scale_);
|
| + }
|
| +
|
| + gfx::RectF TransformRect(const gfx::RectF& r) const {
|
| + return gfx::ScaleRect(r, scale_) + translation_;
|
| + }
|
| + gfx::RectF TransformRectReverse(const gfx::RectF& r) const {
|
| + return gfx::ScaleRect(r - translation_, 1.f / scale_);
|
| + }
|
| +
|
| + void ApplyToCanvas(SkCanvas* canvas) const;
|
| +
|
| + float scale() const { return scale_; }
|
| + gfx::Vector2dF translation() const { return translation_; }
|
| +
|
| + std::string ToString() const { return "todo"; }
|
| +
|
| + private:
|
| + // Scale is applied before translation, i.e.
|
| + // this->Transform(p) == scale_ * p + translation_
|
| + float scale_;
|
| + gfx::Vector2dF translation_;
|
| +};
|
| +
|
| +} // namespace cc
|
| +
|
| +#endif // CC_BASE_SCALE_TRANSLATE2D_H_
|
|
|