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

Commit f2d6711d authored by John Stultz's avatar John Stultz Committed by Lajos Molnar
Browse files

codec2: vndk/C2Buffer: Rework CreateLinearBlock to use fetchAllocator()



The current code in _C2BlockFactory::CreateLinearBlock()
duplicates logic in C2Store code and creates extra complexity to
extend it for the future DMABUF Heaps case.

So make use of fetchAllocator() instead.

Close review would be appreciated!

Signed-off-by: default avatarJohn Stultz <john.stultz@linaro.org>
Change-Id: I7c3cc40fe82bd0b7646ff62c3456b158682e04e0
parent 653ddd1c
Loading
Loading
Loading
Loading
+10 −16
Original line number Diff line number Diff line
@@ -396,14 +396,11 @@ std::shared_ptr<_C2BlockPoolData> _C2BlockFactory::GetLinearBlockPoolData(
std::shared_ptr<C2LinearBlock> _C2BlockFactory::CreateLinearBlock(
        const C2Handle *handle) {
    // TODO: get proper allocator? and mutex?
    static std::unique_ptr<C2Allocator> sAllocator = []{
        std::unique_ptr<C2Allocator> allocator;
        if (android::GetPreferredLinearAllocatorId(android::GetCodec2PoolMask()) ==
                android::C2PlatformAllocatorStore::BLOB) {
            allocator = std::make_unique<C2AllocatorBlob>(android::C2PlatformAllocatorStore::BLOB);
        } else {
            allocator = std::make_unique<C2AllocatorIon>(android::C2PlatformAllocatorStore::ION);
        }
    static std::shared_ptr<C2Allocator> sAllocator = []{
        std::shared_ptr<C2Allocator> allocator;
        std::shared_ptr<C2AllocatorStore> allocatorStore = android::GetCodec2PlatformAllocatorStore();
        allocatorStore->fetchAllocator(C2AllocatorStore::DEFAULT_LINEAR, &allocator);

        return allocator;
    }();

@@ -426,14 +423,11 @@ std::shared_ptr<C2LinearBlock> _C2BlockFactory::CreateLinearBlock(
std::shared_ptr<C2LinearBlock> _C2BlockFactory::CreateLinearBlock(
        const C2Handle *cHandle, const std::shared_ptr<BufferPoolData> &data) {
    // TODO: get proper allocator? and mutex?
    static std::unique_ptr<C2Allocator> sAllocator = []{
        std::unique_ptr<C2Allocator> allocator;
        if (android::GetPreferredLinearAllocatorId(android::GetCodec2PoolMask()) ==
                android::C2PlatformAllocatorStore::BLOB) {
            allocator = std::make_unique<C2AllocatorBlob>(android::C2PlatformAllocatorStore::BLOB);
        } else {
            allocator = std::make_unique<C2AllocatorIon>(android::C2PlatformAllocatorStore::ION);
        }
    static std::shared_ptr<C2Allocator> sAllocator = []{
        std::shared_ptr<C2Allocator> allocator;
        std::shared_ptr<C2AllocatorStore> allocatorStore = android::GetCodec2PlatformAllocatorStore();
        allocatorStore->fetchAllocator(C2AllocatorStore::DEFAULT_LINEAR, &allocator);

        return allocator;
    }();