Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #ifndef _UI_POINTER_CONTROLLER_H |
| 18 | #define _UI_POINTER_CONTROLLER_H |
| 19 | |
Michael Wright | a0bc6b1 | 2020-06-26 20:25:34 +0100 | [diff] [blame] | 20 | #include <PointerControllerInterface.h> |
| 21 | #include <gui/DisplayEventReceiver.h> |
Arthur Hung | b9b3200 | 2018-12-18 17:39:43 +0800 | [diff] [blame] | 22 | #include <input/DisplayViewport.h> |
Jeff Brown | 9d3b1a4 | 2013-07-01 19:07:15 -0700 | [diff] [blame] | 23 | #include <input/Input.h> |
Jeff Brown | 8a90e6e | 2012-05-11 12:24:35 -0700 | [diff] [blame] | 24 | #include <utils/BitSet.h> |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 25 | #include <utils/Looper.h> |
Michael Wright | a0bc6b1 | 2020-06-26 20:25:34 +0100 | [diff] [blame] | 26 | #include <utils/RefBase.h> |
| 27 | |
| 28 | #include <map> |
| 29 | #include <memory> |
| 30 | #include <vector> |
| 31 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 32 | #include "MouseCursorController.h" |
| 33 | #include "PointerControllerContext.h" |
Michael Wright | a0bc6b1 | 2020-06-26 20:25:34 +0100 | [diff] [blame] | 34 | #include "SpriteController.h" |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 35 | #include "TouchSpotController.h" |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 36 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 39 | /* |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 40 | * Tracks pointer movements and draws the pointer sprite to a surface. |
| 41 | * |
| 42 | * Handles pointer acceleration and animation. |
| 43 | */ |
Michael Wright | a0bc6b1 | 2020-06-26 20:25:34 +0100 | [diff] [blame] | 44 | class PointerController : public PointerControllerInterface { |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 45 | public: |
Michael Wright | a0bc6b1 | 2020-06-26 20:25:34 +0100 | [diff] [blame] | 46 | static std::shared_ptr<PointerController> create( |
| 47 | const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper, |
| 48 | const sp<SpriteController>& spriteController); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 49 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 50 | virtual ~PointerController() = default; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 51 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 52 | virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 53 | virtual void move(float deltaX, float deltaY); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 54 | virtual void setButtonState(int32_t buttonState); |
| 55 | virtual int32_t getButtonState() const; |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 56 | virtual void setPosition(float x, float y); |
| 57 | virtual void getPosition(float* outX, float* outY) const; |
Arthur Hung | b9b3200 | 2018-12-18 17:39:43 +0800 | [diff] [blame] | 58 | virtual int32_t getDisplayId() const; |
Jeff Brown | 538881e | 2011-05-25 18:23:38 -0700 | [diff] [blame] | 59 | virtual void fade(Transition transition); |
| 60 | virtual void unfade(Transition transition); |
Garfield Tan | b1b07be | 2020-01-09 11:30:04 -0800 | [diff] [blame] | 61 | virtual void setDisplayViewport(const DisplayViewport& viewport); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 62 | |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 63 | virtual void setPresentation(Presentation presentation); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 64 | virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, |
| 65 | BitSet32 spotIdBits, int32_t displayId); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 66 | virtual void clearSpots(); |
| 67 | |
Michael Wright | f9d9ce77 | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 68 | void updatePointerIcon(int32_t iconId); |
Jun Mukai | d4eaef7 | 2015-10-30 15:54:33 -0700 | [diff] [blame] | 69 | void setCustomPointerIcon(const SpriteIcon& icon); |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 70 | void setInactivityTimeout(InactivityTimeout inactivityTimeout); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 71 | void doInactivityTimeout(); |
Jun Mukai | 19a5601 | 2015-11-24 11:25:52 -0800 | [diff] [blame] | 72 | void reloadPointerResources(); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 73 | void onDisplayViewportsUpdated(std::vector<DisplayViewport>& viewports); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 74 | |
| 75 | private: |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 76 | friend PointerControllerContext::LooperCallback; |
| 77 | friend PointerControllerContext::MessageHandler; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 78 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 79 | mutable std::mutex mLock; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 80 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 81 | PointerControllerContext mContext; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 82 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 83 | MouseCursorController mCursorController; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 84 | |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 85 | struct Locked { |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 86 | Presentation presentation; |
Jeff Brown | 2352b97 | 2011-04-12 22:39:53 -0700 | [diff] [blame] | 87 | |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 88 | std::unordered_map<int32_t /* displayId */, TouchSpotController> spotControllers; |
Arthur Hung | b9b3200 | 2018-12-18 17:39:43 +0800 | [diff] [blame] | 89 | } mLocked GUARDED_BY(mLock); |
Jeff Brown | 05dc66a | 2011-03-02 14:41:58 -0800 | [diff] [blame] | 90 | |
Michael Wright | a0bc6b1 | 2020-06-26 20:25:34 +0100 | [diff] [blame] | 91 | PointerController(const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper, |
| 92 | const sp<SpriteController>& spriteController); |
Liam Harrington | c782be6 | 2020-07-17 19:48:24 +0000 | [diff] [blame] | 93 | void clearSpotsLocked(); |
Jeff Brown | b4ff35d | 2011-01-02 16:37:43 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } // namespace android |
| 97 | |
| 98 | #endif // _UI_POINTER_CONTROLLER_H |