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

Commit 439afadf authored by Brian Lindahl's avatar Brian Lindahl
Browse files

Push HWC cache slot generation down into CompositionEngine

Stop caching buffers inside SurfaceFlinger and remove the tight coupling
between SurfaceFlinger's ClientCache and the Hardware Composer cache.
This allows a better seperation of responsibility, where buffer cache
management is not split between HwcSlotGenerator and HwcBufferCache, but
is instead solely handled by HwcBufferCache.

Note that FramebufferSurface and VirtualDisplaySurface no longer use
HwcBufferCache, but instead use their own cache slot management that
is solely based on BufferQueue slot numbers.

Also do minor refactoring in FramebufferSurface to simplify code.

Bug: 258196272
Test: started and stopped multiple YouTube videos on adt4 and verified
no change in graphic buffer usage
Test: atest HwcBufferCacheTest
Test: atest OutputPrepareTest

Change-Id: Ica7955ab4bc70e3c70207390e36dff73a2fc4949
parent 0cbe4654
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -165,7 +165,6 @@ filegroup {
        "FrameTracer/FrameTracer.cpp",
        "FrameTracer/FrameTracer.cpp",
        "FrameTracker.cpp",
        "FrameTracker.cpp",
        "HdrLayerInfoReporter.cpp",
        "HdrLayerInfoReporter.cpp",
        "HwcSlotGenerator.cpp",
        "WindowInfosListenerInvoker.cpp",
        "WindowInfosListenerInvoker.cpp",
        "Layer.cpp",
        "Layer.cpp",
        "LayerFE.cpp",
        "LayerFE.cpp",
+6 −2
Original line number Original line Diff line number Diff line
@@ -118,7 +118,8 @@ ClientCache::add(const client_cache_t& cacheId, const sp<GraphicBuffer>& buffer)
                                                                 Usage::READABLE));
                                                                 Usage::READABLE));
}
}


void ClientCache::erase(const client_cache_t& cacheId) {
sp<GraphicBuffer> ClientCache::erase(const client_cache_t& cacheId) {
    sp<GraphicBuffer> buffer;
    auto& [processToken, id] = cacheId;
    auto& [processToken, id] = cacheId;
    std::vector<sp<ErasedRecipient>> pendingErase;
    std::vector<sp<ErasedRecipient>> pendingErase;
    {
    {
@@ -126,9 +127,11 @@ void ClientCache::erase(const client_cache_t& cacheId) {
        ClientCacheBuffer* buf = nullptr;
        ClientCacheBuffer* buf = nullptr;
        if (!getBuffer(cacheId, &buf)) {
        if (!getBuffer(cacheId, &buf)) {
            ALOGE("failed to erase buffer, could not retrieve buffer");
            ALOGE("failed to erase buffer, could not retrieve buffer");
            return;
            return nullptr;
        }
        }


        buffer = buf->buffer->getBuffer();

        for (auto& recipient : buf->recipients) {
        for (auto& recipient : buf->recipients) {
            sp<ErasedRecipient> erasedRecipient = recipient.promote();
            sp<ErasedRecipient> erasedRecipient = recipient.promote();
            if (erasedRecipient) {
            if (erasedRecipient) {
@@ -142,6 +145,7 @@ void ClientCache::erase(const client_cache_t& cacheId) {
    for (auto& recipient : pendingErase) {
    for (auto& recipient : pendingErase) {
        recipient->bufferErased(cacheId);
        recipient->bufferErased(cacheId);
    }
    }
    return buffer;
}
}


std::shared_ptr<renderengine::ExternalTexture> ClientCache::get(const client_cache_t& cacheId) {
std::shared_ptr<renderengine::ExternalTexture> ClientCache::get(const client_cache_t& cacheId) {
+13 −1
Original line number Original line Diff line number Diff line
@@ -33,6 +33,17 @@


namespace android {
namespace android {


// This class manages a cache of buffer handles between SurfaceFlinger clients
// and the SurfaceFlinger process which optimizes away some of the cost of
// sending buffer handles across processes.
//
// Buffers are explicitly cached and uncached by the SurfaceFlinger client. When
// a buffer is uncached, it is not only purged from this cache, but the buffer
// ID is also passed down to CompositionEngine to purge it from a similar cache
// used between SurfaceFlinger and Composer HAL. The buffer ID used to purge
// both the SurfaceFlinger side of this other cache, as well as Composer HAL's
// side of the cache.
//
class ClientCache : public Singleton<ClientCache> {
class ClientCache : public Singleton<ClientCache> {
public:
public:
    ClientCache();
    ClientCache();
@@ -41,7 +52,8 @@ public:


    base::expected<std::shared_ptr<renderengine::ExternalTexture>, AddError> add(
    base::expected<std::shared_ptr<renderengine::ExternalTexture>, AddError> add(
            const client_cache_t& cacheId, const sp<GraphicBuffer>& buffer);
            const client_cache_t& cacheId, const sp<GraphicBuffer>& buffer);
    void erase(const client_cache_t& cacheId);

    sp<GraphicBuffer> erase(const client_cache_t& cacheId);


    std::shared_ptr<renderengine::ExternalTexture> get(const client_cache_t& cacheId);
    std::shared_ptr<renderengine::ExternalTexture> get(const client_cache_t& cacheId);


+3 −0
Original line number Original line Diff line number Diff line
@@ -52,6 +52,9 @@ struct CompositionRefreshArgs {
    // All the layers that have queued updates.
    // All the layers that have queued updates.
    Layers layersWithQueuedFrames;
    Layers layersWithQueuedFrames;


    // All graphic buffers that will no longer be used and should be removed from caches.
    std::vector<uint64_t> bufferIdsToUncache;

    // Controls how the color mode is chosen for an output
    // Controls how the color mode is chosen for an output
    OutputColorSetting outputColorSetting{OutputColorSetting::kEnhanced};
    OutputColorSetting outputColorSetting{OutputColorSetting::kEnhanced};


+0 −1
Original line number Original line Diff line number Diff line
@@ -163,7 +163,6 @@ struct LayerFECompositionState {


    // The buffer and related state
    // The buffer and related state
    sp<GraphicBuffer> buffer;
    sp<GraphicBuffer> buffer;
    int bufferSlot{BufferQueue::INVALID_BUFFER_SLOT};
    sp<Fence> acquireFence = Fence::NO_FENCE;
    sp<Fence> acquireFence = Fence::NO_FENCE;
    Region surfaceDamage;
    Region surfaceDamage;
    uint64_t frameNumber = 0;
    uint64_t frameNumber = 0;
Loading