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

Commit 70eb2960 authored by Sungtak Lee's avatar Sungtak Lee Committed by Android (Google) Code Review
Browse files

Merge "Revist C2HandleGralloc::WrapNativeHandle"

parents 8d1e0c5b a4d13be8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ struct InputSurfaceConnection::Impl : public ComponentWrapper {

        std::shared_ptr<C2GraphicAllocation> alloc;
        C2Handle* handle = WrapNativeCodec2GrallocHandle(
                native_handle_clone(buffer->handle),
                buffer->handle,
                buffer->width, buffer->height,
                buffer->format, buffer->usage, buffer->stride);
        mAllocatorMutex.lock();
+1 −5
Original line number Diff line number Diff line
@@ -225,18 +225,14 @@ status_t C2OMXNode::emptyBuffer(
    if (omxBuf.mBufferType == OMXBuffer::kBufferTypeANWBuffer
            && omxBuf.mGraphicBuffer != nullptr) {
        std::shared_ptr<C2GraphicAllocation> alloc;
        native_handle_t *clonedHandle = native_handle_clone(omxBuf.mGraphicBuffer->handle);
        handle = WrapNativeCodec2GrallocHandle(
                clonedHandle,
                omxBuf.mGraphicBuffer->handle,
                omxBuf.mGraphicBuffer->width,
                omxBuf.mGraphicBuffer->height,
                omxBuf.mGraphicBuffer->format,
                omxBuf.mGraphicBuffer->usage,
                omxBuf.mGraphicBuffer->stride);
        c2_status_t err = mAllocator->priorGraphicAllocation(handle, &alloc);
        if (clonedHandle) {
            native_handle_delete(clonedHandle);
        }
        if (err != OK) {
            return UNKNOWN_ERROR;
        }
+1 −1
Original line number Diff line number Diff line
@@ -578,7 +578,7 @@ std::shared_ptr<C2Buffer> GraphicMetadataBuffer::asC2Buffer() {

    ALOGV("VideoNativeMetadata: %dx%d", buffer->width, buffer->height);
    C2Handle *handle = WrapNativeCodec2GrallocHandle(
            native_handle_clone(buffer->handle),
            buffer->handle,
            buffer->width,
            buffer->height,
            buffer->format,
+24 −4
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ public:
        return xd != nullptr && xd->magic == MAGIC;
    }

    static C2HandleGralloc* WrapNativeHandle(
    static C2HandleGralloc* WrapAndMoveNativeHandle(
            const native_handle_t *const handle,
            uint32_t width, uint32_t height, uint32_t format, uint64_t usage,
            uint32_t stride, uint32_t generation, uint64_t igbp_id = 0, uint32_t igbp_slot = 0) {
@@ -181,6 +181,26 @@ public:
        return reinterpret_cast<C2HandleGralloc *>(res);
    }

    static C2HandleGralloc* WrapNativeHandle(
            const native_handle_t *const handle,
            uint32_t width, uint32_t height, uint32_t format, uint64_t usage,
            uint32_t stride, uint32_t generation, uint64_t igbp_id = 0, uint32_t igbp_slot = 0) {
        if (handle == nullptr) {
            return nullptr;
        }
        native_handle_t *clone = native_handle_clone(handle);
        if (clone == nullptr) {
            return nullptr;
        }
        C2HandleGralloc *res = WrapAndMoveNativeHandle(
                clone, width, height, format, usage, stride, generation, igbp_id, igbp_slot);
        if (res == nullptr) {
            native_handle_close(clone);
        }
        native_handle_delete(clone);
        return res;
    }

    static native_handle_t* UnwrapNativeHandle(
            const C2Handle *const handle) {
        const ExtraData *xd = getExtraData(handle);
@@ -366,7 +386,7 @@ c2_status_t C2AllocationGralloc::map(
        if (mHandle) {
            mHandle->getIgbpData(&generation, &igbp_id, &igbp_slot);
        }
        mLockedHandle = C2HandleGralloc::WrapNativeHandle(
        mLockedHandle = C2HandleGralloc::WrapAndMoveNativeHandle(
                mBuffer, mInfo.mapperInfo.width, mInfo.mapperInfo.height,
                (uint32_t)mInfo.mapperInfo.format, mInfo.mapperInfo.usage, mInfo.stride,
                generation, igbp_id, igbp_slot);
@@ -743,7 +763,7 @@ c2_status_t C2AllocatorGralloc::Impl::newGraphicAllocation(
                    return;
                }
                info.stride = stride;
                buffer = std::move(buffers[0]);
                buffer = buffers[0];
            });
    if (err != C2_OK) {
        return err;
@@ -752,7 +772,7 @@ c2_status_t C2AllocatorGralloc::Impl::newGraphicAllocation(

    allocation->reset(new C2AllocationGralloc(
            info, mMapper, buffer,
            C2HandleGralloc::WrapNativeHandle(
            C2HandleGralloc::WrapAndMoveNativeHandle(
                    buffer.getNativeHandle(),
                    info.mapperInfo.width, info.mapperInfo.height,
                    (uint32_t)info.mapperInfo.format, info.mapperInfo.usage, info.stride,
+21 −29
Original line number Diff line number Diff line
@@ -269,12 +269,9 @@ private:
            }
        }
        if (slotBuffer) {
            native_handle_t *grallocHandle = native_handle_clone(slotBuffer->handle);

            if (grallocHandle) {
            ALOGV("buffer wraps %llu %d", (unsigned long long)mProducerId, slot);
            C2Handle *c2Handle = android::WrapNativeCodec2GrallocHandle(
                        grallocHandle,
                    slotBuffer->handle,
                    slotBuffer->width,
                    slotBuffer->height,
                    slotBuffer->format,
@@ -283,8 +280,6 @@ private:
                    slotBuffer->getGenerationNumber(),
                    mProducerId, slot);
            if (c2Handle) {
                    // Moved everything to c2Handle.
                    native_handle_delete(grallocHandle);
                std::shared_ptr<C2GraphicAllocation> alloc;
                c2_status_t err = mAllocator->priorGraphicAllocation(c2Handle, &alloc);
                if (err != C2_OK) {
@@ -297,9 +292,6 @@ private:
                *block = _C2BlockFactory::CreateGraphicBlock(alloc, poolData);
                return C2_OK;
            }
                native_handle_close(grallocHandle);
                native_handle_delete(grallocHandle);
            }
            // Block was not created. call requestBuffer# again next time.
            slotBuffer.clear();
            (void)mProducer->cancelBuffer(slot, fenceHandle).isOk();