Merge "Tweak IMapper 4.0 VTS to run with AIDL IAllocator" into tm-dev

This commit is contained in:
TreeHugger Robot 2022-05-23 21:10:30 +00:00 committed by Android (Google) Code Review
commit 412f907bd3
14 changed files with 180 additions and 58 deletions

View file

@ -32,6 +32,7 @@ cc_library_static {
"TestCommandReader.cpp", "TestCommandReader.cpp",
], ],
static_libs: [ static_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.composer@2.1", "android.hardware.graphics.composer@2.1",
"android.hardware.graphics.mapper@2.0-vts", "android.hardware.graphics.mapper@2.0-vts",
"android.hardware.graphics.mapper@3.0-vts", "android.hardware.graphics.mapper@3.0-vts",
@ -39,6 +40,7 @@ cc_library_static {
"libgtest", "libgtest",
], ],
export_static_lib_headers: [ export_static_lib_headers: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.composer@2.1", "android.hardware.graphics.composer@2.1",
"android.hardware.graphics.mapper@2.0-vts", "android.hardware.graphics.mapper@2.0-vts",
"android.hardware.graphics.mapper@3.0-vts", "android.hardware.graphics.mapper@3.0-vts",

View file

@ -318,7 +318,7 @@ Gralloc::Gralloc() {
[this] { [this] {
ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>("default", "default", ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>("default", "default",
/*errOnFailure=*/false)); /*errOnFailure=*/false));
if (mGralloc4->getAllocator() == nullptr || mGralloc4->getMapper() == nullptr) { if (!mGralloc4->hasAllocator() || mGralloc4->getMapper() == nullptr) {
mGralloc4 = nullptr; mGralloc4 = nullptr;
ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default", ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default",
/*errOnFailure=*/false)); /*errOnFailure=*/false));

View file

@ -32,14 +32,17 @@ cc_test {
// TODO(b/64437680): Assume these libs are always available on the device. // TODO(b/64437680): Assume these libs are always available on the device.
shared_libs: [ shared_libs: [
"libbase", "libbase",
"libbinder_ndk",
"libfmq", "libfmq",
"libsync", "libsync",
"android.hardware.common-V2-ndk",
"android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.1", "android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@3.0", "android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@4.0", "android.hardware.graphics.mapper@4.0",
], ],
static_libs: [ static_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.allocator@3.0", "android.hardware.graphics.allocator@3.0",
"android.hardware.graphics.allocator@4.0", "android.hardware.graphics.allocator@4.0",
@ -49,10 +52,14 @@ cc_test {
"android.hardware.graphics.mapper@2.1-vts", "android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0-vts", "android.hardware.graphics.mapper@3.0-vts",
"android.hardware.graphics.mapper@4.0-vts", "android.hardware.graphics.mapper@4.0-vts",
"libaidlcommonsupport",
], ],
header_libs: [ header_libs: [
"android.hardware.graphics.composer@2.1-command-buffer", "android.hardware.graphics.composer@2.1-command-buffer",
], ],
disable_framework: true, disable_framework: true,
test_suites: ["general-tests", "vts"], test_suites: [
"general-tests",
"vts",
],
} }

View file

