Transform.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef ANDROID_TRANSFORM_H
  17. #define ANDROID_TRANSFORM_H
  18. #include <stdint.h>
  19. #include <sys/types.h>
  20. #include <ui/Point.h>
  21. #include <ui/Rect.h>
  22. #include <ui/vec2.h>
  23. #include <ui/vec3.h>
  24. #include <hardware/hardware.h>
  25. namespace android {
  26. class Region;
  27. // ---------------------------------------------------------------------------
  28. class Transform
  29. {
  30. public:
  31. Transform();
  32. Transform(const Transform& other);
  33. explicit Transform(uint32_t orientation);
  34. ~Transform();
  35. enum orientation_flags {
  36. ROT_0 = 0x00000000,
  37. FLIP_H = HAL_TRANSFORM_FLIP_H,
  38. FLIP_V = HAL_TRANSFORM_FLIP_V,
  39. ROT_90 = HAL_TRANSFORM_ROT_90,
  40. ROT_180 = FLIP_H|FLIP_V,
  41. ROT_270 = ROT_180|ROT_90,
  42. ROT_INVALID = 0x80
  43. };
  44. enum type_mask {
  45. IDENTITY = 0,
  46. TRANSLATE = 0x1,
  47. ROTATE = 0x2,
  48. SCALE = 0x4,
  49. UNKNOWN = 0x8
  50. };
  51. // query the transform
  52. bool transformed() const;
  53. bool preserveRects() const;
  54. uint32_t getType() const;
  55. uint32_t getOrientation() const;
  56. const vec3& operator [] (size_t i) const; // returns column i
  57. float tx() const;
  58. float ty() const;
  59. // modify the transform
  60. void reset();
  61. void set(float tx, float ty);
  62. void set(float a, float b, float c, float d);
  63. status_t set(uint32_t flags, float w, float h);
  64. // transform data
  65. Rect makeBounds(int w, int h) const;
  66. vec2 transform(int x, int y) const;
  67. Region transform(const Region& reg) const;
  68. Rect transform(const Rect& bounds) const;
  69. Transform operator * (const Transform& rhs) const;
  70. Transform inverse() const;
  71. // for debugging
  72. void dump(const char* name) const;
  73. private:
  74. struct mat33 {
  75. vec3 v[3];
  76. inline const vec3& operator [] (int i) const { return v[i]; }
  77. inline vec3& operator [] (int i) { return v[i]; }
  78. };
  79. enum { UNKNOWN_TYPE = 0x80000000 };
  80. // assumes the last row is < 0 , 0 , 1 >
  81. vec2 transform(const vec2& v) const;
  82. vec3 transform(const vec3& v) const;
  83. uint32_t type() const;
  84. static bool absIsOne(float f);
  85. static bool isZero(float f);
  86. mat33 mMatrix;
  87. mutable uint32_t mType;
  88. };
  89. // ---------------------------------------------------------------------------
  90. }; // namespace android
  91. #endif /* ANDROID_TRANSFORM_H */