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

Commit 1c8d7209 authored by Alec Mouri's avatar Alec Mouri
Browse files

[SurfaceFlinger] support EGLImage management in BLAST

This mirrors a performance optimization for BufferQueueLayers where
EGLImages were allocated in onFrameAvailable. Here when buffers are
passed over to SurfaceFlinger in a transaction, an EGLImage is also
created for that buffer.

This is critical for reducing jank when operating in higher refresh
rates, as eglCreateImageKHR can take long enough for frames to miss.

Bug: 133627730
Test: systrace of chrome in landscope orientation caches properly
Change-Id: I2022564fbecace7cadd00c89abdcc358d6323315
parent 0fafdb81
Loading
Loading
Loading
Loading
+4 −11
Original line number Original line Diff line number Diff line
@@ -50,12 +50,6 @@ BufferStateLayer::BufferStateLayer(const LayerCreationArgs& args)
    mOverrideScalingMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
    mOverrideScalingMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
    mCurrentState.dataspace = ui::Dataspace::V0_SRGB;
    mCurrentState.dataspace = ui::Dataspace::V0_SRGB;
}
}
BufferStateLayer::~BufferStateLayer() {
    if (mActiveBuffer != nullptr) {
        auto& engine(mFlinger->getRenderEngine());
        engine.unbindExternalTextureBuffer(mActiveBuffer->getId());
    }
}


// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// Interface implementation for Layer
// Interface implementation for Layer
@@ -571,11 +565,6 @@ status_t BufferStateLayer::updateActiveBuffer() {
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }


    if (mActiveBuffer != nullptr) {
        // todo: get this to work with BufferStateLayerCache
        auto& engine(mFlinger->getRenderEngine());
        engine.unbindExternalTextureBuffer(mActiveBuffer->getId());
    }
    mActiveBuffer = s.buffer;
    mActiveBuffer = s.buffer;
    mActiveBufferFence = s.acquireFence;
    mActiveBufferFence = s.acquireFence;
    auto& layerCompositionState = getCompositionLayer()->editState().frontEnd;
    auto& layerCompositionState = getCompositionLayer()->editState().frontEnd;
@@ -621,6 +610,10 @@ void BufferStateLayer::onFirstRef() {
    }
    }
}
}


void BufferStateLayer::bufferErased(const client_cache_t& clientCacheId) {
    mFlinger->getRenderEngine().unbindExternalTextureBuffer(clientCacheId.id);
}

