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

Commit 2377145a authored by Lajos Molnar's avatar Lajos Molnar Committed by Android (Google) Code Review
Browse files

Merge "codec2: do not count padding into allocation's capacity." into sc-dev

parents a55c6e78 4c826e41
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -898,6 +898,12 @@ public:
     * Obtains a linear writeable block of given |capacity| and |usage|. If successful, the
     * block is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     *
     * \note The returned buffer may have a larger capacity than requested. In this case the
     * larger (returned) capacity may be fully used.
     *
     * \note There is no guarantee on the alignedness of the returned block. The only guarantee is
     * that its capacity is equal to or larger than the requested capacity.
     *
     * \param capacity the size of requested block.
     * \param usage    the memory usage info for the requested block. Returned blocks will be
     *                 optimized for this usage, but may be used with any usage. One exception:
@@ -926,6 +932,12 @@ public:
     * Obtains a circular writeable block of given |capacity| and |usage|. If successful, the
     * block is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     *
     * \note The returned buffer may have a larger capacity than requested. In this case the
     * larger (returned) capacity may be fully used.
     *
     * \note There is no guarantee on the alignedness of the returned block. The only guarantee is
     * that its capacity is equal to or larger than the requested capacity.
     *
     * \param capacity the size of requested circular block. (note: the size of the obtained
     *                 block could be slightly larger, e.g. to accommodate any system-required
     *                 alignment)
@@ -956,6 +968,12 @@ public:
     * Obtains a 2D graphic block of given |width|, |height|, |format| and |usage|. If successful,
     * the block is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     *
     * \note The returned buffer may have a larger capacity (width and height) than requested. In
     * this case the larger (returned) capacity may be fully used.
     *
     * \note There is no guarantee on the alignedness of the returned block. The only guarantee is
     * that its capacity is equal to or larger than the requested capacity (width and height).
     *
     * \param width  the width of requested block (the obtained block could be slightly larger, e.g.
     *               to accommodate any system-required alignment)
     * \param height the height of requested block (the obtained block could be slightly larger,
@@ -1000,6 +1018,12 @@ public:
     * fence is signalled when the temporary restriction on fetch is lifted.
     * e.g. more memory is available to fetch because some meomory or prior blocks were released.
     *
     * \note The returned buffer may have a larger capacity than requested. In this case the
     * larger (returned) capacity may be fully used.
     *
     * \note There is no guarantee on the alignedness of the returned block. The only guarantee is
     * that its capacity is equal to or larger than the requested capacity.
     *
     * \param capacity the size of requested block.
     * \param usage    the memory usage info for the requested block. Returned blocks will be
     *                 optimized for this usage, but may be used with any usage. One exception:
@@ -1039,6 +1063,12 @@ public:
     * fence is signalled when the temporary restriction on fetch is lifted.
     * e.g. more memory is available to fetch because some meomory or prior blocks were released.
     *
     * \note The returned buffer may have a larger capacity (width and height) than requested. In
     * this case the larger (returned) capacity may be fully used.
     *
     * \note There is no guarantee on the alignedness of the returned block. The only guarantee is
     * that its capacity is equal to or larger than the requested capacity (width and height).
     *
     * \param width  the width of requested block (the obtained block could be slightly larger, e.g.
     *               to accommodate any system-required alignment)
     * \param height the height of requested block (the obtained block could be slightly larger,
+0 −1
Original line number Diff line number Diff line
@@ -574,7 +574,6 @@ enum C2Config::profile_t : uint32_t {
    PROFILE_MPEGH_HIGH,                         ///< MPEG-H High
    PROFILE_MPEGH_LC,                           ///< MPEG-H Low-complexity
    PROFILE_MPEGH_BASELINE,                     ///< MPEG-H Baseline

};

enum C2Config::level_t : uint32_t {
+2 −0
Original line number Diff line number Diff line
@@ -178,6 +178,8 @@ c2_status_t C2AllocatorBlob::newLinearAllocation(
        return C2_CORRUPTED;
    }

    // Note: the BLOB allocator does not support padding as this functionality is expected
    // to be provided by the gralloc implementation.
    std::shared_ptr<C2GraphicAllocation> graphicAllocation;
    c2_status_t status = mC2AllocatorGralloc->newGraphicAllocation(
            capacity, kLinearBufferHeight, kLinearBufferFormat, usage, &graphicAllocation);
+4 −3
Original line number Diff line number Diff line
@@ -417,15 +417,16 @@ C2AllocationIon::Impl *C2AllocationIon::Impl::Alloc(int ionFd, size_t size, size
                buffer = -1;
            }
        }
        return new Impl(ionFd, allocSize, bufferFd, buffer, id, ret);

        // the padding is not usable so deduct it from the advertised capacity
        return new Impl(ionFd, allocSize - sPadding, bufferFd, buffer, id, ret);
    } else {
        ret = ion_alloc_fd(ionFd, allocSize, align, heapMask, flags, &bufferFd);
        ALOGV("ion_alloc_fd(ionFd = %d, size = %zu, align = %zu, prot = %d, flags = %d) "
              "returned (%d) ; bufferFd = %d",
              ionFd, allocSize, align, heapMask, flags, ret, bufferFd);

        return new ImplV2(ionFd, allocSize, bufferFd, id, ret);
        // the padding is not usable so deduct it from the advertised capacity
        return new ImplV2(ionFd, allocSize - sPadding, bufferFd, id, ret);
    }
}

