summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorAlec Mouri <alecmouri@google.com>2022-04-07 20:58:00 +0000
committerAlec Mouri <alecmouri@google.com>2022-04-14 22:47:22 +0000
commit168f6ccfce328a1224297ba5b7af2779fcee0d9a (patch)
treef95fc435b3ba94f38046b2b85e69f48a92b3171a /libs
parent4d8a05d372f8cf40a294ed4e9718b54b51f15a34 (diff)
downloadnative-168f6ccfce328a1224297ba5b7af2779fcee0d9a.tar.gz
Set better defaults for layer stack and oriented display space
When the device is not logically rotated and there is a 90 degree or 270 degree physical installation, then the content rectangle and bounds of the layer stack space and the oriented display space must be consistent with the framebuffer space and un-oriented display space. That is, if the framebuffer space and un-oriented display space are in portrait, then the layer stack space and the oriented display space should be in landscape without any cropping effects. Prior to this patch, devices with a rotated physical install orientation would have its boot animation cropped due to the mismatch in the logical display space and physical display space Bug: 203165976 Test: boot animation is not cropped Change-Id: I965b6c0578e982fe1b2a4dbdb18c24b5922388a9
Diffstat (limited to 'libs')
-rw-r--r--libs/ui/include/ui/Size.h12
-rw-r--r--libs/ui/tests/Size_test.cpp32
2 files changed, 44 insertions, 0 deletions
diff --git a/libs/ui/include/ui/Size.h b/libs/ui/include/ui/Size.h
index ecc192dcae..bdcbd569fc 100644
--- a/libs/ui/include/ui/Size.h
+++ b/libs/ui/include/ui/Size.h
@@ -23,6 +23,8 @@
#include <type_traits>
#include <utility>
+#include <ui/Rotation.h>
+
namespace android::ui {
// A simple value type representing a two-dimensional size.
@@ -61,6 +63,16 @@ struct Size {
set(Size(w, h));
}
+ // Applies a rotation onto the size
+ void rotate(Rotation rotation) {
+ if (rotation == ROTATION_90 || rotation == ROTATION_270) {
+ transpose();
+ }
+ }
+
+ // Swaps the width and height, emulating a 90 degree rotation.
+ void transpose() { std::swap(width, height); }
+
// Sets the value to kInvalidSize
void makeInvalid();
diff --git a/libs/ui/tests/Size_test.cpp b/libs/ui/tests/Size_test.cpp
index acef47fb97..0a236e60e4 100644
--- a/libs/ui/tests/Size_test.cpp
+++ b/libs/ui/tests/Size_test.cpp
@@ -61,6 +61,38 @@ TEST(SizeTest, BasicLessThanComparison) {
EXPECT_FALSE(Size(1, 1) < Size(1, 1));
}
+TEST(SizeTest, Transpose) {
+ Size s(123, 456);
+ s.transpose();
+ EXPECT_EQ(s, Size(456, 123));
+}
+
+TEST(SizeTest, Rotate) {
+ {
+ Size s(123, 456);
+ s.rotate(Rotation::Rotation0);
+ EXPECT_EQ(s, Size(123, 456));
+ }
+
+ {
+ Size s(123, 456);
+ s.rotate(Rotation::Rotation90);
+ EXPECT_EQ(s, Size(456, 123));
+ }
+
+ {
+ Size s(123, 456);
+ s.rotate(Rotation::Rotation180);
+ EXPECT_EQ(s, Size(123, 456));
+ }
+
+ {
+ Size s(123, 456);
+ s.rotate(Rotation::Rotation270);
+ EXPECT_EQ(s, Size(456, 123));
+ }
+}
+
TEST(SizeTest, ValidAndEmpty) {
{
Size s;