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

Commit 03414a1c authored by Riley Andrews's avatar Riley Andrews
Browse files

Turn on support for async cursor update in surfaceflinger.

If available, surfaceflinger will use the hwc setCursorPositionAsync()
api to change the position of supported cursor layers outside of
the usual prepare/set loop.

Change-Id: Ib3fc5c0c390b3489ddbba202379840a1d2748917
parent d8e5e813
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ public:
        eOpaque             = 0x00000400,
        eOpaque             = 0x00000400,
        eProtectedByApp     = 0x00000800,
        eProtectedByApp     = 0x00000800,
        eProtectedByDRM     = 0x00001000,
        eProtectedByDRM     = 0x00001000,
        eCursorWindow       = 0x00002000,


        eFXSurfaceNormal    = 0x00000000,
        eFXSurfaceNormal    = 0x00000000,
        eFXSurfaceDim       = 0x00020000,
        eFXSurfaceDim       = 0x00020000,
+3 −1
Original line number Original line Diff line number Diff line
@@ -64,7 +64,9 @@ public:
        USAGE_HW_2D             = GRALLOC_USAGE_HW_2D,
        USAGE_HW_2D             = GRALLOC_USAGE_HW_2D,
        USAGE_HW_COMPOSER       = GRALLOC_USAGE_HW_COMPOSER,
        USAGE_HW_COMPOSER       = GRALLOC_USAGE_HW_COMPOSER,
        USAGE_HW_VIDEO_ENCODER  = GRALLOC_USAGE_HW_VIDEO_ENCODER,
        USAGE_HW_VIDEO_ENCODER  = GRALLOC_USAGE_HW_VIDEO_ENCODER,
        USAGE_HW_MASK           = GRALLOC_USAGE_HW_MASK
        USAGE_HW_MASK           = GRALLOC_USAGE_HW_MASK,

        USAGE_CURSOR            = GRALLOC_USAGE_CURSOR,
    };
    };


    GraphicBuffer();
    GraphicBuffer();
