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

Commit 7a376674 authored by Michael Wright's avatar Michael Wright Committed by Garfield Tan
Browse files

Move PointerController from sp to shared_ptr

Bug: 160010896
Test: atest PointerController_test, atest InputReader_test, manual usage
Change-Id: Ic43ab94ca76c736fde0d217efeab99b2afd6f622
Merged-In: Ic43ab94ca76c736fde0d217efeab99b2afd6f622
(cherry picked from commit 17db18e8)
parent 4efc619e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -335,7 +335,8 @@ public:
    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;

    /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
    virtual std::shared_ptr<PointerControllerInterface> obtainPointerController(
            int32_t deviceId) = 0;

    /* Notifies the input reader policy that some input devices have changed
     * and provides information about all current input devices.
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ namespace android {
 * The pointer controller is responsible for providing synchronization and for tracking
 * display orientation changes if needed.
 */
class PointerControllerInterface : public virtual RefBase {
class PointerControllerInterface {
protected:
    PointerControllerInterface() { }
    virtual ~PointerControllerInterface() { }
+7 −5
Original line number Diff line number Diff line
@@ -390,8 +390,9 @@ bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now, int32_t keyCode, int32
    }
}

sp<PointerControllerInterface> InputReader::getPointerControllerLocked(int32_t deviceId) {
    sp<PointerControllerInterface> controller = mPointerController.promote();
std::shared_ptr<PointerControllerInterface> InputReader::getPointerControllerLocked(
        int32_t deviceId) {
    std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
    if (controller == nullptr) {
        controller = mPolicy->obtainPointerController(deviceId);
        mPointerController = controller;
@@ -401,7 +402,7 @@ sp<PointerControllerInterface> InputReader::getPointerControllerLocked(int32_t d
}

void InputReader::updatePointerDisplayLocked() {
    sp<PointerControllerInterface> controller = mPointerController.promote();
    std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
    if (controller == nullptr) {
        return;
    }
@@ -424,7 +425,7 @@ void InputReader::updatePointerDisplayLocked() {
}

void InputReader::fadePointerLocked() {
    sp<PointerControllerInterface> controller = mPointerController.promote();
    std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
    if (controller != nullptr) {
        controller->fade(PointerControllerInterface::TRANSITION_GRADUAL);
    }
@@ -725,7 +726,8 @@ void InputReader::ContextImpl::fadePointer() {
    mReader->fadePointerLocked();
}

sp<PointerControllerInterface> InputReader::ContextImpl::getPointerController(int32_t deviceId) {
std::shared_ptr<PointerControllerInterface> InputReader::ContextImpl::getPointerController(
        int32_t deviceId) {
    // lock is already held by the input loop
    return mReader->getPointerControllerLocked(deviceId);
}
+11 −9
Original line number Diff line number Diff line
@@ -17,19 +17,20 @@
#ifndef _UI_INPUTREADER_INPUT_READER_H
#define _UI_INPUTREADER_INPUT_READER_H

#include "EventHub.h"
#include "InputListener.h"
#include "InputReaderBase.h"
#include "InputReaderContext.h"
#include "InputThread.h"

#include <PointerControllerInterface.h>
#include <utils/Condition.h>
#include <utils/Mutex.h>

#include <memory>
#include <unordered_map>
#include <vector>

#include "EventHub.h"
#include "InputListener.h"
#include "InputReaderBase.h"
#include "InputReaderContext.h"
#include "InputThread.h"

namespace android {

class InputDevice;
@@ -104,7 +105,8 @@ protected:
        virtual void disableVirtualKeysUntil(nsecs_t time) override;
        virtual bool shouldDropVirtualKey(nsecs_t now, int32_t keyCode, int32_t scanCode) override;
        virtual void fadePointer() override;
        virtual sp<PointerControllerInterface> getPointerController(int32_t deviceId) override;
        virtual std::shared_ptr<PointerControllerInterface> getPointerController(
                int32_t deviceId) override;
        virtual void requestTimeoutAtTime(nsecs_t when) override;
        virtual int32_t bumpGeneration() override;
        virtual void getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) override;
@@ -160,8 +162,8 @@ private:
    void dispatchExternalStylusState(const StylusState& state);

    // The PointerController that is shared among all the input devices that need it.
    wp<PointerControllerInterface> mPointerController;
    sp<PointerControllerInterface> getPointerControllerLocked(int32_t deviceId);
    std::weak_ptr<PointerControllerInterface> mPointerController;
    std::shared_ptr<PointerControllerInterface> getPointerControllerLocked(int32_t deviceId);
    void updatePointerDisplayLocked();
    void fadePointerLocked();

+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public:
    virtual bool shouldDropVirtualKey(nsecs_t now, int32_t keyCode, int32_t scanCode) = 0;

    virtual void fadePointer() = 0;
    virtual sp<PointerControllerInterface> getPointerController(int32_t deviceId) = 0;
    virtual std::shared_ptr<PointerControllerInterface> getPointerController(int32_t deviceId) = 0;

    virtual void requestTimeoutAtTime(nsecs_t when) = 0;
    virtual int32_t bumpGeneration() = 0;
Loading