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

Commit 142a00d2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make prior{Linear/Graphic}Allocation own handle" into pi-dev

parents 56ecf3e3 3deddf1b
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -655,7 +655,8 @@ public:
     * (Re)creates a 1D allocation from a native |handle|. If successful, the allocation is stored
     * (Re)creates a 1D allocation from a native |handle|. If successful, the allocation is stored
     * in |allocation|. Otherwise, |allocation| is set to 'nullptr'.
     * in |allocation|. Otherwise, |allocation| is set to 'nullptr'.
     *
     *
     * \param handle      the handle for the existing allocation
     * \param handle      the handle for the existing allocation. On success, the allocation will
     *                    take ownership of |handle|.
     * \param allocation  pointer to where the allocation shall be stored on success. nullptr
     * \param allocation  pointer to where the allocation shall be stored on success. nullptr
     *                    will be stored here on failure
     *                    will be stored here on failure
     *
     *
@@ -712,7 +713,8 @@ public:
     * (Re)creates a 2D allocation from a native handle.  If successful, the allocation is stored
     * (Re)creates a 2D allocation from a native handle.  If successful, the allocation is stored
     * in |allocation|. Otherwise, |allocation| is set to 'nullptr'.
     * in |allocation|. Otherwise, |allocation| is set to 'nullptr'.
     *
     *
     * \param handle      the handle for the existing allocation
     * \param handle      the handle for the existing allocation. On success, the allocation will
     *                    take ownership of |handle|.
     * \param allocation  pointer to where the allocation shall be stored on success. nullptr
     * \param allocation  pointer to where the allocation shall be stored on success. nullptr
     *                    will be stored here on failure
     *                    will be stored here on failure
     *
     *
+5 −2
Original line number Original line Diff line number Diff line
@@ -255,6 +255,7 @@ C2AllocationGralloc::C2AllocationGralloc(
      mHidlHandle(std::move(hidlHandle)),
      mHidlHandle(std::move(hidlHandle)),
      mHandle(handle),
      mHandle(handle),
      mBuffer(nullptr),
      mBuffer(nullptr),
      mLockedHandle(nullptr),
      mLocked(false),
      mLocked(false),
      mAllocatorId(allocatorId) {
      mAllocatorId(allocatorId) {
}
}
@@ -269,6 +270,8 @@ C2AllocationGralloc::~C2AllocationGralloc() {
        unmap(addr, C2Rect(), nullptr);
        unmap(addr, C2Rect(), nullptr);
    }
    }
    mMapper->freeBuffer(const_cast<native_handle_t *>(mBuffer));
    mMapper->freeBuffer(const_cast<native_handle_t *>(mBuffer));
    native_handle_delete(const_cast<native_handle_t*>(
            reinterpret_cast<const native_handle_t*>(mHandle)));
}
}


c2_status_t C2AllocationGralloc::map(
c2_status_t C2AllocationGralloc::map(
@@ -608,8 +611,8 @@ c2_status_t C2AllocatorGralloc::Impl::priorGraphicAllocation(
        return C2_BAD_VALUE;
        return C2_BAD_VALUE;
    }
    }


    hidl_handle hidlHandle = C2HandleGralloc::UnwrapNativeHandle(grallocHandle);
    hidl_handle hidlHandle;

    hidlHandle.setTo(C2HandleGralloc::UnwrapNativeHandle(grallocHandle), true);
    allocation->reset(new C2AllocationGralloc(info, mMapper, hidlHandle, grallocHandle, mTraits->id));
    allocation->reset(new C2AllocationGralloc(info, mMapper, hidlHandle, grallocHandle, mTraits->id));
    return C2_OK;
    return C2_OK;
}
}
+6 −9
Original line number Original line Diff line number Diff line
@@ -150,7 +150,6 @@ private:
     * so that we can capture the error.
     * so that we can capture the error.
     *
     *
     * \param ionFd     ion client (ownership transferred to created object)
     * \param ionFd     ion client (ownership transferred to created object)
     * \param owned     whehter native_handle_t is owned by an allocation or not.
     * \param capacity  size of allocation
     * \param capacity  size of allocation
     * \param bufferFd  buffer handle (ownership transferred to created object). Must be
     * \param bufferFd  buffer handle (ownership transferred to created object). Must be
     *                  invalid if err is not 0.
     *                  invalid if err is not 0.
@@ -158,9 +157,8 @@ private:
     *                  invalid if err is not 0.
     *                  invalid if err is not 0.
     * \param err       errno during buffer allocation or import
     * \param err       errno during buffer allocation or import
     */
     */
    Impl(int ionFd, bool owned, size_t capacity, int bufferFd, ion_user_handle_t buffer, C2Allocator::id_t id, int err)
    Impl(int ionFd, size_t capacity, int bufferFd, ion_user_handle_t buffer, C2Allocator::id_t id, int err)
        : mIonFd(ionFd),
        : mIonFd(ionFd),
          mHandleOwned(owned),
          mHandle(bufferFd, capacity),
          mHandle(bufferFd, capacity),
          mBuffer(buffer),
          mBuffer(buffer),
          mId(id),
          mId(id),
