Merge changes from topics "cursor_type_hotspot", "set_viewport_in_input_reader" am: 43beafe0b0
Change-Id: Ib3930377b494bf7bafce339165dff428a30563b6
This commit is contained in:
commit
036b105b6e
7 changed files with 80 additions and 15 deletions
|
@ -99,6 +99,16 @@ std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportByPor
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewportById(
|
||||||
|
int32_t displayId) const {
|
||||||
|
for (const DisplayViewport& currentViewport : mDisplays) {
|
||||||
|
if (currentViewport.displayId == displayId) {
|
||||||
|
return std::make_optional(currentViewport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
void InputReaderConfiguration::setDisplayViewports(const std::vector<DisplayViewport>& viewports) {
|
void InputReaderConfiguration::setDisplayViewports(const std::vector<DisplayViewport>& viewports) {
|
||||||
mDisplays = viewports;
|
mDisplays = viewports;
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,6 +172,9 @@ struct InputReaderConfiguration {
|
||||||
// Used to determine which DisplayViewport should be tied to which InputDevice.
|
// Used to determine which DisplayViewport should be tied to which InputDevice.
|
||||||
std::unordered_map<std::string, uint8_t> portAssociations;
|
std::unordered_map<std::string, uint8_t> portAssociations;
|
||||||
|
|
||||||
|
// The suggested display ID to show the cursor.
|
||||||
|
int32_t defaultPointerDisplayId;
|
||||||
|
|
||||||
// Velocity control parameters for mouse pointer movements.
|
// Velocity control parameters for mouse pointer movements.
|
||||||
VelocityControlParameters pointerVelocityControlParameters;
|
VelocityControlParameters pointerVelocityControlParameters;
|
||||||
|
|
||||||
|
@ -274,6 +277,7 @@ struct InputReaderConfiguration {
|
||||||
std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
|
std::optional<DisplayViewport> getDisplayViewportByUniqueId(const std::string& uniqueDisplayId)
|
||||||
const;
|
const;
|
||||||
std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const;
|
std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t physicalPort) const;
|
||||||
|
std::optional<DisplayViewport> getDisplayViewportById(int32_t displayId) const;
|
||||||
void setDisplayViewports(const std::vector<DisplayViewport>& viewports);
|
void setDisplayViewports(const std::vector<DisplayViewport>& viewports);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#ifndef _INPUTFLINGER_POINTER_CONTROLLER_INTERFACE_H
|
#ifndef _INPUTFLINGER_POINTER_CONTROLLER_INTERFACE_H
|
||||||
#define _INPUTFLINGER_POINTER_CONTROLLER_INTERFACE_H
|
#define _INPUTFLINGER_POINTER_CONTROLLER_INTERFACE_H
|
||||||
|
|
||||||
|
#include <input/DisplayViewport.h>
|
||||||
#include <input/Input.h>
|
#include <input/Input.h>
|
||||||
#include <utils/BitSet.h>
|
#include <utils/BitSet.h>
|
||||||
#include <utils/RefBase.h>
|
#include <utils/RefBase.h>
|
||||||
|
@ -101,6 +102,9 @@ public:
|
||||||
|
|
||||||
/* Gets the id of the display where the pointer should be shown. */
|
/* Gets the id of the display where the pointer should be shown. */
|
||||||
virtual int32_t getDisplayId() const = 0;
|
virtual int32_t getDisplayId() const = 0;
|
||||||
|
|
||||||
|
/* Sets the associated display of this pointer. Pointer should show on that display. */
|
||||||
|
virtual void setDisplayViewport(const DisplayViewport& displayViewport) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
|
@ -189,12 +189,32 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
|
||||||
|
|
||||||
// Update the PointerController if viewports changed.
|
// Update the PointerController if viewports changed.
|
||||||
if (mParameters.mode == Parameters::MODE_POINTER) {
|
if (mParameters.mode == Parameters::MODE_POINTER) {
|
||||||
getPolicy()->obtainPointerController(getDeviceId());
|
updatePointerControllerDisplayViewport(*config);
|
||||||
}
|
}
|
||||||
bumpGeneration();
|
bumpGeneration();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CursorInputMapper::updatePointerControllerDisplayViewport(
|
||||||
|
const InputReaderConfiguration& config) {
|
||||||
|
std::optional<DisplayViewport> viewport =
|
||||||
|
config.getDisplayViewportById(config.defaultPointerDisplayId);
|
||||||
|
if (!viewport) {
|
||||||
|
ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input "
|
||||||
|
"mapper. Fall back to default display",
|
||||||
|
config.defaultPointerDisplayId);
|
||||||
|
viewport = config.getDisplayViewportById(ADISPLAY_ID_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!viewport) {
|
||||||
|
ALOGE("Still can't find a viable viewport to update cursor input mapper. Skip setting it to"
|
||||||
|
" PointerController.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mPointerController->setDisplayViewport(*viewport);
|
||||||
|
}
|
||||||
|
|
||||||
void CursorInputMapper::configureParameters() {
|
void CursorInputMapper::configureParameters() {
|
||||||
mParameters.mode = Parameters::MODE_POINTER;
|
mParameters.mode = Parameters::MODE_POINTER;
|
||||||
String8 cursorModeString;
|
String8 cursorModeString;
|
||||||
|
|
|
@ -116,6 +116,7 @@ private:
|
||||||
void dumpParameters(std::string& dump);
|
void dumpParameters(std::string& dump);
|
||||||
|
|
||||||
void sync(nsecs_t when);
|
void sync(nsecs_t when);
|
||||||
|
void updatePointerControllerDisplayViewport(const InputReaderConfiguration& config);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
|
@ -557,9 +557,10 @@ bool TouchInputMapper::hasExternalStylus() const {
|
||||||
* Determine which DisplayViewport to use.
|
* Determine which DisplayViewport to use.
|
||||||
* 1. If display port is specified, return the matching viewport. If matching viewport not
|
* 1. If display port is specified, return the matching viewport. If matching viewport not
|
||||||
* found, then return.
|
* found, then return.
|
||||||
* 2. If a device has associated display, get the matching viewport by either unique id or by
|
* 2. Always use the suggested viewport from WindowManagerService for pointers.
|
||||||
|
* 3. If a device has associated display, get the matching viewport by either unique id or by
|
||||||
* the display type (internal or external).
|
* the display type (internal or external).
|
||||||
* 3. Otherwise, use a non-display viewport.
|
* 4. Otherwise, use a non-display viewport.
|
||||||
*/
|
*/
|
||||||
std::optional<DisplayViewport> TouchInputMapper::findViewport() {
|
std::optional<DisplayViewport> TouchInputMapper::findViewport() {
|
||||||
if (mParameters.hasAssociatedDisplay) {
|
if (mParameters.hasAssociatedDisplay) {
|
||||||
|
@ -575,6 +576,18 @@ std::optional<DisplayViewport> TouchInputMapper::findViewport() {
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mDeviceMode == DEVICE_MODE_POINTER) {
|
||||||
|
std::optional<DisplayViewport> viewport =
|
||||||
|
mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);
|
||||||
|
if (viewport) {
|
||||||
|
return viewport;
|
||||||
|
} else {
|
||||||
|
ALOGW("Can't find designated display viewport with ID %" PRId32 " for pointers.",
|
||||||
|
mConfig.defaultPointerDisplayId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if uniqueDisplayId is specified in idc file.
|
||||||
if (!mParameters.uniqueDisplayId.empty()) {
|
if (!mParameters.uniqueDisplayId.empty()) {
|
||||||
return mConfig.getDisplayViewportByUniqueId(mParameters.uniqueDisplayId);
|
return mConfig.getDisplayViewportByUniqueId(mParameters.uniqueDisplayId);
|
||||||
}
|
}
|
||||||
|
@ -758,6 +771,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
|
||||||
(mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) {
|
(mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) {
|
||||||
if (mPointerController == nullptr || viewportChanged) {
|
if (mPointerController == nullptr || viewportChanged) {
|
||||||
mPointerController = getPolicy()->obtainPointerController(getDeviceId());
|
mPointerController = getPolicy()->obtainPointerController(getDeviceId());
|
||||||
|
mPointerController->setDisplayViewport(mViewport);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mPointerController.clear();
|
mPointerController.clear();
|
||||||
|
|
|
@ -85,10 +85,6 @@ public:
|
||||||
mMaxY = maxY;
|
mMaxY = maxY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDisplayId(int32_t displayId) {
|
|
||||||
mDisplayId = displayId;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setPosition(float x, float y) {
|
virtual void setPosition(float x, float y) {
|
||||||
mX = x;
|
mX = x;
|
||||||
mY = y;
|
mY = y;
|
||||||
|
@ -111,6 +107,10 @@ public:
|
||||||
return mDisplayId;
|
return mDisplayId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void setDisplayViewport(const DisplayViewport& viewport) {
|
||||||
|
mDisplayId = viewport.displayId;
|
||||||
|
}
|
||||||
|
|
||||||
const std::map<int32_t, std::vector<int32_t>>& getSpots() {
|
const std::map<int32_t, std::vector<int32_t>>& getSpots() {
|
||||||
return mSpotsByDisplay;
|
return mSpotsByDisplay;
|
||||||
}
|
}
|
||||||
|
@ -255,6 +255,10 @@ public:
|
||||||
mConfig.showTouches = enabled;
|
mConfig.showTouches = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDefaultPointerDisplayId(int32_t pointerDisplayId) {
|
||||||
|
mConfig.defaultPointerDisplayId = pointerDisplayId;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DisplayViewport createDisplayViewport(int32_t displayId, int32_t width, int32_t height,
|
DisplayViewport createDisplayViewport(int32_t displayId, int32_t width, int32_t height,
|
||||||
int32_t orientation, const std::string& uniqueId, std::optional<uint8_t> physicalPort,
|
int32_t orientation, const std::string& uniqueId, std::optional<uint8_t> physicalPort,
|
||||||
|
@ -3159,12 +3163,18 @@ TEST_F(CursorInputMapperTest, Process_ShouldHandleDisplayId) {
|
||||||
CursorInputMapper* mapper = new CursorInputMapper(mDevice);
|
CursorInputMapper* mapper = new CursorInputMapper(mDevice);
|
||||||
addMapperAndConfigure(mapper);
|
addMapperAndConfigure(mapper);
|
||||||
|
|
||||||
// Setup PointerController for second display.
|
// Setup for second display.
|
||||||
constexpr int32_t SECOND_DISPLAY_ID = 1;
|
constexpr int32_t SECOND_DISPLAY_ID = 1;
|
||||||
|
const std::string SECOND_DISPLAY_UNIQUE_ID = "local:1";
|
||||||
|
mFakePolicy->addDisplayViewport(SECOND_DISPLAY_ID, 800, 480, DISPLAY_ORIENTATION_0,
|
||||||
|
SECOND_DISPLAY_UNIQUE_ID, NO_PORT,
|
||||||
|
ViewportType::VIEWPORT_EXTERNAL);
|
||||||
|
mFakePolicy->setDefaultPointerDisplayId(SECOND_DISPLAY_ID);
|
||||||
|
configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
|
||||||
|
|
||||||
mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
|
mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
|
||||||
mFakePointerController->setPosition(100, 200);
|
mFakePointerController->setPosition(100, 200);
|
||||||
mFakePointerController->setButtonState(0);
|
mFakePointerController->setButtonState(0);
|
||||||
mFakePointerController->setDisplayId(SECOND_DISPLAY_ID);
|
|
||||||
|
|
||||||
NotifyMotionArgs args;
|
NotifyMotionArgs args;
|
||||||
process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 10);
|
process(mapper, ARBITRARY_TIME, EV_REL, REL_X, 10);
|
||||||
|
@ -6329,14 +6339,16 @@ TEST_F(MultiTouchInputMapperTest, Viewports_Fallback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShouldHandleDisplayId) {
|
TEST_F(MultiTouchInputMapperTest, Process_Pointer_ShouldHandleDisplayId) {
|
||||||
// Setup PointerController for second display.
|
// Setup for second display.
|
||||||
sp<FakePointerController> fakePointerController = new FakePointerController();
|
sp<FakePointerController> fakePointerController = new FakePointerController();
|
||||||
fakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
|
fakePointerController->setBounds(0, 0, DISPLAY_WIDTH - 1, DISPLAY_HEIGHT - 1);
|
||||||
fakePointerController->setPosition(100, 200);
|
fakePointerController->setPosition(100, 200);
|
||||||
fakePointerController->setButtonState(0);
|
fakePointerController->setButtonState(0);
|
||||||
fakePointerController->setDisplayId(SECONDARY_DISPLAY_ID);
|
|
||||||
mFakePolicy->setPointerController(mDevice->getId(), fakePointerController);
|
mFakePolicy->setPointerController(mDevice->getId(), fakePointerController);
|
||||||
|
|
||||||
|
mFakePolicy->setDefaultPointerDisplayId(SECONDARY_DISPLAY_ID);
|
||||||
|
prepareSecondaryDisplay(ViewportType::VIEWPORT_EXTERNAL);
|
||||||
|
|
||||||
MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
|
MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
|
||||||
prepareDisplay(DISPLAY_ORIENTATION_0);
|
prepareDisplay(DISPLAY_ORIENTATION_0);
|
||||||
prepareAxes(POSITION);
|
prepareAxes(POSITION);
|
||||||
|
|
Loading…
Reference in a new issue