Skip to content

Commit d728bf5

Browse files
author
Jeff Brown
committed
Make display manager tell input system about viewports.
The window manager is no longer responsible for telling the input system about the display viewport. Change-Id: I932882bae55decef55f25093bb2a7ebac1620bb1
1 parent 631938f commit d728bf5

18 files changed

+419
-213
lines changed

services/input/InputReader.cpp

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -203,34 +203,18 @@ static void synthesizeButtonKeys(InputReaderContext* context, int32_t action,
203203

204204
// --- InputReaderConfiguration ---
205205

206-
bool InputReaderConfiguration::getDisplayInfo(int32_t displayId, bool external,
207-
int32_t* width, int32_t* height, int32_t* orientation) const {
208-
if (displayId == 0) {
209-
const DisplayInfo& info = external ? mExternalDisplay : mInternalDisplay;
210-
if (info.width > 0 && info.height > 0) {
211-
if (width) {
212-
*width = info.width;
213-
}
214-
if (height) {
215-
*height = info.height;
216-
}
217-
if (orientation) {
218-
*orientation = info.orientation;
219-
}
220-
return true;
221-
}
206+
bool InputReaderConfiguration::getDisplayInfo(bool external, DisplayViewport* outViewport) const {
207+
const DisplayViewport& viewport = external ? mExternalDisplay : mInternalDisplay;
208+
if (viewport.displayId >= 0) {
209+
*outViewport = viewport;
210+
return true;
222211
}
223212
return false;
224213
}
225214

226-
void InputReaderConfiguration::setDisplayInfo(int32_t displayId, bool external,
227-
int32_t width, int32_t height, int32_t orientation) {
228-
if (displayId == 0) {
229-
DisplayInfo& info = external ? mExternalDisplay : mInternalDisplay;
230-
info.width = width;
231-
info.height = height;
232-
info.orientation = orientation;
233-
}
215+
void InputReaderConfiguration::setDisplayInfo(bool external, const DisplayViewport& viewport) {
216+
DisplayViewport& v = external ? mExternalDisplay : mInternalDisplay;
217+
v = viewport;
234218
}
235219

236220

@@ -2001,9 +1985,11 @@ void KeyboardInputMapper::configure(nsecs_t when,
20011985
}
20021986

20031987
if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
2004-
if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0) {
2005-
if (!config->getDisplayInfo(mParameters.associatedDisplayId,
2006-
false /*external*/, NULL, NULL, &mOrientation)) {
1988+
if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
1989+
DisplayViewport v;
1990+
if (config->getDisplayInfo(false /*external*/, &v)) {
1991+
mOrientation = v.orientation;
1992+
} else {
20071993
mOrientation = DISPLAY_ORIENTATION_0;
20081994
}
20091995
} else {
@@ -2017,16 +2003,16 @@ void KeyboardInputMapper::configureParameters() {
20172003
getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"),
20182004
mParameters.orientationAware);
20192005

2020-
mParameters.associatedDisplayId = -1;
2006+
mParameters.hasAssociatedDisplay = false;
20212007
if (mParameters.orientationAware) {
2022-
mParameters.associatedDisplayId = 0;
2008+
mParameters.hasAssociatedDisplay = true;
20232009
}
20242010
}
20252011

20262012
void KeyboardInputMapper::dumpParameters(String8& dump) {
20272013
dump.append(INDENT3 "Parameters:\n");
2028-
dump.appendFormat(INDENT4 "AssociatedDisplayId: %d\n",
2029-
mParameters.associatedDisplayId);
2014+
dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n",
2015+
toString(mParameters.hasAssociatedDisplay));
20302016
dump.appendFormat(INDENT4 "OrientationAware: %s\n",
20312017
toString(mParameters.orientationAware));
20322018
}
@@ -2086,7 +2072,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
20862072

20872073
if (down) {
20882074
// Rotate key codes according to orientation if needed.
2089-
if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0) {
2075+
if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
20902076
keyCode = rotateKeyCode(keyCode, mOrientation);
20912077
}
20922078

@@ -2317,9 +2303,11 @@ void CursorInputMapper::configure(nsecs_t when,
23172303
}
23182304

23192305
if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
2320-
if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0) {
2321-
if (!config->getDisplayInfo(mParameters.associatedDisplayId,
2322-
false /*external*/, NULL, NULL, &mOrientation)) {
2306+
if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
2307+
DisplayViewport v;
2308+
if (config->getDisplayInfo(false /*external*/, &v)) {
2309+
mOrientation = v.orientation;
2310+
} else {
23232311
mOrientation = DISPLAY_ORIENTATION_0;
23242312
}
23252313
} else {
@@ -2344,16 +2332,16 @@ void CursorInputMapper::configureParameters() {
23442332
getDevice()->getConfiguration().tryGetProperty(String8("cursor.orientationAware"),
23452333
mParameters.orientationAware);
23462334

2347-
mParameters.associatedDisplayId = -1;
2335+
mParameters.hasAssociatedDisplay = false;
23482336
if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
2349-
mParameters.associatedDisplayId = 0;
2337+
mParameters.hasAssociatedDisplay = true;
23502338
}
23512339
}
23522340

23532341
void CursorInputMapper::dumpParameters(String8& dump) {
23542342
dump.append(INDENT3 "Parameters:\n");
2355-
dump.appendFormat(INDENT4 "AssociatedDisplayId: %d\n",
2356-
mParameters.associatedDisplayId);
2343+
dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n",
2344+
toString(mParameters.hasAssociatedDisplay));
23572345

23582346
switch (mParameters.mode) {
23592347
case Parameters::MODE_POINTER:
@@ -2420,7 +2408,7 @@ void CursorInputMapper::sync(nsecs_t when) {
24202408
bool moved = deltaX != 0 || deltaY != 0;
24212409

24222410
// Rotate delta according to orientation if needed.
2423-
if (mParameters.orientationAware && mParameters.associatedDisplayId >= 0
2411+
if (mParameters.orientationAware && mParameters.hasAssociatedDisplay
24242412
&& (deltaX != 0.0f || deltaY != 0.0f)) {
24252413
rotateDelta(mOrientation, &deltaX, &deltaY);
24262414
}
@@ -2782,15 +2770,15 @@ void TouchInputMapper::configureParameters() {
27822770
getDevice()->getConfiguration().tryGetProperty(String8("touch.orientationAware"),
27832771
mParameters.orientationAware);
27842772

2785-
mParameters.associatedDisplayId = -1;
2773+
mParameters.hasAssociatedDisplay = false;
27862774
mParameters.associatedDisplayIsExternal = false;
27872775
if (mParameters.orientationAware
27882776
|| mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
27892777
|| mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) {
2778+
mParameters.hasAssociatedDisplay = true;
27902779
mParameters.associatedDisplayIsExternal =
27912780
mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
27922781
&& getDevice()->isExternal();
2793-
mParameters.associatedDisplayId = 0;
27942782
}
27952783
}
27962784

@@ -2822,8 +2810,9 @@ void TouchInputMapper::dumpParameters(String8& dump) {
28222810
ALOG_ASSERT(false);
28232811
}
28242812

2825-
dump.appendFormat(INDENT4 "AssociatedDisplay: id=%d, isExternal=%s\n",
2826-
mParameters.associatedDisplayId, toString(mParameters.associatedDisplayIsExternal));
2813+
dump.appendFormat(INDENT4 "AssociatedDisplay: present=%s, isExternal=%s\n",
2814+
toString(mParameters.hasAssociatedDisplay),
2815+
toString(mParameters.associatedDisplayIsExternal));
28272816
dump.appendFormat(INDENT4 "OrientationAware: %s\n",
28282817
toString(mParameters.orientationAware));
28292818
}
@@ -2861,7 +2850,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
28612850
mSource |= AINPUT_SOURCE_STYLUS;
28622851
}
28632852
} else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
2864-
&& mParameters.associatedDisplayId >= 0) {
2853+
&& mParameters.hasAssociatedDisplay) {
28652854
mSource = AINPUT_SOURCE_TOUCHSCREEN;
28662855
mDeviceMode = DEVICE_MODE_DIRECT;
28672856
if (hasStylus()) {
@@ -2881,15 +2870,13 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
28812870
}
28822871

28832872
// Get associated display dimensions.
2884-
if (mParameters.associatedDisplayId >= 0) {
2885-
if (!mConfig.getDisplayInfo(mParameters.associatedDisplayId,
2886-
mParameters.associatedDisplayIsExternal,
2887-
&mAssociatedDisplayWidth, &mAssociatedDisplayHeight,
2888-
&mAssociatedDisplayOrientation)) {
2873+
if (mParameters.hasAssociatedDisplay) {
2874+
if (!mConfig.getDisplayInfo(mParameters.associatedDisplayIsExternal,
2875+
&mAssociatedDisplayViewport)) {
28892876
ALOGI(INDENT "Touch device '%s' could not query the properties of its associated "
2890-
"display %d. The device will be inoperable until the display size "
2877+
"display. The device will be inoperable until the display size "
28912878
"becomes available.",
2892-
getDeviceName().string(), mParameters.associatedDisplayId);
2879+
getDeviceName().string());
28932880
mDeviceMode = DEVICE_MODE_DISABLED;
28942881
return;
28952882
}
@@ -2898,10 +2885,16 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
28982885
// Configure dimensions.
28992886
int32_t width, height, orientation;
29002887
if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
2901-
width = mAssociatedDisplayWidth;
2902-
height = mAssociatedDisplayHeight;
2888+
width = mAssociatedDisplayViewport.logicalRight - mAssociatedDisplayViewport.logicalLeft;
2889+
height = mAssociatedDisplayViewport.logicalBottom - mAssociatedDisplayViewport.logicalTop;
2890+
if (mAssociatedDisplayViewport.orientation == DISPLAY_ORIENTATION_90
2891+
|| mAssociatedDisplayViewport.orientation == DISPLAY_ORIENTATION_270) {
2892+
int32_t temp = height;
2893+
height = width;
2894+
width = temp;
2895+
}
29032896
orientation = mParameters.orientationAware ?
2904-
mAssociatedDisplayOrientation : DISPLAY_ORIENTATION_0;
2897+
mAssociatedDisplayViewport.orientation : DISPLAY_ORIENTATION_0;
29052898
} else {
29062899
width = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
29072900
height = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
@@ -3163,8 +3156,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
31633156
int32_t rawWidth = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
31643157
int32_t rawHeight = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
31653158
float rawDiagonal = hypotf(rawWidth, rawHeight);
3166-
float displayDiagonal = hypotf(mAssociatedDisplayWidth,
3167-
mAssociatedDisplayHeight);
3159+
float displayDiagonal = hypotf(width, height);
31683160

31693161
// Scale movements such that one whole swipe of the touch pad covers a
31703162
// given area relative to the diagonal size of the display when no acceleration

services/input/InputReader.h

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <androidfw/Input.h>
2525
#include <androidfw/VelocityControl.h>
2626
#include <androidfw/VelocityTracker.h>
27-
#include <ui/DisplayInfo.h>
2827
#include <utils/KeyedVector.h>
2928
#include <utils/threads.h>
3029
#include <utils/Timers.h>
@@ -48,6 +47,45 @@ namespace android {
4847
class InputDevice;
4948
class InputMapper;
5049

50+
/*
51+
* Describes how coordinates are mapped on a physical display.
52+
* See com.android.server.display.DisplayViewport.
53+
*/
54+
struct DisplayViewport {
55+
int32_t displayId; // -1 if invalid
56+
int32_t orientation;
57+
int32_t logicalLeft;
58+
int32_t logicalTop;
59+
int32_t logicalRight;
60+
int32_t logicalBottom;
61+
int32_t physicalLeft;
62+
int32_t physicalTop;
63+
int32_t physicalRight;
64+
int32_t physicalBottom;
65+
66+
DisplayViewport() :
67+
displayId(-1), orientation(DISPLAY_ORIENTATION_0),
68+
logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
69+
physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0) {
70+
}
71+
72+
bool operator==(const DisplayViewport& other) const {
73+
return displayId == other.displayId
74+
&& orientation == other.orientation
75+
&& logicalLeft == other.logicalLeft
76+
&& logicalTop == other.logicalTop
77+
&& logicalRight == other.logicalRight
78+
&& logicalBottom == other.logicalBottom
79+
&& physicalLeft == other.physicalLeft
80+
&& physicalTop == other.physicalTop
81+
&& physicalRight == other.physicalRight
82+
&& physicalBottom == other.physicalBottom;
83+
}
84+
85+
bool operator!=(const DisplayViewport& other) const {
86+
return !(*this == other);
87+
}
88+
};
5189

5290
/*
5391
* Input reader configuration.
@@ -180,25 +218,12 @@ struct InputReaderConfiguration {
180218
pointerGestureZoomSpeedRatio(0.3f),
181219
showTouches(false) { }
182220

183-
bool getDisplayInfo(int32_t displayId, bool external,
184-
int32_t* width, int32_t* height, int32_t* orientation) const;
185-
186-
void setDisplayInfo(int32_t displayId, bool external,
187-
int32_t width, int32_t height, int32_t orientation);
221+
bool getDisplayInfo(bool external, DisplayViewport* outViewport) const;
222+
void setDisplayInfo(bool external, const DisplayViewport& viewport);
188223

189224
private:
190-
struct DisplayInfo {
191-
int32_t width;
192-
int32_t height;
193-
int32_t orientation;
194-
195-
DisplayInfo() :
196-
width(-1), height(-1), orientation(DISPLAY_ORIENTATION_0) {
197-
}
198-
};
199-
200-
DisplayInfo mInternalDisplay;
201-
DisplayInfo mExternalDisplay;
225+
DisplayViewport mInternalDisplay;
226+
DisplayViewport mExternalDisplay;
202227
};
203228

204229

@@ -992,7 +1017,7 @@ class KeyboardInputMapper : public InputMapper {
9921017

9931018
// Immutable configuration parameters.
9941019
struct Parameters {
995-
int32_t associatedDisplayId;
1020+
bool hasAssociatedDisplay;
9961021
bool orientationAware;
9971022
} mParameters;
9981023

@@ -1042,7 +1067,7 @@ class CursorInputMapper : public InputMapper {
10421067
};
10431068

10441069
Mode mode;
1045-
int32_t associatedDisplayId;
1070+
bool hasAssociatedDisplay;
10461071
bool orientationAware;
10471072
} mParameters;
10481073

@@ -1143,7 +1168,7 @@ class TouchInputMapper : public InputMapper {
11431168
};
11441169

11451170
DeviceType deviceType;
1146-
int32_t associatedDisplayId;
1171+
bool hasAssociatedDisplay;
11471172
bool associatedDisplayIsExternal;
11481173
bool orientationAware;
11491174

@@ -1277,10 +1302,8 @@ class TouchInputMapper : public InputMapper {
12771302
int32_t mSurfaceWidth;
12781303
int32_t mSurfaceHeight;
12791304

1280-
// The associated display orientation and width and height set by configureSurface().
1281-
int32_t mAssociatedDisplayOrientation;
1282-
int32_t mAssociatedDisplayWidth;
1283-
int32_t mAssociatedDisplayHeight;
1305+
// The associated display viewport set by configureSurface().
1306+
DisplayViewport mAssociatedDisplayViewport;
12841307

12851308
// Translation and scaling factors, orientation-independent.
12861309
float mXScale;

services/input/PointerController.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,17 @@ void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout
307307
}
308308
}
309309

310-
void PointerController::setDisplaySize(int32_t width, int32_t height) {
310+
void PointerController::setDisplayViewport(int32_t width, int32_t height, int32_t orientation) {
311311
AutoMutex _l(mLock);
312312

313+
// Adjust to use the display's unrotated coordinate frame.
314+
if (orientation == DISPLAY_ORIENTATION_90
315+
|| orientation == DISPLAY_ORIENTATION_270) {
316+
int32_t temp = height;
317+
height = width;
318+
width = temp;
319+
}
320+
313321
if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
314322
mLocked.displayWidth = width;
315323
mLocked.displayHeight = height;
@@ -324,12 +332,7 @@ void PointerController::setDisplaySize(int32_t width, int32_t height) {
324332
}
325333

326334
fadeOutAndReleaseAllSpotsLocked();
327-
updatePointerLocked();
328335
}
329-
}
330-
331-
void PointerController::setDisplayOrientation(int32_t orientation) {
332-
AutoMutex _l(mLock);
333336

334337
if (mLocked.displayOrientation != orientation) {
335338
// Apply offsets to convert from the pixel top-left corner position to the pixel center.
@@ -380,9 +383,9 @@ void PointerController::setDisplayOrientation(int32_t orientation) {
380383
mLocked.pointerX = x - 0.5f;
381384
mLocked.pointerY = y - 0.5f;
382385
mLocked.displayOrientation = orientation;
383-
384-
updatePointerLocked();
385386
}
387+
388+
updatePointerLocked();
386389
}
387390

388391
void PointerController::setPointerIcon(const SpriteIcon& icon) {

0 commit comments

Comments
 (0)