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

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

Merge "Codec2: finalize allocator/block allocator API"

parents 8df81580 0b924ce4
Loading
Loading
Loading
Loading
+165 −78
Original line number Original line Diff line number Diff line
@@ -1528,6 +1528,60 @@ protected:
 */
 */
class C2Allocator {
class C2Allocator {
public:
public:
    /**
     * Allocator ID type.
     */
    typedef uint32_t id_t;

    /**
     * Allocation types. This is a bitmask and is used in C2Allocator::Info
     * to list the supported allocation types of an allocator.
     */
    enum type_t : uint32_t {
        LINEAR  = 1 << 0, //
        GRAPHIC = 1 << 1,
    };

    /**
     * Information about an allocator.
     */
    struct Info {
        C2String name;              ///< allocator name
        id_t id;                    ///< allocator ID
        type_t supportedTypes;      ///< supported allocation types
        C2MemoryUsage minimumUsage; ///< usage that is minimally required for allocations
        C2MemoryUsage maximumUsage; ///< usage that is maximally allowed for allocations
    };

    /**
     * Returns the unique name of this allocator.
     *
     * This method MUST be "non-blocking" and return within 1ms.
     *
     * \return the name of this allocator.
     * \retval an empty string if there was not enough memory to allocate the actual name.
     */
    virtual C2String getName() const = 0;

    /**
     * Returns a unique ID for this allocator. This ID is used to get this allocator from the
     * allocator store, and to identify this allocator across all processes.
     *
     * This method MUST be "non-blocking" and return within 1ms.
     *
     * \return a unique ID for this allocator.
     */
    virtual id_t getId() const = 0;

    /**
     * Returns the allocator information.
     *
     * This method MUST be "non-blocking" and return within 1ms.
     *
     * \return allocator information
     */
    virtual std::shared_ptr<const Info> getInfo() const = 0;

