diff options
author | Liam Harrington <wharrington@google.com> | 2020-08-14 04:00:11 +0000 |
---|---|---|
committer | Liam Harrington <wharrington@google.com> | 2020-08-19 23:02:09 +0000 |
commit | ce6371395599eea49038c4c6a1ba5b86d55be86e (patch) | |
tree | 2a2b714b1c501e84d8513b15e6305cba6ab4d7ea /libs/input/PointerControllerContext.h | |
parent | f623c1e2c2a7f2ff71f0360f74c93d4ef799ab39 (diff) |
Switch to callback animation
Modified current animation logic to use callbacks from the controllers
to further clean and modularize code.
Test: Pixel 3XL device, atest PointerController_test, compile
Change-Id: I1073bd78687cca491663c0349751dab4b30aa8e2
Diffstat (limited to 'libs/input/PointerControllerContext.h')
-rw-r--r-- | libs/input/PointerControllerContext.h | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/libs/input/PointerControllerContext.h b/libs/input/PointerControllerContext.h index 92e1bda25f56..98073fea323e 100644 --- a/libs/input/PointerControllerContext.h +++ b/libs/input/PointerControllerContext.h @@ -26,6 +26,7 @@ #include <utils/Looper.h> #include <utils/RefBase.h> +#include <functional> #include <map> #include <memory> #include <vector> @@ -35,6 +36,8 @@ namespace android { class PointerController; +class MouseCursorController; +class TouchSpotController; /* * Pointer resources. @@ -96,7 +99,6 @@ public: void startAnimation(); void setInactivityTimeout(InactivityTimeout inactivityTimeout); - void setAnimationPending(bool animationPending); nsecs_t getAnimationTime(); void clearSpotsByDisplay(int32_t displayId); @@ -107,9 +109,11 @@ public: sp<PointerControllerPolicyInterface> getPolicy(); sp<SpriteController> getSpriteController(); - void initializeDisplayEventReceiver(); void handleDisplayEvents(); + void addAnimationCallback(int32_t displayId, std::function<bool(nsecs_t)> callback); + void removeAnimationCallback(int32_t displayId); + class MessageHandler : public virtual android::MessageHandler { public: enum { @@ -127,22 +131,47 @@ public: }; private: + class PointerAnimator { + public: + PointerAnimator(PointerControllerContext& context); + + void addCallback(int32_t displayId, std::function<bool(nsecs_t)> callback); + void removeCallback(int32_t displayId); + void handleVsyncEvents(); + nsecs_t getAnimationTimeLocked(); + + mutable std::mutex mLock; + + private: + struct Locked { + bool animationPending{false}; + nsecs_t animationTime{systemTime(SYSTEM_TIME_MONOTONIC)}; + + std::unordered_map<int32_t, std::function<bool(nsecs_t)>> callbacks; + } mLocked GUARDED_BY(mLock); + + DisplayEventReceiver mDisplayEventReceiver; + + PointerControllerContext& mContext; + + void initializeDisplayEventReceiver(); + void startAnimationLocked(); + void handleCallbacksLocked(nsecs_t timestamp); + }; + sp<PointerControllerPolicyInterface> mPolicy; sp<Looper> mLooper; sp<SpriteController> mSpriteController; sp<MessageHandler> mHandler; sp<LooperCallback> mCallback; - DisplayEventReceiver mDisplayEventReceiver; - PointerController& mController; + PointerAnimator mAnimator; + mutable std::mutex mLock; struct Locked { - bool animationPending; - nsecs_t animationTime; - InactivityTimeout inactivityTimeout; } mLocked GUARDED_BY(mLock); |