1/* 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 17#ifndef ANDROID_HWUI_MATRIX_H 18#define ANDROID_HWUI_MATRIX_H 19 20#include <SkMatrix.h> 21 22#include <cutils/compiler.h> 23 24#include "Rect.h" 25 26namespace android { 27namespace uirenderer { 28 29/////////////////////////////////////////////////////////////////////////////// 30// Classes 31/////////////////////////////////////////////////////////////////////////////// 32 33class ANDROID_API Matrix4 { 34public: 35 float data[16]; 36 37 enum Entry { 38 kScaleX = 0, 39 kSkewY = 1, 40 kPerspective0 = 3, 41 kSkewX = 4, 42 kScaleY = 5, 43 kPerspective1 = 7, 44 kScaleZ = 10, 45 kTranslateX = 12, 46 kTranslateY = 13, 47 kTranslateZ = 14, 48 kPerspective2 = 15 49 }; 50 51 Matrix4() { 52 loadIdentity(); 53 } 54 55 Matrix4(const float* v) { 56 load(v); 57 } 58 59 Matrix4(const Matrix4& v) { 60 load(v); 61 } 62 63 Matrix4(const SkMatrix& v) { 64 load(v); 65 } 66 67 void loadIdentity(); 68 69 void load(const float* v); 70 void load(const Matrix4& v); 71 void load(const SkMatrix& v); 72 73 void loadInverse(const Matrix4& v); 74 75 void loadTranslate(float x, float y, float z); 76 void loadScale(float sx, float sy, float sz); 77 void loadSkew(float sx, float sy); 78 void loadRotate(float angle, float x, float y, float z); 79 void loadMultiply(const Matrix4& u, const Matrix4& v); 80 81 void loadOrtho(float left, float right, float bottom, float top, float near, float far); 82 83 void multiply(const Matrix4& v) { 84 Matrix4 u; 85 u.loadMultiply(*this, v); 86 load(u); 87 } 88 89 void multiply(float v); 90 91 void translate(float x, float y, float z) { 92 Matrix4 u; 93 u.loadTranslate(x, y, z); 94 multiply(u); 95 } 96 97 void scale(float sx, float sy, float sz) { 98 Matrix4 u; 99 u.loadScale(sx, sy, sz); 100 multiply(u); 101 } 102 103 void skew(float sx, float sy) { 104 Matrix4 u; 105 u.loadSkew(sx, sy); 106 multiply(u); 107 } 108 109 void rotate(float angle, float x, float y, float z) { 110 Matrix4 u; 111 u.loadRotate(angle, x, y, z); 112 multiply(u); 113 } 114 115 bool isPureTranslate() const; 116 bool isSimple() const; 117 bool isIdentity() const; 118 bool isPerspective() const; 119 120 bool changesBounds() const; 121 122 void copyTo(float* v) const; 123 void copyTo(SkMatrix& v) const; 124 125 void mapRect(Rect& r) const; 126 void mapPoint(float& x, float& y) const; 127 128 float getTranslateX(); 129 float getTranslateY(); 130 131 void dump() const; 132 133private: 134 bool mSimpleMatrix; 135 bool mIsIdentity; 136 137 inline float get(int i, int j) const { 138 return data[i * 4 + j]; 139 } 140 141 inline void set(int i, int j, float v) { 142 data[i * 4 + j] = v; 143 } 144}; // class Matrix4 145 146/////////////////////////////////////////////////////////////////////////////// 147// Types 148/////////////////////////////////////////////////////////////////////////////// 149 150typedef Matrix4 mat4; 151 152}; // namespace uirenderer 153}; // namespace android 154 155#endif // ANDROID_HWUI_MATRIX_H 156