blob: c2f0010a3e8da4a3c93ee324b76897d94fce9e9a [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>
Mathias Agopianff2ed702013-09-01 21:36:12 -070025#include <ui/vec2.h>
26#include <ui/vec3.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Mathias Agopian0694d0f2010-10-24 14:53:05 -070028#include <hardware/hardware.h>
29
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030namespace android {
31
32class Region;
33
34// ---------------------------------------------------------------------------
35
36class Transform
37{
38public:
39 Transform();
40 Transform(const Transform& other);
Mathias Agopianeda65402010-02-22 03:15:57 -080041 explicit Transform(uint32_t orientation);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042 ~Transform();
43
44 enum orientation_flags {
45 ROT_0 = 0x00000000,
Mathias Agopian0694d0f2010-10-24 14:53:05 -070046 FLIP_H = HAL_TRANSFORM_FLIP_H,
47 FLIP_V = HAL_TRANSFORM_FLIP_V,
48 ROT_90 = HAL_TRANSFORM_ROT_90,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049 ROT_180 = FLIP_H|FLIP_V,
50 ROT_270 = ROT_180|ROT_90,
Mathias Agopianeda65402010-02-22 03:15:57 -080051 ROT_INVALID = 0x80
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 };
53
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070054 enum type_mask {
55 IDENTITY = 0,
56 TRANSLATE = 0x1,
Mathias Agopianeda65402010-02-22 03:15:57 -080057 ROTATE = 0x2,
58 SCALE = 0x4,
59 UNKNOWN = 0x8
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070060 };
61
Mathias Agopianeda65402010-02-22 03:15:57 -080062 // query the transform
63 bool transformed() const;
64 bool preserveRects() const;
65 uint32_t getType() const;
66 uint32_t getOrientation() const;
67
Mathias Agopianff2ed702013-09-01 21:36:12 -070068 const vec3& operator [] (size_t i) const; // returns column i
Mathias Agopian41b6aab2011-08-30 18:51:54 -070069 float tx() const;
70 float ty() const;
Mathias Agopianeda65402010-02-22 03:15:57 -080071
72 // modify the transform
Mathias Agopiand1296592010-03-09 19:17:47 -080073 void reset();
74 void set(float tx, float ty);
75 void set(float a, float b, float c, float d);
76 status_t set(uint32_t flags, float w, float h);
Mathias Agopianeda65402010-02-22 03:15:57 -080077
78 // transform data
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 Rect makeBounds(int w, int h) const;
Mathias Agopianff2ed702013-09-01 21:36:12 -070080 vec2 transform(int x, int y) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081 Region transform(const Region& reg) const;
Jamie Gennis161534a2012-05-07 13:51:53 -070082 Rect transform(const Rect& bounds) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 Transform operator * (const Transform& rhs) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084
Mathias Agopian3da16722013-02-28 17:12:07 -080085 Transform inverse() const;
86
Mathias Agopiand1296592010-03-09 19:17:47 -080087 // for debugging
88 void dump(const char* name) const;
89
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090private:
Mathias Agopianeda65402010-02-22 03:15:57 -080091 struct mat33 {
92 vec3 v[3];
93 inline const vec3& operator [] (int i) const { return v[i]; }
94 inline vec3& operator [] (int i) { return v[i]; }
95 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096
Mathias Agopianeda65402010-02-22 03:15:57 -080097 enum { UNKNOWN_TYPE = 0x80000000 };
98
99 // assumes the last row is < 0 , 0 , 1 >
100 vec2 transform(const vec2& v) const;
101 vec3 transform(const vec3& v) const;
Mathias Agopianeda65402010-02-22 03:15:57 -0800102 uint32_t type() const;
103 static bool absIsOne(float f);
Mathias Agopianeda65402010-02-22 03:15:57 -0800104 static bool isZero(float f);
105
Mathias Agopianeda65402010-02-22 03:15:57 -0800106 mat33 mMatrix;
107 mutable uint32_t mType;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108};
109
110// ---------------------------------------------------------------------------
111}; // namespace android
112
113#endif /* ANDROID_TRANSFORM_H */