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

Commit d0bbe896 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I7c3cc40f,I6447a920 am: 01310532

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1432313

Change-Id: Ic82f4aaa4dc935edd717ff7525eaf03f14393eff
parents c923d394 01310532
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -734,6 +734,22 @@ public:
    }

    virtual ~C2Allocator() = default;

    /**
     * Returns a true if the handle looks valid for this allocator.
     *
     * It does not actually validate that the handle represents a valid allocation (by this
     * allocator), only that the handle could have been returned by this allocator. As such,
     * multiple allocators may return true for looksValid for the same handle.
     *
     * This method MUST be "non-blocking", MUST not access kernel and/or device drivers, and
     * return within 1us.
     *
     * \param handle      the handle for an existing allocation (possibly from another
     *                    allocator)
     */
    virtual bool checkHandle(const C2Handle *const handle) const = 0;

protected:
    C2Allocator() = default;
};
+2 −2
Original line number Diff line number Diff line
@@ -175,12 +175,12 @@ std::shared_ptr<const C2Allocator::Traits> C2AllocatorBlob::getTraits() const {
}

// static
bool C2AllocatorBlob::isValid(const C2Handle* const o) {
bool C2AllocatorBlob::CheckHandle(const C2Handle* const o) {
    size_t capacity;
    // Distinguish C2Handle purely allocated by C2AllocatorGralloc, or one allocated through
    // C2AllocatorBlob, by checking the handle's height is 1, and its format is
    // PixelFormat::BLOB by GetCapacityFromHandle().
    return C2AllocatorGralloc::isValid(o) && GetCapacityFromHandle(o, &capacity) == C2_OK;
    return C2AllocatorGralloc::CheckHandle(o) && GetCapacityFromHandle(o, &capacity) == C2_OK;
}

}  // namespace android
+14 −13
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ private:
    const static uint32_t MAGIC = '\xc2gr\x00';

    static
    const ExtraData* getExtraData(const C2Handle *const handle) {
    const ExtraData* GetExtraData(const C2Handle *const handle) {
        if (handle == nullptr
                || native_handle_is_invalid(handle)
                || handle->numInts < NUM_INTS) {
@@ -114,23 +114,23 @@ private:
    }

    static
    ExtraData *getExtraData(C2Handle *const handle) {
        return const_cast<ExtraData *>(getExtraData(const_cast<const C2Handle *const>(handle)));
    ExtraData *GetExtraData(C2Handle *const handle) {
        return const_cast<ExtraData *>(GetExtraData(const_cast<const C2Handle *const>(handle)));
    }

public:
    void getIgbpData(uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot) const {
        const ExtraData *ed = getExtraData(this);
        const ExtraData *ed = GetExtraData(this);
        *generation = ed->generation;
        *igbp_id = unsigned(ed->igbp_id_lo) | uint64_t(unsigned(ed->igbp_id_hi)) << 32;
        *igbp_slot = ed->igbp_slot;
    }

    static bool isValid(const C2Handle *const o) {
    static bool IsValid(const C2Handle *const o) {
        if (o == nullptr) { // null handle is always valid
            return true;
        }
        const ExtraData *xd = getExtraData(o);
        const ExtraData *xd = GetExtraData(o);
        // we cannot validate width/height/format/usage without accessing gralloc driver
        return xd != nullptr && xd->magic == MAGIC;
    }
@@ -152,7 +152,7 @@ public:
        native_handle_t *res = native_handle_create(handle->numFds, handle->numInts + NUM_INTS);
        if (res != nullptr) {
            memcpy(&res->data, &handle->data, sizeof(int) * (handle->numFds + handle->numInts));
            *getExtraData(res) = xd;
            *GetExtraData(res) = xd;
        }
        return reinterpret_cast<C2HandleGralloc *>(res);
    }
@@ -180,10 +180,10 @@ public:
    static bool MigrateNativeHandle(
            native_handle_t *handle,
            uint32_t generation, uint64_t igbp_id, uint32_t igbp_slot) {
        if (handle == nullptr || !isValid(handle)) {
        if (handle == nullptr || !IsValid(handle)) {
            return false;
        }
        ExtraData *ed = getExtraData(handle);
        ExtraData *ed = GetExtraData(handle);
        if (!ed) return false;
        ed->generation = generation;
        ed->igbp_id_lo = uint32_t(igbp_id & 0xFFFFFFFF);
@@ -195,7 +195,7 @@ public:

    static native_handle_t* UnwrapNativeHandle(
            const C2Handle *const handle) {
        const ExtraData *xd = getExtraData(handle);
        const ExtraData *xd = GetExtraData(handle);
        if (xd == nullptr || xd->magic != MAGIC) {
            return nullptr;
        }
@@ -211,7 +211,7 @@ public:
            uint32_t *width, uint32_t *height, uint32_t *format,
            uint64_t *usage, uint32_t *stride,
            uint32_t *generation, uint64_t *igbp_id, uint32_t *igbp_slot) {
        const ExtraData *xd = getExtraData(handle);
        const ExtraData *xd = GetExtraData(handle);
        if (xd == nullptr) {
            return nullptr;
        }
@@ -784,8 +784,9 @@ c2_status_t C2AllocatorGralloc::status() const {
    return mImpl->status();
}

bool C2AllocatorGralloc::isValid(const C2Handle* const o) {
    return C2HandleGralloc::isValid(o);
// static
bool C2AllocatorGralloc::CheckHandle(const C2Handle* const o) {
    return C2HandleGralloc::IsValid(o);
}

} // namespace android
+4 −5
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ const C2Handle C2HandleIon::cHeader = {
};

// static
bool C2HandleIon::isValid(const C2Handle * const o) {
bool C2HandleIon::IsValid(const C2Handle * const o) {
    if (!o || memcmp(o, &cHeader, sizeof(cHeader))) {
        return false;
    }
@@ -579,7 +579,7 @@ c2_status_t C2AllocatorIon::priorLinearAllocation(
        return mInit;
    }

    if (!C2HandleIon::isValid(handle)) {
    if (!C2HandleIon::IsValid(handle)) {
        return C2_BAD_VALUE;
    }

@@ -596,9 +596,8 @@ c2_status_t C2AllocatorIon::priorLinearAllocation(
    return ret;
}

bool C2AllocatorIon::isValid(const C2Handle* const o) {
    return C2HandleIon::isValid(o);
bool C2AllocatorIon::CheckHandle(const C2Handle* const o) {
    return C2HandleIon::IsValid(o);
}

} // namespace android
+13 −30
Original line number Diff line number Diff line
@@ -397,26 +397,18 @@ 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;
    }();

    if (sAllocator == nullptr)
        return nullptr;

    bool isValidHandle = false;
    if (sAllocator->getId() == android::C2PlatformAllocatorStore::BLOB) {
        isValidHandle = C2AllocatorBlob::isValid(handle);
    } else {
        isValidHandle = C2AllocatorIon::isValid(handle);
    }
    bool isValidHandle = sAllocator->checkHandle(handle);

    std::shared_ptr<C2LinearAllocation> alloc;
    if (isValidHandle) {
@@ -432,26 +424,18 @@ 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;
    }();

    if (sAllocator == nullptr)
        return nullptr;

    bool isValidHandle = false;
    if (sAllocator->getId() == android::C2PlatformAllocatorStore::BLOB) {
        isValidHandle = C2AllocatorBlob::isValid(cHandle);
    } else {
        isValidHandle = C2AllocatorIon::isValid(cHandle);
    }
    bool isValidHandle = sAllocator->checkHandle(cHandle);

    std::shared_ptr<C2LinearAllocation> alloc;
    if (isValidHandle) {
@@ -1149,7 +1133,7 @@ std::shared_ptr<C2GraphicBlock> _C2BlockFactory::CreateGraphicBlock(
    static std::unique_ptr<C2AllocatorGralloc> sAllocator = std::make_unique<C2AllocatorGralloc>(0);

    std::shared_ptr<C2GraphicAllocation> alloc;
    if (C2AllocatorGralloc::isValid(cHandle)) {
    if (sAllocator->isValid(cHandle)) {
        c2_status_t err = sAllocator->priorGraphicAllocation(cHandle, &alloc);
        const std::shared_ptr<C2PooledBlockPoolData> poolData =
                std::make_shared<C2PooledBlockPoolData>(data);
@@ -1361,4 +1345,3 @@ std::shared_ptr<C2Buffer> C2Buffer::CreateLinearBuffer(const C2ConstLinearBlock
std::shared_ptr<C2Buffer> C2Buffer::CreateGraphicBuffer(const C2ConstGraphicBlock &block) {
    return std::shared_ptr<C2Buffer>(new C2Buffer({ block }));
}
Loading