From f4483700a8582077db6415b99de4f3c2a6c87000 Mon Sep 17 00:00:00 2001 From: Emilian Peev Date: Mon, 9 Apr 2018 16:47:22 +0100 Subject: [PATCH] Camera: Allocate graphics buffers via 'IAllocator' Camera graphic buffers should always be allocated using the respective HIDL API. Bug: 77681294 Test: run vts --skip-all-system-status-check --skip-preconditions --primary-abi-only --module VtsHalCameraProviderV2_4Target -l INFO Change-Id: Ibef88548fc3d29df606e4f66f5f3f4e89d3bf654 Merged-In: Ibef88548fc3d29df606e4f66f5f3f4e89d3bf654 --- camera/provider/2.4/vts/functional/Android.bp | 3 + .../VtsHalCameraProviderV2_4TargetTest.cpp | 87 ++++++++++++++----- 2 files changed, 70 insertions(+), 20 deletions(-) diff --git a/camera/provider/2.4/vts/functional/Android.bp b/camera/provider/2.4/vts/functional/Android.bp index 81d3de1566..55829f788f 100644 --- a/camera/provider/2.4/vts/functional/Android.bp +++ b/camera/provider/2.4/vts/functional/Android.bp @@ -36,8 +36,11 @@ cc_test { "android.hardware.camera.device@3.2", "android.hardware.camera.device@3.3", "android.hardware.camera.provider@2.4", + "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.common@1.0", "android.hardware.graphics.mapper@2.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 0c3fe37ba5..6a1d91e7a5 100644 --- a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp +++ b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp @@ -43,6 +43,13 @@ #include #include +#include +#include +#include +#include +#include +#include + #include #include @@ -99,6 +106,9 @@ using ::android::hardware::camera::device::V1_0::FrameCallbackFlag; using ::android::hardware::camera::device::V1_0::HandleTimestampMessage; using ::android::hardware::MessageQueue; using ::android::hardware::kSynchronizedReadWrite; +using ::android::hidl::allocator::V1_0::IAllocator; +using ::android::hidl::memory::V1_0::IMemory; +using ::android::hidl::memory::V1_0::IMapper; using ResultMetadataQueue = MessageQueue; using ::android::hidl::manager::V1_0::IServiceManager; @@ -606,6 +616,8 @@ public: void setParameters( const sp<::android::hardware::camera::device::V1_0::ICameraDevice> &device, const CameraParameters &cameraParams); + void allocateGraphicBuffer(uint32_t width, uint32_t height, uint64_t usage, + PixelFormat format, hidl_handle *buffer_handle /*out*/); void waitForFrameLocked(DataCallbackMsg msgFrame, std::unique_lock &l); void openEmptyDeviceSession(const std::string &name, @@ -2994,15 +3006,15 @@ TEST_F(CameraHidlTest, processCaptureRequestPreview) { }); ASSERT_TRUE(ret.isOk()); - sp gb = new GraphicBuffer( - previewStream.width, previewStream.height, - static_cast(halStreamConfig.streams[0].overrideFormat), 1, + hidl_handle buffer_handle; + allocateGraphicBuffer(previewStream.width, previewStream.height, android_convertGralloc1To0Usage(halStreamConfig.streams[0].producerUsage, - halStreamConfig.streams[0].consumerUsage)); - ASSERT_NE(nullptr, gb.get()); + halStreamConfig.streams[0].consumerUsage), + halStreamConfig.streams[0].overrideFormat, &buffer_handle); + StreamBuffer outputBuffer = {halStreamConfig.streams[0].id, bufferId, - hidl_handle(gb->getNativeBuffer()->handle), + buffer_handle, BufferStatus::OK, nullptr, nullptr}; @@ -3128,15 +3140,15 @@ TEST_F(CameraHidlTest, processCaptureRequestInvalidSinglePreview) { &supportsPartialResults /*out*/, &partialResultCount /*out*/); - sp gb = new GraphicBuffer( - previewStream.width, previewStream.height, - static_cast(halStreamConfig.streams[0].overrideFormat), 1, + hidl_handle buffer_handle; + allocateGraphicBuffer(previewStream.width, previewStream.height, android_convertGralloc1To0Usage(halStreamConfig.streams[0].producerUsage, - halStreamConfig.streams[0].consumerUsage)); + halStreamConfig.streams[0].consumerUsage), + halStreamConfig.streams[0].overrideFormat, &buffer_handle); StreamBuffer outputBuffer = {halStreamConfig.streams[0].id, bufferId, - hidl_handle(gb->getNativeBuffer()->handle), + buffer_handle, BufferStatus::OK, nullptr, nullptr}; @@ -3272,7 +3284,6 @@ TEST_F(CameraHidlTest, flushPreviewRequest) { &previewStream /*out*/, &halStreamConfig /*out*/, &supportsPartialResults /*out*/, &partialResultCount /*out*/); - std::shared_ptr resultQueue; auto resultQueueRet = session->getCaptureResultMetadataQueue( @@ -3300,15 +3311,15 @@ TEST_F(CameraHidlTest, flushPreviewRequest) { }); ASSERT_TRUE(ret.isOk()); - sp gb = new GraphicBuffer( - previewStream.width, previewStream.height, - static_cast(halStreamConfig.streams[0].overrideFormat), 1, + hidl_handle buffer_handle; + allocateGraphicBuffer(previewStream.width, previewStream.height, android_convertGralloc1To0Usage(halStreamConfig.streams[0].producerUsage, - halStreamConfig.streams[0].consumerUsage)); - ASSERT_NE(nullptr, gb.get()); + halStreamConfig.streams[0].consumerUsage), + halStreamConfig.streams[0].overrideFormat, &buffer_handle); + StreamBuffer outputBuffer = {halStreamConfig.streams[0].id, bufferId, - hidl_handle(gb->getNativeBuffer()->handle), + buffer_handle, BufferStatus::OK, nullptr, nullptr}; @@ -3341,7 +3352,6 @@ TEST_F(CameraHidlTest, flushPreviewRequest) { Return returnStatus = session->flush(); ASSERT_TRUE(returnStatus.isOk()); ASSERT_EQ(Status::OK, returnStatus); - { std::unique_lock l(mLock); while (!inflightReq.errorCodeValid && @@ -3369,7 +3379,6 @@ TEST_F(CameraHidlTest, flushPreviewRequest) { << static_cast(inflightReq.errorCode); } } - ret = session->close(); ASSERT_TRUE(ret.isOk()); } @@ -3894,6 +3903,44 @@ void CameraHidlTest::setParameters( ASSERT_EQ(Status::OK, returnStatus); } +void CameraHidlTest::allocateGraphicBuffer(uint32_t width, uint32_t height, uint64_t usage, + PixelFormat format, hidl_handle *buffer_handle /*out*/) { + ASSERT_NE(buffer_handle, nullptr); + + sp allocator = + android::hardware::graphics::allocator::V2_0::IAllocator::getService(); + ASSERT_NE(nullptr, allocator.get()); + + 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()); + + 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()); +} + int main(int argc, char **argv) { ::testing::AddGlobalTestEnvironment(CameraHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv);