blob: 20fa11a46ace8c5023b949086b4a9918cb2aa950 [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026namespace android {
27
28class Region;
29
30// ---------------------------------------------------------------------------
31
32class Transform
33{
34public:
35 Transform();
36 Transform(const Transform& other);
Mathias Agopianeda65402010-02-22 03:15:57 -080037 explicit Transform(uint32_t orientation);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038 ~Transform();
39
Mathias Agopianeda65402010-02-22 03:15:57 -080040 // FIXME: must match OVERLAY_TRANSFORM_*, pull from hardware.h
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041 enum orientation_flags {
42 ROT_0 = 0x00000000,
43 FLIP_H = 0x00000001,
44 FLIP_V = 0x00000002,
45 ROT_90 = 0x00000004,
46 ROT_180 = FLIP_H|FLIP_V,
47 ROT_270 = ROT_180|ROT_90,
Mathias Agopianeda65402010-02-22 03:15:57 -080048 ROT_INVALID = 0x80
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049 };
50
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070051 enum type_mask {
52 IDENTITY = 0,
53 TRANSLATE = 0x1,
Mathias Agopianeda65402010-02-22 03:15:57 -080054 ROTATE = 0x2,
55 SCALE = 0x4,
56 UNKNOWN = 0x8
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070057 };
58
Mathias Agopianeda65402010-02-22 03:15:57 -080059 // query the transform
60 bool transformed() const;
61 bool preserveRects() const;
62 uint32_t getType() const;
63 uint32_t getOrientation() const;
64
65 float const* operator [] (int i) const; // returns column i
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 int tx() const;
67 int ty() const;
Mathias Agopianeda65402010-02-22 03:15:57 -080068
69 // modify the transform
Mathias Agopiand1296592010-03-09 19:17:47 -080070 void reset();
71 void set(float tx, float ty);
72 void set(float a, float b, float c, float d);
73 status_t set(uint32_t flags, float w, float h);
Mathias Agopianeda65402010-02-22 03:15:57 -080074
75 // transform data
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 Rect makeBounds(int w, int h) const;
Mathias Agopian78fd5012010-04-20 14:51:04 -070077 void transform(float* point, int x, int y) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078 Region transform(const Region& reg) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 Transform operator * (const Transform& rhs) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080
Mathias Agopiand1296592010-03-09 19:17:47 -080081 // for debugging
82 void dump(const char* name) const;
83
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084private:
Mathias Agopianeda65402010-02-22 03:15:57 -080085 struct vec3 {
86 float v[3];
87 inline vec3() { }
88 inline vec3(float a, float b, float c) {
89 v[0] = a; v[1] = b; v[2] = c;
90 }
91 inline float operator [] (int i) const { return v[i]; }
92 inline float& operator [] (int i) { return v[i]; }
93 };
94 struct vec2 {
95 float v[2];
96 inline vec2() { }
97 inline vec2(float a, float b) {
98 v[0] = a; v[1] = b;
99 }
100 inline float operator [] (int i) const { return v[i]; }
101 inline float& operator [] (int i) { return v[i]; }
102 };
103 struct mat33 {
104 vec3 v[3];
105 inline const vec3& operator [] (int i) const { return v[i]; }
106 inline vec3& operator [] (int i) { return v[i]; }
107 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108
Mathias Agopianeda65402010-02-22 03:15:57 -0800109 enum { UNKNOWN_TYPE = 0x80000000 };
110
111 // assumes the last row is < 0 , 0 , 1 >
112 vec2 transform(const vec2& v) const;
113 vec3 transform(const vec3& v) const;
114 Rect transform(const Rect& bounds) const;
115 uint32_t type() const;
116 static bool absIsOne(float f);
Mathias Agopianeda65402010-02-22 03:15:57 -0800117 static bool isZero(float f);
118
Mathias Agopianeda65402010-02-22 03:15:57 -0800119 mat33 mMatrix;
120 mutable uint32_t mType;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800121};
122
123// ---------------------------------------------------------------------------
124}; // namespace android
125
126#endif /* ANDROID_TRANSFORM_H */