Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: cc/base/scale_translate2d.h

Issue 2563743004: [3/5] Add translated rasterization support for RasterBuffer & below (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CC_BASE_SCALE_TRANSLATE2D_H_
6 #define CC_BASE_SCALE_TRANSLATE2D_H_
7
8 #include "ui/gfx/geometry/rect_f.h"
9 #include "ui/gfx/geometry/vector2d_f.h"
10
11 class SkCanvas;
12
13 namespace cc {
14
15 class ScaleTranslate2d {
16 public:
17 constexpr ScaleTranslate2d() : scale_(1.f) { }
18 constexpr ScaleTranslate2d(float scale, const gfx::Vector2dF& translation)
19 : scale_(scale), translation_(translation) {}
20
21 bool operator==(const ScaleTranslate2d& other) const {
22 return scale_ == other.scale_ && translation_ == other.translation_;
23 }
24 bool operator!=(const ScaleTranslate2d& other) const {
25 return !(*this == other);
26 }
27
28 static ScaleTranslate2d PreScale(const ScaleTranslate2d& t, float scale) {
29 return ScaleTranslate2d(t.scale_ * scale, t.translation_);
30 }
31 void PreScale(float scale) { *this = PreScale(*this, scale); }
32
33 static ScaleTranslate2d PostScale(const ScaleTranslate2d& t, float scale) {
34 return ScaleTranslate2d(t.scale_ * scale,
35 gfx::ScaleVector2d(t.translation_, scale));
36 }
37 void PostScale(float scale) { *this = PostScale(*this, scale); }
38
39 static ScaleTranslate2d PreTranslate(const ScaleTranslate2d& t,
40 const gfx::Vector2dF& translation) {
41 return ScaleTranslate2d(
42 t.scale_,
43 gfx::ScaleVector2d(translation, t.scale_) + t.translation_);
44 }
45 void PreTranslate(const gfx::Vector2dF& translation) {
46 *this = PreTranslate(*this, translation);
47 }
48
49 static ScaleTranslate2d PostTranslate(const ScaleTranslate2d& t,
50 const gfx::Vector2dF& translation) {
51 return ScaleTranslate2d(t.scale_, t.translation_ + translation);
52 }
53 void PostTranslate(const gfx::Vector2dF& translation) {
54 *this = PostTranslate(*this, translation);
55 }
56
57 static ScaleTranslate2d Concat(const ScaleTranslate2d& post,
58 const ScaleTranslate2d& pre) {
59 return ScaleTranslate2d(
60 pre.scale_ * post.scale_,
61 gfx::ScaleVector2d(pre.translation_, post.scale_) +
62 post.translation_);
63 }
64 void PreConcat(const ScaleTranslate2d& other) {
65 *this = Concat(*this, other);
66 }
67 void PostConcat(const ScaleTranslate2d& other) {
68 *this = Concat(other, *this);
69 }
70
71 static ScaleTranslate2d Inverse(const ScaleTranslate2d& t) {
72 return ScaleTranslate2d(
73 1 / t.scale_,
74 gfx::ScaleVector2d(-t.translation_, 1 / t.scale_));
75 }
76 void Invert() { *this = Inverse(*this); }
77
78 gfx::PointF TransformPoint(const gfx::PointF& p) const {
79 return gfx::ScalePoint(p, scale_) + translation_;
80 }
81 gfx::PointF TransformPointReverse(const gfx::PointF& p) const {
82 return gfx::ScalePoint(p - translation_, 1.f / scale_);
83 }
84
85 gfx::RectF TransformRect(const gfx::RectF& r) const {
86 return gfx::ScaleRect(r, scale_) + translation_;
87 }
88 gfx::RectF TransformRectReverse(const gfx::RectF& r) const {
89 return gfx::ScaleRect(r - translation_, 1.f / scale_);
90 }
91
92 void ApplyToCanvas(SkCanvas* canvas) const;
93
94 float scale() const { return scale_; }
95 gfx::Vector2dF translation() const { return translation_; }
96
97 std::string ToString() const { return "todo"; }
98
99 private:
100 // Scale is applied before translation, i.e.
101 // this->Transform(p) == scale_ * p + translation_
102 float scale_;
103 gfx::Vector2dF translation_;
104 };
105
106 } // namespace cc
107
108 #endif // CC_BASE_SCALE_TRANSLATE2D_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698