codec2: Add C2Alloctor::checkHandle()
This patch adds a virtual checkHandle() to simplify some ugly
logic in the vndk/C2Buffer.cpp to determine the subclass and
call that class' isValid() function.
Signed-off-by: John Stultz <john.stultz@linaro.org>
Change-Id: I6447a920f6d889742369f773d8be56ca8a973cae
diff --git a/media/codec2/vndk/C2Buffer.cpp b/media/codec2/vndk/C2Buffer.cpp
index 0b08f31..5ec9925 100644
--- a/media/codec2/vndk/C2Buffer.cpp
+++ b/media/codec2/vndk/C2Buffer.cpp
@@ -410,12 +410,7 @@
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) {
@@ -445,12 +440,7 @@
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) {
@@ -1148,7 +1138,7 @@
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);
@@ -1330,4 +1320,3 @@
std::shared_ptr<C2Buffer> C2Buffer::CreateGraphicBuffer(const C2ConstGraphicBlock &block) {
return std::shared_ptr<C2Buffer>(new C2Buffer({ block }));
}
-