    /**
    /**
     * Allocates a 1D allocation of given |capacity| and |usage|. If successful, the allocation is
     * Allocates a 1D allocation of given |capacity| and |usage|. If successful, the allocation is
     * stored in |allocation|. Otherwise, |allocation| is set to 'nullptr'.
     * stored in |allocation|. Otherwise, |allocation| is set to 'nullptr'.
@@ -1550,7 +1604,7 @@ public:
     * \retval C2_OMITTED   this allocator does not support 1D allocations
     * \retval C2_OMITTED   this allocator does not support 1D allocations
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     */
     */
    virtual C2Status allocateLinearBuffer(
    virtual C2Status newLinearAllocation(
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            std::shared_ptr<C2LinearAllocation> *allocation /* nonnull */) {
            std::shared_ptr<C2LinearAllocation> *allocation /* nonnull */) {
        *allocation = nullptr;
        *allocation = nullptr;
@@ -1573,7 +1627,7 @@ public:
     * \retval C2_OMITTED   this allocator does not support 1D allocations
     * \retval C2_OMITTED   this allocator does not support 1D allocations
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     */
     */
    virtual C2Status recreateLinearBuffer(
    virtual C2Status priorLinearAllocation(
            const C2Handle *handle __unused,
            const C2Handle *handle __unused,
            std::shared_ptr<C2LinearAllocation> *allocation /* nonnull */) {
            std::shared_ptr<C2LinearAllocation> *allocation /* nonnull */) {
        *allocation = nullptr;
        *allocation = nullptr;
@@ -1606,7 +1660,7 @@ public:
     * \retval C2_OMITTED   this allocator does not support 2D allocations
     * \retval C2_OMITTED   this allocator does not support 2D allocations
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     */
     */
    virtual C2Status allocateGraphicBuffer(
    virtual C2Status newGraphicAllocation(
            uint32_t width __unused, uint32_t height __unused, uint32_t format __unused,
            uint32_t width __unused, uint32_t height __unused, uint32_t format __unused,
            C2MemoryUsage usage __unused,
            C2MemoryUsage usage __unused,
            std::shared_ptr<C2GraphicAllocation> *allocation /* nonnull */) {
            std::shared_ptr<C2GraphicAllocation> *allocation /* nonnull */) {
@@ -1630,7 +1684,7 @@ public:
     * \retval C2_OMITTED   this allocator does not support 2D allocations
     * \retval C2_OMITTED   this allocator does not support 2D allocations
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during recreation (unexpected)
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during recreation (unexpected)
     */
     */
    virtual C2Status recreateGraphicBuffer(
    virtual C2Status priorGraphicAllocation(
            const C2Handle *handle __unused,
            const C2Handle *handle __unused,
            std::shared_ptr<C2GraphicAllocation> *allocation /* nonnull */) {
            std::shared_ptr<C2GraphicAllocation> *allocation /* nonnull */) {
        *allocation = nullptr;
        *allocation = nullptr;
@@ -1644,37 +1698,73 @@ protected:
};
};


/**
/**
 *  Block allocators are used by components to allocate memory for output buffers. They can
 *  Block pools are used by components to obtain output buffers in an efficient way. They can
 *  support either linear (1D), circular (1D) or graphic (2D) allocations.
 *  support either linear (1D), circular (1D) or graphic (2D) blocks.
 *
 *
 *  Never constructed on stack.
 *  Block pools decouple the recycling of memory/allocations from the components. They are meant to
 *  be an opaque service (there are no public APIs other than obtaining blocks) provided by the
 *  platform. Block pools are also meant to decouple allocations from memory used by buffers. This
 *  is accomplished by allowing pools to allot multiple memory 'blocks' on a single allocation. As
 *  their name suggest, block pools maintain a pool of memory blocks. When a component asks for
 *  a memory block, pools will try to return a free memory block already in the pool. If no such
 *  block exists, they will allocate memory using the backing allocator and allot a block on that
 *  allocation. When blocks are no longer used in the system, they are recycled back to the block
 *  pool and are available as free blocks.
 *
 *
 *  Block allocators are provided by the framework.
 *  Never constructed on stack.
 */
 */
class C2BlockAllocator {
class C2BlockPool {
public:
public:
    /**
    /**
     * Allocates a linear writeable block of given |capacity| and |usage|. If successful, the
     * Block pool ID type.
     */
    typedef uint64_t local_id_t;

    enum : local_id_t {
        BASIC_LINEAR = 0,  ///< ID of basic (unoptimized) block pool for fetching 1D blocks
        BASIC_GRAPHIC = 1, ///< ID of basic (unoptimized) block pool for fetching 2D blocks
        PLATFORM_START = 0x10,
    };

    /**
     * Returns the ID for this block pool. This ID is used to get this block pool from the platform.
     * It is only valid in the current process.
     *
     * This method MUST be "non-blocking" and return within 1ms.
     *
     * \return a local ID for this block pool.
     */
    virtual local_id_t getLocalId() const = 0;

    /**
     * Returns the ID of the backing allocator of this block pool.
     *
     * This method MUST be "non-blocking" and return within 1ms.
     *
     * \return the ID of the backing allocator of this block pool.
     */
    virtual C2Allocator::id_t getAllocatorId() const = 0;

    /**
     * Obtains a linear writeable block of given |capacity| and |usage|. If successful, the
     * block is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     * block is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     *
     *
     * \param capacity the size of requested block.
     * \param capacity the size of requested block.
     * \param usage           the memory usage info for the requested allocation. \note that the
     * \param usage    the memory usage info for the requested block. Returned blocks will be
     *                      returned allocation may be later used/mapped with different usage.
     *                 optimized for this usage, but may be used with any usage. One exception:
     *                      The allocator shall lay out the buffer to be optimized for this usage,
     *                 protected blocks/buffers can only be used in a protected scenario.
     *                      but must support any usage. One exception: protected buffers can
     * \param block    pointer to where the obtained block shall be stored on success. nullptr will
     *                      only be used in a protected scenario.
     *                 be stored here on failure
     * \param block      pointer to where the allocated block shall be stored on success. nullptr
     *                      will be stored here on failure
     *
     *
     * \retval C2_OK        the allocation was successful
     * \retval C2_OK        the operation was successful
     * \retval C2_NO_MEMORY not enough memory to complete the allocation
     * \retval C2_NO_MEMORY not enough memory to complete any required allocation
     * \retval C2_TIMED_OUT the allocation timed out
     * \retval C2_TIMED_OUT the operation timed out
     * \retval C2_REFUSED   no permission to complete the allocation
     * \retval C2_REFUSED   no permission to complete any required allocation
     * \retval C2_BAD_VALUE capacity or usage are not supported (invalid) (caller error)
     * \retval C2_BAD_VALUE capacity or usage are not supported (invalid) (caller error)
     * \retval C2_OMITTED   this allocator does not support linear allocations
     * \retval C2_OMITTED   this pool does not support linear blocks
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during operation (unexpected)
     */
     */
    virtual C2Status allocateLinearBlock(
    virtual C2Status fetchLinearBlock(
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            std::shared_ptr<C2LinearBlock> *block /* nonnull */) {
            std::shared_ptr<C2LinearBlock> *block /* nonnull */) {
        *block = nullptr;
        *block = nullptr;
@@ -1682,28 +1772,27 @@ public:
    }
    }


    /**
    /**
     * Allocates a circular writeable block of given |capacity| and |usage|. If successful, the
     * Obtains a circular writeable block of given |capacity| and |usage|. If successful, the
     * block is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     * block is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     *
     *
     * \param capacity        the size of requested circular block. (the allocation could be slightly
     * \param capacity the size of requested circular block. (note: the size of the obtained
     *                      larger, e.g. to account for any system-required alignment)
     *                 block could be slightly larger, e.g. to accommodate any system-required
     * \param usage           the memory usage info for the requested allocation. \note that the
     *                 alignment)
     *                      returned allocation may be later used/mapped with different usage.
     * \param usage    the memory usage info for the requested block. Returned blocks will be
     *                      The allocator shall lay out the buffer to be optimized for this usage,
     *                 optimized for this usage, but may be used with any usage. One exception:
     *                      but must support any usage. One exception: protected buffers can
     *                 protected blocks/buffers can only be used in a protected scenario.
     *                      only be used in a protected scenario.
     * \param block    pointer to where the obtained block shall be stored on success. nullptr
     * \param block      pointer to where the allocated block shall be stored on success. nullptr
     *                 will be stored here on failure
     *                 will be stored here on failure
     *
     *
     * \retval C2_OK            the allocation was successful
     * \retval C2_OK        the operation was successful
     * \retval C2_NO_MEMORY     not enough memory to complete the allocation
     * \retval C2_NO_MEMORY not enough memory to complete any required allocation
     * \retval C2_TIMED_OUT     the allocation timed out
     * \retval C2_TIMED_OUT the operation timed out
     * \retval C2_REFUSED       no permission to complete the allocation
     * \retval C2_REFUSED   no permission to complete any required allocation
     * \retval C2_BAD_VALUE capacity or usage are not supported (invalid) (caller error)
     * \retval C2_BAD_VALUE capacity or usage are not supported (invalid) (caller error)
     * \retval C2_OMITTED       this allocator does not support circular allocations
     * \retval C2_OMITTED   this pool does not support circular blocks
     * \retval C2_CORRUPTED     some unknown, unrecoverable error occured during allocation (unexpected)
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during operation (unexpected)
     */
     */
    virtual C2Status allocateCircularBlock(
    virtual C2Status fetchCircularBlock(
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            std::shared_ptr<C2CircularBlock> *block /* nonnull */) {
            std::shared_ptr<C2CircularBlock> *block /* nonnull */) {
        *block = nullptr;
        *block = nullptr;
@@ -1711,32 +1800,30 @@ public:
    }
    }


    /**
    /**
     * Allocates a 2D graphic block of given |width|, |height|, |format| and |usage|. If successful,
     * Obtains a 2D graphic block of given |width|, |height|, |format| and |usage|. If successful,
     * the allocation is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     * the block is stored in |block|. Otherwise, |block| is set to 'nullptr'.
     *
     *
     * \param width           the width of requested allocation (the allocation could be slightly
     * \param width  the width of requested block (the obtained block could be slightly larger, e.g.
     *                      larger, e.g. to account for any system-required alignment)
     *               to accommodate any system-required alignment)
     * \param height          the height of requested allocation (the allocation could be slightly
     * \param height the height of requested block (the obtained block could be slightly larger,
     *                      larger, e.g. to account for any system-required alignment)
     *               e.g. to accommodate any system-required alignment)
     * \param format          the pixel format of requested allocation. This could be a vendor
     * \param format the pixel format of requested block. This could be a vendor specific format.
     *                      specific format.
     * \param usage  the memory usage info for the requested block. Returned blocks will be
     * \param usage           the memory usage info for the requested allocation. \note that the
     *               optimized for this usage, but may be used with any usage. One exception:
     *                      returned allocation may be later used/mapped with different usage.
     *               protected blocks/buffers can only be used in a protected scenario.
     *                      The allocator should layout the buffer to be optimized for this usage,
     * \param block  pointer to where the obtained block shall be stored on success. nullptr
     *                      but must support any usage. One exception: protected buffers can
     *                      only be used in a protected scenario.
     * \param block      pointer to where the allocation shall be stored on success. nullptr
     *               will be stored here on failure
     *               will be stored here on failure
     *
     *
     * \retval C2_OK            the allocation was successful
     * \retval C2_OK        the operation was successful
     * \retval C2_NO_MEMORY     not enough memory to complete the allocation
     * \retval C2_NO_MEMORY not enough memory to complete any required allocation
     * \retval C2_TIMED_OUT     the allocation timed out
     * \retval C2_TIMED_OUT the operation timed out
     * \retval C2_REFUSED       no permission to complete the allocation
     * \retval C2_REFUSED   no permission to complete any required allocation
     * \retval C2_BAD_VALUE     width, height, format or usage are not supported (invalid) (caller error)
     * \retval C2_BAD_VALUE width, height, format or usage are not supported (invalid) (caller
     * \retval C2_OMITTED       this allocator does not support 2D allocations
     *                      error)
     * \retval C2_CORRUPTED     some unknown, unrecoverable error occured during allocation (unexpected)
     * \retval C2_OMITTED   this pool does not support 2D blocks
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during operation (unexpected)
     */
     */
    virtual C2Status allocateGraphicBlock(
    virtual C2Status fetchGraphicBlock(
            uint32_t width __unused, uint32_t height __unused, uint32_t format __unused,
            uint32_t width __unused, uint32_t height __unused, uint32_t format __unused,
            C2MemoryUsage usage __unused,
            C2MemoryUsage usage __unused,
            std::shared_ptr<C2GraphicBlock> *block /* nonnull */) {
            std::shared_ptr<C2GraphicBlock> *block /* nonnull */) {
@@ -1745,9 +1832,9 @@ public:
    }
    }


protected:
protected:
    C2BlockAllocator() = default;
    C2BlockPool() = default;


    virtual ~C2BlockAllocator() = default;
    virtual ~C2BlockPool() = default;
};
};


/// @}
/// @}
+27 −6
Original line number Original line Diff line number Diff line
@@ -542,11 +542,9 @@ struct C2ComponentInfo {


class C2AllocatorStore {
class C2AllocatorStore {
public:
public:
    // TBD
    typedef C2Allocator::id_t id_t;

    typedef uint32_t ID;


    enum ID_ : uint32_t {
    enum : C2Allocator::id_t {
        DEFAULT_LINEAR,     ///< basic linear allocator type
        DEFAULT_LINEAR,     ///< basic linear allocator type
        DEFAULT_GRAPHIC,    ///< basic graphic allocator type
        DEFAULT_GRAPHIC,    ///< basic graphic allocator type
        PLATFORM_START = 0x10,
        PLATFORM_START = 0x10,
@@ -554,7 +552,30 @@ public:
    };
    };


    /**
    /**
     * Creates an allocator.
     * Returns the unique name of this allocator store.
     *
     * This method MUST be "non-blocking" and return within 1ms.
     *
     * \return the name of this allocator store.
     * \retval an empty string if there was not enough memory to allocate the actual name.
     */
    virtual C2String getName() const = 0;

    /**
     * Returns the set of allocators supported by this allocator store.
     *
     * This method SHALL return within 1ms.
     *
     * \retval vector of allocator information (as shared pointers)
     * \retval an empty vector if there was not enough memory to allocate the whole vector.
     */
    virtual std::vector<std::shared_ptr<const C2Allocator::Info>> listAllocators() const = 0;

    /**
     * Retrieves/creates a shared allocator object.
     *
     * The allocator is created on first use, and the same allocator is returned on subsequent
     * concurrent uses in the same process. The allocator is freed when it is no longer referenced.
     *
     *
     * \param id      the ID of the allocator to create. This is defined by the store, but
     * \param id      the ID of the allocator to create. This is defined by the store, but
     *                the ID of the default linear and graphic allocators is formalized.
     *                the ID of the default linear and graphic allocators is formalized.
@@ -568,7 +589,7 @@ public:
     * \retval C2_NOT_FOUND no such allocator
     * \retval C2_NOT_FOUND no such allocator
     * \retval C2_NO_MEMORY not enough memory to create the allocator
     * \retval C2_NO_MEMORY not enough memory to create the allocator
     */
     */
    virtual C2Status createAllocator(ID id, std::shared_ptr<C2Allocator>* const allocator) = 0;
    virtual C2Status getAllocator(id_t id, std::shared_ptr<C2Allocator>* const allocator) = 0;


    virtual ~C2AllocatorStore() = default;
    virtual ~C2AllocatorStore() = default;
};
};
+2 −2
Original line number Original line Diff line number Diff line
@@ -118,8 +118,8 @@ struct C2Worklet {
    std::list<std::unique_ptr<C2Param>> tunings; //< tunings to be applied before processing this
    std::list<std::unique_ptr<C2Param>> tunings; //< tunings to be applied before processing this
                                                 // worklet
                                                 // worklet
    std::list<C2Param::Type> requestedInfos;
    std::list<C2Param::Type> requestedInfos;
    std::vector<std::shared_ptr<C2BlockAllocator>> allocators; //< This vector shall be the same size as
    std::vector<std::shared_ptr<C2BlockPool>> allocators; //< This vector shall be the same size as
                                                          //< output.buffers.
                                                          //< output.buffers. \deprecated


    // OUT
    // OUT
    C2BufferPack output;
    C2BufferPack output;
+22 −22
Original line number Original line Diff line number Diff line
@@ -38,13 +38,13 @@ public:
    ~C2BufferTest() = default;
    ~C2BufferTest() = default;


    void allocateLinear(size_t capacity) {
    void allocateLinear(size_t capacity) {
        C2Status err = mLinearAllocator->allocateLinearBuffer(
        C2Status err = mLinearAllocator->newLinearAllocation(
                capacity,
                capacity,
                { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
                { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
                &mLinearAllocation);
                &mLinearAllocation);
        if (err != C2_OK) {
        if (err != C2_OK) {
            mLinearAllocation.reset();
            mLinearAllocation.reset();
            FAIL() << "C2Allocator::allocateLinearBuffer() failed: " << err;
            FAIL() << "C2Allocator::newLinearAllocation() failed: " << err;
        }
        }
    }
    }


@@ -77,12 +77,12 @@ public:
        mAddr = nullptr;
        mAddr = nullptr;
    }
    }


    std::shared_ptr<C2BlockAllocator> makeLinearBlockAllocator() {
    std::shared_ptr<C2BlockPool> makeLinearBlockPool() {
        return std::make_shared<C2DefaultBlockAllocator>(mLinearAllocator);
        return std::make_shared<C2BasicLinearBlockPool>(mLinearAllocator);
    }
    }


    void allocateGraphic(uint32_t width, uint32_t height) {
    void allocateGraphic(uint32_t width, uint32_t height) {
        C2Status err = mGraphicAllocator->allocateGraphicBuffer(
        C2Status err = mGraphicAllocator->newGraphicAllocation(
                width,
                width,
                height,
                height,
                HAL_PIXEL_FORMAT_YCBCR_420_888,
                HAL_PIXEL_FORMAT_YCBCR_420_888,
@@ -90,7 +90,7 @@ public:
                &mGraphicAllocation);
                &mGraphicAllocation);
        if (err != C2_OK) {
        if (err != C2_OK) {
            mGraphicAllocation.reset();
            mGraphicAllocation.reset();
            FAIL() << "C2Allocator::allocateLinearBuffer() failed: " << err;
            FAIL() << "C2Allocator::newGraphicAllocation() failed: " << err;
        }
        }
    }
    }


@@ -118,8 +118,8 @@ public:
        ASSERT_EQ(C2_OK, mGraphicAllocation->unmap(nullptr));
        ASSERT_EQ(C2_OK, mGraphicAllocation->unmap(nullptr));
    }
    }


    std::shared_ptr<C2BlockAllocator> makeGraphicBlockAllocator() {
    std::shared_ptr<C2BlockPool> makeGraphicBlockPool() {
        return std::make_shared<C2DefaultGraphicBlockAllocator>(mGraphicAllocator);
        return std::make_shared<C2BasicGraphicBlockPool>(mGraphicAllocator);
    }
    }


private:
private:
@@ -155,13 +155,13 @@ TEST_F(C2BufferTest, LinearAllocationTest) {
    }
    }
}
}


TEST_F(C2BufferTest, BlockAllocatorTest) {
TEST_F(C2BufferTest, BlockPoolTest) {
    constexpr size_t kCapacity = 1024u * 1024u;
    constexpr size_t kCapacity = 1024u * 1024u;


    std::shared_ptr<C2BlockAllocator> blockAllocator(makeLinearBlockAllocator());
    std::shared_ptr<C2BlockPool> blockPool(makeLinearBlockPool());


    std::shared_ptr<C2LinearBlock> block;
    std::shared_ptr<C2LinearBlock> block;
    ASSERT_EQ(C2_OK, blockAllocator->allocateLinearBlock(
    ASSERT_EQ(C2_OK, blockPool->fetchLinearBlock(
            kCapacity,
            kCapacity,
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            &block));
            &block));
@@ -285,14 +285,14 @@ TEST_F(C2BufferTest, GraphicAllocationTest) {
    ASSERT_TRUE(verifyPlane({ 0, 0, kWidth / 4, kHeight }, vInfo, v, 0));
    ASSERT_TRUE(verifyPlane({ 0, 0, kWidth / 4, kHeight }, vInfo, v, 0));
}
}


TEST_F(C2BufferTest, GraphicBlockAllocatorTest) {
TEST_F(C2BufferTest, GraphicBlockPoolTest) {
    constexpr uint32_t kWidth = 320;
    constexpr uint32_t kWidth = 320;
    constexpr uint32_t kHeight = 240;
    constexpr uint32_t kHeight = 240;


    std::shared_ptr<C2BlockAllocator> blockAllocator(makeGraphicBlockAllocator());
    std::shared_ptr<C2BlockPool> blockPool(makeGraphicBlockPool());


    std::shared_ptr<C2GraphicBlock> block;
    std::shared_ptr<C2GraphicBlock> block;
    ASSERT_EQ(C2_OK, blockAllocator->allocateGraphicBlock(
    ASSERT_EQ(C2_OK, blockPool->fetchGraphicBlock(
            kWidth,
            kWidth,
            kHeight,
            kHeight,
            HAL_PIXEL_FORMAT_YCBCR_420_888,
            HAL_PIXEL_FORMAT_YCBCR_420_888,
@@ -370,8 +370,8 @@ public:
};
};


TEST_F(C2BufferTest, BufferDataTest) {
TEST_F(C2BufferTest, BufferDataTest) {
    std::shared_ptr<C2BlockAllocator> linearBlockAllocator(makeLinearBlockAllocator());
    std::shared_ptr<C2BlockPool> linearBlockPool(makeLinearBlockPool());
    std::shared_ptr<C2BlockAllocator> graphicBlockAllocator(makeGraphicBlockAllocator());
    std::shared_ptr<C2BlockPool> graphicBlockPool(makeGraphicBlockPool());


    constexpr uint32_t kWidth1 = 320;
    constexpr uint32_t kWidth1 = 320;
    constexpr uint32_t kHeight1 = 240;
    constexpr uint32_t kHeight1 = 240;
@@ -384,23 +384,23 @@ TEST_F(C2BufferTest, BufferDataTest) {


    std::shared_ptr<C2LinearBlock> linearBlock1;
    std::shared_ptr<C2LinearBlock> linearBlock1;
    std::shared_ptr<C2LinearBlock> linearBlock2;
    std::shared_ptr<C2LinearBlock> linearBlock2;
    ASSERT_EQ(C2_OK, linearBlockAllocator->allocateLinearBlock(
    ASSERT_EQ(C2_OK, linearBlockPool->fetchLinearBlock(
            kCapacity1,
            kCapacity1,
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            &linearBlock1));
            &linearBlock1));
    ASSERT_EQ(C2_OK, linearBlockAllocator->allocateLinearBlock(
    ASSERT_EQ(C2_OK, linearBlockPool->fetchLinearBlock(
            kCapacity2,
            kCapacity2,
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            &linearBlock2));
            &linearBlock2));
    std::shared_ptr<C2GraphicBlock> graphicBlock1;
    std::shared_ptr<C2GraphicBlock> graphicBlock1;
    std::shared_ptr<C2GraphicBlock> graphicBlock2;
    std::shared_ptr<C2GraphicBlock> graphicBlock2;
    ASSERT_EQ(C2_OK, graphicBlockAllocator->allocateGraphicBlock(
    ASSERT_EQ(C2_OK, graphicBlockPool->fetchGraphicBlock(
            kWidth1,
            kWidth1,
            kHeight1,
            kHeight1,
            HAL_PIXEL_FORMAT_YCBCR_420_888,
            HAL_PIXEL_FORMAT_YCBCR_420_888,
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            &graphicBlock1));
            &graphicBlock1));
    ASSERT_EQ(C2_OK, graphicBlockAllocator->allocateGraphicBlock(
    ASSERT_EQ(C2_OK, graphicBlockPool->fetchGraphicBlock(
            kWidth2,
            kWidth2,
            kHeight2,
            kHeight2,
            HAL_PIXEL_FORMAT_YCBCR_420_888,
            HAL_PIXEL_FORMAT_YCBCR_420_888,
@@ -454,11 +454,11 @@ typedef C2GlobalParam<C2Info, C2Int32Value, kParamIndexNumber1> C2Number1Info;
typedef C2GlobalParam<C2Info, C2Int32Value, kParamIndexNumber2> C2Number2Info;
typedef C2GlobalParam<C2Info, C2Int32Value, kParamIndexNumber2> C2Number2Info;


TEST_F(C2BufferTest, BufferTest) {
TEST_F(C2BufferTest, BufferTest) {
    std::shared_ptr<C2BlockAllocator> alloc(makeLinearBlockAllocator());
    std::shared_ptr<C2BlockPool> alloc(makeLinearBlockPool());
    constexpr size_t kCapacity = 1024u;
    constexpr size_t kCapacity = 1024u;
    std::shared_ptr<C2LinearBlock> block;
    std::shared_ptr<C2LinearBlock> block;


    ASSERT_EQ(C2_OK, alloc->allocateLinearBlock(
    ASSERT_EQ(C2_OK, alloc->fetchLinearBlock(
            kCapacity,
            kCapacity,
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            { C2MemoryUsage::kSoftwareRead, C2MemoryUsage::kSoftwareWrite },
            &block));
            &block));
+28 −8

File changed.

Preview size limit exceeded, changes collapsed.

Loading