diff --git a/sensors/1.0/vts/functional/Android.bp b/sensors/1.0/vts/functional/Android.bp index aaefccbe19..4941ac2d52 100644 --- a/sensors/1.0/vts/functional/Android.bp +++ b/sensors/1.0/vts/functional/Android.bp @@ -23,11 +23,6 @@ cc_test { "VtsHalSensorsV1_0TargetTest.cpp", ], static_libs: [ - "android.hardware.graphics.allocator@2.0", - "android.hardware.graphics.allocator@3.0", - "android.hardware.graphics.mapper@2.0", - "android.hardware.graphics.mapper@2.1", - "android.hardware.graphics.mapper@3.0", "android.hardware.sensors@1.0", "VtsHalSensorsTargetTestUtils", ], diff --git a/sensors/2.0/vts/functional/Android.bp b/sensors/2.0/vts/functional/Android.bp index 08c59b6378..c0803c7e6a 100644 --- a/sensors/2.0/vts/functional/Android.bp +++ b/sensors/2.0/vts/functional/Android.bp @@ -25,11 +25,6 @@ cc_test { "android.hardware.sensors@2.X-shared-utils", ], static_libs: [ - "android.hardware.graphics.allocator@2.0", - "android.hardware.graphics.allocator@3.0", - "android.hardware.graphics.mapper@2.0", - "android.hardware.graphics.mapper@2.1", - "android.hardware.graphics.mapper@3.0", "android.hardware.sensors@1.0", "android.hardware.sensors@1.0-convert", "android.hardware.sensors@2.0", diff --git a/sensors/2.1/vts/functional/Android.bp b/sensors/2.1/vts/functional/Android.bp index c4f5e9d2d7..920b6423bf 100644 --- a/sensors/2.1/vts/functional/Android.bp +++ b/sensors/2.1/vts/functional/Android.bp @@ -27,11 +27,6 @@ cc_test { "android.hardware.sensors@2.X-shared-utils", ], static_libs: [ - "android.hardware.graphics.allocator@2.0", - "android.hardware.graphics.allocator@3.0", - "android.hardware.graphics.mapper@2.0", - "android.hardware.graphics.mapper@2.1", - "android.hardware.graphics.mapper@3.0", "android.hardware.sensors@1.0", "android.hardware.sensors@1.0-convert", "android.hardware.sensors@2.0", diff --git a/sensors/common/vts/2_X/Android.bp b/sensors/common/vts/2_X/Android.bp index 8cdb5d181a..e5eceb5ed5 100644 --- a/sensors/common/vts/2_X/Android.bp +++ b/sensors/common/vts/2_X/Android.bp @@ -29,11 +29,6 @@ cc_defaults { "libbinder", ], static_libs: [ - "android.hardware.graphics.allocator@2.0", - "android.hardware.graphics.allocator@3.0", - "android.hardware.graphics.mapper@2.0", - "android.hardware.graphics.mapper@2.1", - "android.hardware.graphics.mapper@3.0", "android.hardware.sensors@1.0", "android.hardware.sensors@1.0-convert", "android.hardware.sensors@2.0", diff --git a/sensors/common/vts/utils/Android.bp b/sensors/common/vts/utils/Android.bp index ca4346a963..baaed6cc20 100644 --- a/sensors/common/vts/utils/Android.bp +++ b/sensors/common/vts/utils/Android.bp @@ -31,13 +31,17 @@ cc_library_static { "libutils", ], static_libs: [ - "android.hardware.graphics.allocator@2.0", - "android.hardware.graphics.allocator@3.0", - "android.hardware.graphics.mapper@2.0", - "android.hardware.graphics.mapper@2.1", - "android.hardware.graphics.mapper@3.0", "android.hardware.sensors@1.0", "android.hardware.sensors@2.0", "android.hardware.sensors@2.1", ], + whole_static_libs: [ + "android.hardware.graphics.allocator@2.0", + "android.hardware.graphics.allocator@3.0", + "android.hardware.graphics.allocator@4.0", + "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@2.1", + "android.hardware.graphics.mapper@3.0", + "android.hardware.graphics.mapper@4.0", + ], } diff --git a/sensors/common/vts/utils/GrallocWrapper.cpp b/sensors/common/vts/utils/GrallocWrapper.cpp index e63faa2e1c..47d1f42152 100644 --- a/sensors/common/vts/utils/GrallocWrapper.cpp +++ b/sensors/common/vts/utils/GrallocWrapper.cpp @@ -18,9 +18,11 @@ #include #include +#include #include #include #include +#include #include @@ -29,19 +31,19 @@ using IAllocator2 = ::android::hardware::graphics::allocator::V2_0::IAllocator; using IAllocator3 = ::android::hardware::graphics::allocator::V3_0::IAllocator; +using IAllocator4 = ::android::hardware::graphics::allocator::V4_0::IAllocator; using IMapper2 = ::android::hardware::graphics::mapper::V2_0::IMapper; using IMapper2_1 = ::android::hardware::graphics::mapper::V2_1::IMapper; using IMapper3 = ::android::hardware::graphics::mapper::V3_0::IMapper; +using IMapper4 = ::android::hardware::graphics::mapper::V4_0::IMapper; using Error2 = ::android::hardware::graphics::mapper::V2_0::Error; using Error3 = ::android::hardware::graphics::mapper::V3_0::Error; +using Error4 = ::android::hardware::graphics::mapper::V4_0::Error; using ::android::hardware::graphics::common::V1_0::BufferUsage; using ::android::hardware::graphics::common::V1_0::PixelFormat; -// This is a typedef to the same underlying type across v2.0 and v3.0 -using ::android::hardware::graphics::mapper::V2_0::BufferDescriptor; - using ::android::hardware::hidl_handle; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; @@ -58,7 +60,6 @@ class IGrallocHalWrapper { virtual ~IGrallocHalWrapper() = default; // IAllocator - virtual std::string dumpDebugInfo() = 0; virtual native_handle_t* allocate(uint32_t size) = 0; virtual void freeBuffer(native_handle_t* bufferHandle) = 0; @@ -75,6 +76,24 @@ bool failed(Error2 error) { bool failed(Error3 error) { return (error != Error3::NONE); } +bool failed(Error4 error) { + return (error != Error4::NONE); +} + +template +struct FirstArg; + +// Template specialization for pointer to a non-static member function, which exposes +// the type of the first argument given to said function +template +struct FirstArg { + using type = Arg1; +}; + +// Alias to FirstArg which also removes any reference type and const associated +template +using BaseTypeOfFirstArg = typename std::remove_const< + typename std::remove_reference::type>::type>::type; // Since all the type and function names are the same for the things we use across the major HAL // versions, we use template magic to avoid repeating ourselves. @@ -88,7 +107,6 @@ class GrallocHalWrapper : public IGrallocHalWrapper { } } - virtual std::string dumpDebugInfo() override; virtual native_handle_t* allocate(uint32_t size) override; virtual void freeBuffer(native_handle_t* bufferHandle) override; @@ -101,21 +119,19 @@ class GrallocHalWrapper : public IGrallocHalWrapper { sp mAllocator; sp mMapper; - BufferDescriptor getDescriptor(uint32_t size); + // v2.0 and v3.0 use vec for BufferDescriptor, but v4.0 uses vec, so use + // some template magic to deduce the right type based off of the first argument to allocate(), + // which is always the version-specific BufferDescriptor type + typedef BaseTypeOfFirstArg BufferDescriptorT; + + BufferDescriptorT getDescriptor(uint32_t size); native_handle_t* importBuffer(const hidl_handle& rawHandle); }; -template -std::string GrallocHalWrapper::dumpDebugInfo() { - std::string debugInfo; - mAllocator->dumpDebugInfo([&](const hidl_string& tmpDebugInfo) { debugInfo = tmpDebugInfo; }); - return debugInfo; -} - template native_handle_t* GrallocHalWrapper::allocate(uint32_t size) { constexpr uint32_t kBufferCount = 1; - BufferDescriptor descriptor = getDescriptor(size); + BufferDescriptorT descriptor = getDescriptor(size); native_handle_t* bufferHandle = nullptr; auto callback = [&](auto error, uint32_t /*stride*/, const hidl_vec& buffers) { @@ -142,7 +158,8 @@ void GrallocHalWrapper::freeBuffer(native_handle_t* bufferH } template -BufferDescriptor GrallocHalWrapper::getDescriptor(uint32_t size) { +typename GrallocHalWrapper::BufferDescriptorT +GrallocHalWrapper::getDescriptor(uint32_t size) { typename MapperT::BufferDescriptorInfo descriptorInfo = { .width = size, .height = 1, @@ -151,8 +168,8 @@ BufferDescriptor GrallocHalWrapper::getDescriptor(uint32_t .usage = kBufferUsage, }; - BufferDescriptor descriptor; - auto callback = [&](auto error, const BufferDescriptor& tmpDescriptor) { + BufferDescriptorT descriptor; + auto callback = [&](auto error, const BufferDescriptorT& tmpDescriptor) { if (failed(error)) { ALOGE("Failed to create descriptor: %" PRId32, static_cast(error)); } else { @@ -189,7 +206,7 @@ void* GrallocHalWrapper::lock(native_handle_t* bufferHandle void* data = nullptr; mMapper->lock(bufferHandle, kBufferUsage, accessRegion, acquireFenceHandle, - [&](auto error, void* tmpData, ...) { // V3_0 passes extra args we don't use + [&](auto error, void* tmpData, ...) { // V3/4 pass extra args we don't use if (failed(error)) { ALOGE("Failed to lock buffer %p: %" PRId32, bufferHandle, static_cast(error)); @@ -214,28 +231,40 @@ void GrallocHalWrapper::unlock(native_handle_t* bufferHandl } // anonymous namespace GrallocWrapper::GrallocWrapper() { - sp allocator3 = IAllocator3::getService(); - sp mapper3 = IMapper3::getService(); + sp allocator4 = IAllocator4::getService(); + sp mapper4 = IMapper4::getService(); - if (allocator3 != nullptr && mapper3 != nullptr) { + if (allocator4 != nullptr && mapper4 != nullptr) { + ALOGD("Using IAllocator/IMapper v4.0"); mGrallocHal = std::unique_ptr( - new GrallocHalWrapper(allocator3, mapper3)); + new GrallocHalWrapper(allocator4, mapper4)); } else { - ALOGD("Graphics HALs 3.0 not found (allocator %d mapper %d), falling back to 2.x", - (allocator3 != nullptr), (mapper3 != nullptr)); + ALOGD("Graphics HALs 4.0 not found (allocator %d mapper %d), falling back to 3.0", + (allocator4 != nullptr), (mapper4 != nullptr)); - sp allocator2 = IAllocator2::getService(); - sp mapper2 = IMapper2_1::getService(); - if (mapper2 == nullptr) { - mapper2 = IMapper2::getService(); - } + sp allocator3 = IAllocator3::getService(); + sp mapper3 = IMapper3::getService(); - if (allocator2 != nullptr && mapper2 != nullptr) { + if (allocator3 != nullptr && mapper3 != nullptr) { mGrallocHal = std::unique_ptr( - new GrallocHalWrapper(allocator2, mapper2)); + new GrallocHalWrapper(allocator3, mapper3)); } else { - ALOGE("Couldn't open 2.x/3.0 graphics HALs (2.x allocator %d mapper %d)", - (allocator2 != nullptr), (mapper2 != nullptr)); + ALOGD("Graphics HALs 3.0 not found (allocator %d mapper %d), falling back to 2.x", + (allocator3 != nullptr), (mapper3 != nullptr)); + + sp allocator2 = IAllocator2::getService(); + sp mapper2 = IMapper2_1::getService(); + if (mapper2 == nullptr) { + mapper2 = IMapper2::getService(); + } + + if (allocator2 != nullptr && mapper2 != nullptr) { + mGrallocHal = std::unique_ptr( + new GrallocHalWrapper(allocator2, mapper2)); + } else { + ALOGE("Couldn't open graphics HALs (2.x allocator %d mapper %d)", + (allocator2 != nullptr), (mapper2 != nullptr)); + } } } } @@ -248,10 +277,6 @@ GrallocWrapper::~GrallocWrapper() { mAllocatedBuffers.clear(); } -std::string GrallocWrapper::dumpDebugInfo() { - return mGrallocHal->dumpDebugInfo(); -} - std::pair GrallocWrapper::allocate(uint32_t size) { native_handle_t* bufferHandle = mGrallocHal->allocate(size); void* buffer = nullptr; diff --git a/sensors/common/vts/utils/include/sensors-vts-utils/GrallocWrapper.h b/sensors/common/vts/utils/include/sensors-vts-utils/GrallocWrapper.h index 41e6334893..ebbcb2c06f 100644 --- a/sensors/common/vts/utils/include/sensors-vts-utils/GrallocWrapper.h +++ b/sensors/common/vts/utils/include/sensors-vts-utils/GrallocWrapper.h @@ -37,8 +37,6 @@ class GrallocWrapper { // returns false, other methods are not safe to call. bool isInitialized() const { return (mGrallocHal != nullptr); }; - std::string dumpDebugInfo(); - // Allocates a gralloc buffer suitable for direct channel sensors usage with the given size. // The buffer should be freed using freeBuffer when it's not needed anymore; otherwise it'll // be freed when this object is destroyed.