blob: 3bf3903929d5b598f1a60823d0aafc6d089fba43 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mathias Agopianeda65402010-02-22 03:15:57 -080017#include <math.h>
18
Lloyd Pique32cbe282018-10-19 13:09:22 -070019#include <android-base/stringprintf.h>
Mathias Agopianeda65402010-02-22 03:15:57 -080020#include <cutils/compiler.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021#include <ui/Region.h>
Peiyong Linefefaac2018-08-17 12:27:51 -070022#include <ui/Transform.h>
23#include <utils/String8.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080024
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025namespace android {
Peiyong Linefefaac2018-08-17 12:27:51 -070026namespace ui {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Mathias Agopianeda65402010-02-22 03:15:57 -080028Transform::Transform() {
29 reset();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030}
31
32Transform::Transform(const Transform& other)
Mathias Agopianeda65402010-02-22 03:15:57 -080033 : mMatrix(other.mMatrix), mType(other.mType) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034}
35
Lloyd Piqueb62cebc2019-11-20 18:31:52 -080036Transform::Transform(uint32_t orientation, int w, int h) {
37 set(orientation, w, h);
Chih-Chung Chang52e72002010-01-21 17:31:06 -080038}
39
Peiyong Linefefaac2018-08-17 12:27:51 -070040Transform::~Transform() = default;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041
Mathias Agopiand1296592010-03-09 19:17:47 -080042static const float EPSILON = 0.0f;
Mathias Agopianeda65402010-02-22 03:15:57 -080043
44bool Transform::isZero(float f) {
Mathias Agopiand1296592010-03-09 19:17:47 -080045 return fabs(f) <= EPSILON;
Mathias Agopianeda65402010-02-22 03:15:57 -080046}
47
Mathias Agopiand1296592010-03-09 19:17:47 -080048bool Transform::absIsOne(float f) {
49 return isZero(fabs(f) - 1.0f);
Mathias Agopianeda65402010-02-22 03:15:57 -080050}
51
Lloyd Piqueea629282019-12-03 15:57:10 -080052bool Transform::operator==(const Transform& other) const {
53 return mMatrix[0][0] == other.mMatrix[0][0] && mMatrix[0][1] == other.mMatrix[0][1] &&
54 mMatrix[0][2] == other.mMatrix[0][2] && mMatrix[1][0] == other.mMatrix[1][0] &&
55 mMatrix[1][1] == other.mMatrix[1][1] && mMatrix[1][2] == other.mMatrix[1][2] &&
56 mMatrix[2][0] == other.mMatrix[2][0] && mMatrix[2][1] == other.mMatrix[2][1] &&
57 mMatrix[2][2] == other.mMatrix[2][2];
Lloyd Piqueea629282019-12-03 15:57:10 -080058}
59
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060Transform Transform::operator * (const Transform& rhs) const
61{
Mathias Agopianeda65402010-02-22 03:15:57 -080062 if (CC_LIKELY(mType == IDENTITY))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 return rhs;
64
65 Transform r(*this);
Mathias Agopianeda65402010-02-22 03:15:57 -080066 if (rhs.mType == IDENTITY)
67 return r;
68
69 // TODO: we could use mType to optimize the matrix multiply
70 const mat33& A(mMatrix);
71 const mat33& B(rhs.mMatrix);
72 mat33& D(r.mMatrix);
Peiyong Linefefaac2018-08-17 12:27:51 -070073 for (size_t i = 0; i < 3; i++) {
Mathias Agopianeda65402010-02-22 03:15:57 -080074 const float v0 = A[0][i];
75 const float v1 = A[1][i];
76 const float v2 = A[2][i];
77 D[0][i] = v0*B[0][0] + v1*B[0][1] + v2*B[0][2];
78 D[1][i] = v0*B[1][0] + v1*B[1][1] + v2*B[1][2];
79 D[2][i] = v0*B[2][0] + v1*B[2][1] + v2*B[2][2];
80 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081 r.mType |= rhs.mType;
Mathias Agopianeda65402010-02-22 03:15:57 -080082
83 // TODO: we could recompute this value from r and rhs
84 r.mType &= 0xFF;
85 r.mType |= UNKNOWN_TYPE;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086 return r;
87}
88
chaviwc01e1372020-07-01 12:37:31 -070089Transform Transform::operator * (float value) const {
90 Transform r(*this);
91 const mat33& M(mMatrix);
92 mat33& R(r.mMatrix);
93 for (size_t i = 0; i < 3; i++) {
94 for (size_t j = 0; j < 2; j++) {
95 R[i][j] = M[i][j] * value;
96 }
97 }
98 r.type();
99 return r;
100}
101
Peiyong Linefefaac2018-08-17 12:27:51 -0700102Transform& Transform::operator=(const Transform& other) {
103 mMatrix = other.mMatrix;
104 mType = other.mType;
105 return *this;
106}
107
Mathias Agopianff2ed702013-09-01 21:36:12 -0700108const vec3& Transform::operator [] (size_t i) const {
109 return mMatrix[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110}
111
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700112float Transform::tx() const {
113 return mMatrix[2][0];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800114}
115
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700116float Transform::ty() const {
117 return mMatrix[2][1];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118}
119
chaviwc01e1372020-07-01 12:37:31 -0700120float Transform::dsdx() const {
Robert Carre07e1032018-11-26 12:55:53 -0800121 return mMatrix[0][0];
122}
123
chaviwc01e1372020-07-01 12:37:31 -0700124float Transform::dtdx() const {
125 return mMatrix[1][0];
126}
127
128float Transform::dtdy() const {
129 return mMatrix[0][1];
130}
131
132float Transform::dsdy() const {
Robert Carre07e1032018-11-26 12:55:53 -0800133 return mMatrix[1][1];
134}
135
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136void Transform::reset() {
Mathias Agopianeda65402010-02-22 03:15:57 -0800137 mType = IDENTITY;
Peiyong Linefefaac2018-08-17 12:27:51 -0700138 for(size_t i = 0; i < 3; i++) {
Mathias Agopianeda65402010-02-22 03:15:57 -0800139 vec3& v(mMatrix[i]);
Peiyong Linefefaac2018-08-17 12:27:51 -0700140 for (size_t j = 0; j < 3; j++)
141 v[j] = ((i == j) ? 1.0f : 0.0f);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 }
143}
144
Mathias Agopianeda65402010-02-22 03:15:57 -0800145void Transform::set(float tx, float ty)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146{
Mathias Agopianeda65402010-02-22 03:15:57 -0800147 mMatrix[2][0] = tx;
148 mMatrix[2][1] = ty;
149 mMatrix[2][2] = 1.0f;
150
151 if (isZero(tx) && isZero(ty)) {
152 mType &= ~TRANSLATE;
153 } else {
154 mType |= TRANSLATE;
155 }
156}
157
158void Transform::set(float a, float b, float c, float d)
159{
160 mat33& M(mMatrix);
161 M[0][0] = a; M[1][0] = b;
162 M[0][1] = c; M[1][1] = d;
163 M[0][2] = 0; M[1][2] = 0;
164 mType = UNKNOWN_TYPE;
165}
166
Mathias Agopiand1296592010-03-09 19:17:47 -0800167status_t Transform::set(uint32_t flags, float w, float h)
Mathias Agopianeda65402010-02-22 03:15:57 -0800168{
Mathias Agopiand1296592010-03-09 19:17:47 -0800169 if (flags & ROT_INVALID) {
170 // that's not allowed!
171 reset();
172 return BAD_VALUE;
173 }
174
Mathias Agopian0694d0f2010-10-24 14:53:05 -0700175 Transform H, V, R;
Mathias Agopian883dffa2010-10-25 18:29:35 -0700176 if (flags & ROT_90) {
177 // w & h are inverted when rotating by 90 degrees
Peiyong Lin3db42342018-08-16 09:15:59 -0700178 std::swap(w, h);
Mathias Agopian883dffa2010-10-25 18:29:35 -0700179 }
180
Mathias Agopianeda65402010-02-22 03:15:57 -0800181 if (flags & FLIP_H) {
Mathias Agopian0694d0f2010-10-24 14:53:05 -0700182 H.mType = (FLIP_H << 8) | SCALE;
183 H.mType |= isZero(w) ? IDENTITY : TRANSLATE;
184 mat33& M(H.mMatrix);
185 M[0][0] = -1;
186 M[2][0] = w;
Mathias Agopianeda65402010-02-22 03:15:57 -0800187 }
188
189 if (flags & FLIP_V) {
Mathias Agopian0694d0f2010-10-24 14:53:05 -0700190 V.mType = (FLIP_V << 8) | SCALE;
191 V.mType |= isZero(h) ? IDENTITY : TRANSLATE;
192 mat33& M(V.mMatrix);
193 M[1][1] = -1;
194 M[2][1] = h;
Mathias Agopianeda65402010-02-22 03:15:57 -0800195 }
196
Mathias Agopian0694d0f2010-10-24 14:53:05 -0700197 if (flags & ROT_90) {
Mathias Agopian883dffa2010-10-25 18:29:35 -0700198 const float original_w = h;
Mathias Agopian0694d0f2010-10-24 14:53:05 -0700199 R.mType = (ROT_90 << 8) | ROTATE;
Mathias Agopian883dffa2010-10-25 18:29:35 -0700200 R.mType |= isZero(original_w) ? IDENTITY : TRANSLATE;
Mathias Agopian0694d0f2010-10-24 14:53:05 -0700201 mat33& M(R.mMatrix);
Mathias Agopian883dffa2010-10-25 18:29:35 -0700202 M[0][0] = 0; M[1][0] =-1; M[2][0] = original_w;
Mathias Agopian0694d0f2010-10-24 14:53:05 -0700203 M[0][1] = 1; M[1][1] = 0;
Mathias Agopianeda65402010-02-22 03:15:57 -0800204 }
205
Mathias Agopian883dffa2010-10-25 18:29:35 -0700206 *this = (R*(H*V));
Mathias Agopiand1296592010-03-09 19:17:47 -0800207 return NO_ERROR;
Mathias Agopianeda65402010-02-22 03:15:57 -0800208}
209
chaviwc01e1372020-07-01 12:37:31 -0700210void Transform::set(const std::array<float, 9>& matrix) {
211 mat33& M(mMatrix);
212 M[0][0] = matrix[0]; M[1][0] = matrix[1]; M[2][0] = matrix[2];
213 M[0][1] = matrix[3]; M[1][1] = matrix[4]; M[2][1] = matrix[5];
214 M[0][2] = matrix[6]; M[1][2] = matrix[7]; M[2][2] = matrix[8];
215 mType = UNKNOWN_TYPE;
216 type();
217}
218
Mathias Agopianff2ed702013-09-01 21:36:12 -0700219vec2 Transform::transform(const vec2& v) const {
Mathias Agopianeda65402010-02-22 03:15:57 -0800220 vec2 r;
221 const mat33& M(mMatrix);
222 r[0] = M[0][0]*v[0] + M[1][0]*v[1] + M[2][0];
223 r[1] = M[0][1]*v[0] + M[1][1]*v[1] + M[2][1];
224 return r;
225}
226
Mathias Agopianff2ed702013-09-01 21:36:12 -0700227vec3 Transform::transform(const vec3& v) const {
Mathias Agopianeda65402010-02-22 03:15:57 -0800228 vec3 r;
229 const mat33& M(mMatrix);
230 r[0] = M[0][0]*v[0] + M[1][0]*v[1] + M[2][0]*v[2];
231 r[1] = M[0][1]*v[0] + M[1][1]*v[1] + M[2][1]*v[2];
232 r[2] = M[0][2]*v[0] + M[1][2]*v[1] + M[2][2]*v[2];
233 return r;
234}
235
chaviwc01e1372020-07-01 12:37:31 -0700236vec2 Transform::transform(float x, float y) const {
237 return transform(vec2(x, y));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800238}
239
240Rect Transform::makeBounds(int w, int h) const
241{
Mathias Agopianeda65402010-02-22 03:15:57 -0800242 return transform( Rect(w, h) );
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800243}
244
Pablo Ceballos51450032016-08-03 10:20:45 -0700245Rect Transform::transform(const Rect& bounds, bool roundOutwards) const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800246{
247 Rect r;
Mathias Agopianeda65402010-02-22 03:15:57 -0800248 vec2 lt( bounds.left, bounds.top );
249 vec2 rt( bounds.right, bounds.top );
250 vec2 lb( bounds.left, bounds.bottom );
251 vec2 rb( bounds.right, bounds.bottom );
252
253 lt = transform(lt);
254 rt = transform(rt);
255 lb = transform(lb);
256 rb = transform(rb);
257
Pablo Ceballos51450032016-08-03 10:20:45 -0700258 if (roundOutwards) {
Peiyong Linefefaac2018-08-17 12:27:51 -0700259 r.left = static_cast<int32_t>(floorf(std::min({lt[0], rt[0], lb[0], rb[0]})));
260 r.top = static_cast<int32_t>(floorf(std::min({lt[1], rt[1], lb[1], rb[1]})));
261 r.right = static_cast<int32_t>(ceilf(std::max({lt[0], rt[0], lb[0], rb[0]})));
262 r.bottom = static_cast<int32_t>(ceilf(std::max({lt[1], rt[1], lb[1], rb[1]})));
Pablo Ceballos51450032016-08-03 10:20:45 -0700263 } else {
Peiyong Linefefaac2018-08-17 12:27:51 -0700264 r.left = static_cast<int32_t>(floorf(std::min({lt[0], rt[0], lb[0], rb[0]}) + 0.5f));
265 r.top = static_cast<int32_t>(floorf(std::min({lt[1], rt[1], lb[1], rb[1]}) + 0.5f));
266 r.right = static_cast<int32_t>(floorf(std::max({lt[0], rt[0], lb[0], rb[0]}) + 0.5f));
267 r.bottom = static_cast<int32_t>(floorf(std::max({lt[1], rt[1], lb[1], rb[1]}) + 0.5f));
Pablo Ceballos51450032016-08-03 10:20:45 -0700268 }
Mathias Agopianeda65402010-02-22 03:15:57 -0800269
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800270 return r;
271}
272
Dan Stoza80d61162017-12-20 15:57:52 -0800273FloatRect Transform::transform(const FloatRect& bounds) const
274{
275 vec2 lt(bounds.left, bounds.top);
276 vec2 rt(bounds.right, bounds.top);
277 vec2 lb(bounds.left, bounds.bottom);
278 vec2 rb(bounds.right, bounds.bottom);
279
280 lt = transform(lt);
281 rt = transform(rt);
282 lb = transform(lb);
283 rb = transform(rb);
284
285 FloatRect r;
Peiyong Lin3db42342018-08-16 09:15:59 -0700286 r.left = std::min({lt[0], rt[0], lb[0], rb[0]});
287 r.top = std::min({lt[1], rt[1], lb[1], rb[1]});
288 r.right = std::max({lt[0], rt[0], lb[0], rb[0]});
289 r.bottom = std::max({lt[1], rt[1], lb[1], rb[1]});
Dan Stoza80d61162017-12-20 15:57:52 -0800290
291 return r;
292}
293
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800294Region Transform::transform(const Region& reg) const
295{
296 Region out;
Dan Stoza22f7fc42016-05-10 16:19:53 -0700297 if (CC_UNLIKELY(type() > TRANSLATE)) {
Mathias Agopianeda65402010-02-22 03:15:57 -0800298 if (CC_LIKELY(preserveRects())) {
Mathias Agopian20f68782009-05-11 00:03:41 -0700299 Region::const_iterator it = reg.begin();
300 Region::const_iterator const end = reg.end();
301 while (it != end) {
302 out.orSelf(transform(*it++));
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800303 }
304 } else {
305 out.set(transform(reg.bounds()));
306 }
307 } else {
Peiyong Linefefaac2018-08-17 12:27:51 -0700308 int xpos = static_cast<int>(floorf(tx() + 0.5f));
309 int ypos = static_cast<int>(floorf(ty() + 0.5f));
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700310 out = reg.translate(xpos, ypos);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800311 }
312 return out;
313}
314
Mathias Agopianeda65402010-02-22 03:15:57 -0800315uint32_t Transform::type() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800316{
Mathias Agopianeda65402010-02-22 03:15:57 -0800317 if (mType & UNKNOWN_TYPE) {
318 // recompute what this transform is
319
320 const mat33& M(mMatrix);
321 const float a = M[0][0];
322 const float b = M[1][0];
323 const float c = M[0][1];
324 const float d = M[1][1];
325 const float x = M[2][0];
326 const float y = M[2][1];
327
328 bool scale = false;
329 uint32_t flags = ROT_0;
330 if (isZero(b) && isZero(c)) {
Mathias Agopiand1296592010-03-09 19:17:47 -0800331 if (a<0) flags |= FLIP_H;
332 if (d<0) flags |= FLIP_V;
333 if (!absIsOne(a) || !absIsOne(d)) {
334 scale = true;
Mathias Agopianeda65402010-02-22 03:15:57 -0800335 }
336 } else if (isZero(a) && isZero(d)) {
Mathias Agopiand1296592010-03-09 19:17:47 -0800337 flags |= ROT_90;
Mathias Agopian883dffa2010-10-25 18:29:35 -0700338 if (b>0) flags |= FLIP_V;
339 if (c<0) flags |= FLIP_H;
Mathias Agopiand1296592010-03-09 19:17:47 -0800340 if (!absIsOne(b) || !absIsOne(c)) {
341 scale = true;
Mathias Agopianeda65402010-02-22 03:15:57 -0800342 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800343 } else {
Mathias Agopian29a367b2011-07-12 14:51:45 -0700344 // there is a skew component and/or a non 90 degrees rotation
Mathias Agopianeda65402010-02-22 03:15:57 -0800345 flags = ROT_INVALID;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800346 }
Mathias Agopianeda65402010-02-22 03:15:57 -0800347
348 mType = flags << 8;
349 if (flags & ROT_INVALID) {
350 mType |= UNKNOWN;
351 } else {
352 if ((flags & ROT_90) || ((flags & ROT_180) == ROT_180))
353 mType |= ROTATE;
354 if (flags & FLIP_H)
355 mType ^= SCALE;
356 if (flags & FLIP_V)
357 mType ^= SCALE;
358 if (scale)
359 mType |= SCALE;
360 }
361
362 if (!isZero(x) || !isZero(y))
363 mType |= TRANSLATE;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800364 }
Mathias Agopianeda65402010-02-22 03:15:57 -0800365 return mType;
366}
367
Mathias Agopian3da16722013-02-28 17:12:07 -0800368Transform Transform::inverse() const {
369 // our 3x3 matrix is always of the form of a 2x2 transformation
370 // followed by a translation: T*M, therefore:
371 // (T*M)^-1 = M^-1 * T^-1
372 Transform result;
373 if (mType <= TRANSLATE) {
Michael Lentine28ea2172014-11-19 18:32:37 -0800374 // 1 0 0
375 // 0 1 0
376 // x y 1
Mathias Agopian3da16722013-02-28 17:12:07 -0800377 result = *this;
378 result.mMatrix[2][0] = -result.mMatrix[2][0];
379 result.mMatrix[2][1] = -result.mMatrix[2][1];
380 } else {
Michael Lentine28ea2172014-11-19 18:32:37 -0800381 // a c 0
382 // b d 0
383 // x y 1
Mathias Agopian3da16722013-02-28 17:12:07 -0800384 const mat33& M(mMatrix);
385 const float a = M[0][0];
386 const float b = M[1][0];
387 const float c = M[0][1];
388 const float d = M[1][1];
389 const float x = M[2][0];
390 const float y = M[2][1];
391
Peiyong Linefefaac2018-08-17 12:27:51 -0700392 const float idet = 1.0f / (a*d - b*c);
Michael Lentine28ea2172014-11-19 18:32:37 -0800393 result.mMatrix[0][0] = d*idet;
394 result.mMatrix[0][1] = -c*idet;
395 result.mMatrix[1][0] = -b*idet;
396 result.mMatrix[1][1] = a*idet;
397 result.mType = mType;
Mathias Agopian3da16722013-02-28 17:12:07 -0800398
Michael Lentine28ea2172014-11-19 18:32:37 -0800399 vec2 T(-x, -y);
400 T = result.transform(T);
401 result.mMatrix[2][0] = T[0];
402 result.mMatrix[2][1] = T[1];
Mathias Agopian3da16722013-02-28 17:12:07 -0800403 }
404 return result;
405}
406
Mathias Agopianeda65402010-02-22 03:15:57 -0800407uint32_t Transform::getType() const {
408 return type() & 0xFF;
409}
410
411uint32_t Transform::getOrientation() const
412{
413 return (type() >> 8) & 0xFF;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800414}
415
416bool Transform::preserveRects() const
417{
Mathias Agopianab7c13f2011-07-25 13:57:16 -0700418 return (getOrientation() & ROT_INVALID) ? false : true;
Mathias Agopianeda65402010-02-22 03:15:57 -0800419}
420
Lloyd Pique7e06e7f2019-03-15 18:36:44 -0700421mat4 Transform::asMatrix4() const {
422 // Internally Transform uses a 3x3 matrix since the transform is meant for
423 // two-dimensional values. An equivalent 4x4 matrix means inserting an extra
424 // row and column which adds as an identity transform on the third
425 // dimension.
426
427 mat4 m = mat4{mat4::NO_INIT}; // NO_INIT since we explicitly set every element
428
429 m[0][0] = mMatrix[0][0];
430 m[0][1] = mMatrix[0][1];
431 m[0][2] = 0.f;
432 m[0][3] = mMatrix[0][2];
433
434 m[1][0] = mMatrix[1][0];
435 m[1][1] = mMatrix[1][1];
436 m[1][2] = 0.f;
437 m[1][3] = mMatrix[1][2];
438
439 m[2][0] = 0.f;
440 m[2][1] = 0.f;
441 m[2][2] = 1.f;
442 m[2][3] = 0.f;
443
444 m[3][0] = mMatrix[2][0];
445 m[3][1] = mMatrix[2][1];
446 m[3][2] = 0.f;
447 m[3][3] = mMatrix[2][2];
448
449 return m;
450}
451
Lloyd Pique32cbe282018-10-19 13:09:22 -0700452void Transform::dump(std::string& out, const char* name) const {
453 using android::base::StringAppendF;
Mathias Agopianeda65402010-02-22 03:15:57 -0800454
Lloyd Pique32cbe282018-10-19 13:09:22 -0700455 type(); // Ensure the information in mType is up to date
Mathias Agopianeda65402010-02-22 03:15:57 -0800456
Lloyd Pique32cbe282018-10-19 13:09:22 -0700457 const uint32_t type = mType;
458 const uint32_t orient = type >> 8;
459
460 StringAppendF(&out, "%s 0x%08x (", name, orient);
461
462 if (orient & ROT_INVALID) {
463 out.append("ROT_INVALID ");
Mathias Agopiand1296592010-03-09 19:17:47 -0800464 } else {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700465 if (orient & ROT_90) {
466 out.append("ROT_90 ");
Mathias Agopiand1296592010-03-09 19:17:47 -0800467 } else {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700468 out.append("ROT_0 ");
Mathias Agopiand1296592010-03-09 19:17:47 -0800469 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700470 if (orient & FLIP_V) out.append("FLIP_V ");
471 if (orient & FLIP_H) out.append("FLIP_H ");
Mathias Agopiand1296592010-03-09 19:17:47 -0800472 }
Mathias Agopianeda65402010-02-22 03:15:57 -0800473
Lloyd Pique32cbe282018-10-19 13:09:22 -0700474 StringAppendF(&out, ") 0x%02x (", type);
Mathias Agopianeda65402010-02-22 03:15:57 -0800475
Lloyd Pique32cbe282018-10-19 13:09:22 -0700476 if (!(type & (SCALE | ROTATE | TRANSLATE))) out.append("IDENTITY ");
477 if (type & SCALE) out.append("SCALE ");
478 if (type & ROTATE) out.append("ROTATE ");
479 if (type & TRANSLATE) out.append("TRANSLATE ");
480
481 out.append(")\n");
482
483 for (size_t i = 0; i < 3; i++) {
484 StringAppendF(&out, " %.4f %.4f %.4f\n", static_cast<double>(mMatrix[0][i]),
485 static_cast<double>(mMatrix[1][i]), static_cast<double>(mMatrix[2][i]));
486 }
487}
488
489void Transform::dump(const char* name) const {
490 std::string out;
491 dump(out, name);
492 ALOGD("%s", out.c_str());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800493}
494
Peiyong Linefefaac2018-08-17 12:27:51 -0700495} // namespace ui
496} // namespace android