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

Commit ebc2c059 authored by Marissa Wall's avatar Marissa Wall
Browse files

blast: cache buffers

Cache incoming buffers so they don't have to be imported by mapper
everytime they are set.

Amended by Change-Id: I3040f6d8886ca9b130115784c199edfdd9c85c7e

Test: Transaction_test
Bug: 80477568
Change-Id: Icd167c5e5bd59d7331b829667b1139919393d98b
parent 17b4e457
Loading
Loading
Loading
Loading
+78 −0
Original line number Diff line number Diff line
@@ -695,6 +695,42 @@ public:
        }
        return err;
    }

    virtual status_t cacheBuffer(const sp<IBinder>& token, const sp<GraphicBuffer>& buffer,
                                 int32_t* outBufferId) {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());

        data.writeStrongBinder(token);
        if (buffer) {
            data.writeBool(true);
            data.write(*buffer);
        } else {
            data.writeBool(false);
        }

        status_t result = remote()->transact(BnSurfaceComposer::CACHE_BUFFER, data, &reply);
        if (result != NO_ERROR) {
            return result;
        }

        int32_t id = -1;
        result = reply.readInt32(&id);
        if (result == NO_ERROR) {
            *outBufferId = id;
        }
        return result;
    }

    virtual status_t uncacheBuffer(const sp<IBinder>& token, int32_t bufferId) {
        Parcel data, reply;
        data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());

        data.writeStrongBinder(token);
        data.writeInt32(bufferId);

        return remote()->transact(BnSurfaceComposer::UNCACHE_BUFFER, data, &reply);
    }
};

// Out-of-line virtual method definition to trigger vtable emission in this
@@ -1136,6 +1172,48 @@ status_t BnSurfaceComposer::onTransact(
            }
            return error;
        }
        case CACHE_BUFFER: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            sp<IBinder> token;
            status_t result = data.readStrongBinder(&token);
            if (result != NO_ERROR) {
                ALOGE("cache buffer failure in reading token: %d", result);
                return result;
            }

            sp<GraphicBuffer> buffer = new GraphicBuffer();
            if (data.readBool()) {
                result = data.read(*buffer);
                if (result != NO_ERROR) {
                    ALOGE("cache buffer failure in reading buffer: %d", result);
                    return result;
                }
            }
            int32_t bufferId = -1;
            status_t error = cacheBuffer(token, buffer, &bufferId);
            if (error == NO_ERROR) {
                reply->writeInt32(bufferId);
            }
            return error;
        }
        case UNCACHE_BUFFER: {
            CHECK_INTERFACE(ISurfaceComposer, data, reply);
            sp<IBinder> token;
            status_t result = data.readStrongBinder(&token);
            if (result != NO_ERROR) {
                ALOGE("uncache buffer failure in reading token: %d", result);
                return result;
            }

            int32_t bufferId = -1;
            result = data.readInt32(&bufferId);
            if (result != NO_ERROR) {
                ALOGE("uncache buffer failure in reading buffer id: %d", result);
                return result;
            }

            return uncacheBuffer(token, bufferId);
        }
        default: {
            return BBinder::onTransact(code, data, reply, flags);
        }
+10 −0
Original line number Diff line number Diff line
@@ -94,6 +94,9 @@ status_t layer_state_t::write(Parcel& output) const
        }
    }

    output.writeStrongBinder(cachedBuffer.token);
    output.writeInt32(cachedBuffer.bufferId);

    return NO_ERROR;
}

@@ -164,6 +167,9 @@ status_t layer_state_t::read(const Parcel& input)
        listenerCallbacks.emplace_back(listener, callbackIds);
    }

    cachedBuffer.token = input.readStrongBinder();
    cachedBuffer.bufferId = input.readInt32();

    return NO_ERROR;
}

@@ -372,6 +378,10 @@ void layer_state_t::merge(const layer_state_t& other) {
    }
#endif

    if (other.what & eCachedBufferChanged) {
        what |= eCachedBufferChanged;
        cachedBuffer = other.cachedBuffer;
    }
    if ((other.what & what) != other.what) {
        ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
              "other.what=0x%" PRIu64 " what=0x%" PRIu64,
+35 −0
Original line number Diff line number Diff line
@@ -660,6 +660,21 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBuffe
    return *this;
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCachedBuffer(
        const sp<SurfaceControl>& sc, int32_t bufferId) {
    layer_state_t* s = getLayerState(sc);
    if (!s) {
        mStatus = BAD_INDEX;
        return *this;
    }
    s->what |= layer_state_t::eCachedBufferChanged;
    s->cachedBuffer.token = IInterface::asBinder(TransactionCompletedListener::getIInstance());
    s->cachedBuffer.bufferId = bufferId;

    registerSurfaceControlForCallback(sc);
    return *this;
}

SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setAcquireFence(
        const sp<SurfaceControl>& sc, const sp<Fence>& fence) {
    layer_state_t* s = getLayerState(sc);
@@ -1057,6 +1072,26 @@ status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token,

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

status_t SurfaceComposerClient::cacheBuffer(const sp<GraphicBuffer>& buffer, int32_t* outBufferId) {
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
    if (buffer == nullptr || outBufferId == nullptr) {
        return BAD_VALUE;
    }
    return sf->cacheBuffer(IInterface::asBinder(TransactionCompletedListener::getIInstance()),
                           buffer, outBufferId);
}

status_t SurfaceComposerClient::uncacheBuffer(int32_t bufferId) {
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
    if (bufferId < 0) {
        return BAD_VALUE;
    }
    return sf->uncacheBuffer(IInterface::asBinder(TransactionCompletedListener::getIInstance()),
                             bufferId);
}

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

status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
    return sf->enableVSyncInjections(enable);
+7 −0
Original line number Diff line number Diff line
@@ -316,6 +316,11 @@ public:
     * Requires the ACCESS_SURFACE_FLINGER permission.
     */
    virtual status_t getProtectedContentSupport(bool* outSupported) const = 0;

    virtual status_t cacheBuffer(const sp<IBinder>& token, const sp<GraphicBuffer>& buffer,
                                 int32_t* outBufferId) = 0;

    virtual status_t uncacheBuffer(const sp<IBinder>& token, int32_t bufferId) = 0;
};

// ----------------------------------------------------------------------------
@@ -358,6 +363,8 @@ public:
        SET_DISPLAY_CONTENT_SAMPLING_ENABLED,
        GET_DISPLAYED_CONTENT_SAMPLE,
        GET_PROTECTED_CONTENT_SUPPORT,
        CACHE_BUFFER,
        UNCACHE_BUFFER,
    };

    virtual status_t onTransact(uint32_t code, const Parcel& data,
+7 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ struct layer_state_t {
        eInputInfoChanged = 0x40000000,
        eCornerRadiusChanged = 0x80000000,
        eFrameChanged = 0x1'00000000,
        eCachedBufferChanged = 0x2'00000000,
    };

    layer_state_t()
@@ -125,6 +126,10 @@ struct layer_state_t {
        float dtdy{0};
        float dsdy{0};
    };
    struct cached_buffer_t {
        sp<IBinder> token = nullptr;
        int32_t bufferId = -1;
    };
    sp<IBinder> surface;
    uint64_t what;
    float x;
@@ -173,6 +178,8 @@ struct layer_state_t {
#ifndef NO_INPUT
    InputWindowInfo inputInfo;
#endif

    cached_buffer_t cachedBuffer;
};

struct ComposerState {
Loading