blob: 4fe261af72de5cec7b9d12b44f8be519d1c550f7 [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
17#ifndef ANDROID_TRANSFORM_H
18#define ANDROID_TRANSFORM_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <ui/Point.h>
24#include <ui/Rect.h>
25
Mathias Agopian0694d0f2010-10-24 14:53:05 -070026#include <hardware/hardware.h>
27
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028namespace android {
29
30class Region;
31
32// ---------------------------------------------------------------------------
33
34class Transform
35{
36public:
37 Transform();
38 Transform(const Transform& other);
Mathias Agopianeda65402010-02-22 03:15:57 -080039 explicit Transform(uint32_t orientation);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040 ~Transform();
41
42 enum orientation_flags {
43 ROT_0 = 0x00000000,
Mathias Agopian0694d0f2010-10-24 14:53:05 -070044 FLIP_H = HAL_TRANSFORM_FLIP_H,
45 FLIP_V = HAL_TRANSFORM_FLIP_V,
46 ROT_90 = HAL_TRANSFORM_ROT_90,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047 ROT_180 = FLIP_H|FLIP_V,
48 ROT_270 = ROT_180|ROT_90,
Mathias Agopianeda65402010-02-22 03:15:57 -080049 ROT_INVALID = 0x80
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050 };
51
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070052 enum type_mask {
53 IDENTITY = 0,
54 TRANSLATE = 0x1,
Mathias Agopianeda65402010-02-22 03:15:57 -080055 ROTATE = 0x2,
56 SCALE = 0x4,
57 UNKNOWN = 0x8
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070058 };
59
Mathias Agopianeda65402010-02-22 03:15:57 -080060 // query the transform
61 bool transformed() const;
62 bool preserveRects() const;
63 uint32_t getType() const;
64 uint32_t getOrientation() const;
65
66 float const* operator [] (int i) const; // returns column i
Mathias Agopian41b6aab2011-08-30 18:51:54 -070067 float tx() const;
68 float ty() const;
Mathias Agopianeda65402010-02-22 03:15:57 -080069
70 // modify the transform
Mathias Agopiand1296592010-03-09 19:17:47 -080071 void reset();
72 void set(float tx, float ty);
73 void set(float a, float b, float c, float d);
74 status_t set(uint32_t flags, float w, float h);
Mathias Agopianeda65402010-02-22 03:15:57 -080075
76 // transform data
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 Rect makeBounds(int w, int h) const;
Mathias Agopian78fd5012010-04-20 14:51:04 -070078 void transform(float* point, int x, int y) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 Region transform(const Region& reg) const;
Jamie Gennis161534a2012-05-07 13:51:53 -070080 Rect transform(const Rect& bounds) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081 Transform operator * (const Transform& rhs) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082
Mathias Agopiand1296592010-03-09 19:17:47 -080083 // for debugging
84 void dump(const char* name) const;
85
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086private:
Mathias Agopianeda65402010-02-22 03:15:57 -080087 struct vec3 {
88 float v[3];
89 inline vec3() { }
90 inline vec3(float a, float b, float c) {
91 v[0] = a; v[1] = b; v[2] = c;
92 }
93 inline float operator [] (int i) const { return v[i]; }
94 inline float& operator [] (int i) { return v[i]; }
95 };
96 struct vec2 {
97 float v[2];
98 inline vec2() { }
99 inline vec2(float a, float b) {
100 v[0] = a; v[1] = b;
101 }
102 inline float operator [] (int i) const { return v[i]; }
103 inline float& operator [] (int i) { return v[i]; }
104 };
105 struct mat33 {
106 vec3 v[3];
107 inline const vec3& operator [] (int i) const { return v[i]; }
108 inline vec3& operator [] (int i) { return v[i]; }
109 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110
Mathias Agopianeda65402010-02-22 03:15:57 -0800111 enum { UNKNOWN_TYPE = 0x80000000 };
112
113 // assumes the last row is < 0 , 0 , 1 >
114 vec2 transform(const vec2& v) const;
115 vec3 transform(const vec3& v) const;
Mathias Agopianeda65402010-02-22 03:15:57 -0800116 uint32_t type() const;
117 static bool absIsOne(float f);
Mathias Agopianeda65402010-02-22 03:15:57 -0800118 static bool isZero(float f);
119
Mathias Agopianeda65402010-02-22 03:15:57 -0800120 mat33 mMatrix;
121 mutable uint32_t mType;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122};
123
124// ---------------------------------------------------------------------------
125}; // namespace android
126
127#endif /* ANDROID_TRANSFORM_H */