summaryrefslogtreecommitdiff
path: root/graphics/mapper/4.0/utils/vts/MapperVts.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/mapper/4.0/utils/vts/MapperVts.cpp')
-rw-r--r--graphics/mapper/4.0/utils/vts/MapperVts.cpp128
1 files changed, 85 insertions, 43 deletions
diff --git a/graphics/mapper/4.0/utils/vts/MapperVts.cpp b/graphics/mapper/4.0/utils/vts/MapperVts.cpp
index 5b2a94e65d..c6c9834eaf 100644
--- a/graphics/mapper/4.0/utils/vts/MapperVts.cpp
+++ b/graphics/mapper/4.0/utils/vts/MapperVts.cpp
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+#include <aidlcommonsupport/NativeHandle.h>
+#include <android-base/properties.h>
+#include <android/binder_manager.h>
#include <gralloctypes/Gralloc4.h>
#include <mapper-vts/4.0/MapperVts.h>
@@ -24,27 +27,42 @@ namespace mapper {
namespace V4_0 {
namespace vts {
-Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& mapperServiceName,
+Gralloc::Gralloc(const std::string& aidlAllocatorServiceName,
+ const std::string& hidlAllocatorServiceName, const std::string& mapperServiceName,
bool errOnFailure) {
if (errOnFailure) {
- init(allocatorServiceName, mapperServiceName);
+ init(aidlAllocatorServiceName, hidlAllocatorServiceName, mapperServiceName);
} else {
- initNoErr(allocatorServiceName, mapperServiceName);
+ initNoErr(aidlAllocatorServiceName, hidlAllocatorServiceName, mapperServiceName);
}
}
-void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
- mAllocator = IAllocator::getService(allocatorServiceName);
- ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
+void Gralloc::init(const std::string& aidlAllocatorServiceName,
+ const std::string& hidlAllocatorServiceName,
+ const std::string& mapperServiceName) {
+ mAidlAllocator = aidl::android::hardware::graphics::allocator::IAllocator::fromBinder(
+ ndk::SpAIBinder(AServiceManager_checkService(aidlAllocatorServiceName.c_str())));
+
+ if (mAidlAllocator == nullptr) {
+ mHidlAllocator = IAllocator::getService(hidlAllocatorServiceName);
+ }
+ ASSERT_TRUE(nullptr != mAidlAllocator || mHidlAllocator != nullptr)
+ << "failed to get allocator service";
mMapper = IMapper::getService(mapperServiceName);
ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service";
ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode";
}
-void Gralloc::initNoErr(const std::string& allocatorServiceName,
+void Gralloc::initNoErr(const std::string& aidlAllocatorServiceName,
+ const std::string& hidlAllocatorServiceName,
const std::string& mapperServiceName) {
- mAllocator = IAllocator::getService(allocatorServiceName);
+ mAidlAllocator = aidl::android::hardware::graphics::allocator::IAllocator::fromBinder(
+ ndk::SpAIBinder(AServiceManager_checkService(aidlAllocatorServiceName.c_str())));
+
+ if (mAidlAllocator == nullptr) {
+ mHidlAllocator = IAllocator::getService(hidlAllocatorServiceName);
+ }
mMapper = IMapper::getService(mapperServiceName);
if (mMapper.get()) {
@@ -67,10 +85,6 @@ Gralloc::~Gralloc() {
mImportedBuffers.clear();
}
-sp<IAllocator> Gralloc::getAllocator() const {
- return mAllocator;
-}
-
const native_handle_t* Gralloc::cloneBuffer(const hidl_handle& rawHandle,
enum Tolerance /*tolerance*/) {
const native_handle_t* bufferHandle = native_handle_clone(rawHandle.getNativeHandle());
@@ -89,33 +103,40 @@ std::vector<const native_handle_t*> Gralloc::allocate(const BufferDescriptor& de
uint32_t* outStride) {
std::vector<const native_handle_t*> bufferHandles;
bufferHandles.reserve(count);
- mAllocator->allocate(descriptor, count,
- [&](const auto& tmpError, const auto& tmpStride, const auto& tmpBuffers) {
- if (canTolerate(tolerance, tmpError)) {
- return;
- }
-
- ASSERT_EQ(Error::NONE, tmpError) << "failed to allocate buffers";
- ASSERT_EQ(count, tmpBuffers.size()) << "invalid buffer array";
-
- for (uint32_t i = 0; i < count; i++) {
- const native_handle_t* bufferHandle = nullptr;
- if (import) {
- ASSERT_NO_FATAL_FAILURE(
- bufferHandle = importBuffer(tmpBuffers[i], tolerance));
- } else {
- ASSERT_NO_FATAL_FAILURE(
- bufferHandle = cloneBuffer(tmpBuffers[i], tolerance));
- }
- if (bufferHandle) {
- bufferHandles.push_back(bufferHandle);
- }
- }
-
- if (outStride) {
- *outStride = tmpStride;
- }
- });
+
+ auto callback = [&](Error error, uint32_t stride,
+ const hidl_vec<hidl_handle>& buffers) -> void {
+ if (canTolerate(tolerance, error)) {
+ return;
+ }
+
+ if (error != Error::NONE) {
+ if (base::GetIntProperty("ro.vendor.build.version.sdk", 0, 0, INT_MAX) < 33) {
+ GTEST_SKIP() << "Old vendor grallocs may not support P010";
+ } else {
+ GTEST_FAIL() << "failed to allocate buffers";
+ }
+ }
+ ASSERT_EQ(count, buffers.size()) << "invalid buffer array";
+
+ for (uint32_t i = 0; i < count; i++) {
+ const native_handle_t* bufferHandle = nullptr;
+ if (import) {
+ ASSERT_NO_FATAL_FAILURE(bufferHandle = importBuffer(buffers[i], tolerance));
+ } else {
+ ASSERT_NO_FATAL_FAILURE(bufferHandle = cloneBuffer(buffers[i], tolerance));
+ }
+ if (bufferHandle) {
+ bufferHandles.push_back(bufferHandle);
+ }
+ }
+
+ if (outStride) {
+ *outStride = stride;
+ }
+ };
+
+ rawAllocate(descriptor, count, callback);
if (::testing::Test::HasFatalFailure()) {
bufferHandles.clear();
@@ -133,14 +154,27 @@ const native_handle_t* Gralloc::allocate(const IMapper::BufferDescriptorInfo& de
}
auto buffers = allocate(descriptor, 1, import, tolerance, outStride);
- if (::testing::Test::HasFatalFailure()) {
+ if (::testing::Test::HasFatalFailure() || ::testing::Test::IsSkipped() || buffers.size() != 1) {
return nullptr;
}
+ return buffers[0];
+}
- if (buffers.size() != 1) {
- return nullptr;
+void Gralloc::rawAllocate(
+ const BufferDescriptor& descriptor, uint32_t count,
+ std::function<void(Error, uint32_t, const hidl_vec<hidl_handle>&)> callback) {
+ if (mAidlAllocator) {
+ aidl::android::hardware::graphics::allocator::AllocationResult result;
+ auto status = mAidlAllocator->allocate(descriptor, count, &result);
+ const Error error = toHidlError(status);
+ std::vector<hidl_handle> handles;
+ for (const auto& aidlHandle : result.buffers) {
+ handles.push_back(hidl_handle(makeFromAidl(aidlHandle)));
+ }
+ callback(error, result.stride, handles);
+ } else {
+ mHidlAllocator->allocate(descriptor, count, callback);
}
- return buffers[0];
}
sp<IMapper> Gralloc::getMapper() const {
@@ -303,6 +337,14 @@ bool Gralloc::isSupported(const IMapper::BufferDescriptorInfo& descriptorInfo) {
return supported;
}
+bool Gralloc::isSupportedNoFailure(const IMapper::BufferDescriptorInfo& descriptorInfo) {
+ bool supported = false;
+ mMapper->isSupported(descriptorInfo, [&](const auto& tmpError, const auto& tmpSupported) {
+ supported = tmpSupported && tmpError == Error::NONE;
+ });
+ return supported;
+}
+
Error Gralloc::get(const native_handle_t* bufferHandle, const IMapper::MetadataType& metadataType,
hidl_vec<uint8_t>* outVec) {
Error err;