Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8728a2fe authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev Committed by android-build-merger
Browse files

Hold a weak reference to PointerController when handling vsync

am: 33c5903e

Change-Id: If3e218dfdaa68953d184812884b7ed80ab16acfa
parents aab95377 33c5903e
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -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.");
    }
+1 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ private:
    sp<Looper> mLooper;
    sp<SpriteController> mSpriteController;
    sp<WeakMessageHandler> mHandler;
    sp<LooperCallback> mCallback;

    DisplayEventReceiver mDisplayEventReceiver;