blob: 97567bab202b8e4b20be5f7542504d8b320b6ada [file] [log] [blame]
Jeff Brownb4ff35d2011-01-02 16:37:43 -08001/*
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 Wrighta0bc6b12020-06-26 20:25:34 +010020#include <PointerControllerInterface.h>
21#include <gui/DisplayEventReceiver.h>
Arthur Hungb9b32002018-12-18 17:39:43 +080022#include <input/DisplayViewport.h>
Jeff Brown9d3b1a42013-07-01 19:07:15 -070023#include <input/Input.h>
Jeff Brown8a90e6e2012-05-11 12:24:35 -070024#include <utils/BitSet.h>
Jeff Brown05dc66a2011-03-02 14:41:58 -080025#include <utils/Looper.h>
Michael Wrighta0bc6b12020-06-26 20:25:34 +010026#include <utils/RefBase.h>
27
28#include <map>
29#include <memory>
30#include <vector>
31
Liam Harringtonc782be62020-07-17 19:48:24 +000032#include "MouseCursorController.h"
33#include "PointerControllerContext.h"
Michael Wrighta0bc6b12020-06-26 20:25:34 +010034#include "SpriteController.h"
Liam Harringtonc782be62020-07-17 19:48:24 +000035#include "TouchSpotController.h"
Jeff Brownb4ff35d2011-01-02 16:37:43 -080036
Jeff Brownb4ff35d2011-01-02 16:37:43 -080037namespace android {
38
Jeff Brown2352b972011-04-12 22:39:53 -070039/*
Jeff Brownb4ff35d2011-01-02 16:37:43 -080040 * Tracks pointer movements and draws the pointer sprite to a surface.
41 *
42 * Handles pointer acceleration and animation.
43 */
Michael Wrighta0bc6b12020-06-26 20:25:34 +010044class PointerController : public PointerControllerInterface {
Jeff Brownb4ff35d2011-01-02 16:37:43 -080045public:
Michael Wrighta0bc6b12020-06-26 20:25:34 +010046 static std::shared_ptr<PointerController> create(
47 const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper,
48 const sp<SpriteController>& spriteController);
Jeff Brown05dc66a2011-03-02 14:41:58 -080049
Liam Harringtonc782be62020-07-17 19:48:24 +000050 virtual ~PointerController() = default;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080051
Liam Harringtonc782be62020-07-17 19:48:24 +000052 virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080053 virtual void move(float deltaX, float deltaY);
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070054 virtual void setButtonState(int32_t buttonState);
55 virtual int32_t getButtonState() const;
Jeff Brownb4ff35d2011-01-02 16:37:43 -080056 virtual void setPosition(float x, float y);
57 virtual void getPosition(float* outX, float* outY) const;
Arthur Hungb9b32002018-12-18 17:39:43 +080058 virtual int32_t getDisplayId() const;
Jeff Brown538881e2011-05-25 18:23:38 -070059 virtual void fade(Transition transition);
60 virtual void unfade(Transition transition);
Garfield Tanb1b07be2020-01-09 11:30:04 -080061 virtual void setDisplayViewport(const DisplayViewport& viewport);
Jeff Brownb4ff35d2011-01-02 16:37:43 -080062
Jeff Brown2352b972011-04-12 22:39:53 -070063 virtual void setPresentation(Presentation presentation);
Liam Harringtonc782be62020-07-17 19:48:24 +000064 virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
65 BitSet32 spotIdBits, int32_t displayId);
Jeff Brown2352b972011-04-12 22:39:53 -070066 virtual void clearSpots();
67
Michael Wrightf9d9ce772016-05-13 17:44:16 +010068 void updatePointerIcon(int32_t iconId);
Jun Mukaid4eaef72015-10-30 15:54:33 -070069 void setCustomPointerIcon(const SpriteIcon& icon);
Jeff Brown2352b972011-04-12 22:39:53 -070070 void setInactivityTimeout(InactivityTimeout inactivityTimeout);
Liam Harringtonc782be62020-07-17 19:48:24 +000071 void doInactivityTimeout();
Jun Mukai19a56012015-11-24 11:25:52 -080072 void reloadPointerResources();
Liam Harringtonc782be62020-07-17 19:48:24 +000073 void onDisplayViewportsUpdated(std::vector<DisplayViewport>& viewports);
Jeff Brownb4ff35d2011-01-02 16:37:43 -080074
75private:
Liam Harringtonc782be62020-07-17 19:48:24 +000076 friend PointerControllerContext::LooperCallback;
77 friend PointerControllerContext::MessageHandler;
Jeff Brown2352b972011-04-12 22:39:53 -070078
Liam Harringtonc782be62020-07-17 19:48:24 +000079 mutable std::mutex mLock;
Jeff Brown2352b972011-04-12 22:39:53 -070080
Liam Harringtonc782be62020-07-17 19:48:24 +000081 PointerControllerContext mContext;
Jeff Brown2352b972011-04-12 22:39:53 -070082
Liam Harringtonc782be62020-07-17 19:48:24 +000083 MouseCursorController mCursorController;
Jeff Brown2352b972011-04-12 22:39:53 -070084
Jeff Brownb4ff35d2011-01-02 16:37:43 -080085 struct Locked {
Jeff Brown2352b972011-04-12 22:39:53 -070086 Presentation presentation;
Jeff Brown2352b972011-04-12 22:39:53 -070087
Liam Harringtonc782be62020-07-17 19:48:24 +000088 std::unordered_map<int32_t /* displayId */, TouchSpotController> spotControllers;
Arthur Hungb9b32002018-12-18 17:39:43 +080089 } mLocked GUARDED_BY(mLock);
Jeff Brown05dc66a2011-03-02 14:41:58 -080090
Michael Wrighta0bc6b12020-06-26 20:25:34 +010091 PointerController(const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper,
92 const sp<SpriteController>& spriteController);
Liam Harringtonc782be62020-07-17 19:48:24 +000093 void clearSpotsLocked();
Jeff Brownb4ff35d2011-01-02 16:37:43 -080094};
95
96} // namespace android
97
98#endif // _UI_POINTER_CONTROLLER_H