Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include "InputListener.h" |
| 20 | #include "NotifyArgs.h" |
| 21 | #include "PointerChoreographerPolicyInterface.h" |
| 22 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame^] | 23 | #include <android-base/thread_annotations.h> |
| 24 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 25 | namespace android { |
| 26 | |
| 27 | /** |
| 28 | * PointerChoreographer manages the icons shown by the system for input interactions. |
| 29 | * This includes showing the mouse cursor, stylus hover icons, and touch spots. |
| 30 | * It is responsible for accumulating the location of the mouse cursor, and populating |
| 31 | * the cursor position for incoming events, if necessary. |
| 32 | */ |
| 33 | class PointerChoreographerInterface : public InputListenerInterface { |
| 34 | public: |
| 35 | /** |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame^] | 36 | * Set the display that pointers, like the mouse cursor and drawing tablets, |
| 37 | * should be drawn on. |
| 38 | */ |
| 39 | virtual void setDefaultMouseDisplayId(int32_t displayId) = 0; |
| 40 | virtual void setDisplayViewports(const std::vector<DisplayViewport>& viewports) = 0; |
| 41 | virtual std::optional<DisplayViewport> getViewportForPointerDevice( |
| 42 | int32_t associatedDisplayId = ADISPLAY_ID_NONE) = 0; |
| 43 | virtual FloatPoint getMouseCursorPosition(int32_t displayId) = 0; |
| 44 | /** |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 45 | * This method may be called on any thread (usually by the input manager on a binder thread). |
| 46 | */ |
| 47 | virtual void dump(std::string& dump) = 0; |
| 48 | }; |
| 49 | |
| 50 | class PointerChoreographer : public PointerChoreographerInterface { |
| 51 | public: |
| 52 | explicit PointerChoreographer(InputListenerInterface& listener, |
| 53 | PointerChoreographerPolicyInterface&); |
| 54 | ~PointerChoreographer() override = default; |
| 55 | |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame^] | 56 | void setDefaultMouseDisplayId(int32_t displayId) override; |
| 57 | void setDisplayViewports(const std::vector<DisplayViewport>& viewports) override; |
| 58 | std::optional<DisplayViewport> getViewportForPointerDevice( |
| 59 | int32_t associatedDisplayId) override; |
| 60 | FloatPoint getMouseCursorPosition(int32_t displayId) override; |
| 61 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 62 | void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override; |
| 63 | void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override; |
| 64 | void notifyKey(const NotifyKeyArgs& args) override; |
| 65 | void notifyMotion(const NotifyMotionArgs& args) override; |
| 66 | void notifySwitch(const NotifySwitchArgs& args) override; |
| 67 | void notifySensor(const NotifySensorArgs& args) override; |
| 68 | void notifyVibratorState(const NotifyVibratorStateArgs& args) override; |
| 69 | void notifyDeviceReset(const NotifyDeviceResetArgs& args) override; |
| 70 | void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override; |
| 71 | |
| 72 | void dump(std::string& dump) override; |
| 73 | |
| 74 | private: |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame^] | 75 | void updatePointerControllersLocked() REQUIRES(mLock); |
| 76 | void notifyPointerDisplayIdChangedLocked() REQUIRES(mLock); |
| 77 | const DisplayViewport* findViewportByIdLocked(int32_t displayId) const REQUIRES(mLock); |
| 78 | int32_t getTargetMouseDisplayLocked(int32_t associatedDisplayId) const REQUIRES(mLock); |
| 79 | |
| 80 | NotifyMotionArgs processMotion(const NotifyMotionArgs& args); |
| 81 | NotifyMotionArgs processMouseEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock); |
| 82 | NotifyMotionArgs processTouchscreenEventLocked(const NotifyMotionArgs& args) REQUIRES(mLock); |
| 83 | |
| 84 | std::mutex mLock; |
| 85 | |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 86 | InputListenerInterface& mNextListener; |
Byoungho Jung | da10dd3 | 2023-10-06 17:03:45 +0900 | [diff] [blame^] | 87 | PointerChoreographerPolicyInterface& mPolicy; |
| 88 | |
| 89 | std::map<int32_t, std::shared_ptr<PointerControllerInterface>> mMousePointersByDisplay |
| 90 | GUARDED_BY(mLock); |
| 91 | |
| 92 | int32_t mDefaultMouseDisplayId GUARDED_BY(mLock); |
| 93 | int32_t mNotifiedPointerDisplayId GUARDED_BY(mLock); |
| 94 | std::vector<InputDeviceInfo> mInputDeviceInfos GUARDED_BY(mLock); |
| 95 | std::vector<DisplayViewport> mViewports GUARDED_BY(mLock); |
Prabir Pradhan | b56e92c | 2023-06-09 23:40:37 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } // namespace android |