void BufferStateLayer::HwcSlotGenerator::bufferErased(const client_cache_t& clientCacheId) {
void BufferStateLayer::HwcSlotGenerator::bufferErased(const client_cache_t& clientCacheId) {
    std::lock_guard lock(mMutex);
    std::lock_guard lock(mMutex);
    if (!clientCacheId.isValid()) {
    if (!clientCacheId.isValid()) {
+3 −1
Original line number Original line Diff line number Diff line
@@ -34,7 +34,6 @@ class SlotGenerationTest;
class BufferStateLayer : public BufferLayer {
class BufferStateLayer : public BufferLayer {
public:
public:
    explicit BufferStateLayer(const LayerCreationArgs&);
    explicit BufferStateLayer(const LayerCreationArgs&);
    ~BufferStateLayer() override;


    // -----------------------------------------------------------------------
    // -----------------------------------------------------------------------
    // Interface implementation for Layer
    // Interface implementation for Layer
@@ -103,6 +102,9 @@ public:
    bool fenceHasSignaled() const override;
    bool fenceHasSignaled() const override;
    bool framePresentTimeIsCurrent() const override;
    bool framePresentTimeIsCurrent() const override;


    // Inherit from ClientCache::ErasedRecipient
    void bufferErased(const client_cache_t& clientCacheId) override;

private:
private:
    nsecs_t getDesiredPresentTime() override;
    nsecs_t getDesiredPresentTime() override;
    std::shared_ptr<FenceTime> getCurrentFenceTime() const override;
    std::shared_ptr<FenceTime> getCurrentFenceTime() const override;
+9 −7
Original line number Original line Diff line number Diff line
@@ -17,8 +17,6 @@
#ifndef ANDROID_LAYER_H
#ifndef ANDROID_LAYER_H
#define ANDROID_LAYER_H
#define ANDROID_LAYER_H


#include <sys/types.h>

#include <compositionengine/LayerFE.h>
#include <compositionengine/LayerFE.h>
#include <gui/BufferQueue.h>
#include <gui/BufferQueue.h>
#include <gui/ISurfaceComposerClient.h>
#include <gui/ISurfaceComposerClient.h>
@@ -28,6 +26,7 @@
#include <math/vec4.h>
#include <math/vec4.h>
#include <renderengine/Mesh.h>
#include <renderengine/Mesh.h>
#include <renderengine/Texture.h>
#include <renderengine/Texture.h>
#include <sys/types.h>
#include <ui/FloatRect.h>
#include <ui/FloatRect.h>
#include <ui/FrameStats.h>
#include <ui/FrameStats.h>
#include <ui/GraphicBuffer.h>
#include <ui/GraphicBuffer.h>
@@ -44,16 +43,16 @@
#include <vector>
#include <vector>


#include "Client.h"
#include "Client.h"
#include "ClientCache.h"
#include "DisplayHardware/ComposerHal.h"
#include "DisplayHardware/HWComposer.h"
#include "FrameTracker.h"
#include "FrameTracker.h"
#include "LayerVector.h"
#include "LayerVector.h"
#include "MonitoredProducer.h"
#include "MonitoredProducer.h"
#include "RenderArea.h"
#include "SurfaceFlinger.h"
#include "SurfaceFlinger.h"
#include "TransactionCompletedThread.h"
#include "TransactionCompletedThread.h"


#include "DisplayHardware/ComposerHal.h"
#include "DisplayHardware/HWComposer.h"
#include "RenderArea.h"

using namespace android::surfaceflinger;
using namespace android::surfaceflinger;


namespace android {
namespace android {
@@ -94,7 +93,7 @@ struct LayerCreationArgs {
    LayerMetadata metadata;
    LayerMetadata metadata;
};
};


class Layer : public virtual compositionengine::LayerFE {
class Layer : public virtual compositionengine::LayerFE, public ClientCache::ErasedRecipient {
    static std::atomic<int32_t> sSequence;
    static std::atomic<int32_t> sSequence;


public:
public:
@@ -690,6 +689,9 @@ public:
    compositionengine::OutputLayer* findOutputLayerForDisplay(
    compositionengine::OutputLayer* findOutputLayerForDisplay(
            const sp<const DisplayDevice>& display) const;
            const sp<const DisplayDevice>& display) const;


    // Inherit from ClientCache::ErasedRecipient
    void bufferErased(const client_cache_t& /*clientCacheId*/) override {}

protected:
protected:
    // constant
    // constant
    sp<SurfaceFlinger> mFlinger;
    sp<SurfaceFlinger> mFlinger;
+3 −0
Original line number Original line Diff line number Diff line
@@ -4122,6 +4122,9 @@ uint32_t SurfaceFlinger::setClientStateLocked(
    sp<GraphicBuffer> buffer;
    sp<GraphicBuffer> buffer;
    if (bufferChanged && cacheIdChanged) {
    if (bufferChanged && cacheIdChanged) {
        ClientCache::getInstance().add(s.cachedBuffer, s.buffer);
        ClientCache::getInstance().add(s.cachedBuffer, s.buffer);
        ClientCache::getInstance().registerErasedRecipient(s.cachedBuffer,
                                                           wp<ClientCache::ErasedRecipient>(layer));
        getRenderEngine().cacheExternalTextureBuffer(s.buffer);
        buffer = s.buffer;
        buffer = s.buffer;
    } else if (cacheIdChanged) {
    } else if (cacheIdChanged) {
        buffer = ClientCache::getInstance().get(s.cachedBuffer);
        buffer = ClientCache::getInstance().get(s.cachedBuffer);