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..51b6e626d65cac083edda61e7318f545f1c32f00 |
--- /dev/null |
+++ b/cc/base/scale_translate2d.h |
@@ -0,0 +1,104 @@ |
+// 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 "ui/gfx/geometry/rect_f.h" |
+#include "ui/gfx/geometry/vector2d_f.h" |
+ |
+class SkCanvas; |
+ |
+namespace cc { |
+ |
+class ScaleTranslate2d { |
enne (OOO)
2016/08/29 20:21:18
There are a lot of functions here. Which of these
|
+ public: |
+ constexpr ScaleTranslate2d() : pre_scale_(0.f) {} |
+ constexpr ScaleTranslate2d(float pre_scale, const gfx::Vector2dF& translation) |
+ : pre_scale_(pre_scale), translation_(translation) {} |
+ |
+ bool operator==(const ScaleTranslate2d& other) const { |
+ return pre_scale_ == other.pre_scale_ && translation_ == other.translation_; |
+ } |
+ bool operator!=(const ScaleTranslate2d& other) const { |
+ return !(*this == other); |
+ } |
+ |
+ static ScaleTranslate2d PreScale(const ScaleTranslate2d& t, float scale) { |
+ return ScaleTranslate2d(t.pre_scale_ * scale, t.translation_); |
+ } |
+ void PreScale(float scale) { *this = PreScale(*this, scale); } |
+ |
+ static ScaleTranslate2d PostScale(const ScaleTranslate2d& t, float scale) { |
+ return ScaleTranslate2d(t.pre_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.pre_scale_, |
+ gfx::ScaleVector2d(translation, t.pre_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.pre_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.pre_scale_ * post.pre_scale_, |
+ gfx::ScaleVector2d(pre.translation_, post.pre_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.f / t.pre_scale_, |
+ gfx::ScaleVector2d(-t.translation_, 1.f / t.pre_scale_)); |
+ } |
+ void Invert() { *this = Inverse(*this); } |
+ |
+ gfx::PointF Transform(const gfx::PointF& p) const { |
+ return gfx::ScalePoint(p, pre_scale_) + translation_; |
+ } |
+ gfx::PointF TransformReverse(const gfx::PointF& p) const { |
+ return gfx::ScalePoint(p - translation_, 1.f / pre_scale_); |
+ } |
+ |
+ gfx::RectF Transform(const gfx::RectF& r) const { |
enne (OOO)
2016/08/29 20:21:18
Would it make sense to make these functions match
|
+ return gfx::ScaleRect(r, pre_scale_) + translation_; |
+ } |
+ gfx::RectF TransformReverse(const gfx::RectF& r) const { |
+ return gfx::ScaleRect(r - translation_, 1.f / pre_scale_); |
+ } |
+ |
+ void ApplyToCanvas(SkCanvas* canvas) const; |
+ |
+ float pre_scale() const { return pre_scale_; } |
+ gfx::Vector2dF translation() const { return translation_; } |
+ |
+ private: |
+ float pre_scale_; |
enne (OOO)
2016/08/29 20:21:18
bikeshed: I'd just call this "scale" with comments
|
+ gfx::Vector2dF translation_; |
+}; |
+ |
+} // namespace cc |
+ |
+#endif // CC_BASE_SCALE_TRANSLATE2D_H_ |