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

Commit aaff73f9 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

surfaceflinger: simplify HWC buffer cache clean up

When a Layer is no longer connected, we destroy the associated HWC
layers on next call to SurfaceFlinger::rebuildLayerStacks or when
the Layer is destroyed.  There is no need to listen to
onBuffersReleased.  Besides, we need to perform the cleanup from the
main thread as we only talk to HWC process from the main thread.

While at it, move HWComposerBufferCache to its own files.

Bug: 35320590
Test: manual
Change-Id: Ifa32f24076b094c8fa9cda8572b03d5bfb8e0b93
parent d7c99dd4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ LOCAL_SRC_FILES := \
    DisplayHardware/ComposerHal.cpp \
    DisplayHardware/FramebufferSurface.cpp \
    DisplayHardware/HWC2.cpp \
    DisplayHardware/HWComposerBufferCache.cpp \
    DisplayHardware/PowerHAL.cpp \
    DisplayHardware/VirtualDisplaySurface.cpp \
    Effects/Daltonizer.cpp \
+2 −2
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ status_t FramebufferSurface::nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>&
    status_t err = acquireBufferLocked(&item, 0);
    if (err == BufferQueue::NO_BUFFER_AVAILABLE) {
#ifdef USE_HWC2
        mHwcBufferCache->getHwcBuffer(mCurrentBufferSlot, mCurrentBuffer,
        mHwcBufferCache.getHwcBuffer(mCurrentBufferSlot, mCurrentBuffer,
                &outSlot, &outBuffer);
#else
        outBuffer = mCurrentBuffer;
@@ -178,7 +178,7 @@ status_t FramebufferSurface::nextBuffer(sp<GraphicBuffer>& outBuffer, sp<Fence>&

    outFence = item.mFence;
#ifdef USE_HWC2
    mHwcBufferCache->getHwcBuffer(mCurrentBufferSlot, mCurrentBuffer,
    mHwcBufferCache.getHwcBuffer(mCurrentBufferSlot, mCurrentBuffer,
            &outSlot, &outBuffer);
    outDataspace = item.mDataSpace;
#else
+2 −5
Original line number Diff line number Diff line
@@ -18,14 +18,13 @@
#define ANDROID_SF_FRAMEBUFFER_SURFACE_H

#include "DisplaySurface.h"
#include "HWComposerBufferCache.h"

#include <stdint.h>
#include <sys/types.h>

#include <gui/ConsumerBase.h>

#include <memory>

// ---------------------------------------------------------------------------
namespace android {
// ---------------------------------------------------------------------------
@@ -33,7 +32,6 @@ namespace android {
class Rect;
class String8;
class HWComposer;
class HWComposerBufferCache;

// ---------------------------------------------------------------------------

@@ -96,8 +94,7 @@ private:
    HWComposer& mHwc;

#ifdef USE_HWC2
    std::unique_ptr<HWComposerBufferCache> mHwcBufferCache =
        std::make_unique<HWComposerBufferCache>();
    HWComposerBufferCache mHwcBufferCache;

    // Previous buffer to release after getting an updated retire fence
    bool mHasPendingRelease;
+0 −36
Original line number Diff line number Diff line
@@ -925,41 +925,5 @@ void HWComposer::DisplayData::reset() {
    *this = DisplayData();
}

void HWComposerBufferCache::clear()
{
    mBuffers.clear();
}

void HWComposerBufferCache::getHwcBuffer(int slot,
        const sp<GraphicBuffer>& buffer,
        uint32_t* outSlot, sp<GraphicBuffer>* outBuffer)
{
#ifdef BYPASS_IHWC
    *outSlot = slot;
    *outBuffer = buffer;
#else
    if (slot == BufferQueue::INVALID_BUFFER_SLOT || slot < 0) {
        // default to slot 0
        slot = 0;
    }

    if (static_cast<size_t>(slot) >= mBuffers.size()) {
        mBuffers.resize(slot + 1);
    }

    *outSlot = slot;

    if (mBuffers[slot] == buffer) {
        // already cached in HWC, skip sending the buffer
        *outBuffer = nullptr;
    } else {
        *outBuffer = buffer;

        // update cache
        mBuffers[slot] = buffer;
    }
#endif
}

// ---------------------------------------------------------------------------
}; // namespace android
+0 −15
Original line number Diff line number Diff line
@@ -26,8 +26,6 @@
#include <stdint.h>
#include <sys/types.h>

#include <gui/BufferQueue.h>

#include <ui/Fence.h>

#include <utils/BitSet.h>
@@ -236,19 +234,6 @@ private:
    mutable std::atomic<bool> mDumpMayLockUp;
};

class HWComposerBufferCache {
public:
    void clear();

    void getHwcBuffer(int slot, const sp<GraphicBuffer>& buffer,
            uint32_t* outSlot, sp<GraphicBuffer>* outBuffer);

private:
    // a vector as we expect "slot" to be in the range of [0, 63] (that is,
    // less than BufferQueue::NUM_BUFFER_SLOTS).
    std::vector<sp<GraphicBuffer>> mBuffers;
};

// ---------------------------------------------------------------------------
}; // namespace android

Loading