2009-03-04 03:31:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_TRANSFORM_H
|
|
|
|
#define ANDROID_TRANSFORM_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <ui/Point.h>
|
|
|
|
#include <ui/Rect.h>
|
2013-09-02 04:36:12 +00:00
|
|
|
#include <ui/vec2.h>
|
|
|
|
#include <ui/vec3.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-10-24 21:53:05 +00:00
|
|
|
#include <hardware/hardware.h>
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
namespace android {
|
|
|
|
|
|
|
|
class Region;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Transform
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Transform();
|
|
|
|
Transform(const Transform& other);
|
2010-02-22 11:15:57 +00:00
|
|
|
explicit Transform(uint32_t orientation);
|
2009-03-04 03:31:44 +00:00
|
|
|
~Transform();
|
|
|
|
|
|
|
|
enum orientation_flags {
|
|
|
|
ROT_0 = 0x00000000,
|
2010-10-24 21:53:05 +00:00
|
|
|
FLIP_H = HAL_TRANSFORM_FLIP_H,
|
|
|
|
FLIP_V = HAL_TRANSFORM_FLIP_V,
|
|
|
|
ROT_90 = HAL_TRANSFORM_ROT_90,
|
2009-03-04 03:31:44 +00:00
|
|
|
ROT_180 = FLIP_H|FLIP_V,
|
|
|
|
ROT_270 = ROT_180|ROT_90,
|
2010-02-22 11:15:57 +00:00
|
|
|
ROT_INVALID = 0x80
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
2009-09-24 01:34:53 +00:00
|
|
|
enum type_mask {
|
|
|
|
IDENTITY = 0,
|
|
|
|
TRANSLATE = 0x1,
|
2010-02-22 11:15:57 +00:00
|
|
|
ROTATE = 0x2,
|
|
|
|
SCALE = 0x4,
|
|
|
|
UNKNOWN = 0x8
|
2009-09-24 01:34:53 +00:00
|
|
|
};
|
|
|
|
|
2010-02-22 11:15:57 +00:00
|
|
|
// query the transform
|
|
|
|
bool transformed() const;
|
|
|
|
bool preserveRects() const;
|
|
|
|
uint32_t getType() const;
|
|
|
|
uint32_t getOrientation() const;
|
|
|
|
|
2013-09-02 04:36:12 +00:00
|
|
|
const vec3& operator [] (size_t i) const; // returns column i
|
2011-08-31 01:51:54 +00:00
|
|
|
float tx() const;
|
|
|
|
float ty() const;
|
2010-02-22 11:15:57 +00:00
|
|
|
|
|
|
|
// modify the transform
|
2010-03-10 03:17:47 +00:00
|
|
|
void reset();
|
|
|
|
void set(float tx, float ty);
|
|
|
|
void set(float a, float b, float c, float d);
|
|
|
|
status_t set(uint32_t flags, float w, float h);
|
2010-02-22 11:15:57 +00:00
|
|
|
|
|
|
|
// transform data
|
2009-03-04 03:31:44 +00:00
|
|
|
Rect makeBounds(int w, int h) const;
|
2013-09-02 04:36:12 +00:00
|
|
|
vec2 transform(int x, int y) const;
|
2009-03-04 03:31:44 +00:00
|
|
|
Region transform(const Region& reg) const;
|
2012-05-07 20:51:53 +00:00
|
|
|
Rect transform(const Rect& bounds) const;
|
2009-03-04 03:31:44 +00:00
|
|
|
Transform operator * (const Transform& rhs) const;
|
|
|
|
|
2013-03-01 01:12:07 +00:00
|
|
|
Transform inverse() const;
|
|
|
|
|
2010-03-10 03:17:47 +00:00
|
|
|
// for debugging
|
|
|
|
void dump(const char* name) const;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
private:
|
2010-02-22 11:15:57 +00:00
|
|
|
struct mat33 {
|
|
|
|
vec3 v[3];
|
|
|
|
inline const vec3& operator [] (int i) const { return v[i]; }
|
|
|
|
inline vec3& operator [] (int i) { return v[i]; }
|
|
|
|
};
|
|
|
|
|
|
|
|
enum { UNKNOWN_TYPE = 0x80000000 };
|
|
|
|
|
|
|
|
// assumes the last row is < 0 , 0 , 1 >
|
|
|
|
vec2 transform(const vec2& v) const;
|
|
|
|
vec3 transform(const vec3& v) const;
|
|
|
|
uint32_t type() const;
|
|
|
|
static bool absIsOne(float f);
|
|
|
|
static bool isZero(float f);
|
|
|
|
|
|
|
|
mat33 mMatrix;
|
|
|
|
mutable uint32_t mType;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif /* ANDROID_TRANSFORM_H */
|