blob: 6a5ea510482b4030b2511ca8c4dd4290509de7b6 [file] [log] [blame]
Romain Guy08ae3172010-06-21 19:35:50 -07001/*
2 * Copyright (C) 2010 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
Romain Guy5cbbce52010-06-27 22:59:20 -070017#define LOG_TAG "OpenGLRenderer"
Romain Guy08ae3172010-06-21 19:35:50 -070018
19#include <math.h>
20#include <stdlib.h>
Romain Guy3e168332010-06-22 13:29:14 -070021#include <string.h>
Romain Guy08ae3172010-06-21 19:35:50 -070022
23#include <utils/Log.h>
24
Romain Guyf6a11b82010-06-23 17:47:49 -070025#include <SkMatrix.h>
26
Romain Guy85bf02f2010-06-22 13:11:24 -070027#include "Matrix.h"
Romain Guy08ae3172010-06-21 19:35:50 -070028
29namespace android {
Romain Guy9d5316e2010-06-24 19:30:36 -070030namespace uirenderer {
Romain Guy08ae3172010-06-21 19:35:50 -070031
Romain Guy8ce00302013-01-15 18:51:42 -080032///////////////////////////////////////////////////////////////////////////////
33// Defines
34///////////////////////////////////////////////////////////////////////////////
35
36static const float EPSILON = 0.0000001f;
37
38///////////////////////////////////////////////////////////////////////////////
39// Matrix
40///////////////////////////////////////////////////////////////////////////////
41
Romain Guyc74f45a2013-02-26 19:10:14 -080042const Matrix4& Matrix4::identity() {
43 static Matrix4 sIdentity;
44 return sIdentity;
45}
46
Romain Guy08ae3172010-06-21 19:35:50 -070047void Matrix4::loadIdentity() {
Romain Guyaf28b512010-08-12 14:34:44 -070048 data[kScaleX] = 1.0f;
49 data[kSkewY] = 0.0f;
50 data[2] = 0.0f;
51 data[kPerspective0] = 0.0f;
Romain Guy08ae3172010-06-21 19:35:50 -070052
Romain Guyaf28b512010-08-12 14:34:44 -070053 data[kSkewX] = 0.0f;
54 data[kScaleY] = 1.0f;
55 data[6] = 0.0f;
56 data[kPerspective1] = 0.0f;
Romain Guy08ae3172010-06-21 19:35:50 -070057
Romain Guyaf28b512010-08-12 14:34:44 -070058 data[8] = 0.0f;
59 data[9] = 0.0f;
60 data[kScaleZ] = 1.0f;
61 data[11] = 0.0f;
Romain Guy08ae3172010-06-21 19:35:50 -070062
Romain Guyaf28b512010-08-12 14:34:44 -070063 data[kTranslateX] = 0.0f;
64 data[kTranslateY] = 0.0f;
65 data[kTranslateZ] = 0.0f;
66 data[kPerspective2] = 1.0f;
67
Romain Guy8ce00302013-01-15 18:51:42 -080068 mType = kTypeIdentity | kTypeRectToRect;
69}
70
71static bool isZero(float f) {
72 return fabs(f) <= EPSILON;
73}
74
75uint32_t Matrix4::getType() const {
76 if (mType & kTypeUnknown) {
77 mType = kTypeIdentity;
78
79 if (data[kPerspective0] != 0.0f || data[kPerspective1] != 0.0f ||
80 data[kPerspective2] != 1.0f) {
81 mType |= kTypePerspective;
82 }
83
84 if (data[kTranslateX] != 0.0f || data[kTranslateY] != 0.0f) {
85 mType |= kTypeTranslate;
86 }
87
88 float m00 = data[kScaleX];
89 float m01 = data[kSkewX];
90 float m10 = data[kSkewY];
91 float m11 = data[kScaleY];
92
93 if (m01 != 0.0f || m10 != 0.0f) {
94 mType |= kTypeAffine;
95 }
96
97 if (m00 != 1.0f || m11 != 1.0f) {
98 mType |= kTypeScale;
99 }
100
101 // The following section determines whether the matrix will preserve
102 // rectangles. For instance, a rectangle transformed by a pure
103 // translation matrix will result in a rectangle. A rectangle
104 // transformed by a 45 degrees rotation matrix is not a rectangle.
105 // If the matrix has a perspective component then we already know
106 // it doesn't preserve rectangles.
107 if (!(mType & kTypePerspective)) {
108 if ((isZero(m00) && isZero(m11) && !isZero(m01) && !isZero(m10)) ||
109 (isZero(m01) && isZero(m10) && !isZero(m00) && !isZero(m11))) {
110 mType |= kTypeRectToRect;
111 }
112 }
113 }
114 return mType;
115}
116
117uint32_t Matrix4::getGeometryType() const {
118 return getType() & sGeometryMask;
119}
120
121bool Matrix4::rectToRect() const {
122 return getType() & kTypeRectToRect;
Romain Guy08ae3172010-06-21 19:35:50 -0700123}
124
Chris Craik710f46d2012-09-17 17:25:49 -0700125bool Matrix4::changesBounds() const {
Romain Guy8ce00302013-01-15 18:51:42 -0800126 return getType() & (kTypeScale | kTypeAffine | kTypePerspective);
Romain Guye8cb9c142010-10-04 14:14:11 -0700127}
128
Chris Craik710f46d2012-09-17 17:25:49 -0700129bool Matrix4::isPureTranslate() const {
Romain Guy8ce00302013-01-15 18:51:42 -0800130 return getGeometryType() == kTypeTranslate;
Romain Guy6620c6d2010-12-06 18:07:02 -0800131}
132
Chris Craik710f46d2012-09-17 17:25:49 -0700133bool Matrix4::isSimple() const {
Romain Guy8ce00302013-01-15 18:51:42 -0800134 return getGeometryType() <= (kTypeScale | kTypeTranslate);
Romain Guy181d0a62011-06-09 18:52:38 -0700135}
136
Chris Craik710f46d2012-09-17 17:25:49 -0700137bool Matrix4::isIdentity() const {
Romain Guy8ce00302013-01-15 18:51:42 -0800138 return getGeometryType() == kTypeIdentity;
Romain Guy302a9df2011-08-16 13:55:02 -0700139}
140
Romain Guya3dc55f2012-09-28 13:55:44 -0700141bool Matrix4::isPerspective() const {
Romain Guy8ce00302013-01-15 18:51:42 -0800142 return getType() & kTypePerspective;
Romain Guya3dc55f2012-09-28 13:55:44 -0700143}
144
Romain Guy08ae3172010-06-21 19:35:50 -0700145void Matrix4::load(const float* v) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700146 memcpy(data, v, sizeof(data));
Romain Guy8ce00302013-01-15 18:51:42 -0800147 mType = kTypeUnknown;
Romain Guy08ae3172010-06-21 19:35:50 -0700148}
149
150void Matrix4::load(const Matrix4& v) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700151 memcpy(data, v.data, sizeof(data));
Romain Guy8ce00302013-01-15 18:51:42 -0800152 mType = v.getType();
Romain Guy08ae3172010-06-21 19:35:50 -0700153}
154
Romain Guyf6a11b82010-06-23 17:47:49 -0700155void Matrix4::load(const SkMatrix& v) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700156 memset(data, 0, sizeof(data));
Romain Guyf6a11b82010-06-23 17:47:49 -0700157
Romain Guyaf28b512010-08-12 14:34:44 -0700158 data[kScaleX] = v[SkMatrix::kMScaleX];
159 data[kSkewX] = v[SkMatrix::kMSkewX];
160 data[kTranslateX] = v[SkMatrix::kMTransX];
Romain Guyf6a11b82010-06-23 17:47:49 -0700161
Romain Guyaf28b512010-08-12 14:34:44 -0700162 data[kSkewY] = v[SkMatrix::kMSkewY];
163 data[kScaleY] = v[SkMatrix::kMScaleY];
164 data[kTranslateY] = v[SkMatrix::kMTransY];
Romain Guyf6a11b82010-06-23 17:47:49 -0700165
Romain Guyaf28b512010-08-12 14:34:44 -0700166 data[kPerspective0] = v[SkMatrix::kMPersp0];
167 data[kPerspective1] = v[SkMatrix::kMPersp1];
168 data[kPerspective2] = v[SkMatrix::kMPersp2];
Romain Guyf6a11b82010-06-23 17:47:49 -0700169
Romain Guyaf28b512010-08-12 14:34:44 -0700170 data[kScaleZ] = 1.0f;
171
Romain Guy8ce00302013-01-15 18:51:42 -0800172 // NOTE: The flags are compatible between SkMatrix and this class.
173 // However, SkMatrix::getType() does not return the flag
174 // kRectStaysRect. The return value is masked with 0xF
175 // so we need the extra rectStaysRect() check
176 mType = v.getType();
177 if (v.rectStaysRect()) {
178 mType |= kTypeRectToRect;
179 }
Romain Guyf6a11b82010-06-23 17:47:49 -0700180}
181
182void Matrix4::copyTo(SkMatrix& v) const {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700183 v.reset();
Romain Guyf6a11b82010-06-23 17:47:49 -0700184
Romain Guyaf28b512010-08-12 14:34:44 -0700185 v.set(SkMatrix::kMScaleX, data[kScaleX]);
186 v.set(SkMatrix::kMSkewX, data[kSkewX]);
187 v.set(SkMatrix::kMTransX, data[kTranslateX]);
Romain Guyf6a11b82010-06-23 17:47:49 -0700188
Romain Guyaf28b512010-08-12 14:34:44 -0700189 v.set(SkMatrix::kMSkewY, data[kSkewY]);
190 v.set(SkMatrix::kMScaleY, data[kScaleY]);
191 v.set(SkMatrix::kMTransY, data[kTranslateY]);
Romain Guyf6a11b82010-06-23 17:47:49 -0700192
Romain Guyaf28b512010-08-12 14:34:44 -0700193 v.set(SkMatrix::kMPersp0, data[kPerspective0]);
194 v.set(SkMatrix::kMPersp1, data[kPerspective1]);
195 v.set(SkMatrix::kMPersp2, data[kPerspective2]);
Romain Guyf6a11b82010-06-23 17:47:49 -0700196}
197
Romain Guy079ba2c2010-07-16 14:12:24 -0700198void Matrix4::loadInverse(const Matrix4& v) {
199 double scale = 1.0 /
Romain Guyaf28b512010-08-12 14:34:44 -0700200 (v.data[kScaleX] * ((double) v.data[kScaleY] * v.data[kPerspective2] -
201 (double) v.data[kTranslateY] * v.data[kPerspective1]) +
202 v.data[kSkewX] * ((double) v.data[kTranslateY] * v.data[kPerspective0] -
203 (double) v.data[kSkewY] * v.data[kPerspective2]) +
204 v.data[kTranslateX] * ((double) v.data[kSkewY] * v.data[kPerspective1] -
205 (double) v.data[kScaleY] * v.data[kPerspective0]));
Romain Guy079ba2c2010-07-16 14:12:24 -0700206
Romain Guyaf28b512010-08-12 14:34:44 -0700207 data[kScaleX] = (v.data[kScaleY] * v.data[kPerspective2] -
208 v.data[kTranslateY] * v.data[kPerspective1]) * scale;
209 data[kSkewX] = (v.data[kTranslateX] * v.data[kPerspective1] -
210 v.data[kSkewX] * v.data[kPerspective2]) * scale;
211 data[kTranslateX] = (v.data[kSkewX] * v.data[kTranslateY] -
212 v.data[kTranslateX] * v.data[kScaleY]) * scale;
Romain Guy079ba2c2010-07-16 14:12:24 -0700213
Romain Guyaf28b512010-08-12 14:34:44 -0700214 data[kSkewY] = (v.data[kTranslateY] * v.data[kPerspective0] -
215 v.data[kSkewY] * v.data[kPerspective2]) * scale;
216 data[kScaleY] = (v.data[kScaleX] * v.data[kPerspective2] -
217 v.data[kTranslateX] * v.data[kPerspective0]) * scale;
218 data[kTranslateY] = (v.data[kTranslateX] * v.data[kSkewY] -
219 v.data[kScaleX] * v.data[kTranslateY]) * scale;
Romain Guy079ba2c2010-07-16 14:12:24 -0700220
Romain Guyaf28b512010-08-12 14:34:44 -0700221 data[kPerspective0] = (v.data[kSkewY] * v.data[kPerspective1] -
222 v.data[kScaleY] * v.data[kPerspective0]) * scale;
223 data[kPerspective1] = (v.data[kSkewX] * v.data[kPerspective0] -
224 v.data[kScaleX] * v.data[kPerspective1]) * scale;
225 data[kPerspective2] = (v.data[kScaleX] * v.data[kScaleY] -
226 v.data[kSkewX] * v.data[kSkewY]) * scale;
227
Romain Guy8ce00302013-01-15 18:51:42 -0800228 mType = kTypeUnknown;
Romain Guy079ba2c2010-07-16 14:12:24 -0700229}
230
Romain Guy08ae3172010-06-21 19:35:50 -0700231void Matrix4::copyTo(float* v) const {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700232 memcpy(v, data, sizeof(data));
Romain Guy08ae3172010-06-21 19:35:50 -0700233}
234
Romain Guy624234f2013-03-05 16:43:31 -0800235float Matrix4::getTranslateX() const {
Romain Guyaf28b512010-08-12 14:34:44 -0700236 return data[kTranslateX];
Romain Guybd6b79b2010-06-26 00:13:53 -0700237}
238
Romain Guy624234f2013-03-05 16:43:31 -0800239float Matrix4::getTranslateY() const {
Romain Guyaf28b512010-08-12 14:34:44 -0700240 return data[kTranslateY];
Romain Guybd6b79b2010-06-26 00:13:53 -0700241}
242
Romain Guyddb80be2010-09-20 19:04:33 -0700243void Matrix4::multiply(float v) {
244 for (int i = 0; i < 16; i++) {
245 data[i] *= v;
246 }
Romain Guy8ce00302013-01-15 18:51:42 -0800247 mType = kTypeUnknown;
Romain Guyddb80be2010-09-20 19:04:33 -0700248}
249
Romain Guy08ae3172010-06-21 19:35:50 -0700250void Matrix4::loadTranslate(float x, float y, float z) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700251 loadIdentity();
Romain Guy302a9df2011-08-16 13:55:02 -0700252
Romain Guyaf28b512010-08-12 14:34:44 -0700253 data[kTranslateX] = x;
254 data[kTranslateY] = y;
255 data[kTranslateZ] = z;
Romain Guy302a9df2011-08-16 13:55:02 -0700256
Romain Guy8ce00302013-01-15 18:51:42 -0800257 mType = kTypeTranslate | kTypeRectToRect;
Romain Guy08ae3172010-06-21 19:35:50 -0700258}
259
260void Matrix4::loadScale(float sx, float sy, float sz) {
Romain Guy7ae7ac42010-06-25 13:46:18 -0700261 loadIdentity();
Romain Guy302a9df2011-08-16 13:55:02 -0700262
Romain Guyaf28b512010-08-12 14:34:44 -0700263 data[kScaleX] = sx;
264 data[kScaleY] = sy;
265 data[kScaleZ] = sz;
Romain Guy302a9df2011-08-16 13:55:02 -0700266
Romain Guy8ce00302013-01-15 18:51:42 -0800267 mType = kTypeScale | kTypeRectToRect;
Romain Guy08ae3172010-06-21 19:35:50 -0700268}
269
Romain Guy807daf72011-01-18 11:19:19 -0800270void Matrix4::loadSkew(float sx, float sy) {
271 loadIdentity();
272
273 data[kScaleX] = 1.0f;
274 data[kSkewX] = sx;
275 data[kTranslateX] = 0.0f;
276
277 data[kSkewY] = sy;
278 data[kScaleY] = 1.0f;
279 data[kTranslateY] = 0.0f;
280
281 data[kPerspective0] = 0.0f;
282 data[kPerspective1] = 0.0f;
283 data[kPerspective2] = 1.0f;
284
Romain Guy8ce00302013-01-15 18:51:42 -0800285 mType = kTypeUnknown;
286}
287
288void Matrix4::loadRotate(float angle) {
289 angle *= float(M_PI / 180.0f);
290 float c = cosf(angle);
291 float s = sinf(angle);
292
293 loadIdentity();
294
295 data[kScaleX] = c;
296 data[kSkewX] = -s;
297
298 data[kSkewY] = s;
299 data[kScaleY] = c;
300
301 mType = kTypeUnknown;
Romain Guy807daf72011-01-18 11:19:19 -0800302}
303
Romain Guy08ae3172010-06-21 19:35:50 -0700304void Matrix4::loadRotate(float angle, float x, float y, float z) {
Romain Guyaf28b512010-08-12 14:34:44 -0700305 data[kPerspective0] = 0.0f;
306 data[kPerspective1] = 0.0f;
307 data[11] = 0.0f;
308 data[kTranslateX] = 0.0f;
309 data[kTranslateY] = 0.0f;
310 data[kTranslateZ] = 0.0f;
311 data[kPerspective2] = 1.0f;
Romain Guy08ae3172010-06-21 19:35:50 -0700312
Romain Guy7ae7ac42010-06-25 13:46:18 -0700313 angle *= float(M_PI / 180.0f);
314 float c = cosf(angle);
315 float s = sinf(angle);
Romain Guy08ae3172010-06-21 19:35:50 -0700316
Romain Guy7ae7ac42010-06-25 13:46:18 -0700317 const float length = sqrtf(x * x + y * y + z * z);
Romain Guy889f8d12010-07-29 14:37:42 -0700318 float recipLen = 1.0f / length;
319 x *= recipLen;
320 y *= recipLen;
321 z *= recipLen;
322
Romain Guy7ae7ac42010-06-25 13:46:18 -0700323 const float nc = 1.0f - c;
324 const float xy = x * y;
325 const float yz = y * z;
326 const float zx = z * x;
327 const float xs = x * s;
328 const float ys = y * s;
329 const float zs = z * s;
Romain Guy08ae3172010-06-21 19:35:50 -0700330
Romain Guyaf28b512010-08-12 14:34:44 -0700331 data[kScaleX] = x * x * nc + c;
332 data[kSkewX] = xy * nc - zs;
333 data[8] = zx * nc + ys;
334 data[kSkewY] = xy * nc + zs;
335 data[kScaleY] = y * y * nc + c;
336 data[9] = yz * nc - xs;
337 data[2] = zx * nc - ys;
338 data[6] = yz * nc + xs;
339 data[kScaleZ] = z * z * nc + c;
340
Romain Guy8ce00302013-01-15 18:51:42 -0800341 mType = kTypeUnknown;
Romain Guy08ae3172010-06-21 19:35:50 -0700342}
343
344void Matrix4::loadMultiply(const Matrix4& u, const Matrix4& v) {
345 for (int i = 0 ; i < 4 ; i++) {
346 float x = 0;
347 float y = 0;
348 float z = 0;
349 float w = 0;
350
351 for (int j = 0 ; j < 4 ; j++) {
Romain Guyc7d53492010-06-25 13:41:57 -0700352 const float e = v.get(i, j);
Romain Guy08ae3172010-06-21 19:35:50 -0700353 x += u.get(j, 0) * e;
354 y += u.get(j, 1) * e;
355 z += u.get(j, 2) * e;
356 w += u.get(j, 3) * e;
357 }
358
359 set(i, 0, x);
360 set(i, 1, y);
361 set(i, 2, z);
362 set(i, 3, w);
363 }
Romain Guyaf28b512010-08-12 14:34:44 -0700364
Romain Guy8ce00302013-01-15 18:51:42 -0800365 mType = kTypeUnknown;
Romain Guy08ae3172010-06-21 19:35:50 -0700366}
367
368void Matrix4::loadOrtho(float left, float right, float bottom, float top, float near, float far) {
369 loadIdentity();
Romain Guy302a9df2011-08-16 13:55:02 -0700370
Romain Guyaf28b512010-08-12 14:34:44 -0700371 data[kScaleX] = 2.0f / (right - left);
372 data[kScaleY] = 2.0f / (top - bottom);
373 data[kScaleZ] = -2.0f / (far - near);
374 data[kTranslateX] = -(right + left) / (right - left);
375 data[kTranslateY] = -(top + bottom) / (top - bottom);
376 data[kTranslateZ] = -(far + near) / (far - near);
Romain Guy302a9df2011-08-16 13:55:02 -0700377
Romain Guy8ce00302013-01-15 18:51:42 -0800378 mType = kTypeTranslate | kTypeScale | kTypeRectToRect;
Romain Guy08ae3172010-06-21 19:35:50 -0700379}
380
Romain Guy0ba681b2010-08-12 15:37:00 -0700381#define MUL_ADD_STORE(a, b, c) a = (a) * (b) + (c)
382
383void Matrix4::mapPoint(float& x, float& y) const {
Romain Guy8ce00302013-01-15 18:51:42 -0800384 if (isSimple()) {
Romain Guy0ba681b2010-08-12 15:37:00 -0700385 MUL_ADD_STORE(x, data[kScaleX], data[kTranslateX]);
386 MUL_ADD_STORE(y, data[kScaleY], data[kTranslateY]);
387 return;
388 }
389
390 float dx = x * data[kScaleX] + y * data[kSkewX] + data[kTranslateX];
391 float dy = x * data[kSkewY] + y * data[kScaleY] + data[kTranslateY];
392 float dz = x * data[kPerspective0] + y * data[kPerspective1] + data[kPerspective2];
393 if (dz) dz = 1.0f / dz;
394
395 x = dx * dz;
396 y = dy * dz;
397}
398
Romain Guy9d5316e2010-06-24 19:30:36 -0700399void Matrix4::mapRect(Rect& r) const {
Romain Guy8ce00302013-01-15 18:51:42 -0800400 if (isSimple()) {
Romain Guyaf28b512010-08-12 14:34:44 -0700401 MUL_ADD_STORE(r.left, data[kScaleX], data[kTranslateX]);
402 MUL_ADD_STORE(r.right, data[kScaleX], data[kTranslateX]);
403 MUL_ADD_STORE(r.top, data[kScaleY], data[kTranslateY]);
404 MUL_ADD_STORE(r.bottom, data[kScaleY], data[kTranslateY]);
Romain Guy5b3b3522010-10-27 18:57:51 -0700405
406 if (r.left > r.right) {
407 float x = r.left;
408 r.left = r.right;
409 r.right = x;
410 }
411
412 if (r.top > r.bottom) {
413 float y = r.top;
414 r.top = r.bottom;
415 r.bottom = y;
416 }
417
Romain Guyaf28b512010-08-12 14:34:44 -0700418 return;
419 }
Romain Guy9d5316e2010-06-24 19:30:36 -0700420
Romain Guyaf28b512010-08-12 14:34:44 -0700421 float vertices[] = {
Romain Guy1d83e192010-08-17 11:37:00 -0700422 r.left, r.top,
423 r.right, r.top,
424 r.right, r.bottom,
425 r.left, r.bottom
Romain Guyaf28b512010-08-12 14:34:44 -0700426 };
Romain Guy9d5316e2010-06-24 19:30:36 -0700427
Romain Guyaf28b512010-08-12 14:34:44 -0700428 float x, y, z;
429
430 for (int i = 0; i < 8; i+= 2) {
431 float px = vertices[i];
432 float py = vertices[i + 1];
433
434 x = px * data[kScaleX] + py * data[kSkewX] + data[kTranslateX];
435 y = px * data[kSkewY] + py * data[kScaleY] + data[kTranslateY];
436 z = px * data[kPerspective0] + py * data[kPerspective1] + data[kPerspective2];
437 if (z) z = 1.0f / z;
438
439 vertices[i] = x * z;
440 vertices[i + 1] = y * z;
441 }
442
443 r.left = r.right = vertices[0];
444 r.top = r.bottom = vertices[1];
445
446 for (int i = 2; i < 8; i += 2) {
447 x = vertices[i];
448 y = vertices[i + 1];
449
450 if (x < r.left) r.left = x;
451 else if (x > r.right) r.right = x;
452 if (y < r.top) r.top = y;
453 else if (y > r.bottom) r.bottom = y;
454 }
Romain Guy9d5316e2010-06-24 19:30:36 -0700455}
456
Romain Guy3b753822013-03-05 10:27:35 -0800457void Matrix4::decomposeScale(float& sx, float& sy) const {
458 float len;
459 len = data[mat4::kScaleX] * data[mat4::kScaleX] + data[mat4::kSkewX] * data[mat4::kSkewX];
460 sx = copysignf(sqrtf(len), data[mat4::kScaleX]);
461 len = data[mat4::kScaleY] * data[mat4::kScaleY] + data[mat4::kSkewY] * data[mat4::kSkewY];
462 sy = copysignf(sqrtf(len), data[mat4::kScaleY]);
463}
464
Romain Guy08ae3172010-06-21 19:35:50 -0700465void Matrix4::dump() const {
Romain Guy8ce00302013-01-15 18:51:42 -0800466 ALOGD("Matrix4[simple=%d, type=0x%x", isSimple(), getType());
Steve Block5baa3a62011-12-20 16:23:08 +0000467 ALOGD(" %f %f %f %f", data[kScaleX], data[kSkewX], data[8], data[kTranslateX]);
468 ALOGD(" %f %f %f %f", data[kSkewY], data[kScaleY], data[9], data[kTranslateY]);
469 ALOGD(" %f %f %f %f", data[2], data[6], data[kScaleZ], data[kTranslateZ]);
470 ALOGD(" %f %f %f %f", data[kPerspective0], data[kPerspective1], data[11], data[kPerspective2]);
471 ALOGD("]");
Romain Guy08ae3172010-06-21 19:35:50 -0700472}
473
Romain Guy9d5316e2010-06-24 19:30:36 -0700474}; // namespace uirenderer
475}; // namespace android