diff --git a/camera/common/1.0/default/Android.bp b/camera/common/1.0/default/Android.bp index 21f81f5acc..3e5c6d7812 100644 --- a/camera/common/1.0/default/Android.bp +++ b/camera/common/1.0/default/Android.bp @@ -20,6 +20,7 @@ cc_library_static { "libhardware", "libcamera_metadata", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "libexif", ], include_dirs: ["system/media/private/camera/include"], diff --git a/camera/common/1.0/default/HandleImporter.cpp b/camera/common/1.0/default/HandleImporter.cpp index 21706a84a3..b8c40e95b8 100644 --- a/camera/common/1.0/default/HandleImporter.cpp +++ b/camera/common/1.0/default/HandleImporter.cpp @@ -25,7 +25,9 @@ namespace common { namespace V1_0 { namespace helper { -using MapperError = android::hardware::graphics::mapper::V2_0::Error; +using MapperErrorV2 = android::hardware::graphics::mapper::V2_0::Error; +using MapperErrorV3 = android::hardware::graphics::mapper::V3_0::Error; +using IMapperV3 = android::hardware::graphics::mapper::V3_0::IMapper; HandleImporter::HandleImporter() : mInitialized(false) {} @@ -34,8 +36,14 @@ void HandleImporter::initializeLocked() { return; } - mMapper = IMapper::getService(); - if (mMapper == nullptr) { + mMapperV3 = IMapperV3::getService(); + if (mMapperV3 != nullptr) { + mInitialized = true; + return; + } + + mMapperV2 = IMapper::getService(); + if (mMapperV2 == nullptr) { ALOGE("%s: cannnot acccess graphics mapper HAL!", __FUNCTION__); return; } @@ -45,10 +53,90 @@ void HandleImporter::initializeLocked() { } void HandleImporter::cleanup() { - mMapper.clear(); + mMapperV3.clear(); + mMapperV2.clear(); mInitialized = false; } +template +bool HandleImporter::importBufferInternal(const sp mapper, buffer_handle_t& handle) { + E error; + buffer_handle_t importedHandle; + auto ret = mapper->importBuffer( + hidl_handle(handle), + [&](const auto& tmpError, const auto& tmpBufferHandle) { + error = tmpError; + importedHandle = static_cast(tmpBufferHandle); + }); + + if (!ret.isOk()) { + ALOGE("%s: mapper importBuffer failed: %s", + __FUNCTION__, ret.description().c_str()); + return false; + } + + if (error != E::NONE) { + return false; + } + + handle = importedHandle; + return true; +} + +template +YCbCrLayout HandleImporter::lockYCbCrInternal(const sp mapper, buffer_handle_t& buf, + uint64_t cpuUsage, const IMapper::Rect& accessRegion) { + hidl_handle acquireFenceHandle; + auto buffer = const_cast(buf); + YCbCrLayout layout = {}; + + typename M::Rect accessRegionCopy = {accessRegion.left, accessRegion.top, + accessRegion.width, accessRegion.height}; + mapper->lockYCbCr(buffer, cpuUsage, accessRegionCopy, acquireFenceHandle, + [&](const auto& tmpError, const auto& tmpLayout) { + if (tmpError == E::NONE) { + // Member by member copy from different versions of YCbCrLayout. + layout.y = tmpLayout.y; + layout.cb = tmpLayout.cb; + layout.cr = tmpLayout.cr; + layout.yStride = tmpLayout.yStride; + layout.cStride = tmpLayout.cStride; + layout.chromaStep = tmpLayout.chromaStep; + } else { + ALOGE("%s: failed to lockYCbCr error %d!", __FUNCTION__, tmpError); + } + }); + return layout; +} + +template +int HandleImporter::unlockInternal(const sp mapper, buffer_handle_t& buf) { + int releaseFence = -1; + auto buffer = const_cast(buf); + + mapper->unlock( + buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) { + if (tmpError == E::NONE) { + auto fenceHandle = tmpReleaseFence.getNativeHandle(); + if (fenceHandle) { + if (fenceHandle->numInts != 0 || fenceHandle->numFds != 1) { + ALOGE("%s: bad release fence numInts %d numFds %d", + __FUNCTION__, fenceHandle->numInts, fenceHandle->numFds); + return; + } + releaseFence = dup(fenceHandle->data[0]); + if (releaseFence < 0) { + ALOGE("%s: bad release fence FD %d", + __FUNCTION__, releaseFence); + } + } + } else { + ALOGE("%s: failed to unlock error %d!", __FUNCTION__, tmpError); + } + }); + return releaseFence; +} + // In IComposer, any buffer_handle_t is owned by the caller and we need to // make a clone for hwcomposer2. We also need to translate empty handle // to nullptr. This function does that, in-place. @@ -63,33 +151,16 @@ bool HandleImporter::importBuffer(buffer_handle_t& handle) { initializeLocked(); } - if (mMapper == nullptr) { - ALOGE("%s: mMapper is null!", __FUNCTION__); - return false; + if (mMapperV3 != nullptr) { + return importBufferInternal(mMapperV3, handle); } - MapperError error; - buffer_handle_t importedHandle; - auto ret = mMapper->importBuffer( - hidl_handle(handle), - [&](const auto& tmpError, const auto& tmpBufferHandle) { - error = tmpError; - importedHandle = static_cast(tmpBufferHandle); - }); - - if (!ret.isOk()) { - ALOGE("%s: mapper importBuffer failed: %s", - __FUNCTION__, ret.description().c_str()); - return false; + if (mMapperV2 != nullptr) { + return importBufferInternal(mMapperV2, handle); } - if (error != MapperError::NONE) { - return false; - } - - handle = importedHandle; - - return true; + ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); + return false; } void HandleImporter::freeBuffer(buffer_handle_t handle) { @@ -98,15 +169,23 @@ void HandleImporter::freeBuffer(buffer_handle_t handle) { } Mutex::Autolock lock(mLock); - if (mMapper == nullptr) { - ALOGE("%s: mMapper is null!", __FUNCTION__); + if (mMapperV3 == nullptr && mMapperV2 == nullptr) { + ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return; } - auto ret = mMapper->freeBuffer(const_cast(handle)); - if (!ret.isOk()) { - ALOGE("%s: mapper freeBuffer failed: %s", - __FUNCTION__, ret.description().c_str()); + if (mMapperV3 != nullptr) { + auto ret = mMapperV3->freeBuffer(const_cast(handle)); + if (!ret.isOk()) { + ALOGE("%s: mapper freeBuffer failed: %s", + __FUNCTION__, ret.description().c_str()); + } + } else { + auto ret = mMapperV2->freeBuffer(const_cast(handle)); + if (!ret.isOk()) { + ALOGE("%s: mapper freeBuffer failed: %s", + __FUNCTION__, ret.description().c_str()); + } } } @@ -138,91 +217,82 @@ void* HandleImporter::lock( buffer_handle_t& buf, uint64_t cpuUsage, size_t size) { Mutex::Autolock lock(mLock); void *ret = 0; - IMapper::Rect accessRegion { 0, 0, static_cast(size), 1 }; if (!mInitialized) { initializeLocked(); } - if (mMapper == nullptr) { - ALOGE("%s: mMapper is null!", __FUNCTION__); + if (mMapperV3 == nullptr && mMapperV2 == nullptr) { + ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return ret; } hidl_handle acquireFenceHandle; auto buffer = const_cast(buf); - mMapper->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle, - [&](const auto& tmpError, const auto& tmpPtr) { - if (tmpError == MapperError::NONE) { - ret = tmpPtr; - } else { - ALOGE("%s: failed to lock error %d!", - __FUNCTION__, tmpError); - } - }); + if (mMapperV3 != nullptr) { + IMapperV3::Rect accessRegion { 0, 0, static_cast(size), 1 }; + // No need to use bytesPerPixel and bytesPerStride because we are using + // an 1-D buffer and accressRegion. + mMapperV3->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle, + [&](const auto& tmpError, const auto& tmpPtr, const auto& /*bytesPerPixel*/, + const auto& /*bytesPerStride*/) { + if (tmpError == MapperErrorV3::NONE) { + ret = tmpPtr; + } else { + ALOGE("%s: failed to lock error %d!", + __FUNCTION__, tmpError); + } + }); + } else { + IMapper::Rect accessRegion { 0, 0, static_cast(size), 1 }; + mMapperV2->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle, + [&](const auto& tmpError, const auto& tmpPtr) { + if (tmpError == MapperErrorV2::NONE) { + ret = tmpPtr; + } else { + ALOGE("%s: failed to lock error %d!", + __FUNCTION__, tmpError); + } + }); + } ALOGV("%s: ptr %p size: %zu", __FUNCTION__, ret, size); return ret; } - YCbCrLayout HandleImporter::lockYCbCr( buffer_handle_t& buf, uint64_t cpuUsage, const IMapper::Rect& accessRegion) { Mutex::Autolock lock(mLock); - YCbCrLayout layout = {}; if (!mInitialized) { initializeLocked(); } - if (mMapper == nullptr) { - ALOGE("%s: mMapper is null!", __FUNCTION__); - return layout; + if (mMapperV3 != nullptr) { + return lockYCbCrInternal( + mMapperV3, buf, cpuUsage, accessRegion); } - hidl_handle acquireFenceHandle; - auto buffer = const_cast(buf); - mMapper->lockYCbCr(buffer, cpuUsage, accessRegion, acquireFenceHandle, - [&](const auto& tmpError, const auto& tmpLayout) { - if (tmpError == MapperError::NONE) { - layout = tmpLayout; - } else { - ALOGE("%s: failed to lockYCbCr error %d!", __FUNCTION__, tmpError); - } - }); + if (mMapperV2 != nullptr) { + return lockYCbCrInternal( + mMapperV2, buf, cpuUsage, accessRegion); + } - ALOGV("%s: layout y %p cb %p cr %p y_str %d c_str %d c_step %d", - __FUNCTION__, layout.y, layout.cb, layout.cr, - layout.yStride, layout.cStride, layout.chromaStep); - return layout; + ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); + return {}; } int HandleImporter::unlock(buffer_handle_t& buf) { - int releaseFence = -1; - auto buffer = const_cast(buf); - mMapper->unlock( - buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) { - if (tmpError == MapperError::NONE) { - auto fenceHandle = tmpReleaseFence.getNativeHandle(); - if (fenceHandle) { - if (fenceHandle->numInts != 0 || fenceHandle->numFds != 1) { - ALOGE("%s: bad release fence numInts %d numFds %d", - __FUNCTION__, fenceHandle->numInts, fenceHandle->numFds); - return; - } - releaseFence = dup(fenceHandle->data[0]); - if (releaseFence <= 0) { - ALOGE("%s: bad release fence FD %d", - __FUNCTION__, releaseFence); - } - } - } else { - ALOGE("%s: failed to unlock error %d!", __FUNCTION__, tmpError); - } - }); + if (mMapperV3 != nullptr) { + return unlockInternal(mMapperV3, buf); + } + if (mMapperV2 != nullptr) { + return unlockInternal(mMapperV2, buf); + } - return releaseFence; + ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); + return -1; } } // namespace helper diff --git a/camera/common/1.0/default/include/HandleImporter.h b/camera/common/1.0/default/include/HandleImporter.h index f9cd9fb604..a93d4554ad 100644 --- a/camera/common/1.0/default/include/HandleImporter.h +++ b/camera/common/1.0/default/include/HandleImporter.h @@ -19,6 +19,7 @@ #include #include +#include #include using android::hardware::graphics::mapper::V2_0::IMapper; @@ -57,10 +58,18 @@ private: void initializeLocked(); void cleanup(); + template + bool importBufferInternal(const sp mapper, buffer_handle_t& handle); + template + YCbCrLayout lockYCbCrInternal(const sp mapper, buffer_handle_t& buf, uint64_t cpuUsage, + const IMapper::Rect& accessRegion); + template + int unlockInternal(const sp mapper, buffer_handle_t& buf); + Mutex mLock; bool mInitialized; - sp mMapper; - + sp mMapperV2; + sp mMapperV3; }; } // namespace helper diff --git a/camera/device/1.0/default/Android.bp b/camera/device/1.0/default/Android.bp index 4a7fc9c1e0..aa3b941c2e 100644 --- a/camera/device/1.0/default/Android.bp +++ b/camera/device/1.0/default/Android.bp @@ -15,6 +15,7 @@ cc_library_shared { "android.hardware.camera.common@1.0", "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "android.hardware.graphics.common@1.0", "android.hidl.allocator@1.0", "android.hidl.memory@1.0", diff --git a/camera/device/3.2/default/Android.bp b/camera/device/3.2/default/Android.bp index 325c0085a4..edb008ed62 100644 --- a/camera/device/3.2/default/Android.bp +++ b/camera/device/3.2/default/Android.bp @@ -13,6 +13,7 @@ cc_library_shared { "android.hardware.camera.device@3.2", "android.hardware.camera.provider@2.4", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "liblog", "libhardware", "libcamera_metadata", diff --git a/camera/device/3.3/default/Android.bp b/camera/device/3.3/default/Android.bp index b1e9b46d8f..39d379d049 100644 --- a/camera/device/3.3/default/Android.bp +++ b/camera/device/3.3/default/Android.bp @@ -15,6 +15,7 @@ cc_library_shared { "android.hardware.camera.device@3.3", "android.hardware.camera.provider@2.4", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "liblog", "libhardware", "libcamera_metadata", diff --git a/camera/device/3.4/default/Android.bp b/camera/device/3.4/default/Android.bp index 272bf42baa..c22b13c2c4 100644 --- a/camera/device/3.4/default/Android.bp +++ b/camera/device/3.4/default/Android.bp @@ -48,6 +48,7 @@ cc_library_shared { "android.hardware.camera.device@3.4", "android.hardware.camera.provider@2.4", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "liblog", "libhardware", "libcamera_metadata", @@ -84,6 +85,7 @@ cc_library_shared { "android.hardware.camera.device@3.4", "android.hardware.camera.provider@2.4", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "liblog", "libhardware", "libcamera_metadata", diff --git a/camera/device/3.5/default/Android.bp b/camera/device/3.5/default/Android.bp index 7a48865a3b..26b3b6734b 100644 --- a/camera/device/3.5/default/Android.bp +++ b/camera/device/3.5/default/Android.bp @@ -49,6 +49,7 @@ cc_library_shared { "android.hardware.camera.device@3.5", "android.hardware.camera.provider@2.4", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "liblog", "libhardware", "libcamera_metadata", @@ -82,6 +83,7 @@ cc_library_shared { "android.hardware.camera.device@3.5", "android.hardware.camera.provider@2.4", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "liblog", "libhardware", "libcamera_metadata", diff --git a/camera/provider/2.4/default/Android.bp b/camera/provider/2.4/default/Android.bp index 9d73934de0..cb78fcb859 100644 --- a/camera/provider/2.4/default/Android.bp +++ b/camera/provider/2.4/default/Android.bp @@ -12,6 +12,7 @@ cc_library_shared { "android.hardware.camera.device@3.5", "android.hardware.camera.provider@2.4", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "android.hidl.allocator@1.0", "android.hidl.memory@1.0", "camera.device@1.0-impl", @@ -50,6 +51,7 @@ cc_library_shared { "android.hardware.camera.device@3.5", "android.hardware.camera.provider@2.4", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "android.hidl.allocator@1.0", "android.hidl.memory@1.0", "camera.device@3.3-impl", diff --git a/camera/provider/2.4/vts/functional/Android.bp b/camera/provider/2.4/vts/functional/Android.bp index 5fb1fd852d..2c3ed37a6a 100644 --- a/camera/provider/2.4/vts/functional/Android.bp +++ b/camera/provider/2.4/vts/functional/Android.bp @@ -42,8 +42,10 @@ cc_test { "android.hardware.camera.provider@2.4", "android.hardware.camera.provider@2.5", "android.hardware.graphics.allocator@2.0", + "android.hardware.graphics.allocator@3.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.mapper@2.0", + "android.hardware.graphics.mapper@3.0", "android.hidl.allocator@1.0", "libgrallocusage", "libhidlmemory", diff --git a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp index 33d23a0030..200dd3f199 100644 --- a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp +++ b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp @@ -54,8 +54,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -6104,36 +6106,66 @@ void CameraHidlTest::allocateGraphicBuffer(uint32_t width, uint32_t height, uint sp allocator = android::hardware::graphics::allocator::V2_0::IAllocator::getService(); - ASSERT_NE(nullptr, allocator.get()); + sp allocatorV3 = + android::hardware::graphics::allocator::V3_0::IAllocator::getService(); + sp mapperV3 = + android::hardware::graphics::mapper::V3_0::IMapper::getService(); sp mapper = android::hardware::graphics::mapper::V2_0::IMapper::getService(); - ASSERT_NE(mapper.get(), nullptr); - - android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo descriptorInfo {}; - descriptorInfo.width = width; - descriptorInfo.height = height; - descriptorInfo.layerCount = 1; - descriptorInfo.format = format; - descriptorInfo.usage = usage; - ::android::hardware::hidl_vec descriptor; - auto ret = mapper->createDescriptor( - descriptorInfo, [&descriptor](android::hardware::graphics::mapper::V2_0::Error err, - ::android::hardware::hidl_vec desc) { - ASSERT_EQ(err, android::hardware::graphics::mapper::V2_0::Error::NONE); - descriptor = desc; - }); - ASSERT_TRUE(ret.isOk()); + if (mapperV3 != nullptr && allocatorV3 != nullptr) { + android::hardware::graphics::mapper::V3_0::IMapper::BufferDescriptorInfo descriptorInfo {}; + descriptorInfo.width = width; + descriptorInfo.height = height; + descriptorInfo.layerCount = 1; + descriptorInfo.format = + static_cast(format); + descriptorInfo.usage = usage; - ret = allocator->allocate(descriptor, 1u, - [&](android::hardware::graphics::mapper::V2_0::Error err, uint32_t /*stride*/, - const ::android::hardware::hidl_vec<::android::hardware::hidl_handle>& buffers) { - ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE, err); - ASSERT_EQ(buffers.size(), 1u); - *buffer_handle = buffers[0]; - }); - ASSERT_TRUE(ret.isOk()); + auto ret = mapperV3->createDescriptor( + descriptorInfo, [&descriptor](android::hardware::graphics::mapper::V3_0::Error err, + ::android::hardware::hidl_vec desc) { + ASSERT_EQ(err, android::hardware::graphics::mapper::V3_0::Error::NONE); + descriptor = desc; + }); + ASSERT_TRUE(ret.isOk()); + + ret = allocatorV3->allocate(descriptor, 1u, + [&](android::hardware::graphics::mapper::V3_0::Error err, uint32_t /*stride*/, + const ::android::hardware::hidl_vec<::android::hardware::hidl_handle>& buffers) { + ASSERT_EQ(android::hardware::graphics::mapper::V3_0::Error::NONE, err); + ASSERT_EQ(buffers.size(), 1u); + *buffer_handle = buffers[0]; + }); + ASSERT_TRUE(ret.isOk()); + } else { + ASSERT_NE(mapper.get(), nullptr); + ASSERT_NE(allocator.get(), nullptr); + android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo descriptorInfo {}; + descriptorInfo.width = width; + descriptorInfo.height = height; + descriptorInfo.layerCount = 1; + descriptorInfo.format = format; + descriptorInfo.usage = usage; + + auto ret = mapper->createDescriptor( + descriptorInfo, [&descriptor](android::hardware::graphics::mapper::V2_0::Error err, + ::android::hardware::hidl_vec desc) { + ASSERT_EQ(err, android::hardware::graphics::mapper::V2_0::Error::NONE); + descriptor = desc; + }); + ASSERT_TRUE(ret.isOk()); + + ret = allocator->allocate(descriptor, 1u, + [&](android::hardware::graphics::mapper::V2_0::Error err, uint32_t /*stride*/, + const ::android::hardware::hidl_vec<::android::hardware::hidl_handle>& buffers) { + ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE, err); + ASSERT_EQ(buffers.size(), 1u); + *buffer_handle = buffers[0]; + }); + ASSERT_TRUE(ret.isOk()); + } } void CameraHidlTest::verifyRecommendedConfigs(const CameraMetadata& chars) {