mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Merge "Support IMapper@3.0 in OMX VTS" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
56e9dd901e
@@ -29,6 +29,21 @@ cc_library_static {
|
||||
"android.hidl.memory@1.0",
|
||||
"android.hardware.media.omx@1.0",
|
||||
"android.hardware.graphics.allocator@2.0",
|
||||
"android.hardware.graphics.allocator@3.0",
|
||||
"android.hardware.graphics.common@1.0",
|
||||
"android.hardware.graphics.common@1.1",
|
||||
"android.hardware.graphics.common@1.2",
|
||||
"android.hardware.graphics.mapper@2.0",
|
||||
"android.hardware.graphics.mapper@3.0",
|
||||
],
|
||||
export_static_lib_headers: [
|
||||
"android.hardware.graphics.allocator@2.0",
|
||||
"android.hardware.graphics.allocator@3.0",
|
||||
"android.hardware.graphics.common@1.0",
|
||||
"android.hardware.graphics.common@1.1",
|
||||
"android.hardware.graphics.common@1.2",
|
||||
"android.hardware.graphics.mapper@2.0",
|
||||
"android.hardware.graphics.mapper@3.0",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -40,7 +55,12 @@ cc_defaults {
|
||||
static_libs: [
|
||||
"VtsHalMediaOmxV1_0CommonUtil",
|
||||
"android.hardware.graphics.allocator@2.0",
|
||||
"android.hardware.graphics.allocator@3.0",
|
||||
"android.hardware.graphics.common@1.0",
|
||||
"android.hardware.graphics.common@1.1",
|
||||
"android.hardware.graphics.common@1.2",
|
||||
"android.hardware.graphics.mapper@2.0",
|
||||
"android.hardware.graphics.mapper@3.0",
|
||||
"android.hardware.graphics.bufferqueue@1.0",
|
||||
"android.hardware.graphics.common@1.0",
|
||||
"android.hardware.media.omx@1.0",
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
|
||||
#include <android/hardware/graphics/allocator/3.0/IAllocator.h>
|
||||
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
|
||||
#include <android/hardware/graphics/mapper/2.0/types.h>
|
||||
#include <android/hardware/graphics/mapper/3.0/IMapper.h>
|
||||
#include <android/hardware/graphics/mapper/3.0/types.h>
|
||||
#include <android/hardware/media/omx/1.0/IOmx.h>
|
||||
#include <android/hardware/media/omx/1.0/IOmxNode.h>
|
||||
#include <android/hardware/media/omx/1.0/IOmxObserver.h>
|
||||
@@ -31,7 +34,9 @@
|
||||
#include <android/hidl/allocator/1.0/IAllocator.h>
|
||||
#include <android/hidl/memory/1.0/IMapper.h>
|
||||
#include <android/hidl/memory/1.0/IMemory.h>
|
||||
#include <cutils/atomic.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <variant>
|
||||
|
||||
using ::android::hardware::graphics::common::V1_0::BufferUsage;
|
||||
using ::android::hardware::graphics::common::V1_0::PixelFormat;
|
||||
@@ -195,67 +200,104 @@ void allocateGraphicBuffers(sp<IOmxNode> omxNode, OMX_U32 portIndex,
|
||||
BufferInfo* buffer, uint32_t nFrameWidth,
|
||||
uint32_t nFrameHeight, int32_t* nStride,
|
||||
int format) {
|
||||
android::hardware::media::omx::V1_0::Status status;
|
||||
sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator =
|
||||
android::hardware::graphics::allocator::V2_0::IAllocator::getService();
|
||||
ASSERT_NE(nullptr, allocator.get());
|
||||
struct AllocatorV2 : public GrallocV2 {
|
||||
sp<IAllocator> mAllocator;
|
||||
sp<IMapper> mMapper;
|
||||
AllocatorV2(sp<IAllocator>&& allocator, sp<IMapper>&& mapper)
|
||||
: mAllocator{std::move(allocator)}, mMapper{std::move(mapper)} {}
|
||||
AllocatorV2() = default;
|
||||
};
|
||||
struct AllocatorV3 : public GrallocV3 {
|
||||
sp<IAllocator> mAllocator;
|
||||
sp<IMapper> mMapper;
|
||||
AllocatorV3(sp<IAllocator>&& allocator, sp<IMapper>&& mapper)
|
||||
: mAllocator{std::move(allocator)}, mMapper{std::move(mapper)} {}
|
||||
AllocatorV3() = default;
|
||||
};
|
||||
std::variant<AllocatorV2, AllocatorV3> grallocVar;
|
||||
|
||||
sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::getService();
|
||||
ASSERT_NE(mapper.get(), nullptr);
|
||||
sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2{};
|
||||
sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3{};
|
||||
sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator2{};
|
||||
sp<android::hardware::graphics::allocator::V3_0::IAllocator> allocator3 =
|
||||
android::hardware::graphics::allocator::V3_0::IAllocator::getService();
|
||||
if (allocator3) {
|
||||
mapper3 =
|
||||
android::hardware::graphics::mapper::V3_0::IMapper::getService();
|
||||
ASSERT_NE(nullptr, mapper3.get());
|
||||
grallocVar.emplace<AllocatorV3>(std::move(allocator3), std::move(mapper3));
|
||||
} else {
|
||||
allocator2 =
|
||||
android::hardware::graphics::allocator::V2_0::IAllocator::getService();
|
||||
ASSERT_NE(nullptr, allocator2.get());
|
||||
mapper2 =
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::getService();
|
||||
ASSERT_NE(nullptr, allocator2.get());
|
||||
grallocVar.emplace<AllocatorV2>(std::move(allocator2), std::move(mapper2));
|
||||
}
|
||||
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo
|
||||
descriptorInfo;
|
||||
uint32_t usage;
|
||||
|
||||
descriptorInfo.width = nFrameWidth;
|
||||
descriptorInfo.height = nFrameHeight;
|
||||
descriptorInfo.layerCount = 1;
|
||||
descriptorInfo.format = static_cast<PixelFormat>(format);
|
||||
descriptorInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN);
|
||||
omxNode->getGraphicBufferUsage(
|
||||
android::hardware::media::omx::V1_0::Status status{};
|
||||
uint64_t usage{};
|
||||
ASSERT_TRUE(omxNode->getGraphicBufferUsage(
|
||||
portIndex,
|
||||
[&status, &usage](android::hardware::media::omx::V1_0::Status _s,
|
||||
uint32_t _n1) {
|
||||
status = _s;
|
||||
usage = _n1;
|
||||
});
|
||||
if (status == android::hardware::media::omx::V1_0::Status::OK) {
|
||||
descriptorInfo.usage |= usage;
|
||||
}
|
||||
}).isOk());
|
||||
ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
|
||||
|
||||
::android::hardware::hidl_vec<uint32_t> descriptor;
|
||||
android::hardware::graphics::mapper::V2_0::Error error;
|
||||
mapper->createDescriptor(
|
||||
descriptorInfo, [&error, &descriptor](
|
||||
android::hardware::graphics::mapper::V2_0::Error _s,
|
||||
::android::hardware::hidl_vec<uint32_t> _n1) {
|
||||
error = _s;
|
||||
descriptor = _n1;
|
||||
});
|
||||
ASSERT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
|
||||
static std::atomic_int32_t bufferIdCounter{0};
|
||||
|
||||
static volatile int32_t nextId = 0;
|
||||
uint64_t id = static_cast<uint64_t>(getpid()) << 32;
|
||||
allocator->allocate(
|
||||
descriptor, 1,
|
||||
[&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1,
|
||||
const ::android::hardware::hidl_vec<
|
||||
::android::hardware::hidl_handle>& _n2) {
|
||||
ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE,
|
||||
_s);
|
||||
*nStride = _n1;
|
||||
buffer->omxBuffer.nativeHandle = _n2[0];
|
||||
buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth;
|
||||
buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight;
|
||||
buffer->omxBuffer.attr.anwBuffer.stride = _n1;
|
||||
buffer->omxBuffer.attr.anwBuffer.format = descriptorInfo.format;
|
||||
buffer->omxBuffer.attr.anwBuffer.usage = descriptorInfo.usage;
|
||||
buffer->omxBuffer.attr.anwBuffer.layerCount =
|
||||
descriptorInfo.layerCount;
|
||||
buffer->omxBuffer.attr.anwBuffer.id =
|
||||
id | static_cast<uint32_t>(android_atomic_inc(&nextId));
|
||||
});
|
||||
std::visit([buffer, nFrameWidth, nFrameHeight, format, usage, nStride](auto&& gralloc) {
|
||||
using Gralloc = std::remove_reference_t<decltype(gralloc)>;
|
||||
using Descriptor = typename Gralloc::Descriptor;
|
||||
using DescriptorInfo = typename Gralloc::DescriptorInfo;
|
||||
using Error = typename Gralloc::Error;
|
||||
using Format = typename Gralloc::Format;
|
||||
using Usage = typename Gralloc::Usage;
|
||||
|
||||
Error error{};
|
||||
Descriptor descriptor{};
|
||||
|
||||
DescriptorInfo descriptorInfo{};
|
||||
descriptorInfo.width = nFrameWidth;
|
||||
descriptorInfo.height = nFrameHeight;
|
||||
descriptorInfo.layerCount = 1;
|
||||
descriptorInfo.format = static_cast<Format>(format);
|
||||
descriptorInfo.usage = usage | Usage(BufferUsage::CPU_READ_OFTEN);
|
||||
|
||||
gralloc.mMapper->createDescriptor(descriptorInfo,
|
||||
[&error, &descriptor](
|
||||
Error _s,
|
||||
const Descriptor& _n1) {
|
||||
error = _s;
|
||||
descriptor = _n1;
|
||||
});
|
||||
ASSERT_EQ(error, Error::NONE);
|
||||
|
||||
gralloc.mAllocator->allocate(
|
||||
descriptor, 1,
|
||||
[&](Error _s, uint32_t _n1,
|
||||
const ::android::hardware::hidl_vec<
|
||||
::android::hardware::hidl_handle>& _n2) {
|
||||
ASSERT_EQ(Error::NONE, _s);
|
||||
*nStride = _n1;
|
||||
buffer->omxBuffer.nativeHandle = _n2[0];
|
||||
buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth;
|
||||
buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight;
|
||||
buffer->omxBuffer.attr.anwBuffer.stride = _n1;
|
||||
buffer->omxBuffer.attr.anwBuffer.format =
|
||||
static_cast<PixelFormat>(descriptorInfo.format);
|
||||
buffer->omxBuffer.attr.anwBuffer.usage =
|
||||
static_cast<uint32_t>(descriptorInfo.usage);
|
||||
buffer->omxBuffer.attr.anwBuffer.layerCount =
|
||||
descriptorInfo.layerCount;
|
||||
buffer->omxBuffer.attr.anwBuffer.id =
|
||||
(static_cast<uint64_t>(getpid()) << 32) |
|
||||
bufferIdCounter.fetch_add(1, std::memory_order_relaxed);
|
||||
});
|
||||
}, grallocVar);
|
||||
}
|
||||
|
||||
// allocate buffers needed on a component port
|
||||
|
||||
@@ -22,6 +22,16 @@
|
||||
#endif
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
|
||||
#include <android/hardware/graphics/allocator/3.0/IAllocator.h>
|
||||
#include <android/hardware/graphics/common/1.0/types.h>
|
||||
#include <android/hardware/graphics/common/1.1/types.h>
|
||||
#include <android/hardware/graphics/common/1.2/types.h>
|
||||
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
|
||||
#include <android/hardware/graphics/mapper/2.0/types.h>
|
||||
#include <android/hardware/graphics/mapper/3.0/IMapper.h>
|
||||
#include <android/hardware/graphics/mapper/3.0/types.h>
|
||||
#include <media/stagefright/foundation/ALooper.h>
|
||||
#include <utils/Condition.h>
|
||||
#include <utils/List.h>
|
||||
@@ -288,6 +298,36 @@ Return<android::hardware::media::omx::V1_0::Status> setPortConfig(
|
||||
/*
|
||||
* common functions declarations
|
||||
*/
|
||||
struct GrallocV2 {
|
||||
using Format = android::hardware::graphics::common::V1_0::PixelFormat;
|
||||
using Usage = android::hardware::hidl_bitfield<
|
||||
android::hardware::graphics::common::V1_0::BufferUsage>;
|
||||
|
||||
using IAllocator = android::hardware::graphics::allocator::V2_0::IAllocator;
|
||||
|
||||
using IMapper = android::hardware::graphics::mapper::V2_0::IMapper;
|
||||
using Error = android::hardware::graphics::mapper::V2_0::Error;
|
||||
using Descriptor = android::hardware::graphics::mapper::V2_0::BufferDescriptor;
|
||||
using YCbCrLayout = android::hardware::graphics::mapper::V2_0::YCbCrLayout;
|
||||
using DescriptorInfo = IMapper::BufferDescriptorInfo;
|
||||
using Rect = IMapper::Rect;
|
||||
};
|
||||
|
||||
struct GrallocV3 {
|
||||
using Format = android::hardware::graphics::common::V1_2::PixelFormat;
|
||||
using Usage = android::hardware::hidl_bitfield<
|
||||
android::hardware::graphics::common::V1_2::BufferUsage>;
|
||||
|
||||
using IAllocator = android::hardware::graphics::allocator::V3_0::IAllocator;
|
||||
|
||||
using IMapper = android::hardware::graphics::mapper::V3_0::IMapper;
|
||||
using Error = android::hardware::graphics::mapper::V3_0::Error;
|
||||
using Descriptor = android::hardware::graphics::mapper::V3_0::BufferDescriptor;
|
||||
using YCbCrLayout = android::hardware::graphics::mapper::V3_0::YCbCrLayout;
|
||||
using DescriptorInfo = IMapper::BufferDescriptorInfo;
|
||||
using Rect = IMapper::Rect;
|
||||
};
|
||||
|
||||
Return<android::hardware::media::omx::V1_0::Status> setRole(
|
||||
sp<IOmxNode> omxNode, const char* role);
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ using ::android::sp;
|
||||
#include <media_video_hidl_test_common.h>
|
||||
#include <system/window.h>
|
||||
#include <fstream>
|
||||
#include <variant>
|
||||
|
||||
static ComponentTestEnvironment* gEnv = nullptr;
|
||||
|
||||
@@ -364,6 +365,61 @@ Return<void> DummyBufferSource::onInputBufferEmptied(
|
||||
return Void();
|
||||
};
|
||||
|
||||
// Variant of mappers
|
||||
struct MapperV2 : public GrallocV2 {
|
||||
sp<IMapper> mMapper;
|
||||
MapperV2(sp<IMapper>&& mapper): mMapper{std::move(mapper)} {}
|
||||
MapperV2() = default;
|
||||
android::hardware::Return<void> lock(
|
||||
void* buffer,
|
||||
Usage usage,
|
||||
const Rect& rect,
|
||||
const android::hardware::hidl_handle& handle,
|
||||
Error* error,
|
||||
void** data) {
|
||||
return mMapper->lock(buffer, usage, rect, handle,
|
||||
[error, data](Error e, void* d) {
|
||||
*error = e;
|
||||
*data = d;
|
||||
});
|
||||
}
|
||||
};
|
||||
struct MapperV3 : public GrallocV3 {
|
||||
sp<IMapper> mMapper;
|
||||
MapperV3(sp<IMapper>&& mapper): mMapper{std::move(mapper)} {}
|
||||
MapperV3() = default;
|
||||
android::hardware::Return<void> lock(
|
||||
void* buffer,
|
||||
Usage usage,
|
||||
const Rect& rect,
|
||||
const android::hardware::hidl_handle& handle,
|
||||
Error* error,
|
||||
void** data) {
|
||||
return mMapper->lock(buffer, usage, rect, handle,
|
||||
[error, data](Error e, void* d, int32_t, int32_t) {
|
||||
*error = e;
|
||||
*data = d;
|
||||
});
|
||||
}
|
||||
};
|
||||
using MapperVar = std::variant<MapperV2, MapperV3>;
|
||||
// Initializes the MapperVar by trying services of different versions.
|
||||
bool initialize(MapperVar& mapperVar) {
|
||||
sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3 =
|
||||
android::hardware::graphics::mapper::V3_0::IMapper::getService();
|
||||
if (mapper3) {
|
||||
mapperVar.emplace<MapperV3>(std::move(mapper3));
|
||||
return true;
|
||||
}
|
||||
sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2 =
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::getService();
|
||||
if (mapper2) {
|
||||
mapperVar.emplace<MapperV2>(std::move(mapper2));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// request VOP refresh
|
||||
void requestIDR(sp<IOmxNode> omxNode, OMX_U32 portIndex) {
|
||||
android::hardware::media::omx::V1_0::Status status;
|
||||
@@ -574,150 +630,166 @@ void waitOnInputConsumption(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
|
||||
|
||||
int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format,
|
||||
std::ifstream& eleStream) {
|
||||
sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::getService();
|
||||
EXPECT_NE(mapper.get(), nullptr);
|
||||
if (mapper.get() == nullptr) return 1;
|
||||
|
||||
android::hardware::hidl_handle fence;
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::Rect rect;
|
||||
android::hardware::graphics::mapper::V2_0::YCbCrLayout ycbcrLayout;
|
||||
android::hardware::graphics::mapper::V2_0::Error error;
|
||||
rect.left = 0;
|
||||
rect.top = 0;
|
||||
rect.width = buffer->omxBuffer.attr.anwBuffer.width;
|
||||
rect.height = buffer->omxBuffer.attr.anwBuffer.height;
|
||||
|
||||
if (format == PixelFormat::YV12 || format == PixelFormat::YCRCB_420_SP ||
|
||||
format == PixelFormat::YCBCR_420_888) {
|
||||
mapper->lockYCbCr(
|
||||
buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence,
|
||||
[&](android::hardware::graphics::mapper::V2_0::Error _e,
|
||||
android::hardware::graphics::mapper::V2_0::YCbCrLayout _n1) {
|
||||
error = _e;
|
||||
ycbcrLayout = _n1;
|
||||
});
|
||||
EXPECT_EQ(error,
|
||||
android::hardware::graphics::mapper::V2_0::Error::NONE);
|
||||
if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
|
||||
return 1;
|
||||
|
||||
int size = ((rect.width * rect.height * 3) >> 1);
|
||||
char* img = new char[size];
|
||||
if (img == nullptr) return 1;
|
||||
eleStream.read(img, size);
|
||||
if (eleStream.gcount() != size) {
|
||||
delete[] img;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* imgTmp = img;
|
||||
char* ipBuffer = static_cast<char*>(ycbcrLayout.y);
|
||||
for (size_t y = rect.height; y > 0; --y) {
|
||||
memcpy(ipBuffer, imgTmp, rect.width);
|
||||
ipBuffer += ycbcrLayout.yStride;
|
||||
imgTmp += rect.width;
|
||||
}
|
||||
|
||||
if (format == PixelFormat::YV12)
|
||||
EXPECT_EQ(ycbcrLayout.chromaStep, 1U);
|
||||
else if (format == PixelFormat::YCRCB_420_SP)
|
||||
EXPECT_EQ(ycbcrLayout.chromaStep, 2U);
|
||||
|
||||
ipBuffer = static_cast<char*>(ycbcrLayout.cb);
|
||||
for (size_t y = rect.height >> 1; y > 0; --y) {
|
||||
for (int32_t x = 0; x < (rect.width >> 1); ++x) {
|
||||
ipBuffer[ycbcrLayout.chromaStep * x] = *imgTmp++;
|
||||
}
|
||||
ipBuffer += ycbcrLayout.cStride;
|
||||
}
|
||||
ipBuffer = static_cast<char*>(ycbcrLayout.cr);
|
||||
for (size_t y = rect.height >> 1; y > 0; --y) {
|
||||
for (int32_t x = 0; x < (rect.width >> 1); ++x) {
|
||||
ipBuffer[ycbcrLayout.chromaStep * x] = *imgTmp++;
|
||||
}
|
||||
ipBuffer += ycbcrLayout.cStride;
|
||||
}
|
||||
|
||||
delete[] img;
|
||||
|
||||
mapper->unlock(buff,
|
||||
[&](android::hardware::graphics::mapper::V2_0::Error _e,
|
||||
android::hardware::hidl_handle _n1) {
|
||||
error = _e;
|
||||
fence = _n1;
|
||||
});
|
||||
EXPECT_EQ(error,
|
||||
android::hardware::graphics::mapper::V2_0::Error::NONE);
|
||||
if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
|
||||
return 1;
|
||||
} else {
|
||||
void* data;
|
||||
mapper->lock(buff, buffer->omxBuffer.attr.anwBuffer.usage, rect, fence,
|
||||
[&](android::hardware::graphics::mapper::V2_0::Error _e,
|
||||
void* _n1) {
|
||||
error = _e;
|
||||
data = _n1;
|
||||
});
|
||||
EXPECT_EQ(error,
|
||||
android::hardware::graphics::mapper::V2_0::Error::NONE);
|
||||
if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
|
||||
return 1;
|
||||
|
||||
if (format == PixelFormat::BGRA_8888) {
|
||||
char* ipBuffer = static_cast<char*>(data);
|
||||
for (size_t y = rect.height; y > 0; --y) {
|
||||
eleStream.read(ipBuffer, rect.width * 4);
|
||||
if (eleStream.gcount() != rect.width * 4) return 1;
|
||||
ipBuffer += buffer->omxBuffer.attr.anwBuffer.stride * 4;
|
||||
}
|
||||
} else {
|
||||
EXPECT_TRUE(false) << "un expected pixel format";
|
||||
return 1;
|
||||
}
|
||||
|
||||
mapper->unlock(buff,
|
||||
[&](android::hardware::graphics::mapper::V2_0::Error _e,
|
||||
android::hardware::hidl_handle _n1) {
|
||||
error = _e;
|
||||
fence = _n1;
|
||||
});
|
||||
EXPECT_EQ(error,
|
||||
android::hardware::graphics::mapper::V2_0::Error::NONE);
|
||||
if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
|
||||
return 1;
|
||||
MapperVar mapperVar;
|
||||
if (!initialize(mapperVar)) {
|
||||
EXPECT_TRUE(false) << "failed to obtain mapper service";
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return std::visit([buffer, buff, format, &eleStream](auto&& mapper) -> int {
|
||||
using Gralloc = std::remove_reference_t<decltype(mapper)>;
|
||||
using Error = typename Gralloc::Error;
|
||||
using Rect = typename Gralloc::Rect;
|
||||
using Usage = typename Gralloc::Usage;
|
||||
using YCbCrLayout = typename Gralloc::YCbCrLayout;
|
||||
|
||||
android::hardware::hidl_handle fence;
|
||||
Rect rect;
|
||||
YCbCrLayout ycbcrLayout;
|
||||
Error error;
|
||||
rect.left = 0;
|
||||
rect.top = 0;
|
||||
rect.width = buffer->omxBuffer.attr.anwBuffer.width;
|
||||
rect.height = buffer->omxBuffer.attr.anwBuffer.height;
|
||||
|
||||
if (format == PixelFormat::YV12 || format == PixelFormat::YCRCB_420_SP ||
|
||||
format == PixelFormat::YCBCR_420_888) {
|
||||
mapper.mMapper->lockYCbCr(
|
||||
buff,
|
||||
static_cast<Usage>(
|
||||
buffer->omxBuffer.attr.anwBuffer.usage),
|
||||
rect,
|
||||
fence,
|
||||
[&](Error _e,
|
||||
const YCbCrLayout& _n1) {
|
||||
error = _e;
|
||||
ycbcrLayout = _n1;
|
||||
});
|
||||
EXPECT_EQ(error, Error::NONE);
|
||||
if (error != Error::NONE)
|
||||
return 1;
|
||||
|
||||
int size = ((rect.width * rect.height * 3) >> 1);
|
||||
char* img = new char[size];
|
||||
if (img == nullptr) return 1;
|
||||
eleStream.read(img, size);
|
||||
if (eleStream.gcount() != size) {
|
||||
delete[] img;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* imgTmp = img;
|
||||
char* ipBuffer = static_cast<char*>(ycbcrLayout.y);
|
||||
for (size_t y = rect.height; y > 0; --y) {
|
||||
memcpy(ipBuffer, imgTmp, rect.width);
|
||||
ipBuffer += ycbcrLayout.yStride;
|
||||
imgTmp += rect.width;
|
||||
}
|
||||
|
||||
if (format == PixelFormat::YV12)
|
||||
EXPECT_EQ(ycbcrLayout.chromaStep, 1U);
|
||||
else if (format == PixelFormat::YCRCB_420_SP)
|
||||
EXPECT_EQ(ycbcrLayout.chromaStep, 2U);
|
||||
|
||||
ipBuffer = static_cast<char*>(ycbcrLayout.cb);
|
||||
for (size_t y = rect.height >> 1; y > 0; --y) {
|
||||
for (int32_t x = 0; x < (rect.width >> 1); ++x) {
|
||||
ipBuffer[ycbcrLayout.chromaStep * x] = *imgTmp++;
|
||||
}
|
||||
ipBuffer += ycbcrLayout.cStride;
|
||||
}
|
||||
ipBuffer = static_cast<char*>(ycbcrLayout.cr);
|
||||
for (size_t y = rect.height >> 1; y > 0; --y) {
|
||||
for (int32_t x = 0; x < (rect.width >> 1); ++x) {
|
||||
ipBuffer[ycbcrLayout.chromaStep * x] = *imgTmp++;
|
||||
}
|
||||
ipBuffer += ycbcrLayout.cStride;
|
||||
}
|
||||
|
||||
delete[] img;
|
||||
|
||||
mapper.mMapper->unlock(buff,
|
||||
[&](Error _e,
|
||||
const android::hardware::hidl_handle& _n1) {
|
||||
error = _e;
|
||||
fence = _n1;
|
||||
});
|
||||
EXPECT_EQ(error, Error::NONE);
|
||||
if (error != Error::NONE)
|
||||
return 1;
|
||||
} else {
|
||||
void* data;
|
||||
mapper.lock(
|
||||
buff,
|
||||
buffer->omxBuffer.attr.anwBuffer.usage,
|
||||
rect,
|
||||
fence,
|
||||
&error,
|
||||
&data);
|
||||
EXPECT_EQ(error, Error::NONE);
|
||||
if (error != Error::NONE)
|
||||
return 1;
|
||||
|
||||
if (format == PixelFormat::BGRA_8888) {
|
||||
char* ipBuffer = static_cast<char*>(data);
|
||||
for (size_t y = rect.height; y > 0; --y) {
|
||||
eleStream.read(ipBuffer, rect.width * 4);
|
||||
if (eleStream.gcount() != rect.width * 4) return 1;
|
||||
ipBuffer += buffer->omxBuffer.attr.anwBuffer.stride * 4;
|
||||
}
|
||||
} else {
|
||||
EXPECT_TRUE(false) << "un expected pixel format";
|
||||
return 1;
|
||||
}
|
||||
|
||||
mapper.mMapper->unlock(
|
||||
buff,
|
||||
[&](Error _e, const android::hardware::hidl_handle& _n1) {
|
||||
error = _e;
|
||||
fence = _n1;
|
||||
});
|
||||
EXPECT_EQ(error, Error::NONE);
|
||||
if (error != Error::NONE)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}, mapperVar);
|
||||
}
|
||||
|
||||
int fillGraphicBuffer(BufferInfo* buffer, PixelFormat format,
|
||||
std::ifstream& eleStream) {
|
||||
sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
|
||||
android::hardware::graphics::mapper::V2_0::IMapper::getService();
|
||||
EXPECT_NE(mapper.get(), nullptr);
|
||||
if (mapper.get() == nullptr) return 1;
|
||||
|
||||
void* buff = nullptr;
|
||||
android::hardware::graphics::mapper::V2_0::Error error;
|
||||
mapper->importBuffer(
|
||||
buffer->omxBuffer.nativeHandle,
|
||||
[&](android::hardware::graphics::mapper::V2_0::Error _e, void* _n1) {
|
||||
error = _e;
|
||||
buff = _n1;
|
||||
});
|
||||
EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
|
||||
if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
|
||||
MapperVar mapperVar;
|
||||
if (!initialize(mapperVar)) {
|
||||
EXPECT_TRUE(false) << "failed to obtain mapper service";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (colorFormatConversion(buffer, buff, format, eleStream)) return 1;
|
||||
return std::visit([buffer, format, &eleStream](auto&& mapper) -> int {
|
||||
using Gralloc = std::remove_reference_t<decltype(mapper)>;
|
||||
using Error = typename Gralloc::Error;
|
||||
|
||||
error = mapper->freeBuffer(buff);
|
||||
EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
|
||||
if (error != android::hardware::graphics::mapper::V2_0::Error::NONE)
|
||||
return 1;
|
||||
void* buff = nullptr;
|
||||
Error error;
|
||||
mapper.mMapper->importBuffer(
|
||||
buffer->omxBuffer.nativeHandle,
|
||||
[&](Error _e, void* _n1) {
|
||||
error = _e;
|
||||
buff = _n1;
|
||||
});
|
||||
EXPECT_EQ(error, Error::NONE);
|
||||
if (error != Error::NONE)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
if (colorFormatConversion(buffer, buff, format, eleStream)) return 1;
|
||||
|
||||
error = mapper.mMapper->freeBuffer(buff);
|
||||
EXPECT_EQ(error, Error::NONE);
|
||||
if (error != Error::NONE)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}, mapperVar);
|
||||
}
|
||||
|
||||
int dispatchGraphicBuffer(sp<IOmxNode> omxNode,
|
||||
|
||||
Reference in New Issue
Block a user