+27 −8
Original line number Diff line number Diff line
@@ -111,8 +111,27 @@ class C2DmaBufAllocation : public C2LinearAllocation {
    virtual bool equals(const std::shared_ptr<C2LinearAllocation>& other) const override;

    // internal methods
    C2DmaBufAllocation(BufferAllocator& alloc, size_t size, C2String heap_name, unsigned flags,
                       C2Allocator::id_t id);

    /**
      * Constructs an allocation via a new allocation.
      *
      * @param alloc     allocator
      * @param allocSize size used for the allocator
      * @param capacity  capacity advertised to the client
      * @param heap_name name of the dmabuf heap (device)
      * @param flags     flags
      * @param id        allocator id
      */
    C2DmaBufAllocation(BufferAllocator& alloc, size_t allocSize, size_t capacity,
                       C2String heap_name, unsigned flags, C2Allocator::id_t id);

    /**
      * Constructs an allocation by wrapping an existing allocation.
      *
      * @param size    capacity advertised to the client
      * @param shareFd dmabuf fd of the wrapped allocation
      * @param id      allocator id
      */
    C2DmaBufAllocation(size_t size, int shareFd, C2Allocator::id_t id);

    c2_status_t status() const;
@@ -246,19 +265,19 @@ C2DmaBufAllocation::~C2DmaBufAllocation() {
    }
}

C2DmaBufAllocation::C2DmaBufAllocation(BufferAllocator& alloc, size_t size, C2String heap_name,
                                       unsigned flags, C2Allocator::id_t id)
    : C2LinearAllocation(size), mHandle(-1, 0) {
C2DmaBufAllocation::C2DmaBufAllocation(BufferAllocator& alloc, size_t allocSize, size_t capacity,
                                       C2String heap_name, unsigned flags, C2Allocator::id_t id)
    : C2LinearAllocation(capacity), mHandle(-1, 0) {
    int bufferFd = -1;
    int ret = 0;

    bufferFd = alloc.Alloc(heap_name, size, flags);
    bufferFd = alloc.Alloc(heap_name, allocSize, flags);
    if (bufferFd < 0) {
        ret = bufferFd;
    }

    // this may be a non-working handle if bufferFd is negative
    mHandle = C2HandleBuf(bufferFd, size);
    mHandle = C2HandleBuf(bufferFd, capacity);
    mId = id;
    mInit = c2_status_t(c2_map_errno<ENOMEM, EACCES, EINVAL>(ret));
}
@@ -381,7 +400,7 @@ c2_status_t C2DmaBufAllocator::newLinearAllocation(
    size_t allocSize = (size_t)capacity + sPadding;
    // TODO: should we align allocation size to mBlockSize to reflect the true allocation size?
    std::shared_ptr<C2DmaBufAllocation> alloc = std::make_shared<C2DmaBufAllocation>(
            mBufferAllocator, allocSize, heap_name, flags, getId());
            mBufferAllocator, allocSize, allocSize - sPadding, heap_name, flags, getId());
    ret = alloc->status();
    if (ret == C2_OK) {
        *allocation = alloc;