Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
transform.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 UI_GFX_TRANSFORM_H_
6#define UI_GFX_TRANSFORM_H_
7
8#include <iosfwd>
9#include <string>
10
11#include "geometry/rect_f.h"
12#include "gfx_export.h"
13
14namespace gfx {
15
16class RectF;
17
18// 4x4 transformation matrix. Transform is cheap and explicitly allows
19// copy/assign.
21 public:
22 Transform();
23
24 Transform(float col1row1,
25 float col2row1,
26 float col3row1,
27 float col4row1,
28 float col1row2,
29 float col2row2,
30 float col3row2,
31 float col4row2,
32 float col1row3,
33 float col2row3,
34 float col3row3,
35 float col4row3,
36 float col1row4,
37 float col2row4,
38 float col3row4,
39 float col4row4);
40 // Constructs a transform from explicit 2d elements. All other matrix
41 // elements remain the same as the corresponding elements of an identity
42 // matrix.
43 Transform(float col1row1,
44 float col2row1,
45 float col1row2,
46 float col2row2,
47 float x_translation,
48 float y_translation);
49
50 bool operator==(const Transform& rhs) const;
51 bool operator!=(const Transform& rhs) const { return !(*this == rhs); };
52
53 float operator[](int index) const {
54 BASE_DCHECK((unsigned)index < 16);
55 return matrix_[index];
56 }
57
58 // Returns true if this is the identity matrix.
59 bool IsIdentity() const;
60
61 // Applies the current transformation on a scaling and assigns the result
62 // to |this|.
63 void Scale(float x, float y);
64
65 // Applies transformation on the given rect. After the function completes,
66 // |rect| will be the smallest axis aligned bounding rect containing the
67 // transformed rect.
68 void TransformRect(RectF* rect) const;
69
70 // Applies transformation on the given point
71 void TransformPoint(PointF* point) const;
72
73 std::string ToString() const;
74
75 private:
76 // Row-major array
77 float matrix_[16];
78 bool is_identity_;
79
80 void UpdateIdentity();
81};
82
83// This is declared here for use in gtest-based unit tests but is defined in
84// the //ui/gfx:test_support target. Depend on that to use this in your unit
85// test. This should not be used in production code - call ToString() instead.
86void PrintTo(const Transform& transform, ::std::ostream* os);
87
88} // namespace gfx
89
90#endif // UI_GFX_TRANSFORM_H_
bool operator!=(const Transform &rhs) const
Definition transform.h:51
float operator[](int index) const
Definition transform.h:53
bool operator==(const FlutterPoint &a, const FlutterPoint &b)
#define GFX_EXPORT
Definition gfx_export.h:26
double y
double x
Definition insets.cc:10
void PrintTo(const Point &point, ::std::ostream *os)
Definition gfx_util.cc:74
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
#define BASE_DCHECK(condition)
Definition logging.h:63