diff options
author | Vladislav Kaznacheev <kaznacheev@google.com> | 2016-09-13 23:11:41 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-09-13 23:11:41 +0000 |
commit | bd46d09d84130eac34fb5973f70a9dbab2bbff23 (patch) | |
tree | 0bb80482863db22ba082342551e3c07810b9b1ca | |
parent | ed0f318f308634958108c988f89b02e8e7bfc73f (diff) | |
parent | 23bb30843ca2c760b15ef07f0d9a344f3b198e41 (diff) |
Hold a weak reference to PointerController when handling vsync am: 33c5903e77 am: 8728a2fe53
am: 23bb30843c
Change-Id: Ifccc705f9b21fb8c24fd7fc83f99d9c58ac85b5c
-rw-r--r-- | libs/input/PointerController.cpp | 26 | ||||
-rw-r--r-- | libs/input/PointerController.h | 1 |
2 files changed, 26 insertions, 1 deletions
diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp index 87a22ce8d35e..89b4fb2345d0 100644 --- a/libs/input/PointerController.cpp +++ b/libs/input/PointerController.cpp @@ -36,6 +36,29 @@ namespace android { +// --- WeakLooperCallback --- + +class WeakLooperCallback: public LooperCallback { +protected: + virtual ~WeakLooperCallback() { } + +public: + WeakLooperCallback(const wp<LooperCallback>& callback) : + mCallback(callback) { + } + + virtual int handleEvent(int fd, int events, void* data) { + sp<LooperCallback> callback = mCallback.promote(); + if (callback != NULL) { + return callback->handleEvent(fd, events, data); + } + return 0; // the client is gone, remove the callback + } + +private: + wp<LooperCallback> mCallback; +}; + // --- PointerController --- // Time to wait before starting the fade when the pointer is inactive. @@ -57,10 +80,11 @@ PointerController::PointerController(const sp<PointerControllerPolicyInterface>& const sp<Looper>& looper, const sp<SpriteController>& spriteController) : mPolicy(policy), mLooper(looper), mSpriteController(spriteController) { mHandler = new WeakMessageHandler(this); + mCallback = new WeakLooperCallback(this); if (mDisplayEventReceiver.initCheck() == NO_ERROR) { mLooper->addFd(mDisplayEventReceiver.getFd(), Looper::POLL_CALLBACK, - Looper::EVENT_INPUT, this, nullptr); + Looper::EVENT_INPUT, mCallback, nullptr); } else { ALOGE("Failed to initialize DisplayEventReceiver."); } diff --git a/libs/input/PointerController.h b/libs/input/PointerController.h index 99292d7ca8a6..4794f3da824c 100644 --- a/libs/input/PointerController.h +++ b/libs/input/PointerController.h @@ -144,6 +144,7 @@ private: sp<Looper> mLooper; sp<SpriteController> mSpriteController; sp<WeakMessageHandler> mHandler; + sp<LooperCallback> mCallback; DisplayEventReceiver mDisplayEventReceiver; |