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

Commit 06d63de0 authored by Chia-I Wu's avatar Chia-I Wu Committed by Iliyan Malchev
Browse files

surfaceflinger: cache HWC client targets and buffers

Remember HWC client targets and buffers, and make sure we send each
unique slot/handle pair only once.  This allows the composer to
clone/register/retain each buffer only once.

Test: builds and boots
Change-Id: Ib485189043a9c132031e82d4d7380ace3bf9453d
parent f757977d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -172,7 +172,9 @@ public:
    void setFilteringEnabled(bool enabled);

    // getCurrentBuffer returns the buffer associated with the current image.
    sp<GraphicBuffer> getCurrentBuffer() const;
    // When outSlot is not nullptr, the current buffer slot index is also
    // returned.
    sp<GraphicBuffer> getCurrentBuffer(int* outSlot = nullptr) const;

    // getCurrentTextureTarget returns the texture target of the current
    // texture as returned by updateTexImage().
+7 −2
Original line number Diff line number Diff line
@@ -930,9 +930,14 @@ uint64_t GLConsumer::getFrameNumber() {
    return mCurrentFrameNumber;
}

sp<GraphicBuffer> GLConsumer::getCurrentBuffer() const {
sp<GraphicBuffer> GLConsumer::getCurrentBuffer(int* outSlot) const {
    Mutex::Autolock lock(mMutex);
    return (mCurrentTextureImage == NULL) ?

    if (outSlot != nullptr) {
        *outSlot = mCurrentTexture;
    }

    return (mCurrentTextureImage == nullptr) ?
            NULL : mCurrentTextureImage->graphicBuffer();
}

+2 −1
Original line number Diff line number Diff line
@@ -1501,7 +1501,8 @@ void Layer::Prepare() {

  if (composition_type_ == HWC2_COMPOSITION_DEVICE) {
    ret = (int32_t)hwc2_hidl_->setLayerBuffer(HWC_DISPLAY_PRIMARY,
                                              hardware_composer_layer_, handle,
                                              hardware_composer_layer_, 0,
                                              handle,
                                              acquire_fence_fd_.Get());

    ALOGE_IF(ret, "HardwareComposer: Error setting layer buffer : %d", ret);
+8 −7
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <android/dvr/composer/1.0/IVrComposerClient.h>
#include <inttypes.h>
#include <log/log.h>
#include <gui/BufferQueue.h>

#include "ComposerHal.h"

@@ -221,9 +222,8 @@ Error Composer::acceptDisplayChanges(Display display)

Error Composer::createLayer(Display display, Layer* outLayer)
{
    const uint32_t bufferSlotCount = 1;
    Error error = kDefaultError;
    mClient->createLayer(display, bufferSlotCount,
    mClient->createLayer(display, BufferQueue::NUM_BUFFER_SLOTS,
            [&](const auto& tmpError, const auto& tmpLayer) {
                error = tmpError;
                if (error != Error::NONE) {
@@ -427,12 +427,13 @@ Error Composer::setActiveConfig(Display display, Config config)
    return unwrapRet(ret);
}

Error Composer::setClientTarget(Display display, const native_handle_t* target,
Error Composer::setClientTarget(Display display, uint32_t slot,
        const native_handle_t* target,
        int acquireFence, Dataspace dataspace,
        const std::vector<IComposerClient::Rect>& damage)
{
    mWriter.selectDisplay(display);
    mWriter.setClientTarget(0, target, acquireFence, dataspace, damage);
    mWriter.setClientTarget(slot, target, acquireFence, dataspace, damage);
    return Error::NONE;
}

@@ -472,7 +473,7 @@ Error Composer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled)

Error Composer::setClientTargetSlotCount(Display display)
{
    const uint32_t bufferSlotCount = 1;
    const uint32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
    auto ret = mClient->setClientTargetSlotCount(display, bufferSlotCount);
    return unwrapRet(ret);
}
@@ -503,11 +504,11 @@ Error Composer::setCursorPosition(Display display, Layer layer,
}

Error Composer::setLayerBuffer(Display display, Layer layer,
        const native_handle_t* buffer, int acquireFence)
        uint32_t slot, const native_handle_t* buffer, int acquireFence)
{
    mWriter.selectDisplay(display);
    mWriter.selectLayer(layer);
    mWriter.setLayerBuffer(0, buffer, acquireFence);
    mWriter.setLayerBuffer(slot, buffer, acquireFence);
    return Error::NONE;
}

+10 −2
Original line number Diff line number Diff line
@@ -172,7 +172,14 @@ public:
    Error presentDisplay(Display display, int* outPresentFence);

    Error setActiveConfig(Display display, Config config);
    Error setClientTarget(Display display, const native_handle_t* target,

    /*
     * The composer caches client targets internally.  When target is nullptr,
     * the composer uses slot to look up the client target from its cache.
     * When target is not nullptr, the cache is updated with the new target.
     */
    Error setClientTarget(Display display, uint32_t slot,
            const native_handle_t* target,
            int acquireFence, Dataspace dataspace,
            const std::vector<IComposerClient::Rect>& damage);
    Error setColorMode(Display display, ColorMode mode);
@@ -190,7 +197,8 @@ public:

    Error setCursorPosition(Display display, Layer layer,
            int32_t x, int32_t y);
    Error setLayerBuffer(Display display, Layer layer,
    /* see setClientTarget for the purpose of slot */
    Error setLayerBuffer(Display display, Layer layer, uint32_t slot,
            const native_handle_t* buffer, int acquireFence);
    Error setLayerSurfaceDamage(Display display, Layer layer,
            const std::vector<IComposerClient::Rect>& damage);
Loading