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 | |
| 26 | #include <GLES/gl.h> |
| 27 | |
| 28 | #include <core/SkMatrix.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | class Region; |
| 33 | |
| 34 | // --------------------------------------------------------------------------- |
| 35 | |
| 36 | class Transform |
| 37 | { |
| 38 | public: |
| 39 | Transform(); |
| 40 | Transform(const Transform& other); |
Chih-Chung Chang | 52e7200 | 2010-01-21 17:31:06 -0800 | [diff] [blame] | 41 | Transform(int32_t flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | ~Transform(); |
| 43 | |
| 44 | enum orientation_flags { |
| 45 | ROT_0 = 0x00000000, |
| 46 | FLIP_H = 0x00000001, |
| 47 | FLIP_V = 0x00000002, |
| 48 | ROT_90 = 0x00000004, |
| 49 | ROT_180 = FLIP_H|FLIP_V, |
| 50 | ROT_270 = ROT_180|ROT_90, |
| 51 | ROT_INVALID = 0x80000000 |
| 52 | }; |
| 53 | |
Mathias Agopian | a2fe0a2 | 2009-09-23 18:34:53 -0700 | [diff] [blame] | 54 | enum type_mask { |
| 55 | IDENTITY = 0, |
| 56 | TRANSLATE = 0x1, |
| 57 | SCALE = 0x2, |
| 58 | AFFINE = 0x4, |
| 59 | PERSPECTIVE = 0x8 |
| 60 | }; |
| 61 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | bool transformed() const; |
| 63 | int32_t getOrientation() const; |
| 64 | bool preserveRects() const; |
| 65 | |
| 66 | int tx() const; |
| 67 | int ty() const; |
| 68 | |
| 69 | void reset(); |
| 70 | void set(float xx, float xy, float yx, float yy); |
| 71 | void set(int tx, int ty); |
Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 72 | void set(float radian, float x, float y); |
| 73 | void scale(float s, float x, float y); |
| 74 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | Rect makeBounds(int w, int h) const; |
| 76 | void transform(GLfixed* point, int x, int y) const; |
| 77 | Region transform(const Region& reg) const; |
| 78 | Rect transform(const Rect& bounds) const; |
| 79 | |
| 80 | Transform operator * (const Transform& rhs) const; |
| 81 | float operator [] (int i) const; |
| 82 | |
| 83 | inline uint32_t getType() const { return type(); } |
| 84 | |
| 85 | inline Transform(bool) : mType(0xFF) { }; |
| 86 | |
| 87 | private: |
| 88 | uint8_t type() const; |
| 89 | |
| 90 | private: |
| 91 | SkMatrix mTransform; |
| 92 | mutable uint32_t mType; |
| 93 | }; |
| 94 | |
| 95 | // --------------------------------------------------------------------------- |
| 96 | }; // namespace android |
| 97 | |
| 98 | #endif /* ANDROID_TRANSFORM_H */ |