diff options
author | Jason Macnak <natsu@google.com> | 2020-04-20 14:43:58 -0700 |
---|---|---|
committer | Jason Macnak <natsu@google.com> | 2020-05-12 11:33:55 -0700 |
commit | f2c9ed13099fb727c06f55ec35a6012353b5fdde (patch) | |
tree | 882c91eb87a1fae9c13e0c28a4bf9220509e1b27 /camera | |
parent | 9a3f5f02e960cc262ff54655de2899cd82247abf (diff) | |
download | platform_hardware_interfaces-f2c9ed13099fb727c06f55ec35a6012353b5fdde.tar.gz platform_hardware_interfaces-f2c9ed13099fb727c06f55ec35a6012353b5fdde.tar.bz2 platform_hardware_interfaces-f2c9ed13099fb727c06f55ec35a6012353b5fdde.zip |
Adds a lock method to HandleImporter w/ access region
... to allow locking 2D regions of non-BLOB buffers.
Bug: b/146515640
Test: cts -m CtsCameraTestCases
Change-Id: Ia68abf96ffe15891520833921e103efa3f7a80c5
Diffstat (limited to 'camera')
-rw-r--r-- | camera/common/1.0/default/HandleImporter.cpp | 51 | ||||
-rw-r--r-- | camera/common/1.0/default/include/HandleImporter.h | 7 |
2 files changed, 34 insertions, 24 deletions
diff --git a/camera/common/1.0/default/HandleImporter.cpp b/camera/common/1.0/default/HandleImporter.cpp index 7792b31880..40cb4e0dae 100644 --- a/camera/common/1.0/default/HandleImporter.cpp +++ b/camera/common/1.0/default/HandleImporter.cpp @@ -232,13 +232,20 @@ void HandleImporter::closeFence(int fd) const { void* HandleImporter::lock( buffer_handle_t& buf, uint64_t cpuUsage, size_t size) { + IMapper::Rect accessRegion{0, 0, static_cast<int>(size), 1}; + return lock(buf, cpuUsage, accessRegion); +} + +void* HandleImporter::lock(buffer_handle_t& buf, uint64_t cpuUsage, + const IMapper::Rect& accessRegion) { Mutex::Autolock lock(mLock); - void *ret = 0; if (!mInitialized) { initializeLocked(); } + void* ret = nullptr; + if (mMapperV4 == nullptr && mMapperV3 == nullptr && mMapperV2 == nullptr) { ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__); return ret; @@ -247,10 +254,10 @@ void* HandleImporter::lock( hidl_handle acquireFenceHandle; auto buffer = const_cast<native_handle_t*>(buf); if (mMapperV4 != nullptr) { - IMapperV4::Rect accessRegion{0, 0, static_cast<int>(size), 1}; - // No need to use bytesPerPixel and bytesPerStride because we are using - // an 1-D buffer and accressRegion. - mMapperV4->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle, + IMapperV4::Rect accessRegionV4{accessRegion.left, accessRegion.top, accessRegion.width, + accessRegion.height}; + + mMapperV4->lock(buffer, cpuUsage, accessRegionV4, acquireFenceHandle, [&](const auto& tmpError, const auto& tmpPtr) { if (tmpError == MapperErrorV4::NONE) { ret = tmpPtr; @@ -259,33 +266,33 @@ void* HandleImporter::lock( } }); } else if (mMapperV3 != nullptr) { - IMapperV3::Rect accessRegion { 0, 0, static_cast<int>(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); - } - }); + IMapperV3::Rect accessRegionV3{accessRegion.left, accessRegion.top, accessRegion.width, + accessRegion.height}; + + mMapperV3->lock(buffer, cpuUsage, accessRegionV3, 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<int>(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); + ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError); } }); } - ALOGV("%s: ptr %p size: %zu", __FUNCTION__, ret, size); + ALOGV("%s: ptr %p accessRegion.top: %d accessRegion.left: %d accessRegion.width: %d " + "accessRegion.height: %d", + __FUNCTION__, ret, accessRegion.top, accessRegion.left, accessRegion.width, + accessRegion.height); return ret; } diff --git a/camera/common/1.0/default/include/HandleImporter.h b/camera/common/1.0/default/include/HandleImporter.h index fc2bbd1197..edc97ad9a7 100644 --- a/camera/common/1.0/default/include/HandleImporter.h +++ b/camera/common/1.0/default/include/HandleImporter.h @@ -46,10 +46,13 @@ public: bool importFence(const native_handle_t* handle, int& fd) const; void closeFence(int fd) const; - // Assume caller has done waiting for acquire fences + // Locks 1-D buffer. Assumes caller has waited for acquire fences. void* lock(buffer_handle_t& buf, uint64_t cpuUsage, size_t size); - // Assume caller has done waiting for acquire fences + // Locks 2-D buffer. Assumes caller has waited for acquire fences. + void* lock(buffer_handle_t& buf, uint64_t cpuUsage, const IMapper::Rect& accessRegion); + + // Assumes caller has waited for acquire fences. YCbCrLayout lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage, const IMapper::Rect& accessRegion); |