From 168f6ccfce328a1224297ba5b7af2779fcee0d9a Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Thu, 7 Apr 2022 20:58:00 +0000 Subject: 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 --- libs/ui/include/ui/Size.h | 12 ++++++++++++ libs/ui/tests/Size_test.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'libs') 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 #include +#include + 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; -- cgit v1.2.3-59-g8ed1b