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 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 * Tracks pointer movements and draws the pointer sprite to a surface. 41 * 42 * Handles pointer acceleration and animation. 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 virtual ~PointerController() = default; 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 private: 76 friend PointerControllerContext::LooperCallback; 77 friend PointerControllerContext::MessageHandler; 78 79 mutable std::mutex mLock; 80 81 PointerControllerContext mContext; 82 83 MouseCursorController mCursorController; 84 85 struct Locked { 86 Presentation presentation; 87 88 std::unordered_map<int32_t /* displayId */, TouchSpotController> spotControllers; 89 } mLocked GUARDED_BY(mLock); 90 91 PointerController(const sp<PointerControllerPolicyInterface>& policy, const sp<Looper>& looper, 92 const sp<SpriteController>& spriteController); 93 void clearSpotsLocked(); 94 }; 95 96 } // namespace android 97 98 #endif // _UI_POINTER_CONTROLLER_H 99