@@ -191,7 +189,7 @@ public:
    static Impl *Import(int ionFd, size_t capacity, int bufferFd, C2Allocator::id_t id) {
    static Impl *Import(int ionFd, size_t capacity, int bufferFd, C2Allocator::id_t id) {
        ion_user_handle_t buffer = -1;
        ion_user_handle_t buffer = -1;
        int ret = ion_import(ionFd, bufferFd, &buffer);
        int ret = ion_import(ionFd, bufferFd, &buffer);
        return new Impl(ionFd, false, capacity, bufferFd, buffer, id, ret);
        return new Impl(ionFd, capacity, bufferFd, buffer, id, ret);
    }
    }


    /**
    /**
@@ -218,7 +216,7 @@ public:
                buffer = -1;
                buffer = -1;
            }
            }
        }
        }
        return new Impl(ionFd, true, size, bufferFd, buffer, id, ret);
        return new Impl(ionFd, size, bufferFd, buffer, id, ret);
    }
    }


    c2_status_t map(size_t offset, size_t size, C2MemoryUsage usage, C2Fence *fence, void **addr) {
    c2_status_t map(size_t offset, size_t size, C2MemoryUsage usage, C2Fence *fence, void **addr) {
@@ -311,13 +309,11 @@ public:
        }
        }
        if (mInit == C2_OK) {
        if (mInit == C2_OK) {
            (void)ion_free(mIonFd, mBuffer);
            (void)ion_free(mIonFd, mBuffer);
            native_handle_close(&mHandle);
        }
        }
        if (mIonFd >= 0) {
        if (mIonFd >= 0) {
            close(mIonFd);
            close(mIonFd);
        }
        }
        if (mHandleOwned) {
            native_handle_close(&mHandle);
        }
    }
    }


    c2_status_t status() const {
    c2_status_t status() const {
@@ -338,7 +334,6 @@ public:


private:
private:
    int mIonFd;
    int mIonFd;
    bool mHandleOwned;
    C2HandleIon mHandle;
    C2HandleIon mHandle;
    ion_user_handle_t mBuffer;
    ion_user_handle_t mBuffer;
    C2Allocator::id_t mId;
    C2Allocator::id_t mId;
@@ -481,6 +476,8 @@ c2_status_t C2AllocatorIon::priorLinearAllocation(
    c2_status_t ret = alloc->status();
    c2_status_t ret = alloc->status();
    if (ret == C2_OK) {
    if (ret == C2_OK) {
        *allocation = alloc;
        *allocation = alloc;
        native_handle_delete(const_cast<native_handle_t*>(
                reinterpret_cast<const native_handle_t*>(handle)));
    }
    }
    return ret;
    return ret;
}
}
+11 −3
Original line number Original line Diff line number Diff line
@@ -135,7 +135,8 @@ private:
    bool mInvalidated; // TODO: implement
    bool mInvalidated; // TODO: implement
    int64_t mExpireUs;
    int64_t mExpireUs;
    bool mHasCache;
    bool mHasCache;
    _C2BlockPoolData mBuffer;
    BufferId mId;
    native_handle_t *mHandle;
    std::weak_ptr<_C2BlockPoolData> mCache;
    std::weak_ptr<_C2BlockPoolData> mCache;


    void updateExpire() {
    void updateExpire() {
@@ -144,11 +145,18 @@ private:


public:
public:
    ClientBuffer(BufferId id, native_handle_t *handle)
    ClientBuffer(BufferId id, native_handle_t *handle)
            : mInvalidated(false), mHasCache(false), mBuffer(id, handle) {
            : mInvalidated(false), mHasCache(false), mId(id), mHandle(handle) {
        (void)mInvalidated;
        (void)mInvalidated;
        mExpireUs = getTimestampNow() + kCacheTtlUs;
        mExpireUs = getTimestampNow() + kCacheTtlUs;
    }
    }


    ~ClientBuffer() {
        if (mHandle) {
            native_handle_close(mHandle);
            native_handle_delete(mHandle);
        }
    }

    bool expire() const {
    bool expire() const {
        int64_t now = getTimestampNow();
        int64_t now = getTimestampNow();
        return now >= mExpireUs;
        return now >= mExpireUs;
@@ -175,7 +183,7 @@ public:
            // Allocates a raw ptr in order to avoid sending #postBufferRelease
            // Allocates a raw ptr in order to avoid sending #postBufferRelease
            // from deleter, in case of native_handle_clone failure.
            // from deleter, in case of native_handle_clone failure.
            _C2BlockPoolData *ptr = new _C2BlockPoolData(
            _C2BlockPoolData *ptr = new _C2BlockPoolData(
                    mBuffer.mId, native_handle_clone(mBuffer.mHandle));
                    mId, native_handle_clone(mHandle));
            if (ptr && ptr->mHandle != NULL) {
            if (ptr && ptr->mHandle != NULL) {
                std::shared_ptr<_C2BlockPoolData>
                std::shared_ptr<_C2BlockPoolData>
                        cache(ptr, BlockPoolDataDtor(impl));
                        cache(ptr, BlockPoolDataDtor(impl));
+1 −4
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@


struct __attribute__((visibility("hidden"))) _C2BlockPoolData {
struct __attribute__((visibility("hidden"))) _C2BlockPoolData {
    uint32_t mId; //BufferId
    uint32_t mId; //BufferId
    // Handle should be copied to somewhere else, and should be managed there.
    native_handle_t *mHandle;
    native_handle_t *mHandle;


    _C2BlockPoolData() : mId(0), mHandle(NULL) {}
    _C2BlockPoolData() : mId(0), mHandle(NULL) {}
@@ -33,10 +34,6 @@ struct __attribute__((visibility("hidden"))) _C2BlockPoolData {
            : mId(id), mHandle(handle) {}
            : mId(id), mHandle(handle) {}


    ~_C2BlockPoolData() {
    ~_C2BlockPoolData() {
        if (mHandle != NULL) {
            native_handle_close(mHandle);
            native_handle_delete(mHandle);
        }
    }
    }
};
};