| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef _UI_POINTER_CONTROLLER_H |
| 18 |
#define _UI_POINTER_CONTROLLER_H |
| 19 |
|
| 20 |
#include <PointerControllerInterface.h> |
| 21 |
#include <gui/DisplayEventReceiver.h> |
| 22 |
#include <input/DisplayViewport.h> |
| 23 |
#include <input/Input.h> |
| 24 |
#include <utils/BitSet.h> |
| 25 |
#include <utils/Looper.h> |
| 26 |
#include <utils/RefBase.h> |
| 27 |
|
| 28 |
#include <map> |
| 29 |
#include <memory> |
| 30 |
#include <vector> |
| 31 |
|
| 32 |
#include "MouseCursorController.h" |
| 33 |
#include "PointerControllerContext.h" |
| 34 |
#include "SpriteController.h" |
| 35 |
#include "TouchSpotController.h" |
| 36 |
|
| 37 |
namespace android { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
class PointerController : public PointerControllerInterface { |
| 45 |
public: |
| 46 |
static std::shared_ptr<PointerController> create( |
| 47 |
const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper, |
| 48 |
const sp<SpriteController>& spriteController); |
| 49 |
|
| 50 |
~PointerController() override; |
| 51 |
|
| 52 |
virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const; |
| 53 |
virtual void move(float deltaX, float deltaY); |
| 54 |
virtual void setButtonState(int32_t buttonState); |
| 55 |
virtual int32_t getButtonState() const; |
| 56 |
virtual void setPosition(float x, float y); |
| 57 |
virtual void getPosition(float* outX, float* outY) const; |
| 58 |
virtual int32_t getDisplayId() const; |
| 59 |
virtual void fade(Transition transition); |
| 60 |
virtual void unfade(Transition transition); |
| 61 |
virtual void setDisplayViewport(const DisplayViewport& viewport); |
| 62 |
|
| 63 |
virtual void setPresentation(Presentation presentation); |
| 64 |
virtual void setSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex, |
| 65 |
BitSet32 spotIdBits, int32_t displayId); |
| 66 |
virtual void clearSpots(); |
| 67 |
|
| 68 |
void updatePointerIcon(int32_t iconId); |
| 69 |
void setCustomPointerIcon(const SpriteIcon& icon); |
| 70 |
void setInactivityTimeout(InactivityTimeout inactivityTimeout); |
| 71 |
void doInactivityTimeout(); |
| 72 |
void reloadPointerResources(); |
| 73 |
void onDisplayViewportsUpdated(std::vector<DisplayViewport>& viewports); |
| 74 |
|
| 75 |
void onDisplayInfosChangedLocked(const std::vector<gui::DisplayInfo>& displayInfos) |
| 76 |
REQUIRES(getLock()); |
| 77 |
|
| 78 |
protected: |
| 79 |
using WindowListenerConsumer = |
| 80 |
std::function<void(const sp<android::gui::WindowInfosListener>&)>; |
| 81 |
|
| 82 |
|
| 83 |
PointerController(const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper, |
| 84 |
const sp<SpriteController>& spriteController, |
| 85 |
WindowListenerConsumer registerListener, |
| 86 |
WindowListenerConsumer unregisterListener); |
| 87 |
|
| 88 |
private: |
| 89 |
PointerController(const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper, |
| 90 |
const sp<SpriteController>& spriteController); |
| 91 |
|
| 92 |
friend PointerControllerContext::LooperCallback; |
| 93 |
friend PointerControllerContext::MessageHandler; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
std::mutex& getLock() const; |
| 100 |
|
| 101 |
PointerControllerContext mContext; |
| 102 |
|
| 103 |
MouseCursorController mCursorController; |
| 104 |
|
| 105 |
struct Locked { |
| 106 |
Presentation presentation; |
| 107 |
int32_t pointerDisplayId = ADISPLAY_ID_NONE; |
| 108 |
|
| 109 |
std::vector<gui::DisplayInfo> mDisplayInfos; |
| 110 |
std::unordered_map<int32_t , TouchSpotController> spotControllers; |
| 111 |
} mLocked GUARDED_BY(getLock()); |
| 112 |
|
| 113 |
class DisplayInfoListener : public gui::WindowInfosListener { |
| 114 |
public: |
| 115 |
explicit DisplayInfoListener(PointerController* pc) : mPointerController(pc){}; |
| 116 |
void onWindowInfosChanged(const std::vector<android::gui::WindowInfo>&, |
| 117 |
const std::vector<android::gui::DisplayInfo>&) override; |
| 118 |
void onPointerControllerDestroyed(); |
| 119 |
|
| 120 |
|
| 121 |
std::mutex mLock; |
| 122 |
|
| 123 |
private: |
| 124 |
PointerController* mPointerController GUARDED_BY(mLock); |
| 125 |
}; |
| 126 |
|
| 127 |
sp<DisplayInfoListener> mDisplayInfoListener; |
| 128 |
const WindowListenerConsumer mUnregisterWindowInfosListener; |
| 129 |
|
| 130 |
const ui::Transform& getTransformForDisplayLocked(int displayId) const REQUIRES(getLock()); |
| 131 |
|
| 132 |
void clearSpotsLocked() REQUIRES(getLock()); |
| 133 |
}; |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
#endif |