@ -35,6 +35,7 @@ cc_library_static {
"libui", "libui",
], ],
static_libs: [ static_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.composer@2.1-vts", "android.hardware.graphics.composer@2.1-vts",
"android.hardware.graphics.composer@2.2", "android.hardware.graphics.composer@2.2",
"android.hardware.graphics.composer3-V1-ndk", "android.hardware.graphics.composer3-V1-ndk",
@ -52,6 +53,7 @@ cc_library_static {
"android.hardware.graphics.mapper@4.0-vts", "android.hardware.graphics.mapper@4.0-vts",
], ],
export_static_lib_headers: [ export_static_lib_headers: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.composer@2.1-vts", "android.hardware.graphics.composer@2.1-vts",
"android.hardware.graphics.composer@2.2", "android.hardware.graphics.composer@2.2",
"android.hardware.graphics.mapper@2.1-vts", "android.hardware.graphics.mapper@2.1-vts",

View file

@ -184,7 +184,7 @@ Gralloc::Gralloc() {
ALOGD("Attempting to initialize gralloc4"); ALOGD("Attempting to initialize gralloc4");
ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>("default", "default", ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>("default", "default",
/*errOnFailure=*/false)); /*errOnFailure=*/false));
if (mGralloc4->getMapper() == nullptr || mGralloc4->getAllocator() == nullptr) { if (mGralloc4->getMapper() == nullptr || !mGralloc4->hasAllocator()) {
mGralloc4 = nullptr; mGralloc4 = nullptr;
ALOGD("Failed to initialize gralloc4, initializing gralloc3"); ALOGD("Failed to initialize gralloc4, initializing gralloc3");
ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default", ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default",

View file

@ -45,18 +45,21 @@ cc_test {
"libGLESv1_CM", "libGLESv1_CM",
"libGLESv2", "libGLESv2",
"libbase", "libbase",
"libbinder_ndk",
"libfmq", "libfmq",
"libgui", "libgui",
"libhidlbase", "libhidlbase",
"libprocessgroup", "libprocessgroup",
"libsync", "libsync",
"libui", "libui",
"android.hardware.common-V2-ndk",
"android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.1", "android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@3.0", "android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@4.0", "android.hardware.graphics.mapper@4.0",
], ],
static_libs: [ static_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.allocator@3.0", "android.hardware.graphics.allocator@3.0",
"android.hardware.graphics.allocator@4.0", "android.hardware.graphics.allocator@4.0",
@ -70,6 +73,7 @@ cc_test {
"android.hardware.graphics.mapper@2.1-vts", "android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0-vts", "android.hardware.graphics.mapper@3.0-vts",
"android.hardware.graphics.mapper@4.0-vts", "android.hardware.graphics.mapper@4.0-vts",
"libaidlcommonsupport",
"libgtest", "libgtest",
"librenderengine", "librenderengine",
"libshaders", "libshaders",

View file

@ -32,15 +32,18 @@ cc_test {
// TODO(b/64437680): Assume these libs are always available on the device. // TODO(b/64437680): Assume these libs are always available on the device.
shared_libs: [ shared_libs: [
"libbase", "libbase",
"libbinder_ndk",
"libfmq", "libfmq",
"libhidlbase", "libhidlbase",
"libsync", "libsync",
"android.hardware.common-V2-ndk",
"android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.1", "android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@3.0", "android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@4.0", "android.hardware.graphics.mapper@4.0",
], ],
static_libs: [ static_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.allocator@3.0", "android.hardware.graphics.allocator@3.0",
"android.hardware.graphics.allocator@4.0", "android.hardware.graphics.allocator@4.0",
@ -54,6 +57,7 @@ cc_test {
"android.hardware.graphics.mapper@2.1-vts", "android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0-vts", "android.hardware.graphics.mapper@3.0-vts",
"android.hardware.graphics.mapper@4.0-vts", "android.hardware.graphics.mapper@4.0-vts",
"libaidlcommonsupport",
], ],
header_libs: [ header_libs: [
"android.hardware.graphics.composer@2.1-command-buffer", "android.hardware.graphics.composer@2.1-command-buffer",
@ -61,5 +65,8 @@ cc_test {
"android.hardware.graphics.composer@2.3-command-buffer", "android.hardware.graphics.composer@2.3-command-buffer",
], ],
disable_framework: true, disable_framework: true,
test_suites: ["general-tests", "vts"], test_suites: [
"general-tests",
"vts",
],
} }

View file

@ -32,6 +32,7 @@ cc_library_static {
"TestCommandReader.cpp", "TestCommandReader.cpp",
], ],
static_libs: [ static_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.composer@2.1", "android.hardware.graphics.composer@2.1",
"android.hardware.graphics.composer@2.2", "android.hardware.graphics.composer@2.2",
"android.hardware.graphics.composer@2.3-vts", "android.hardware.graphics.composer@2.3-vts",

View file

@ -32,14 +32,17 @@ cc_test {
// TODO(b/64437680): Assume these libs are always available on the device. // TODO(b/64437680): Assume these libs are always available on the device.
shared_libs: [ shared_libs: [
"libbase", "libbase",
"libbinder_ndk",
"libfmq", "libfmq",
"libsync", "libsync",
"android.hardware.common-V2-ndk",
"android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@2.1", "android.hardware.graphics.mapper@2.1",
"android.hardware.graphics.mapper@3.0", "android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@4.0", "android.hardware.graphics.mapper@4.0",
], ],
static_libs: [ static_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.allocator@3.0", "android.hardware.graphics.allocator@3.0",
"android.hardware.graphics.allocator@4.0", "android.hardware.graphics.allocator@4.0",
@ -55,6 +58,7 @@ cc_test {
"android.hardware.graphics.mapper@2.1-vts", "android.hardware.graphics.mapper@2.1-vts",
"android.hardware.graphics.mapper@3.0-vts", "android.hardware.graphics.mapper@3.0-vts",
"android.hardware.graphics.mapper@4.0-vts", "android.hardware.graphics.mapper@4.0-vts",
"libaidlcommonsupport",
], ],
header_libs: [ header_libs: [
"android.hardware.graphics.composer@2.1-command-buffer", "android.hardware.graphics.composer@2.1-command-buffer",
@ -63,5 +67,8 @@ cc_test {
"android.hardware.graphics.composer@2.4-command-buffer", "android.hardware.graphics.composer@2.4-command-buffer",
], ],
disable_framework: true, disable_framework: true,
test_suites: ["general-tests", "vts"], test_suites: [
"general-tests",
"vts",
],
} }

View file

@ -32,14 +32,21 @@ cc_library_static {
"-g", "-g",
], ],
static_libs: [ static_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.allocator@4.0", "android.hardware.graphics.allocator@4.0",
"android.hardware.graphics.common-V3-ndk",
"android.hardware.graphics.mapper@4.0", "android.hardware.graphics.mapper@4.0",
"libaidlcommonsupport",
], ],
shared_libs: [ shared_libs: [
"libbinder_ndk",
"libgralloctypes", "libgralloctypes",
"libvndksupport",
], ],
export_static_lib_headers: [ export_static_lib_headers: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.allocator@4.0", "android.hardware.graphics.allocator@4.0",
"android.hardware.graphics.common-V3-ndk",
"android.hardware.graphics.mapper@4.0", "android.hardware.graphics.mapper@4.0",
], ],
export_include_dirs: ["include"], export_include_dirs: ["include"],