+25 −0
Original line number Original line Diff line number Diff line
@@ -681,6 +681,9 @@ status_t HWComposer::prepare() {
                    if (l.compositionType == HWC_OVERLAY) {
                    if (l.compositionType == HWC_OVERLAY) {
                        disp.hasOvComp = true;
                        disp.hasOvComp = true;
                    }
                    }
                    if (l.compositionType == HWC_CURSOR_OVERLAY) {
                        disp.hasOvComp = true;
                    }
                }
                }
                if (disp.list->numHwLayers == (disp.framebufferTarget ? 1 : 0)) {
                if (disp.list->numHwLayers == (disp.framebufferTarget ? 1 : 0)) {
                    disp.hasFbComp = true;
                    disp.hasFbComp = true;
@@ -853,6 +856,16 @@ sp<Fence> HWComposer::getLastRetireFence(int32_t id) const {
    return mDisplayData[id].lastRetireFence;
    return mDisplayData[id].lastRetireFence;
}
}


status_t HWComposer::setCursorPositionAsync(int32_t id, const Rect& pos)
{
    if (mHwc->setCursorPositionAsync) {
        return (status_t)mHwc->setCursorPositionAsync(mHwc, id, pos.left, pos.top);
    }
    else {
        return NO_ERROR;
    }
}

/*
/*
 * Helper template to implement a concrete HWCLayer
 * Helper template to implement a concrete HWCLayer
 * This holds the pointer to the concrete hwc layer type
 * This holds the pointer to the concrete hwc layer type
@@ -935,6 +948,16 @@ public:
            getLayer()->flags &= ~HWC_SKIP_LAYER;
            getLayer()->flags &= ~HWC_SKIP_LAYER;
        }
        }
    }
    }
    virtual void setIsCursorLayerHint(bool isCursor) {
        if (hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_4)) {
            if (isCursor) {
                getLayer()->flags |= HWC_IS_CURSOR_LAYER;
            }
            else {
                getLayer()->flags &= ~HWC_IS_CURSOR_LAYER;
            }
        }
    }
    virtual void setBlending(uint32_t blending) {
    virtual void setBlending(uint32_t blending) {
        getLayer()->blending = blending;
        getLayer()->blending = blending;
    }
    }
@@ -1122,6 +1145,8 @@ void HWComposer::dump(String8& result) const {
                            "HWC",
                            "HWC",
                            "BKGND",
                            "BKGND",
                            "FB TARGET",
                            "FB TARGET",
                            "SIDEBAND",
                            "HWC_CURSOR",
                            "UNKNOWN"};
                            "UNKNOWN"};
                    if (type >= NELEM(compositionTypeName))
                    if (type >= NELEM(compositionTypeName))
                        type = NELEM(compositionTypeName) - 1;
                        type = NELEM(compositionTypeName) - 1;
+3 −0
Original line number Original line Diff line number Diff line
@@ -141,6 +141,8 @@ public:
    // displays, writes to the output buffer are complete.
    // displays, writes to the output buffer are complete.
    sp<Fence> getLastRetireFence(int32_t id) const;
    sp<Fence> getLastRetireFence(int32_t id) const;


    status_t setCursorPositionAsync(int32_t id, const Rect &pos);

    /*
    /*
     * Interface to hardware composer's layers functionality.
     * Interface to hardware composer's layers functionality.
     * This abstracts the HAL interface to layers which can evolve in
     * This abstracts the HAL interface to layers which can evolve in
@@ -157,6 +159,7 @@ public:
        virtual sp<Fence> getAndResetReleaseFence() = 0;
        virtual sp<Fence> getAndResetReleaseFence() = 0;
        virtual void setDefaultState() = 0;
        virtual void setDefaultState() = 0;
        virtual void setSkip(bool skip) = 0;
        virtual void setSkip(bool skip) = 0;
        virtual void setIsCursorLayerHint(bool isCursor = true) = 0;
        virtual void setBlending(uint32_t blending) = 0;
        virtual void setBlending(uint32_t blending) = 0;
        virtual void setTransform(uint32_t transform) = 0;
        virtual void setTransform(uint32_t transform) = 0;
        virtual void setFrame(const Rect& frame) = 0;
        virtual void setFrame(const Rect& frame) = 0;
+27 −2
Original line number Original line Diff line number Diff line
@@ -79,7 +79,8 @@ Layer::Layer(SurfaceFlinger* flinger, const sp<Client>& client,
        mSecure(false),
        mSecure(false),
        mProtectedByApp(false),
        mProtectedByApp(false),
        mHasSurface(false),
        mHasSurface(false),
        mClientRef(client)
        mClientRef(client),
        mPotentialCursor(false)
{
{
    mCurrentCrop.makeInvalid();
    mCurrentCrop.makeInvalid();
    mFlinger->getRenderEngine().genTextures(1, &mTextureName);
    mFlinger->getRenderEngine().genTextures(1, &mTextureName);
@@ -200,6 +201,7 @@ status_t Layer::setBuffers( uint32_t w, uint32_t h,


    mFormat = format;
    mFormat = format;


    mPotentialCursor = (flags & ISurfaceComposerClient::eCursorWindow) ? true : false;
    mSecure = (flags & ISurfaceComposerClient::eSecure) ? true : false;
    mSecure = (flags & ISurfaceComposerClient::eSecure) ? true : false;
    mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false;
    mProtectedByApp = (flags & ISurfaceComposerClient::eProtectedByApp) ? true : false;
    mCurrentOpacity = getOpacityForFormat(format);
    mCurrentOpacity = getOpacityForFormat(format);
@@ -441,7 +443,7 @@ void Layer::setAcquireFence(const sp<const DisplayDevice>& /* hw */,
    // TODO: there is a possible optimization here: we only need to set the
    // TODO: there is a possible optimization here: we only need to set the
    // acquire fence the first time a new buffer is acquired on EACH display.
    // acquire fence the first time a new buffer is acquired on EACH display.


    if (layer.getCompositionType() == HWC_OVERLAY) {
    if (layer.getCompositionType() == HWC_OVERLAY || layer.getCompositionType() == HWC_CURSOR_OVERLAY) {
        sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence();
        sp<Fence> fence = mSurfaceFlingerConsumer->getCurrentFence();
        if (fence->isValid()) {
        if (fence->isValid()) {
            fenceFd = fence->dup();
            fenceFd = fence->dup();
@@ -453,6 +455,26 @@ void Layer::setAcquireFence(const sp<const DisplayDevice>& /* hw */,
    layer.setAcquireFenceFd(fenceFd);
    layer.setAcquireFenceFd(fenceFd);
}
}


Rect Layer::getPosition(
    const sp<const DisplayDevice>& hw)
{
    // this gives us only the "orientation" component of the transform
    const State& s(getCurrentState());

    // apply the layer's transform, followed by the display's global transform
    // here we're guaranteed that the layer's transform preserves rects
    Rect win(s.active.w, s.active.h);
    if (!s.active.crop.isEmpty()) {
        win.intersect(s.active.crop, &win);
    }
    // subtract the transparent region and snap to the bounds
    Rect bounds = reduce(win, s.activeTransparentRegion);
    Rect frame(s.transform.transform(bounds));
    frame.intersect(hw->getViewport(), &frame);
    const Transform& tr(hw->getTransform());
    return Rect(tr.transform(frame));
}

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// drawing...
// drawing...
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
@@ -1187,6 +1209,9 @@ uint32_t Layer::getEffectiveUsage(uint32_t usage) const
        // need a hardware-protected path to external video sink
        // need a hardware-protected path to external video sink
        usage |= GraphicBuffer::USAGE_PROTECTED;
        usage |= GraphicBuffer::USAGE_PROTECTED;
    }
    }
    if (mPotentialCursor) {
        usage |= GraphicBuffer::USAGE_CURSOR;
    }
    usage |= GraphicBuffer::USAGE_HW_COMPOSER;
    usage |= GraphicBuffer::USAGE_HW_COMPOSER;
    return usage;
    return usage;
}
}
Loading