From 2d80c0d66f9ca869d6102f07bd236b7c4c94c205 Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Thu, 23 Mar 2017 15:39:12 -0700 Subject: [PATCH] camera: Map between legacy gralloc0 usage, and HIDL gralloc1 usages Otherwise some bits will be set incorrectly. Also move device@1.0 to use ProducerUsageFlags instead of ProducerUsage, and add a compatibility workaround to set the gralloc0 HW_CAMERA_ZSL flags when ConsumerUsage::CAMERA is passed in. Test: Camera CTS passes, updated VTS tests pass Bug: 35215313 Change-Id: I981dc1a650f838f94d932944fe835fd267f2004d --- .../1.0/ICameraDevicePreviewCallback.hal | 3 +-- camera/device/1.0/default/Android.bp | 4 +-- camera/device/1.0/default/CameraDevice.cpp | 8 ++++-- camera/device/1.0/types.hal | 4 +++ camera/device/3.2/default/Android.bp | 3 ++- .../3.2/default/CameraDeviceSession.cpp | 2 +- camera/device/3.2/default/convert.cpp | 25 ++++++++++++++++--- camera/device/3.2/default/include/convert.h | 2 ++ camera/provider/2.4/vts/functional/Android.bp | 5 +++- .../VtsHalCameraProviderV2_4TargetTest.cpp | 18 ++++++++----- 10 files changed, 56 insertions(+), 18 deletions(-) diff --git a/camera/device/1.0/ICameraDevicePreviewCallback.hal b/camera/device/1.0/ICameraDevicePreviewCallback.hal index 4c9b517265..e772301d1c 100644 --- a/camera/device/1.0/ICameraDevicePreviewCallback.hal +++ b/camera/device/1.0/ICameraDevicePreviewCallback.hal @@ -17,7 +17,6 @@ package android.hardware.camera.device@1.0; import android.hardware.camera.common@1.0::types; -import android.hardware.graphics.allocator@2.0::types; import android.hardware.graphics.common@1.0::types; /** @@ -89,7 +88,7 @@ interface ICameraDevicePreviewCallback { * * @return Status The status code for this operation. */ - setUsage(ProducerUsage usage) generates (Status status); + setUsage(ProducerUsageFlags usage) generates (Status status); /** * Set the expected buffering mode for the preview output. diff --git a/camera/device/1.0/default/Android.bp b/camera/device/1.0/default/Android.bp index 5688fc192a..a2fd0b05be 100644 --- a/camera/device/1.0/default/Android.bp +++ b/camera/device/1.0/default/Android.bp @@ -22,8 +22,8 @@ cc_library_shared { "libbinder", ], static_libs: [ - "android.hardware.camera.common@1.0-helper" + "android.hardware.camera.common@1.0-helper", + "libgrallocusage" ], export_include_dirs: ["."] } - diff --git a/camera/device/1.0/default/CameraDevice.cpp b/camera/device/1.0/default/CameraDevice.cpp index 819525be1e..0cc70a1d30 100644 --- a/camera/device/1.0/default/CameraDevice.cpp +++ b/camera/device/1.0/default/CameraDevice.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include "CameraDevice_1_0.h" namespace android { @@ -29,7 +31,6 @@ namespace device { namespace V1_0 { namespace implementation { -using ::android::hardware::graphics::allocator::V2_0::ProducerUsage; using ::android::hardware::graphics::common::V1_0::PixelFormat; HandleImporter& CameraDevice::sHandleImporter = HandleImporter::getInstance(); @@ -252,7 +253,10 @@ int CameraDevice::sSetUsage(struct preview_stream_ops* w, int usage) { } object->cleanUpCirculatingBuffers(); - return getStatusT(object->mPreviewCallback->setUsage((ProducerUsage) usage)); + ProducerUsageFlags producerUsage; + uint64_t consumerUsage; + ::android_convertGralloc0To1Usage(usage, &producerUsage, &consumerUsage); + return getStatusT(object->mPreviewCallback->setUsage(producerUsage)); } int CameraDevice::sSetSwapInterval(struct preview_stream_ops *w, int interval) { diff --git a/camera/device/1.0/types.hal b/camera/device/1.0/types.hal index b32c938107..1a90fe05d8 100644 --- a/camera/device/1.0/types.hal +++ b/camera/device/1.0/types.hal @@ -16,6 +16,10 @@ package android.hardware.camera.device@1.0; +import android.hardware.graphics.allocator@2.0::types; + +typedef bitfield ProducerUsageFlags; + enum CameraFacing : uint32_t { /** The facing of the camera is opposite to that of the screen. */ BACK = 0, diff --git a/camera/device/3.2/default/Android.bp b/camera/device/3.2/default/Android.bp index e0dc5ff410..5a81d41d1a 100644 --- a/camera/device/3.2/default/Android.bp +++ b/camera/device/3.2/default/Android.bp @@ -17,7 +17,8 @@ cc_library_shared { "libcamera_metadata" ], static_libs: [ - "android.hardware.camera.common@1.0-helper" + "android.hardware.camera.common@1.0-helper", + "libgrallocusage" ], export_include_dirs: ["."] } diff --git a/camera/device/3.2/default/CameraDeviceSession.cpp b/camera/device/3.2/default/CameraDeviceSession.cpp index fb1d1ff7c1..2887a757a3 100644 --- a/camera/device/3.2/default/CameraDeviceSession.cpp +++ b/camera/device/3.2/default/CameraDeviceSession.cpp @@ -611,7 +611,7 @@ Return CameraDeviceSession::configureStreams( return Void(); } mStreamMap[id].rotation = (int) requestedConfiguration.streams[i].rotation; - mStreamMap[id].usage = (uint32_t) requestedConfiguration.streams[i].usage; + mStreamMap[id].usage = convertFromHidlUsage(requestedConfiguration.streams[i].usage); } streams[i] = &mStreamMap[id]; } diff --git a/camera/device/3.2/default/convert.cpp b/camera/device/3.2/default/convert.cpp index 35676df3af..c99d9037c3 100644 --- a/camera/device/3.2/default/convert.cpp +++ b/camera/device/3.2/default/convert.cpp @@ -15,8 +15,12 @@ */ #define LOG_TAG "android.hardware.camera.device@3.2-convert-impl" +#include + #include +#include + #include "include/convert.h" namespace android { @@ -28,6 +32,7 @@ namespace implementation { using ::android::hardware::graphics::common::V1_0::Dataspace; using ::android::hardware::graphics::common::V1_0::PixelFormat; +using ::android::hardware::graphics::allocator::V2_0::ConsumerUsage; using ::android::hardware::camera::device::V3_2::ConsumerUsageFlags; using ::android::hardware::camera::device::V3_2::ProducerUsageFlags; @@ -66,23 +71,37 @@ void convertFromHidl(const Stream &src, Camera3Stream* dst) { dst->format = (int) src.format; dst->data_space = (android_dataspace_t) src.dataSpace; dst->rotation = (int) src.rotation; - dst->usage = (uint32_t) src.usage; + dst->usage = convertFromHidlUsage(src.usage); // Fields to be filled by HAL (max_buffers, priv) are initialized to 0 dst->max_buffers = 0; dst->priv = 0; return; } +uint32_t convertFromHidlUsage(ConsumerUsageFlags usage) { + uint32_t dstUsage = 0; + dstUsage = ::android_convertGralloc1To0Usage(/*producerUsage*/ 0, usage); + // Compatibility workaround - add HW_CAMERA_ZSL when ConsumerUsage.CAMERA is set, to + // match pre-HIDL expected usage flags + if ( (usage & ConsumerUsage::CAMERA) == static_cast(ConsumerUsage::CAMERA)) { + dstUsage |= GRALLOC_USAGE_HW_CAMERA_ZSL; + } + return dstUsage; +} + void convertToHidl(const Camera3Stream* src, HalStream* dst) { dst->id = src->mId; dst->overrideFormat = (PixelFormat) src->format; dst->maxBuffers = src->max_buffers; + ConsumerUsageFlags consumerUsage; + ProducerUsageFlags producerUsage; + ::android_convertGralloc0To1Usage(src->usage, &producerUsage, &consumerUsage); if (src->stream_type == CAMERA3_STREAM_OUTPUT) { dst->consumerUsage = (ConsumerUsageFlags) 0; - dst->producerUsage = (ProducerUsageFlags) src->usage; + dst->producerUsage = producerUsage; } else if (src->stream_type == CAMERA3_STREAM_INPUT) { dst->producerUsage = (ProducerUsageFlags) 0; - dst->consumerUsage = (ConsumerUsageFlags) src->usage; + dst->consumerUsage = consumerUsage; } else { //Should not reach here per current HIDL spec, but we might end up adding // bi-directional stream to HIDL. diff --git a/camera/device/3.2/default/include/convert.h b/camera/device/3.2/default/include/convert.h index 96891f091d..7c8e02f4d2 100644 --- a/camera/device/3.2/default/include/convert.h +++ b/camera/device/3.2/default/include/convert.h @@ -45,6 +45,8 @@ void convertToHidl(const camera_metadata_t* src, CameraMetadata* dst); void convertFromHidl(const Stream &src, Camera3Stream* dst); void convertToHidl(const Camera3Stream* src, HalStream* dst); +uint32_t convertFromHidlUsage(ConsumerUsageFlags usage); + void convertFromHidl( buffer_handle_t*, BufferStatus, camera3_stream_t*, int acquireFence, // inputs camera3_stream_buffer_t* dst); diff --git a/camera/provider/2.4/vts/functional/Android.bp b/camera/provider/2.4/vts/functional/Android.bp index a0be5cbcde..02c42c943a 100644 --- a/camera/provider/2.4/vts/functional/Android.bp +++ b/camera/provider/2.4/vts/functional/Android.bp @@ -33,7 +33,10 @@ cc_test { "libgui", "libui" ], - static_libs: ["VtsHalHidlTargetTestBase"], + static_libs: [ + "VtsHalHidlTargetTestBase", + "libgrallocusage" + ], cflags: [ "-O0", "-g", diff --git a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp index a79c9fafaa..80a816505a 100644 --- a/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp +++ b/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp @@ -21,6 +21,7 @@ #include "CameraParameters.h" #include #include +#include #include #include #include @@ -53,6 +54,7 @@ using ::android::BufferItemConsumer; using ::android::Surface; using ::android::CameraParameters; using ::android::hardware::graphics::common::V1_0::PixelFormat; +using ::android::hardware::graphics::allocator::V2_0::ConsumerUsage; using ::android::hardware::graphics::allocator::V2_0::ProducerUsage; using ::android::hardware::camera::common::V1_0::Status; using ::android::hardware::camera::common::V1_0::CameraDeviceStatus; @@ -60,6 +62,8 @@ using ::android::hardware::camera::common::V1_0::TorchMode; using ::android::hardware::camera::common::V1_0::TorchModeStatus; using ::android::hardware::camera::provider::V2_4::ICameraProvider; using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback; +using ::android::hardware::camera::device::V3_2::ProducerUsageFlags; +using ::android::hardware::camera::device::V3_2::ConsumerUsageFlags; using ::android::hardware::camera::device::V3_2::ICameraDevice; using ::android::hardware::camera::device::V3_2::CaptureRequest; using ::android::hardware::camera::device::V3_2::CaptureResult; @@ -79,6 +83,7 @@ using ::android::hardware::camera::device::V3_2::StreamBuffer; using ::android::hardware::camera::device::V3_2::MsgType; using ::android::hardware::camera::device::V3_2::ErrorMsg; using ::android::hardware::camera::device::V3_2::ErrorCode; +using ::android::hardware::camera::device::V1_0::ProducerUsageFlags; using ::android::hardware::camera::device::V1_0::CameraFacing; using ::android::hardware::camera::device::V1_0::NotifyCallbackMsg; using ::android::hardware::camera::device::V1_0::CommandType; @@ -231,7 +236,7 @@ struct PreviewWindowCb : public ICameraDevicePreviewCallback { Return setCrop(int32_t left, int32_t top, int32_t right, int32_t bottom) override; - Return setUsage(ProducerUsage usage) override; + Return setUsage(ProducerUsageFlags usage) override; Return setSwapInterval(int32_t interval) override; @@ -406,10 +411,11 @@ Return PreviewWindowCb::setCrop(int32_t left, int32_t top, return mapToStatus(rc); } -Return PreviewWindowCb::setUsage(ProducerUsage usage) { - auto rc = native_window_set_usage(mAnw.get(), static_cast(usage)); +Return PreviewWindowCb::setUsage(ProducerUsageFlags usage) { + int dstUsage = ::android_convertGralloc1To0Usage(usage, /*consumerUsage*/ 0); + auto rc = native_window_set_usage(mAnw.get(), dstUsage); if (rc == ::android::OK) { - mPreviewUsage = static_cast(usage); + mPreviewUsage = dstUsage; } return mapToStatus(rc); } @@ -2176,7 +2182,7 @@ TEST_F(CameraHidlTest, configureStreamsZSLInputOutputs) { static_cast (input.width), static_cast (input.height), static_cast (input.format), - GRALLOC_USAGE_HW_CAMERA_ZSL, 0, + static_cast(ConsumerUsage::CAMERA), 0, StreamRotation::ROTATION_0}; Stream inputStream = {streamId++, StreamType::INPUT, static_cast (input.width), @@ -2408,7 +2414,7 @@ TEST_F(CameraHidlTest, configureStreamsVideoStillOutputs) { static_cast (blobIter.width), static_cast (blobIter.height), static_cast (blobIter.format), - GRALLOC_USAGE_HW_VIDEO_ENCODER, 0, + static_cast(ConsumerUsage::VIDEO_ENCODER), 0, StreamRotation::ROTATION_0}; ::android::hardware::hidl_vec streams = { videoStream, blobStream};