blob: 78f5c19601767243d0b99cb3c50e1931150b835d [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>
25
26#include <GLES/gl.h>
27
28#include <core/SkMatrix.h>
29
30namespace android {
31
32class Region;
33
34// ---------------------------------------------------------------------------
35
36class Transform
37{
38public:
39 Transform();
40 Transform(const Transform& other);
41 ~Transform();
42
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,
50 ROT_INVALID = 0x80000000
51 };
52
Mathias Agopiana2fe0a22009-09-23 18:34:53 -070053 enum type_mask {
54 IDENTITY = 0,
55 TRANSLATE = 0x1,
56 SCALE = 0x2,
57 AFFINE = 0x4,
58 PERSPECTIVE = 0x8
59 };
60
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 bool transformed() const;
62 int32_t getOrientation() const;
63 bool preserveRects() const;
64
65 int tx() const;
66 int ty() const;
67
68 void reset();
69 void set(float xx, float xy, float yx, float yy);
70 void set(int tx, int ty);
Mathias Agopian0d1318b2009-03-27 17:58:20 -070071 void set(float radian, float x, float y);
72 void scale(float s, float x, float y);
73
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 Rect makeBounds(int w, int h) const;
75 void transform(GLfixed* point, int x, int y) const;
76 Region transform(const Region& reg) const;
77 Rect transform(const Rect& bounds) const;
78
79 Transform operator * (const Transform& rhs) const;
80 float operator [] (int i) const;
81
82 inline uint32_t getType() const { return type(); }
83
84 inline Transform(bool) : mType(0xFF) { };
85
86private:
87 uint8_t type() const;
88
89private:
90 SkMatrix mTransform;
91 mutable uint32_t mType;
92};
93
94// ---------------------------------------------------------------------------
95}; // namespace android
96
97#endif /* ANDROID_TRANSFORM_H */