blob: b11d0576c43cdb446b3731fda26b2eea93447e61 [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 Agopian1d77b712017-02-17 15:46:13 -080025#include <math/vec2.h>
26#include <math/vec3.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
chaviwa76b2712017-09-20 12:02:26 -070028#include <gui/ISurfaceComposer.h>
29
Mathias Agopian0694d0f2010-10-24 14:53:05 -070030#include <hardware/hardware.h>
31
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032namespace android {
33
34class Region;
35
36// ---------------------------------------------------------------------------
37
38class Transform
39{
40public:
41 Transform();
42 Transform(const Transform& other);
Mathias Agopianeda65402010-02-22 03:15:57 -080043 explicit Transform(uint32_t orientation);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044 ~Transform();
45
46 enum orientation_flags {
47 ROT_0 = 0x00000000,
Mathias Agopian0694d0f2010-10-24 14:53:05 -070048 FLIP_H = HAL_TRANSFORM_FLIP_H,
49 FLIP_V = HAL_TRANSFORM_FLIP_V,
50 ROT_90 = HAL_TRANSFORM_ROT_90,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051 ROT_180 = FLIP_H|FLIP_V,
52 ROT_270 = ROT_180|ROT_90,
Mathias Agopianeda65402010-02-22 03:15:57 -080053 ROT_INVALID = 0x80
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054 };
55
chaviwa76b2712017-09-20 12:02:26 -070056 static orientation_flags fromRotation(ISurfaceComposer::Rotation rotation);
57
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070058 enum type_mask {
59 IDENTITY = 0,
60 TRANSLATE = 0x1,
Mathias Agopianeda65402010-02-22 03:15:57 -080061 ROTATE = 0x2,
62 SCALE = 0x4,
63 UNKNOWN = 0x8
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070064 };
65
Mathias Agopianeda65402010-02-22 03:15:57 -080066 // query the transform
Mathias Agopianeda65402010-02-22 03:15:57 -080067 bool preserveRects() const;
68 uint32_t getType() const;
69 uint32_t getOrientation() const;
70
Mathias Agopianff2ed702013-09-01 21:36:12 -070071 const vec3& operator [] (size_t i) const; // returns column i
Mathias Agopian41b6aab2011-08-30 18:51:54 -070072 float tx() const;
73 float ty() const;
Mathias Agopianeda65402010-02-22 03:15:57 -080074
75 // modify the transform
Mathias Agopiand1296592010-03-09 19:17:47 -080076 void reset();
77 void set(float tx, float ty);
78 void set(float a, float b, float c, float d);
79 status_t set(uint32_t flags, float w, float h);
Mathias Agopianeda65402010-02-22 03:15:57 -080080
81 // transform data
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 Rect makeBounds(int w, int h) const;
Mathias Agopianff2ed702013-09-01 21:36:12 -070083 vec2 transform(int x, int y) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084 Region transform(const Region& reg) const;
Pablo Ceballos51450032016-08-03 10:20:45 -070085 Rect transform(const Rect& bounds,
86 bool roundOutwards = false) const;
Dan Stoza80d61162017-12-20 15:57:52 -080087 FloatRect transform(const FloatRect& bounds) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088 Transform operator * (const Transform& rhs) const;
Pablo Ceballosacbe6782016-03-04 17:54:21 +000089 // assumes the last row is < 0 , 0 , 1 >
90 vec2 transform(const vec2& v) const;
91 vec3 transform(const vec3& v) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080092
Mathias Agopian3da16722013-02-28 17:12:07 -080093 Transform inverse() const;
94
Mathias Agopiand1296592010-03-09 19:17:47 -080095 // for debugging
96 void dump(const char* name) const;
97
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098private:
Mathias Agopianeda65402010-02-22 03:15:57 -080099 struct mat33 {
100 vec3 v[3];
101 inline const vec3& operator [] (int i) const { return v[i]; }
102 inline vec3& operator [] (int i) { return v[i]; }
103 };
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104
Mathias Agopianeda65402010-02-22 03:15:57 -0800105 enum { UNKNOWN_TYPE = 0x80000000 };
106
Mathias Agopianeda65402010-02-22 03:15:57 -0800107 uint32_t type() const;
108 static bool absIsOne(float f);
Mathias Agopianeda65402010-02-22 03:15:57 -0800109 static bool isZero(float f);
110
Mathias Agopianeda65402010-02-22 03:15:57 -0800111 mat33 mMatrix;
112 mutable uint32_t mType;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113};
114
115// ---------------------------------------------------------------------------
116}; // namespace android
117
118#endif /* ANDROID_TRANSFORM_H */