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

Commit d44026fd authored by Andrii Kulian's avatar Andrii Kulian Committed by Kamaljeet Maini
Browse files

Revert "Support mouse pointer on external displays (2/3)"

This reverts commit 84cdf9cc.

Reason for revert: b/120864177

Test: Presubmit
Bug: b/120864177

Change-Id: Ia65e704169527b54cf1d1d470445f96a65fa0294
parent 74f1ce3f
Loading
Loading
Loading
Loading
+64 −72
Original line number Diff line number Diff line
@@ -89,6 +89,10 @@ PointerController::PointerController(const sp<PointerControllerPolicyInterface>&

    mLocked.animationPending = false;

    mLocked.displayWidth = -1;
    mLocked.displayHeight = -1;
    mLocked.displayOrientation = DISPLAY_ORIENTATION_0;

    mLocked.presentation = PRESENTATION_POINTER;
    mLocked.presentationChanged = false;

@@ -106,6 +110,15 @@ PointerController::PointerController(const sp<PointerControllerPolicyInterface>&
    mLocked.lastFrameUpdatedTime = 0;

    mLocked.buttonState = 0;

    mPolicy->loadPointerIcon(&mLocked.pointerIcon);

    loadResources();

    if (mLocked.pointerIcon.isValid()) {
        mLocked.pointerIconChanged = true;
        updatePointerLocked();
    }
}

PointerController::~PointerController() {
@@ -131,15 +144,23 @@ bool PointerController::getBounds(float* outMinX, float* outMinY,

bool PointerController::getBoundsLocked(float* outMinX, float* outMinY,
        float* outMaxX, float* outMaxY) const {

    if (!mLocked.viewport.isValid()) {
    if (mLocked.displayWidth <= 0 || mLocked.displayHeight <= 0) {
        return false;
    }

    *outMinX = mLocked.viewport.logicalLeft;
    *outMinY = mLocked.viewport.logicalTop;
    *outMaxX = mLocked.viewport.logicalRight - 1;
    *outMaxY = mLocked.viewport.logicalBottom - 1;
    *outMinX = 0;
    *outMinY = 0;
    switch (mLocked.displayOrientation) {
    case DISPLAY_ORIENTATION_90:
    case DISPLAY_ORIENTATION_270:
        *outMaxX = mLocked.displayHeight - 1;
        *outMaxY = mLocked.displayWidth - 1;
        break;
    default:
        *outMaxX = mLocked.displayWidth - 1;
        *outMaxY = mLocked.displayHeight - 1;
        break;
    }
    return true;
}

@@ -210,12 +231,6 @@ void PointerController::getPosition(float* outX, float* outY) const {
    *outY = mLocked.pointerY;
}

int32_t PointerController::getDisplayId() const {
    AutoMutex _l(mLock);

    return mLocked.viewport.displayId;
}

void PointerController::fade(Transition transition) {
    AutoMutex _l(mLock);

@@ -340,57 +355,48 @@ void PointerController::setInactivityTimeout(InactivityTimeout inactivityTimeout
void PointerController::reloadPointerResources() {
    AutoMutex _l(mLock);

    loadResourcesLocked();
    updatePointerLocked();
}
    loadResources();

/**
 * The viewport values for deviceHeight and deviceWidth have already been adjusted for rotation,
 * so here we are getting the dimensions in the original, unrotated orientation (orientation 0).
 */
static void getNonRotatedSize(const DisplayViewport& viewport, int32_t& width, int32_t& height) {
    if (viewport.orientation == DISPLAY_ORIENTATION_90
            || viewport.orientation == DISPLAY_ORIENTATION_270) {
        width = viewport.deviceHeight;
        height = viewport.deviceWidth;
    } else {
        width = viewport.deviceWidth;
        height = viewport.deviceHeight;
    }
    if (mLocked.presentation == PRESENTATION_POINTER) {
        mLocked.additionalMouseResources.clear();
        mLocked.animationResources.clear();
        mPolicy->loadPointerIcon(&mLocked.pointerIcon);
        mPolicy->loadAdditionalMouseResources(&mLocked.additionalMouseResources,
                                              &mLocked.animationResources);
    }

void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
    AutoMutex _l(mLock);
    if (viewport == mLocked.viewport) {
        return;
    mLocked.presentationChanged = true;
    updatePointerLocked();
}

    const DisplayViewport oldViewport = mLocked.viewport;
    mLocked.viewport = viewport;
void PointerController::setDisplayViewport(int32_t width, int32_t height, int32_t orientation) {
    AutoMutex _l(mLock);

    int32_t oldDisplayWidth, oldDisplayHeight;
    getNonRotatedSize(oldViewport, oldDisplayWidth, oldDisplayHeight);
    int32_t newDisplayWidth, newDisplayHeight;
    getNonRotatedSize(viewport, newDisplayWidth, newDisplayHeight);
    // Adjust to use the display's unrotated coordinate frame.
    if (orientation == DISPLAY_ORIENTATION_90
            || orientation == DISPLAY_ORIENTATION_270) {
        int32_t temp = height;
        height = width;
        width = temp;
    }

    // Reset cursor position to center if size or display changed.
    if (oldViewport.displayId != viewport.displayId
            || oldDisplayWidth != newDisplayWidth
            || oldDisplayHeight != newDisplayHeight) {
    if (mLocked.displayWidth != width || mLocked.displayHeight != height) {
        mLocked.displayWidth = width;
        mLocked.displayHeight = height;

        float minX, minY, maxX, maxY;
        if (getBoundsLocked(&minX, &minY, &maxX, &maxY)) {
            mLocked.pointerX = (minX + maxX) * 0.5f;
            mLocked.pointerY = (minY + maxY) * 0.5f;
            // Reload icon resources for density may be changed.
            loadResourcesLocked();
        } else {
            mLocked.pointerX = 0;
            mLocked.pointerY = 0;
        }

        fadeOutAndReleaseAllSpotsLocked();
    } else if (oldViewport.orientation != viewport.orientation) {
    }

    if (mLocked.displayOrientation != orientation) {
        // Apply offsets to convert from the pixel top-left corner position to the pixel center.
        // This creates an invariant frame of reference that we can easily rotate when
        // taking into account that the pointer may be located at fractional pixel offsets.
@@ -399,37 +405,37 @@ void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
        float temp;

        // Undo the previous rotation.
        switch (oldViewport.orientation) {
        switch (mLocked.displayOrientation) {
        case DISPLAY_ORIENTATION_90:
            temp = x;
            x =  oldViewport.deviceHeight - y;
            x = mLocked.displayWidth - y;
            y = temp;
            break;
        case DISPLAY_ORIENTATION_180:
            x = oldViewport.deviceWidth - x;
            y = oldViewport.deviceHeight - y;
            x = mLocked.displayWidth - x;
            y = mLocked.displayHeight - y;
            break;
        case DISPLAY_ORIENTATION_270:
            temp = x;
            x = y;
            y = oldViewport.deviceWidth - temp;
            y = mLocked.displayHeight - temp;
            break;
        }

        // Perform the new rotation.
        switch (viewport.orientation) {
        switch (orientation) {
        case DISPLAY_ORIENTATION_90:
            temp = x;
            x = y;
            y = viewport.deviceHeight - temp;
            y = mLocked.displayWidth - temp;
            break;
        case DISPLAY_ORIENTATION_180:
            x = viewport.deviceWidth - x;
            y = viewport.deviceHeight - y;
            x = mLocked.displayWidth - x;
            y = mLocked.displayHeight - y;
            break;
        case DISPLAY_ORIENTATION_270:
            temp = x;
            x = viewport.deviceWidth - y;
            x = mLocked.displayHeight - y;
            y = temp;
            break;
        }
@@ -438,6 +444,7 @@ void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
        // and save the results.
        mLocked.pointerX = x - 0.5f;
        mLocked.pointerY = y - 0.5f;
        mLocked.displayOrientation = orientation;
    }

    updatePointerLocked();
@@ -607,16 +614,11 @@ void PointerController::removeInactivityTimeoutLocked() {
    mLooper->removeMessages(mHandler, MSG_INACTIVITY_TIMEOUT);
}

void PointerController::updatePointerLocked() REQUIRES(mLock) {
    if (!mLocked.viewport.isValid()) {
        return;
    }

void PointerController::updatePointerLocked() {
    mSpriteController->openTransaction();

    mLocked.pointerSprite->setLayer(Sprite::BASE_LAYER_POINTER);
    mLocked.pointerSprite->setPosition(mLocked.pointerX, mLocked.pointerY);
    mLocked.pointerSprite->setDisplayId(mLocked.viewport.displayId);

    if (mLocked.pointerAlpha > 0) {
        mLocked.pointerSprite->setAlpha(mLocked.pointerAlpha);
@@ -727,18 +729,8 @@ void PointerController::fadeOutAndReleaseAllSpotsLocked() {
    }
}

void PointerController::loadResourcesLocked() REQUIRES(mLock) {
void PointerController::loadResources() {
    mPolicy->loadPointerResources(&mResources);

    if (mLocked.presentation == PRESENTATION_POINTER) {
        mLocked.additionalMouseResources.clear();
        mLocked.animationResources.clear();
        mPolicy->loadPointerIcon(&mLocked.pointerIcon);
        mPolicy->loadAdditionalMouseResources(&mLocked.additionalMouseResources,
                                              &mLocked.animationResources);
    }

    mLocked.pointerIconChanged = true;
}


+6 −6
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
#include <vector>

#include <ui/DisplayInfo.h>
#include <input/DisplayViewport.h>
#include <input/Input.h>
#include <PointerControllerInterface.h>
#include <utils/BitSet.h>
@@ -97,7 +96,6 @@ public:
    virtual int32_t getButtonState() const;
    virtual void setPosition(float x, float y);
    virtual void getPosition(float* outX, float* outY) const;
    virtual int32_t getDisplayId() const;
    virtual void fade(Transition transition);
    virtual void unfade(Transition transition);

@@ -108,7 +106,7 @@ public:

    void updatePointerIcon(int32_t iconId);
    void setCustomPointerIcon(const SpriteIcon& icon);
    void setDisplayViewport(const DisplayViewport& viewport);
    void setDisplayViewport(int32_t width, int32_t height, int32_t orientation);
    void setInactivityTimeout(InactivityTimeout inactivityTimeout);
    void reloadPointerResources();

@@ -158,7 +156,9 @@ private:
        size_t animationFrameIndex;
        nsecs_t lastFrameUpdatedTime;

        DisplayViewport viewport;
        int32_t displayWidth;
        int32_t displayHeight;
        int32_t displayOrientation;

        InactivityTimeout inactivityTimeout;

@@ -182,7 +182,7 @@ private:

        Vector<Spot*> spots;
        Vector<sp<Sprite> > recycledSprites;
    } mLocked GUARDED_BY(mLock);
    } mLocked;

    bool getBoundsLocked(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const;
    void setPositionLocked(float x, float y);
@@ -207,7 +207,7 @@ private:
    void fadeOutAndReleaseSpotLocked(Spot* spot);
    void fadeOutAndReleaseAllSpotsLocked();

    void loadResourcesLocked();
    void loadResources();
};

} // namespace android
+3 −21
Original line number Diff line number Diff line
@@ -144,16 +144,13 @@ void SpriteController::doUpdateSprites() {
        }
    }

    // Resize and/or reparent sprites if needed.
    // Resize sprites if needed.
    SurfaceComposerClient::Transaction t;
    bool needApplyTransaction = false;
    for (size_t i = 0; i < numSprites; i++) {
        SpriteUpdate& update = updates.editItemAt(i);
        if (update.state.surfaceControl == nullptr) {
            continue;
        }

        if (update.state.wantSurfaceVisible()) {
        if (update.state.surfaceControl != NULL && update.state.wantSurfaceVisible()) {
            int32_t desiredWidth = update.state.icon.bitmap.width();
            int32_t desiredHeight = update.state.icon.bitmap.height();
            if (update.state.surfaceWidth < desiredWidth
@@ -173,12 +170,6 @@ void SpriteController::doUpdateSprites() {
                }
            }
        }

        // If surface is a new one, we have to set right layer stack.
        if (update.surfaceChanged || update.state.dirty & DIRTY_DISPLAY_ID) {
            t.setLayerStack(update.state.surfaceControl, update.state.displayId);
            needApplyTransaction = true;
        }
    }
    if (needApplyTransaction) {
        t.apply();
@@ -245,7 +236,7 @@ void SpriteController::doUpdateSprites() {
        if (update.state.surfaceControl != NULL && (becomingVisible || becomingHidden
                || (wantSurfaceVisibleAndDrawn && (update.state.dirty & (DIRTY_ALPHA
                        | DIRTY_POSITION | DIRTY_TRANSFORMATION_MATRIX | DIRTY_LAYER
                        | DIRTY_VISIBILITY | DIRTY_HOTSPOT | DIRTY_DISPLAY_ID))))) {
                        | DIRTY_VISIBILITY | DIRTY_HOTSPOT))))) {
            needApplyTransaction = true;

            if (wantSurfaceVisibleAndDrawn
@@ -454,15 +445,6 @@ void SpriteController::SpriteImpl::setTransformationMatrix(
    }
}

void SpriteController::SpriteImpl::setDisplayId(int32_t displayId) {
    AutoMutex _l(mController->mLock);

    if (mLocked.state.displayId != displayId) {
        mLocked.state.displayId = displayId;
        invalidateLocked(DIRTY_DISPLAY_ID);
    }
}

void SpriteController::SpriteImpl::invalidateLocked(uint32_t dirty) {
    bool wasDirty = mLocked.state.dirty;
    mLocked.state.dirty |= dirty;
+1 −7
Original line number Diff line number Diff line
@@ -125,9 +125,6 @@ public:

    /* Sets the sprite transformation matrix. */
    virtual void setTransformationMatrix(const SpriteTransformationMatrix& matrix) = 0;

    /* Sets the id of the display where the sprite should be shown. */
    virtual void setDisplayId(int32_t displayId) = 0;
};

/*
@@ -173,7 +170,6 @@ private:
        DIRTY_LAYER = 1 << 4,
        DIRTY_VISIBILITY = 1 << 5,
        DIRTY_HOTSPOT = 1 << 6,
        DIRTY_DISPLAY_ID = 1 << 7,
    };

    /* Describes the state of a sprite.
@@ -184,7 +180,7 @@ private:
    struct SpriteState {
        inline SpriteState() :
                dirty(0), visible(false),
                positionX(0), positionY(0), layer(0), alpha(1.0f), displayId(ADISPLAY_ID_DEFAULT),
                positionX(0), positionY(0), layer(0), alpha(1.0f),
                surfaceWidth(0), surfaceHeight(0), surfaceDrawn(false), surfaceVisible(false) {
        }

@@ -197,7 +193,6 @@ private:
        int32_t layer;
        float alpha;
        SpriteTransformationMatrix transformationMatrix;
        int32_t displayId;

        sp<SurfaceControl> surfaceControl;
        int32_t surfaceWidth;
@@ -230,7 +225,6 @@ private:
        virtual void setLayer(int32_t layer);
        virtual void setAlpha(float alpha);
        virtual void setTransformationMatrix(const SpriteTransformationMatrix& matrix);
        virtual void setDisplayId(int32_t displayId);

        inline const SpriteState& getStateLocked() const {
            return mLocked.state;
+0 −7
Original line number Diff line number Diff line
@@ -1950,11 +1950,6 @@ public class InputManagerService extends IInputManager.Stub
        return PointerIcon.getDefaultIcon(mContext);
    }

    // Native callback.
    private int getPointerDisplayId() {
        return mWindowManagerCallbacks.getPointerDisplayId();
    }

    // Native callback.
    private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) {
        if (!mSystemReady) {
@@ -2022,8 +2017,6 @@ public class InputManagerService extends IInputManager.Stub
                KeyEvent event, int policyFlags);

        public int getPointerLayer();

        public int getPointerDisplayId();
    }

    /**
Loading