Skip to content

Commit aa93961

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Create viewports in a separate function" into main
2 parents 83302fc + 117b757 commit aa93961

6 files changed

Lines changed: 177 additions & 164 deletions

File tree

services/inputflinger/tests/FakeInputReaderPolicy.cpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@ static const int HW_TIMEOUT_MULTIPLIER = base::GetIntProperty("ro.hw_timeout_mul
3131

3232
} // namespace
3333

34+
DisplayViewport createViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
35+
ui::Rotation orientation, bool isActive, const std::string& uniqueId,
36+
std::optional<uint8_t> physicalPort, ViewportType type) {
37+
const bool isRotated = orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270;
38+
DisplayViewport v;
39+
v.displayId = displayId;
40+
v.orientation = orientation;
41+
v.logicalLeft = 0;
42+
v.logicalTop = 0;
43+
v.logicalRight = isRotated ? height : width;
44+
v.logicalBottom = isRotated ? width : height;
45+
v.physicalLeft = 0;
46+
v.physicalTop = 0;
47+
v.physicalRight = isRotated ? height : width;
48+
v.physicalBottom = isRotated ? width : height;
49+
v.deviceWidth = isRotated ? height : width;
50+
v.deviceHeight = isRotated ? width : height;
51+
v.isActive = isActive;
52+
v.uniqueId = uniqueId;
53+
v.physicalPort = physicalPort;
54+
v.type = type;
55+
return v;
56+
};
57+
3458
void FakeInputReaderPolicy::assertInputDevicesChanged() {
3559
waitForInputDevices(
3660
[](bool devicesChanged) {
@@ -115,33 +139,6 @@ void FakeInputReaderPolicy::addDisplayViewport(DisplayViewport viewport) {
115139
mConfig.setDisplayViewports(mViewports);
116140
}
117141

118-
void FakeInputReaderPolicy::addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width,
119-
int32_t height, ui::Rotation orientation,
120-
bool isActive, const std::string& uniqueId,
121-
std::optional<uint8_t> physicalPort,
122-
ViewportType type) {
123-
const bool isRotated = orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270;
124-
DisplayViewport v;
125-
v.displayId = displayId;
126-
v.orientation = orientation;
127-
v.logicalLeft = 0;
128-
v.logicalTop = 0;
129-
v.logicalRight = isRotated ? height : width;
130-
v.logicalBottom = isRotated ? width : height;
131-
v.physicalLeft = 0;
132-
v.physicalTop = 0;
133-
v.physicalRight = isRotated ? height : width;
134-
v.physicalBottom = isRotated ? width : height;
135-
v.deviceWidth = isRotated ? height : width;
136-
v.deviceHeight = isRotated ? width : height;
137-
v.isActive = isActive;
138-
v.uniqueId = uniqueId;
139-
v.physicalPort = physicalPort;
140-
v.type = type;
141-
142-
addDisplayViewport(v);
143-
}
144-
145142
bool FakeInputReaderPolicy::updateViewport(const DisplayViewport& viewport) {
146143
size_t count = mViewports.size();
147144
for (size_t i = 0; i < count; i++) {

services/inputflinger/tests/FakeInputReaderPolicy.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
namespace android {
3333

34+
DisplayViewport createViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
35+
ui::Rotation orientation, bool isActive, const std::string& uniqueId,
36+
std::optional<uint8_t> physicalPort, ViewportType type);
37+
3438
class FakeInputReaderPolicy : public InputReaderPolicyInterface {
3539
protected:
3640
virtual ~FakeInputReaderPolicy() {}
@@ -50,9 +54,6 @@ class FakeInputReaderPolicy : public InputReaderPolicyInterface {
5054
std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
5155
std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t displayPort) const;
5256
void addDisplayViewport(DisplayViewport viewport);
53-
void addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
54-
ui::Rotation orientation, bool isActive, const std::string& uniqueId,
55-
std::optional<uint8_t> physicalPort, ViewportType type);
5657
bool updateViewport(const DisplayViewport& viewport);
5758
void addExcludedDeviceName(const std::string& deviceName);
5859
void addInputPortAssociation(const std::string& inputPort, uint8_t displayPort);

services/inputflinger/tests/InputMapperTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ void InputMapperTest::setDisplayInfoAndReconfigure(ui::LogicalDisplayId displayI
186186
const std::string& uniqueId,
187187
std::optional<uint8_t> physicalPort,
188188
ViewportType viewportType) {
189-
mFakePolicy->addDisplayViewport(displayId, width, height, orientation, /* isActive= */ true,
190-
uniqueId, physicalPort, viewportType);
189+
DisplayViewport viewport =
190+
createViewport(displayId, width, height, orientation, /* isActive= */ true, uniqueId,
191+
physicalPort, viewportType);
192+
mFakePolicy->addDisplayViewport(viewport);
191193
configureDevice(InputReaderConfiguration::Change::DISPLAY_INFO);
192194
}
193195

0 commit comments

Comments
 (0)