libui: add the Rect::transform method
This change adds a method to Rect to transform a rectangle by a graphics HAL
transform.
Change-Id: Ic0d0988e731bdb5662faee41a5927b1242891658
Bug: 6299171
diff --git a/libs/ui/Rect.cpp b/libs/ui/Rect.cpp
index 5694e00..65fe5f9 100644
--- a/libs/ui/Rect.cpp
+++ b/libs/ui/Rect.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <system/graphics.h>
#include <ui/Rect.h>
namespace android {
@@ -92,4 +93,24 @@
return !(result->isEmpty());
}
+Rect Rect::transform(uint32_t xform, int32_t width, int32_t height) {
+ Rect result(*this);
+ if (xform & HAL_TRANSFORM_FLIP_H) {
+ result = Rect(width - result.right, result.top,
+ width - result.left, result.bottom);
+ }
+ if (xform & HAL_TRANSFORM_FLIP_V) {
+ result = Rect(result.left, height - result.bottom,
+ result.right, height - result.top);
+ }
+ if (xform & HAL_TRANSFORM_ROT_90) {
+ int left = height - result.bottom;
+ int top = result.left;
+ int right = height - result.top;
+ int bottom = result.right;
+ result = Rect(left, top, right, bottom);
+ }
+ return result;
+}
+
}; // namespace android