The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | class Region; |
| 29 | |
| 30 | // --------------------------------------------------------------------------- |
| 31 | |
| 32 | class Transform |
| 33 | { |
| 34 | public: |
| 35 | Transform(); |
| 36 | Transform(const Transform& other); |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 37 | explicit Transform(uint32_t orientation); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | ~Transform(); |
| 39 | |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 40 | typedef int32_t fixed1616; |
| 41 | |
| 42 | // FIXME: must match OVERLAY_TRANSFORM_*, pull from hardware.h |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | enum orientation_flags { |
| 44 | ROT_0 = 0x00000000, |
| 45 | FLIP_H = 0x00000001, |
| 46 | FLIP_V = 0x00000002, |
| 47 | ROT_90 = 0x00000004, |
| 48 | ROT_180 = FLIP_H|FLIP_V, |
| 49 | ROT_270 = ROT_180|ROT_90, |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 50 | ROT_INVALID = 0x80 |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 53 | enum type_mask { |
| 54 | IDENTITY = 0, |
| 55 | TRANSLATE = 0x1, |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 56 | ROTATE = 0x2, |
| 57 | SCALE = 0x4, |
| 58 | UNKNOWN = 0x8 |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 61 | // query the transform |
| 62 | bool transformed() const; |
| 63 | bool preserveRects() const; |
| 64 | uint32_t getType() const; |
| 65 | uint32_t getOrientation() const; |
| 66 | |
| 67 | float const* operator [] (int i) const; // returns column i |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | int tx() const; |
| 69 | int ty() const; |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 70 | |
| 71 | // modify the transform |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | void reset(); |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 73 | void set(float tx, float ty); |
| 74 | void set(float a, float b, float c, float d); |
| 75 | void set(uint32_t flags, float w, float h); |
| 76 | |
| 77 | // transform data |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | Rect makeBounds(int w, int h) const; |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 79 | void transform(fixed1616* point, int x, int y) const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | Region transform(const Region& reg) const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | Transform operator * (const Transform& rhs) const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
| 83 | private: |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 84 | struct vec3 { |
| 85 | float v[3]; |
| 86 | inline vec3() { } |
| 87 | inline vec3(float a, float b, float c) { |
| 88 | v[0] = a; v[1] = b; v[2] = c; |
| 89 | } |
| 90 | inline float operator [] (int i) const { return v[i]; } |
| 91 | inline float& operator [] (int i) { return v[i]; } |
| 92 | }; |
| 93 | struct vec2 { |
| 94 | float v[2]; |
| 95 | inline vec2() { } |
| 96 | inline vec2(float a, float b) { |
| 97 | v[0] = a; v[1] = b; |
| 98 | } |
| 99 | inline float operator [] (int i) const { return v[i]; } |
| 100 | inline float& operator [] (int i) { return v[i]; } |
| 101 | }; |
| 102 | struct mat33 { |
| 103 | vec3 v[3]; |
| 104 | inline const vec3& operator [] (int i) const { return v[i]; } |
| 105 | inline vec3& operator [] (int i) { return v[i]; } |
| 106 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | |
Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 108 | enum { UNKNOWN_TYPE = 0x80000000 }; |
| 109 | |
| 110 | // assumes the last row is < 0 , 0 , 1 > |
| 111 | vec2 transform(const vec2& v) const; |
| 112 | vec3 transform(const vec3& v) const; |
| 113 | Rect transform(const Rect& bounds) const; |
| 114 | uint32_t type() const; |
| 115 | static bool absIsOne(float f); |
| 116 | static bool absEqual(float a, float b); |
| 117 | static bool isZero(float f); |
| 118 | |
| 119 | void dump(const char* name) const; |
| 120 | |
| 121 | mat33 mMatrix; |
| 122 | mutable uint32_t mType; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | // --------------------------------------------------------------------------- |
| 126 | }; // namespace android |
| 127 | |
| 128 | #endif /* ANDROID_TRANSFORM_H */ |