View file

@ -14,7 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
#include <aidlcommonsupport/NativeHandle.h>
#include <android-base/properties.h> #include <android-base/properties.h>
#include <android/binder_manager.h>
#include <gralloctypes/Gralloc4.h> #include <gralloctypes/Gralloc4.h>
#include <mapper-vts/4.0/MapperVts.h> #include <mapper-vts/4.0/MapperVts.h>
@ -35,8 +37,14 @@ Gralloc::Gralloc(const std::string& allocatorServiceName, const std::string& map
} }
void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) { void Gralloc::init(const std::string& allocatorServiceName, const std::string& mapperServiceName) {
mAllocator = IAllocator::getService(allocatorServiceName); mAidlAllocator = aidl::android::hardware::graphics::allocator::IAllocator::fromBinder(
ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service"; ndk::SpAIBinder(AServiceManager_checkService(allocatorServiceName.c_str())));
if (mAidlAllocator == nullptr) {
mHidlAllocator = IAllocator::getService(allocatorServiceName);
}
ASSERT_TRUE(nullptr != mAidlAllocator || mHidlAllocator != nullptr)
<< "failed to get allocator service";
mMapper = IMapper::getService(mapperServiceName); mMapper = IMapper::getService(mapperServiceName);
ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service"; ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service";
@ -45,7 +53,12 @@ void Gralloc::init(const std::string& allocatorServiceName, const std::string& m
void Gralloc::initNoErr(const std::string& allocatorServiceName, void Gralloc::initNoErr(const std::string& allocatorServiceName,
const std::string& mapperServiceName) { const std::string& mapperServiceName) {
mAllocator = IAllocator::getService(allocatorServiceName); mAidlAllocator = aidl::android::hardware::graphics::allocator::IAllocator::fromBinder(
ndk::SpAIBinder(AServiceManager_checkService(allocatorServiceName.c_str())));
if (mAidlAllocator == nullptr) {
mHidlAllocator = IAllocator::getService(allocatorServiceName);
}
mMapper = IMapper::getService(mapperServiceName); mMapper = IMapper::getService(mapperServiceName);
if (mMapper.get()) { if (mMapper.get()) {
@ -68,10 +81,6 @@ Gralloc::~Gralloc() {
mImportedBuffers.clear(); mImportedBuffers.clear();
} }
sp<IAllocator> Gralloc::getAllocator() const {
return mAllocator;
}
const native_handle_t* Gralloc::cloneBuffer(const hidl_handle& rawHandle, const native_handle_t* Gralloc::cloneBuffer(const hidl_handle& rawHandle,
enum Tolerance /*tolerance*/) { enum Tolerance /*tolerance*/) {
const native_handle_t* bufferHandle = native_handle_clone(rawHandle.getNativeHandle()); const native_handle_t* bufferHandle = native_handle_clone(rawHandle.getNativeHandle());
@ -90,30 +99,28 @@ std::vector<const native_handle_t*> Gralloc::allocate(const BufferDescriptor& de
uint32_t* outStride) { uint32_t* outStride) {
std::vector<const native_handle_t*> bufferHandles; std::vector<const native_handle_t*> bufferHandles;
bufferHandles.reserve(count); bufferHandles.reserve(count);
mAllocator->allocate(descriptor, count,
[&](const auto& tmpError, const auto& tmpStride, const auto& tmpBuffers) { auto callback = [&](Error error, uint32_t stride,
if (canTolerate(tolerance, tmpError)) { const hidl_vec<hidl_handle>& buffers) -> void {
if (canTolerate(tolerance, error)) {
return; return;
} }
if (tmpError != Error::NONE) { if (error != Error::NONE) {
if (base::GetIntProperty("ro.vendor.build.version.sdk", 0, 0, if (base::GetIntProperty("ro.vendor.build.version.sdk", 0, 0, INT_MAX) < 33) {
INT_MAX) < 33) {
GTEST_SKIP() << "Old vendor grallocs may not support P010"; GTEST_SKIP() << "Old vendor grallocs may not support P010";
} else { } else {
GTEST_FAIL() << "failed to allocate buffers"; GTEST_FAIL() << "failed to allocate buffers";
} }
} }
ASSERT_EQ(count, tmpBuffers.size()) << "invalid buffer array"; ASSERT_EQ(count, buffers.size()) << "invalid buffer array";
for (uint32_t i = 0; i < count; i++) { for (uint32_t i = 0; i < count; i++) {
const native_handle_t* bufferHandle = nullptr; const native_handle_t* bufferHandle = nullptr;
if (import) { if (import) {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(bufferHandle = importBuffer(buffers[i], tolerance));
bufferHandle = importBuffer(tmpBuffers[i], tolerance));
} else { } else {
ASSERT_NO_FATAL_FAILURE( ASSERT_NO_FATAL_FAILURE(bufferHandle = cloneBuffer(buffers[i], tolerance));
bufferHandle = cloneBuffer(tmpBuffers[i], tolerance));
} }
if (bufferHandle) { if (bufferHandle) {
bufferHandles.push_back(bufferHandle); bufferHandles.push_back(bufferHandle);
@ -121,9 +128,11 @@ std::vector<const native_handle_t*> Gralloc::allocate(const BufferDescriptor& de
} }
if (outStride) { if (outStride) {
*outStride = tmpStride; *outStride = stride;
} }
}); };
rawAllocate(descriptor, count, callback);
if (::testing::Test::HasFatalFailure()) { if (::testing::Test::HasFatalFailure()) {
bufferHandles.clear(); bufferHandles.clear();
@ -147,6 +156,23 @@ const native_handle_t* Gralloc::allocate(const IMapper::BufferDescriptorInfo& de
return buffers[0]; return buffers[0];
} }
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);
}
}
sp<IMapper> Gralloc::getMapper() const { sp<IMapper> Gralloc::getMapper() const {
return mMapper; return mMapper;
} }

View file

@ -20,6 +20,8 @@
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include <aidl/android/hardware/graphics/allocator/AllocationError.h>
#include <aidl/android/hardware/graphics/allocator/IAllocator.h>
#include <android/hardware/graphics/allocator/4.0/IAllocator.h> #include <android/hardware/graphics/allocator/4.0/IAllocator.h>
#include <android/hardware/graphics/mapper/4.0/IMapper.h> #include <android/hardware/graphics/mapper/4.0/IMapper.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -51,9 +53,33 @@ class Gralloc {
const std::string& mapperServiceName = "default", bool errOnFailure = true); const std::string& mapperServiceName = "default", bool errOnFailure = true);
~Gralloc(); ~Gralloc();
static Error toHidlError(aidl::android::hardware::graphics::allocator::AllocationError error) {
switch (error) {
case aidl::android::hardware::graphics::allocator::AllocationError::BAD_DESCRIPTOR:
return Error::BAD_DESCRIPTOR;
case aidl::android::hardware::graphics::allocator::AllocationError::NO_RESOURCES:
return Error::NO_RESOURCES;
case aidl::android::hardware::graphics::allocator::AllocationError::UNSUPPORTED:
return Error::UNSUPPORTED;
}
}
static Error toHidlError(const ndk::ScopedAStatus& status) {
if (status.isOk()) {
return Error::NONE;
}
if (status.getExceptionCode() != EX_SERVICE_SPECIFIC) {
return Error::NO_RESOURCES;
}
return toHidlError(
static_cast<aidl::android::hardware::graphics::allocator::AllocationError>(
status.getServiceSpecificError()));
}
// IAllocator methods // IAllocator methods
sp<IAllocator> getAllocator() const; bool hasAllocator() { return mHidlAllocator != nullptr || mAidlAllocator != nullptr; }
// When import is false, this simply calls IAllocator::allocate. When import // When import is false, this simply calls IAllocator::allocate. When import
// is true, the returned buffers are also imported into the mapper. // is true, the returned buffers are also imported into the mapper.
@ -81,6 +107,10 @@ class Gralloc {
return allocate(descriptorInfo, import, Tolerance::kToleranceStrict, outStride); return allocate(descriptorInfo, import, Tolerance::kToleranceStrict, outStride);
} }
// Dispatches directly to the allocator
void rawAllocate(const BufferDescriptor& descriptor, uint32_t count,
std::function<void(Error, uint32_t, const hidl_vec<hidl_handle>&)> callback);
// IMapper methods // IMapper methods
sp<IMapper> getMapper() const; sp<IMapper> getMapper() const;
@ -143,7 +173,8 @@ class Gralloc {
return cloneBuffer(rawHandle, Tolerance::kToleranceStrict); return cloneBuffer(rawHandle, Tolerance::kToleranceStrict);
} }
sp<IAllocator> mAllocator; sp<IAllocator> mHidlAllocator;
std::shared_ptr<aidl::android::hardware::graphics::allocator::IAllocator> mAidlAllocator;
sp<IMapper> mMapper; sp<IMapper> mMapper;
// Keep track of all cloned and imported handles. When a test fails with // Keep track of all cloned and imported handles. When a test fails with

View file

@ -25,20 +25,27 @@ package {
cc_test { cc_test {
name: "VtsHalGraphicsMapperV4_0TargetTest", name: "VtsHalGraphicsMapperV4_0TargetTest",
defaults: ["VtsHalTargetTestDefaults"], defaults: [
"VtsHalTargetTestDefaults",
"use_libaidlvintf_gtest_helper_static",
],
srcs: ["VtsHalGraphicsMapperV4_0TargetTest.cpp"], srcs: ["VtsHalGraphicsMapperV4_0TargetTest.cpp"],
static_libs: [ static_libs: [
"android.hardware.graphics.common-V3-ndk", "android.hardware.graphics.common-V3-ndk",
"android.hardware.graphics.mapper@4.0-vts", "android.hardware.graphics.mapper@4.0-vts",
"libaidlcommonsupport",
"libgralloctypes", "libgralloctypes",
"libsync", "libsync",
], ],
shared_libs: [ shared_libs: [
"android.hardware.graphics.allocator-V1-ndk",
"android.hardware.graphics.allocator@4.0", "android.hardware.graphics.allocator@4.0",
"android.hardware.graphics.common@1.0", "android.hardware.graphics.common@1.0",
"android.hardware.graphics.common@1.1", "android.hardware.graphics.common@1.1",
"android.hardware.graphics.common@1.2", "android.hardware.graphics.common@1.2",
"android.hardware.graphics.mapper@4.0", "android.hardware.graphics.mapper@4.0",
"libbinder_ndk",
"libvndksupport",
], ],
header_libs: [ header_libs: [
"libsystem_headers", "libsystem_headers",

View file

@ -21,8 +21,12 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <aidl/Vintf.h>
#include <aidl/android/hardware/graphics/allocator/AllocationError.h>
#include <aidl/android/hardware/graphics/allocator/AllocationResult.h>
#include <aidl/android/hardware/graphics/common/PixelFormat.h> #include <aidl/android/hardware/graphics/common/PixelFormat.h>
#include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h> #include <aidl/android/hardware/graphics/common/PlaneLayoutComponentType.h>
#include <aidlcommonsupport/NativeHandle.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/unique_fd.h> #include <android-base/unique_fd.h>
@ -72,7 +76,7 @@ class GraphicsMapperHidlTest
void SetUp() override { void SetUp() override {
ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>(std::get<0>(GetParam()), ASSERT_NO_FATAL_FAILURE(mGralloc = std::make_unique<Gralloc>(std::get<0>(GetParam()),
std::get<1>(GetParam()))); std::get<1>(GetParam())));
ASSERT_NE(nullptr, mGralloc->getAllocator().get()); ASSERT_TRUE(mGralloc->hasAllocator());
ASSERT_NE(nullptr, mGralloc->getMapper().get()); ASSERT_NE(nullptr, mGralloc->getMapper().get());
mDummyDescriptorInfo.name = "dummy"; mDummyDescriptorInfo.name = "dummy";
@ -504,8 +508,8 @@ TEST_P(GraphicsMapperHidlTest, AllocatorAllocate) {
TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNegative) { TEST_P(GraphicsMapperHidlTest, AllocatorAllocateNegative) {
// this assumes any valid descriptor is non-empty // this assumes any valid descriptor is non-empty
BufferDescriptor descriptor; BufferDescriptor descriptor;
mGralloc->getAllocator()->allocate(descriptor, 1,
[&](const auto& tmpError, const auto&, const auto&) { mGralloc->rawAllocate(descriptor, 1, [&](const auto& tmpError, const auto&, const auto&) {
EXPECT_EQ(Error::BAD_DESCRIPTOR, tmpError); EXPECT_EQ(Error::BAD_DESCRIPTOR, tmpError);
}); });
} }
@ -535,9 +539,9 @@ TEST_P(GraphicsMapperHidlTest, AllocatorAllocateThreaded) {
std::atomic<uint64_t> allocationCount(0); std::atomic<uint64_t> allocationCount(0);
auto threadLoop = [&]() { auto threadLoop = [&]() {
while (!timeUp) { while (!timeUp) {
mGralloc->getAllocator()->allocate( mGralloc->rawAllocate(descriptor, 1, [&](const auto&, const auto&, const auto&) {
descriptor, 1, allocationCount++;
[&](const auto&, const auto&, const auto&) { allocationCount++; }); });
} }
}; };
@ -2755,8 +2759,9 @@ TEST_P(GraphicsMapperHidlTest, GetLargeReservedRegion) {
BufferDescriptor descriptor; BufferDescriptor descriptor;
ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(info)); ASSERT_NO_FATAL_FAILURE(descriptor = mGralloc->createDescriptor(info));
Error err; Error err = Error::NONE;
mGralloc->getAllocator()->allocate(
mGralloc->rawAllocate(
descriptor, 1, [&](const auto& tmpError, const auto&, const auto& tmpBuffers) { descriptor, 1, [&](const auto& tmpError, const auto&, const auto& tmpBuffers) {
err = tmpError; err = tmpError;
if (err == Error::NONE) { if (err == Error::NONE) {
@ -2827,11 +2832,27 @@ TEST_P(GraphicsMapperHidlTest, GetReservedRegionBadBuffer) {
} }
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsMapperHidlTest); GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsMapperHidlTest);
namespace {
std::vector<std::string> getAllocatorInstances() {
std::vector<std::string> instances;
for (auto halInstance : android::hardware::getAllHalInstanceNames(IAllocator::descriptor)) {
instances.emplace_back(std::move(halInstance));
}
for (auto aidlInstance : getAidlHalInstanceNames(
aidl::android::hardware::graphics::allocator::IAllocator::descriptor)) {
instances.emplace_back(std::move(aidlInstance));
}
return instances;
}
} // namespace
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
PerInstance, GraphicsMapperHidlTest, PerInstance, GraphicsMapperHidlTest,
testing::Combine( testing::Combine(
testing::ValuesIn( testing::ValuesIn(getAllocatorInstances()),
android::hardware::getAllHalInstanceNames(IAllocator::descriptor)),
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IMapper::descriptor))), testing::ValuesIn(android::hardware::getAllHalInstanceNames(IMapper::descriptor))),
android::hardware::PrintInstanceTupleNameToString<>); android::hardware::PrintInstanceTupleNameToString<>);