Convert from HIDL mapper to libui GraphicBufferMapper
HIDL mapper HAL is deprecated and instead of adding more support for the
new replacement explicitly, we can move the GraphicBufferMapper which
handles all of the backwards compatbility with the HIDL HALs for us.
Test: atest CtsCameraTestCases CtsAppOpsTestCases
Bug: 285605852
Bug: 300115646
Change-Id: Ib97e429a0f3dd1c66ec008fbf3860c9c5667bddd
diff --git a/camera/device/default/Android.bp b/camera/device/default/Android.bp
index b9f10d6..5fbcb5d 100644
--- a/camera/device/default/Android.bp
+++ b/camera/device/default/Android.bp
@@ -40,7 +40,7 @@
shared_libs: [
"android.hardware.camera.common-V1-ndk",
"android.hardware.camera.device-V1-ndk",
- "android.hardware.graphics.allocator-V1-ndk",
+ "android.hardware.graphics.allocator-V2-ndk",
"android.hardware.graphics.mapper@2.0",
"android.hardware.graphics.mapper@3.0",
"android.hardware.graphics.mapper@4.0",
@@ -60,6 +60,7 @@
"libsync",
"libtinyxml2",
"libutils",
+ "libui",
"libyuv",
],
static_libs: [
diff --git a/camera/device/default/ExternalCameraDeviceSession.cpp b/camera/device/default/ExternalCameraDeviceSession.cpp
index 95a36f0..896e0da 100644
--- a/camera/device/default/ExternalCameraDeviceSession.cpp
+++ b/camera/device/default/ExternalCameraDeviceSession.cpp
@@ -2882,13 +2882,23 @@
} break;
case PixelFormat::YCBCR_420_888:
case PixelFormat::YV12: {
- IMapper::Rect outRect{0, 0, static_cast<int32_t>(halBuf.width),
+ android::Rect outRect{0, 0, static_cast<int32_t>(halBuf.width),
static_cast<int32_t>(halBuf.height)};
- YCbCrLayout outLayout = sHandleImporter.lockYCbCr(
+ android_ycbcr result = sHandleImporter.lockYCbCr(
*(halBuf.bufPtr), static_cast<uint64_t>(halBuf.usage), outRect);
- ALOGV("%s: outLayout y %p cb %p cr %p y_str %d c_str %d c_step %d", __FUNCTION__,
- outLayout.y, outLayout.cb, outLayout.cr, outLayout.yStride, outLayout.cStride,
- outLayout.chromaStep);
+ ALOGV("%s: outLayout y %p cb %p cr %p y_str %zu c_str %zu c_step %zu", __FUNCTION__,
+ result.y, result.cb, result.cr, result.ystride, result.cstride,
+ result.chroma_step);
+ if (result.ystride > UINT32_MAX || result.cstride > UINT32_MAX ||
+ result.chroma_step > UINT32_MAX) {
+ return onDeviceError("%s: lockYCbCr failed. Unexpected values!", __FUNCTION__);
+ }
+ YCbCrLayout outLayout = {.y = result.y,
+ .cb = result.cb,
+ .cr = result.cr,
+ .yStride = static_cast<uint32_t>(result.ystride),
+ .cStride = static_cast<uint32_t>(result.cstride),
+ .chromaStep = static_cast<uint32_t>(result.chroma_step)};
// Convert to output buffer size/format
uint32_t outputFourcc = getFourCcFromLayout(outLayout);
diff --git a/camera/device/default/ExternalCameraDeviceSession.h b/camera/device/default/ExternalCameraDeviceSession.h
index 836266f..736bfd1 100644
--- a/camera/device/default/ExternalCameraDeviceSession.h
+++ b/camera/device/default/ExternalCameraDeviceSession.h
@@ -24,6 +24,9 @@
#include <aidl/android/hardware/camera/device/BufferRequest.h>
#include <aidl/android/hardware/camera/device/Stream.h>
#include <android-base/unique_fd.h>
+#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+#include <android/hardware/graphics/mapper/3.0/IMapper.h>
+#include <android/hardware/graphics/mapper/4.0/IMapper.h>
#include <fmq/AidlMessageQueue.h>
#include <utils/Thread.h>
#include <deque>
@@ -55,6 +58,7 @@
using ::android::hardware::camera::common::helper::SimpleThread;
using ::android::hardware::camera::external::common::ExternalCameraConfig;
using ::android::hardware::camera::external::common::SizeHasher;
+using ::android::hardware::graphics::mapper::V2_0::YCbCrLayout;
using ::ndk::ScopedAStatus;
class ExternalCameraDeviceSession : public BnCameraDeviceSession, public OutputThreadInterface {
diff --git a/camera/device/default/ExternalCameraOfflineSession.cpp b/camera/device/default/ExternalCameraOfflineSession.cpp
index 4c7f732..53bd44f 100644
--- a/camera/device/default/ExternalCameraOfflineSession.cpp
+++ b/camera/device/default/ExternalCameraOfflineSession.cpp
@@ -486,13 +486,23 @@
} break;
case PixelFormat::YCBCR_420_888:
case PixelFormat::YV12: {
- IMapper::Rect outRect{0, 0, static_cast<int32_t>(halBuf.width),
+ android::Rect outRect{0, 0, static_cast<int32_t>(halBuf.width),
static_cast<int32_t>(halBuf.height)};
- YCbCrLayout outLayout = sHandleImporter.lockYCbCr(
+ android_ycbcr result = sHandleImporter.lockYCbCr(
*(halBuf.bufPtr), static_cast<uint64_t>(halBuf.usage), outRect);
- ALOGV("%s: outLayout y %p cb %p cr %p y_str %d c_str %d c_step %d", __FUNCTION__,
- outLayout.y, outLayout.cb, outLayout.cr, outLayout.yStride, outLayout.cStride,
- outLayout.chromaStep);
+ ALOGV("%s: outLayout y %p cb %p cr %p y_str %zu c_str %zu c_step %zu", __FUNCTION__,
+ result.y, result.cb, result.cr, result.ystride, result.cstride,
+ result.chroma_step);
+ if (result.ystride > UINT32_MAX || result.cstride > UINT32_MAX ||
+ result.chroma_step > UINT32_MAX) {
+ return onDeviceError("%s: lockYCbCr failed. Unexpected values!", __FUNCTION__);
+ }
+ YCbCrLayout outLayout = {.y = result.y,
+ .cb = result.cb,
+ .cr = result.cr,
+ .yStride = static_cast<uint32_t>(result.ystride),
+ .cStride = static_cast<uint32_t>(result.cstride),
+ .chromaStep = static_cast<uint32_t>(result.chroma_step)};
// Convert to output buffer size/format
uint32_t outputFourcc = getFourCcFromLayout(outLayout);
@@ -544,4 +554,4 @@
} // namespace device
} // namespace camera
} // namespace hardware
-} // namespace android
\ No newline at end of file
+} // namespace android
diff --git a/camera/device/default/ExternalCameraUtils.h b/camera/device/default/ExternalCameraUtils.h
index b37933c..d434905 100644
--- a/camera/device/default/ExternalCameraUtils.h
+++ b/camera/device/default/ExternalCameraUtils.h
@@ -25,7 +25,11 @@
#include <aidl/android/hardware/camera/device/NotifyMsg.h>
#include <aidl/android/hardware/graphics/common/BufferUsage.h>
#include <aidl/android/hardware/graphics/common/PixelFormat.h>
+#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+#include <android/hardware/graphics/mapper/3.0/IMapper.h>
+#include <android/hardware/graphics/mapper/4.0/IMapper.h>
#include <tinyxml2.h>
+#include <map>
#include <unordered_map>
#include <unordered_set>
@@ -37,6 +41,8 @@
using ::aidl::android::hardware::graphics::common::PixelFormat;
using ::android::hardware::camera::common::V1_0::helper::CameraMetadata;
using ::android::hardware::camera::common::V1_0::helper::HandleImporter;
+using ::android::hardware::graphics::mapper::V2_0::IMapper;
+using ::android::hardware::graphics::mapper::V2_0::YCbCrLayout;
namespace android {
namespace hardware {