Merge "Support IMapper@3.0 in OMX VTS" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-07-09 17:25:39 +00:00
committed by Android (Google) Code Review
4 changed files with 361 additions and 187 deletions

View File

@@ -29,6 +29,21 @@ cc_library_static {
"android.hidl.memory@1.0", "android.hidl.memory@1.0",
"android.hardware.media.omx@1.0", "android.hardware.media.omx@1.0",
"android.hardware.graphics.allocator@2.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: [ static_libs: [
"VtsHalMediaOmxV1_0CommonUtil", "VtsHalMediaOmxV1_0CommonUtil",
"android.hardware.graphics.allocator@2.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@2.0",
"android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.bufferqueue@1.0", "android.hardware.graphics.bufferqueue@1.0",
"android.hardware.graphics.common@1.0", "android.hardware.graphics.common@1.0",
"android.hardware.media.omx@1.0", "android.hardware.media.omx@1.0",

View File

@@ -22,8 +22,11 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/hardware/graphics/allocator/2.0/IAllocator.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/IMapper.h>
#include <android/hardware/graphics/mapper/2.0/types.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/IOmx.h>
#include <android/hardware/media/omx/1.0/IOmxNode.h> #include <android/hardware/media/omx/1.0/IOmxNode.h>
#include <android/hardware/media/omx/1.0/IOmxObserver.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/allocator/1.0/IAllocator.h>
#include <android/hidl/memory/1.0/IMapper.h> #include <android/hidl/memory/1.0/IMapper.h>
#include <android/hidl/memory/1.0/IMemory.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::BufferUsage;
using ::android::hardware::graphics::common::V1_0::PixelFormat; 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, BufferInfo* buffer, uint32_t nFrameWidth,
uint32_t nFrameHeight, int32_t* nStride, uint32_t nFrameHeight, int32_t* nStride,
int format) { int format) {
android::hardware::media::omx::V1_0::Status status; struct AllocatorV2 : public GrallocV2 {
sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator = sp<IAllocator> mAllocator;
android::hardware::graphics::allocator::V2_0::IAllocator::getService(); sp<IMapper> mMapper;
ASSERT_NE(nullptr, allocator.get()); 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 = sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper2{};
android::hardware::graphics::mapper::V2_0::IMapper::getService(); sp<android::hardware::graphics::mapper::V3_0::IMapper> mapper3{};
ASSERT_NE(mapper.get(), nullptr); 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 android::hardware::media::omx::V1_0::Status status{};
descriptorInfo; uint64_t usage{};
uint32_t usage; ASSERT_TRUE(omxNode->getGraphicBufferUsage(
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(
portIndex, portIndex,
[&status, &usage](android::hardware::media::omx::V1_0::Status _s, [&status, &usage](android::hardware::media::omx::V1_0::Status _s,
uint32_t _n1) { uint32_t _n1) {
status = _s; status = _s;
usage = _n1; usage = _n1;
}); }).isOk());
if (status == android::hardware::media::omx::V1_0::Status::OK) { ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::OK);
descriptorInfo.usage |= usage;
}
::android::hardware::hidl_vec<uint32_t> descriptor; static std::atomic_int32_t bufferIdCounter{0};
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 volatile int32_t nextId = 0; std::visit([buffer, nFrameWidth, nFrameHeight, format, usage, nStride](auto&& gralloc) {
uint64_t id = static_cast<uint64_t>(getpid()) << 32; using Gralloc = std::remove_reference_t<decltype(gralloc)>;
allocator->allocate( using Descriptor = typename Gralloc::Descriptor;
descriptor, 1, using DescriptorInfo = typename Gralloc::DescriptorInfo;
[&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1, using Error = typename Gralloc::Error;
const ::android::hardware::hidl_vec< using Format = typename Gralloc::Format;
::android::hardware::hidl_handle>& _n2) { using Usage = typename Gralloc::Usage;
ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE,
_s); Error error{};
*nStride = _n1; Descriptor descriptor{};
buffer->omxBuffer.nativeHandle = _n2[0];
buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth; DescriptorInfo descriptorInfo{};
buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight; descriptorInfo.width = nFrameWidth;
buffer->omxBuffer.attr.anwBuffer.stride = _n1; descriptorInfo.height = nFrameHeight;
buffer->omxBuffer.attr.anwBuffer.format = descriptorInfo.format; descriptorInfo.layerCount = 1;
buffer->omxBuffer.attr.anwBuffer.usage = descriptorInfo.usage; descriptorInfo.format = static_cast<Format>(format);
buffer->omxBuffer.attr.anwBuffer.layerCount = descriptorInfo.usage = usage | Usage(BufferUsage::CPU_READ_OFTEN);
descriptorInfo.layerCount;
buffer->omxBuffer.attr.anwBuffer.id = gralloc.mMapper->createDescriptor(descriptorInfo,
id | static_cast<uint32_t>(android_atomic_inc(&nextId)); [&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 // allocate buffers needed on a component port

View File

@@ -22,6 +22,16 @@
#endif #endif
#include <getopt.h> #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 <media/stagefright/foundation/ALooper.h>
#include <utils/Condition.h> #include <utils/Condition.h>
#include <utils/List.h> #include <utils/List.h>
@@ -288,6 +298,36 @@ Return<android::hardware::media::omx::V1_0::Status> setPortConfig(
/* /*
* common functions declarations * 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( Return<android::hardware::media::omx::V1_0::Status> setRole(
sp<IOmxNode> omxNode, const char* role); sp<IOmxNode> omxNode, const char* role);

View File

@@ -63,6 +63,7 @@ using ::android::sp;
#include <media_video_hidl_test_common.h> #include <media_video_hidl_test_common.h>
#include <system/window.h> #include <system/window.h>
#include <fstream> #include <fstream>
#include <variant>
static ComponentTestEnvironment* gEnv = nullptr; static ComponentTestEnvironment* gEnv = nullptr;
@@ -364,6 +365,61 @@ Return<void> DummyBufferSource::onInputBufferEmptied(
return Void(); 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 // request VOP refresh
void requestIDR(sp<IOmxNode> omxNode, OMX_U32 portIndex) { void requestIDR(sp<IOmxNode> omxNode, OMX_U32 portIndex) {
android::hardware::media::omx::V1_0::Status status; 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, int colorFormatConversion(BufferInfo* buffer, void* buff, PixelFormat format,
std::ifstream& eleStream) { std::ifstream& eleStream) {
sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper = MapperVar mapperVar;
android::hardware::graphics::mapper::V2_0::IMapper::getService(); if (!initialize(mapperVar)) {
EXPECT_NE(mapper.get(), nullptr); EXPECT_TRUE(false) << "failed to obtain mapper service";
if (mapper.get() == nullptr) return 1; 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;
} }
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, int fillGraphicBuffer(BufferInfo* buffer, PixelFormat format,
std::ifstream& eleStream) { std::ifstream& eleStream) {
sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper = MapperVar mapperVar;
android::hardware::graphics::mapper::V2_0::IMapper::getService(); if (!initialize(mapperVar)) {
EXPECT_NE(mapper.get(), nullptr); EXPECT_TRUE(false) << "failed to obtain mapper service";
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)
return 1; 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); void* buff = nullptr;
EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE); Error error;
if (error != android::hardware::graphics::mapper::V2_0::Error::NONE) mapper.mMapper->importBuffer(
return 1; 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, int dispatchGraphicBuffer(sp<IOmxNode> omxNode,