| 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> | 
| Mathias Agopian | 1d77b71 | 2017-02-17 15:46:13 -0800 | [diff] [blame] | 25 | #include <math/vec2.h> | 
 | 26 | #include <math/vec3.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 |  | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 28 | #include <gui/ISurfaceComposer.h> | 
 | 29 |  | 
| Mathias Agopian | 0694d0f | 2010-10-24 14:53:05 -0700 | [diff] [blame] | 30 | #include <hardware/hardware.h> | 
 | 31 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | namespace android { | 
 | 33 |  | 
 | 34 | class Region; | 
 | 35 |  | 
 | 36 | // --------------------------------------------------------------------------- | 
 | 37 |  | 
 | 38 | class Transform | 
 | 39 | { | 
 | 40 | public: | 
 | 41 |                     Transform(); | 
 | 42 |                     Transform(const Transform&  other); | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 43 |            explicit Transform(uint32_t orientation); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 |                     ~Transform(); | 
 | 45 |  | 
 | 46 |             enum orientation_flags { | 
 | 47 |                 ROT_0   = 0x00000000, | 
| Mathias Agopian | 0694d0f | 2010-10-24 14:53:05 -0700 | [diff] [blame] | 48 |                 FLIP_H  = HAL_TRANSFORM_FLIP_H, | 
 | 49 |                 FLIP_V  = HAL_TRANSFORM_FLIP_V, | 
 | 50 |                 ROT_90  = HAL_TRANSFORM_ROT_90, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 |                 ROT_180 = FLIP_H|FLIP_V, | 
 | 52 |                 ROT_270 = ROT_180|ROT_90, | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 53 |                 ROT_INVALID = 0x80 | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 |             }; | 
 | 55 |  | 
| chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 56 |             static orientation_flags fromRotation(ISurfaceComposer::Rotation rotation); | 
 | 57 |  | 
| Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 58 |             enum type_mask { | 
 | 59 |                 IDENTITY            = 0, | 
 | 60 |                 TRANSLATE           = 0x1, | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 61 |                 ROTATE              = 0x2, | 
 | 62 |                 SCALE               = 0x4, | 
 | 63 |                 UNKNOWN             = 0x8 | 
| Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 64 |             }; | 
 | 65 |  | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 66 |             // query the transform | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 67 |             bool        preserveRects() const; | 
 | 68 |             uint32_t    getType() const; | 
 | 69 |             uint32_t    getOrientation() const; | 
 | 70 |  | 
| Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 71 |             const vec3& operator [] (size_t i) const;  // returns column i | 
| Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 72 |             float   tx() const; | 
 | 73 |             float   ty() const; | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 74 |  | 
 | 75 |             // modify the transform | 
| Mathias Agopian | d129659 | 2010-03-09 19:17:47 -0800 | [diff] [blame] | 76 |             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 Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 80 |  | 
 | 81 |             // transform data | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 |             Rect    makeBounds(int w, int h) const; | 
| Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 83 |             vec2    transform(int x, int y) const; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 |             Region  transform(const Region& reg) const; | 
| Pablo Ceballos | 5145003 | 2016-08-03 10:20:45 -0700 | [diff] [blame] | 85 |             Rect    transform(const Rect& bounds, | 
 | 86 |                     bool roundOutwards = false) const; | 
| Dan Stoza | 80d6116 | 2017-12-20 15:57:52 -0800 | [diff] [blame] | 87 |             FloatRect transform(const FloatRect& bounds) const; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 |             Transform operator * (const Transform& rhs) const; | 
| Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 89 |             // 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 |  | 
| Mathias Agopian | 3da1672 | 2013-02-28 17:12:07 -0800 | [diff] [blame] | 93 |             Transform inverse() const; | 
 | 94 |  | 
| Mathias Agopian | d129659 | 2010-03-09 19:17:47 -0800 | [diff] [blame] | 95 |             // for debugging | 
 | 96 |             void dump(const char* name) const; | 
 | 97 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | private: | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 99 |     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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 |  | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 105 |     enum { UNKNOWN_TYPE = 0x80000000 }; | 
 | 106 |  | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 107 |     uint32_t type() const; | 
 | 108 |     static bool absIsOne(float f); | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 109 |     static bool isZero(float f); | 
 | 110 |  | 
| Mathias Agopian | eda6540 | 2010-02-22 03:15:57 -0800 | [diff] [blame] | 111 |     mat33               mMatrix; | 
 | 112 |     mutable uint32_t    mType; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | }; | 
 | 114 |  | 
 | 115 | // --------------------------------------------------------------------------- | 
 | 116 | }; // namespace android | 
 | 117 |  | 
 | 118 | #endif /* ANDROID_TRANSFORM_H */ |