mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
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
This commit is contained in:
@@ -30,13 +30,12 @@ cc_library_static {
|
||||
"libgralloctypes",
|
||||
"libhardware",
|
||||
"libcamera_metadata",
|
||||
"android.hardware.graphics.mapper@2.0",
|
||||
"android.hardware.graphics.mapper@3.0",
|
||||
"android.hardware.graphics.mapper@4.0",
|
||||
"libexif",
|
||||
"libui",
|
||||
],
|
||||
include_dirs: ["system/media/private/camera/include"],
|
||||
export_include_dirs: ["include"],
|
||||
export_shared_lib_headers: ["libui"],
|
||||
}
|
||||
|
||||
// NOTE: Deprecated module kept for compatibility reasons.
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
#define LOG_TAG "HandleImporter"
|
||||
#include "HandleImporter.h"
|
||||
|
||||
#include <aidl/android/hardware/graphics/common/Smpte2086.h>
|
||||
#include <gralloctypes/Gralloc4.h>
|
||||
#include <log/log.h>
|
||||
#include "aidl/android/hardware/graphics/common/Smpte2086.h"
|
||||
#include <ui/GraphicBufferMapper.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
@@ -31,12 +32,6 @@ using aidl::android::hardware::graphics::common::PlaneLayout;
|
||||
using aidl::android::hardware::graphics::common::PlaneLayoutComponent;
|
||||
using aidl::android::hardware::graphics::common::PlaneLayoutComponentType;
|
||||
using aidl::android::hardware::graphics::common::Smpte2086;
|
||||
using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType;
|
||||
using MapperErrorV2 = android::hardware::graphics::mapper::V2_0::Error;
|
||||
using MapperErrorV3 = android::hardware::graphics::mapper::V3_0::Error;
|
||||
using MapperErrorV4 = android::hardware::graphics::mapper::V4_0::Error;
|
||||
using IMapperV3 = android::hardware::graphics::mapper::V3_0::IMapper;
|
||||
using IMapperV4 = android::hardware::graphics::mapper::V4_0::IMapper;
|
||||
|
||||
HandleImporter::HandleImporter() : mInitialized(false) {}
|
||||
|
||||
@@ -45,51 +40,20 @@ void HandleImporter::initializeLocked() {
|
||||
return;
|
||||
}
|
||||
|
||||
mMapperV4 = IMapperV4::getService();
|
||||
if (mMapperV4 != nullptr) {
|
||||
mInitialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
mMapperV3 = IMapperV3::getService();
|
||||
if (mMapperV3 != nullptr) {
|
||||
mInitialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
mMapperV2 = IMapper::getService();
|
||||
if (mMapperV2 == nullptr) {
|
||||
ALOGE("%s: cannnot acccess graphics mapper HAL!", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
GraphicBufferMapper::preloadHal();
|
||||
mInitialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
void HandleImporter::cleanup() {
|
||||
mMapperV4.clear();
|
||||
mMapperV3.clear();
|
||||
mMapperV2.clear();
|
||||
mInitialized = false;
|
||||
}
|
||||
|
||||
template <class M, class E>
|
||||
bool HandleImporter::importBufferInternal(const sp<M> mapper, buffer_handle_t& handle) {
|
||||
E error;
|
||||
bool HandleImporter::importBufferInternal(buffer_handle_t& handle) {
|
||||
buffer_handle_t importedHandle;
|
||||
auto ret = mapper->importBuffer(
|
||||
hidl_handle(handle), [&](const auto& tmpError, const auto& tmpBufferHandle) {
|
||||
error = tmpError;
|
||||
importedHandle = static_cast<buffer_handle_t>(tmpBufferHandle);
|
||||
});
|
||||
|
||||
if (!ret.isOk()) {
|
||||
ALOGE("%s: mapper importBuffer failed: %s", __FUNCTION__, ret.description().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (error != E::NONE) {
|
||||
auto status = GraphicBufferMapper::get().importBufferNoValidate(handle, &importedHandle);
|
||||
if (status != OK) {
|
||||
ALOGE("%s: mapper importBuffer failed: %d", __FUNCTION__, status);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -97,172 +61,34 @@ bool HandleImporter::importBufferInternal(const sp<M> mapper, buffer_handle_t& h
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class M, class E>
|
||||
YCbCrLayout HandleImporter::lockYCbCrInternal(const sp<M> mapper, buffer_handle_t& buf,
|
||||
uint64_t cpuUsage,
|
||||
const IMapper::Rect& accessRegion) {
|
||||
hidl_handle acquireFenceHandle;
|
||||
auto buffer = const_cast<native_handle_t*>(buf);
|
||||
YCbCrLayout layout = {};
|
||||
android_ycbcr HandleImporter::lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
|
||||
const android::Rect& accessRegion) {
|
||||
Mutex::Autolock lock(mLock);
|
||||
|
||||
if (!mInitialized) {
|
||||
initializeLocked();
|
||||
}
|
||||
android_ycbcr layout;
|
||||
|
||||
status_t status = GraphicBufferMapper::get().lockYCbCr(buf, cpuUsage, accessRegion, &layout);
|
||||
|
||||
if (status != OK) {
|
||||
ALOGE("%s: failed to lockYCbCr error %d!", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool isMetadataPesent(const sp<IMapperV4> mapper, const buffer_handle_t& buf,
|
||||
MetadataType metadataType) {
|
||||
auto buffer = const_cast<native_handle_t*>(buf);
|
||||
bool ret = false;
|
||||
hidl_vec<uint8_t> vec;
|
||||
mapper->get(buffer, metadataType, [&](const auto& tmpError, const auto& tmpMetadata) {
|
||||
if (tmpError == MapperErrorV4::NONE) {
|
||||
vec = tmpMetadata;
|
||||
} else {
|
||||
ALOGE("%s: failed to get metadata %d!", __FUNCTION__, tmpError);
|
||||
}
|
||||
});
|
||||
|
||||
if (vec.size() > 0) {
|
||||
if (metadataType == gralloc4::MetadataType_Smpte2086) {
|
||||
std::optional<Smpte2086> realSmpte2086;
|
||||
gralloc4::decodeSmpte2086(vec, &realSmpte2086);
|
||||
ret = realSmpte2086.has_value();
|
||||
} else if (metadataType == gralloc4::MetadataType_Smpte2094_10) {
|
||||
std::optional<std::vector<uint8_t>> realSmpte2094_10;
|
||||
gralloc4::decodeSmpte2094_10(vec, &realSmpte2094_10);
|
||||
ret = realSmpte2094_10.has_value();
|
||||
} else if (metadataType == gralloc4::MetadataType_Smpte2094_40) {
|
||||
std::optional<std::vector<uint8_t>> realSmpte2094_40;
|
||||
gralloc4::decodeSmpte2094_40(vec, &realSmpte2094_40);
|
||||
ret = realSmpte2094_40.has_value();
|
||||
} else {
|
||||
ALOGE("%s: Unknown metadata type!", __FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<PlaneLayout> getPlaneLayouts(const sp<IMapperV4> mapper, buffer_handle_t& buf) {
|
||||
auto buffer = const_cast<native_handle_t*>(buf);
|
||||
std::vector<PlaneLayout> getPlaneLayouts(buffer_handle_t& buf) {
|
||||
std::vector<PlaneLayout> planeLayouts;
|
||||
hidl_vec<uint8_t> encodedPlaneLayouts;
|
||||
mapper->get(buffer, gralloc4::MetadataType_PlaneLayouts,
|
||||
[&](const auto& tmpError, const auto& tmpEncodedPlaneLayouts) {
|
||||
if (tmpError == MapperErrorV4::NONE) {
|
||||
encodedPlaneLayouts = tmpEncodedPlaneLayouts;
|
||||
} else {
|
||||
ALOGE("%s: failed to get plane layouts %d!", __FUNCTION__, tmpError);
|
||||
}
|
||||
});
|
||||
|
||||
gralloc4::decodePlaneLayouts(encodedPlaneLayouts, &planeLayouts);
|
||||
status_t status = GraphicBufferMapper::get().getPlaneLayouts(buf, &planeLayouts);
|
||||
if (status != OK) {
|
||||
ALOGE("%s: failed to get PlaneLayouts! Status %d", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
return planeLayouts;
|
||||
}
|
||||
|
||||
template <>
|
||||
YCbCrLayout HandleImporter::lockYCbCrInternal<IMapperV4, MapperErrorV4>(
|
||||
const sp<IMapperV4> mapper, buffer_handle_t& buf, uint64_t cpuUsage,
|
||||
const IMapper::Rect& accessRegion) {
|
||||
hidl_handle acquireFenceHandle;
|
||||
auto buffer = const_cast<native_handle_t*>(buf);
|
||||
YCbCrLayout layout = {};
|
||||
void* mapped = nullptr;
|
||||
|
||||
typename IMapperV4::Rect accessRegionV4 = {accessRegion.left, accessRegion.top,
|
||||
accessRegion.width, accessRegion.height};
|
||||
mapper->lock(buffer, cpuUsage, accessRegionV4, acquireFenceHandle,
|
||||
[&](const auto& tmpError, const auto& tmpPtr) {
|
||||
if (tmpError == MapperErrorV4::NONE) {
|
||||
mapped = tmpPtr;
|
||||
} else {
|
||||
ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError);
|
||||
}
|
||||
});
|
||||
|
||||
if (mapped == nullptr) {
|
||||
return layout;
|
||||
}
|
||||
|
||||
std::vector<PlaneLayout> planeLayouts = getPlaneLayouts(mapper, buf);
|
||||
for (const auto& planeLayout : planeLayouts) {
|
||||
for (const auto& planeLayoutComponent : planeLayout.components) {
|
||||
const auto& type = planeLayoutComponent.type;
|
||||
|
||||
if (!gralloc4::isStandardPlaneLayoutComponentType(type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t* data = reinterpret_cast<uint8_t*>(mapped);
|
||||
data += planeLayout.offsetInBytes;
|
||||
data += planeLayoutComponent.offsetInBits / 8;
|
||||
|
||||
switch (static_cast<PlaneLayoutComponentType>(type.value)) {
|
||||
case PlaneLayoutComponentType::Y:
|
||||
layout.y = data;
|
||||
layout.yStride = planeLayout.strideInBytes;
|
||||
break;
|
||||
case PlaneLayoutComponentType::CB:
|
||||
layout.cb = data;
|
||||
layout.cStride = planeLayout.strideInBytes;
|
||||
layout.chromaStep = planeLayout.sampleIncrementInBits / 8;
|
||||
break;
|
||||
case PlaneLayoutComponentType::CR:
|
||||
layout.cr = data;
|
||||
layout.cStride = planeLayout.strideInBytes;
|
||||
layout.chromaStep = planeLayout.sampleIncrementInBits / 8;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
template <class M, class E>
|
||||
int HandleImporter::unlockInternal(const sp<M> mapper, buffer_handle_t& buf) {
|
||||
int releaseFence = -1;
|
||||
auto buffer = const_cast<native_handle_t*>(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.
|
||||
@@ -277,20 +103,7 @@ bool HandleImporter::importBuffer(buffer_handle_t& handle) {
|
||||
initializeLocked();
|
||||
}
|
||||
|
||||
if (mMapperV4 != nullptr) {
|
||||
return importBufferInternal<IMapperV4, MapperErrorV4>(mMapperV4, handle);
|
||||
}
|
||||
|
||||
if (mMapperV3 != nullptr) {
|
||||
return importBufferInternal<IMapperV3, MapperErrorV3>(mMapperV3, handle);
|
||||
}
|
||||
|
||||
if (mMapperV2 != nullptr) {
|
||||
return importBufferInternal<IMapper, MapperErrorV2>(mMapperV2, handle);
|
||||
}
|
||||
|
||||
ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__);
|
||||
return false;
|
||||
return importBufferInternal(handle);
|
||||
}
|
||||
|
||||
void HandleImporter::freeBuffer(buffer_handle_t handle) {
|
||||
@@ -303,21 +116,9 @@ void HandleImporter::freeBuffer(buffer_handle_t handle) {
|
||||
initializeLocked();
|
||||
}
|
||||
|
||||
if (mMapperV4 != nullptr) {
|
||||
auto ret = mMapperV4->freeBuffer(const_cast<native_handle_t*>(handle));
|
||||
if (!ret.isOk()) {
|
||||
ALOGE("%s: mapper freeBuffer failed: %s", __FUNCTION__, ret.description().c_str());
|
||||
}
|
||||
} else if (mMapperV3 != nullptr) {
|
||||
auto ret = mMapperV3->freeBuffer(const_cast<native_handle_t*>(handle));
|
||||
if (!ret.isOk()) {
|
||||
ALOGE("%s: mapper freeBuffer failed: %s", __FUNCTION__, ret.description().c_str());
|
||||
}
|
||||
} else {
|
||||
auto ret = mMapperV2->freeBuffer(const_cast<native_handle_t*>(handle));
|
||||
if (!ret.isOk()) {
|
||||
ALOGE("%s: mapper freeBuffer failed: %s", __FUNCTION__, ret.description().c_str());
|
||||
}
|
||||
status_t status = GraphicBufferMapper::get().freeBuffer(handle);
|
||||
if (status != OK) {
|
||||
ALOGE("%s: mapper freeBuffer failed. Status %d", __FUNCTION__, status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,12 +146,12 @@ 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};
|
||||
android::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) {
|
||||
const android::Rect& accessRegion) {
|
||||
Mutex::Autolock lock(mLock);
|
||||
|
||||
if (!mInitialized) {
|
||||
@@ -358,81 +159,18 @@ void* HandleImporter::lock(buffer_handle_t& buf, uint64_t cpuUsage,
|
||||
}
|
||||
|
||||
void* ret = nullptr;
|
||||
|
||||
if (mMapperV4 == nullptr && mMapperV3 == nullptr && mMapperV2 == nullptr) {
|
||||
ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
hidl_handle acquireFenceHandle;
|
||||
auto buffer = const_cast<native_handle_t*>(buf);
|
||||
if (mMapperV4 != nullptr) {
|
||||
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;
|
||||
} else {
|
||||
ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError);
|
||||
}
|
||||
});
|
||||
} else if (mMapperV3 != nullptr) {
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
});
|
||||
status_t status = GraphicBufferMapper::get().lock(buf, cpuUsage, accessRegion, &ret);
|
||||
if (status != OK) {
|
||||
ALOGE("%s: failed to lock error %d!", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
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);
|
||||
__FUNCTION__, ret, accessRegion.top, accessRegion.left, accessRegion.width(),
|
||||
accessRegion.height());
|
||||
return ret;
|
||||
}
|
||||
|
||||
YCbCrLayout HandleImporter::lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
|
||||
const IMapper::Rect& accessRegion) {
|
||||
Mutex::Autolock lock(mLock);
|
||||
|
||||
if (!mInitialized) {
|
||||
initializeLocked();
|
||||
}
|
||||
|
||||
if (mMapperV4 != nullptr) {
|
||||
return lockYCbCrInternal<IMapperV4, MapperErrorV4>(mMapperV4, buf, cpuUsage, accessRegion);
|
||||
}
|
||||
|
||||
if (mMapperV3 != nullptr) {
|
||||
return lockYCbCrInternal<IMapperV3, MapperErrorV3>(mMapperV3, buf, cpuUsage, accessRegion);
|
||||
}
|
||||
|
||||
if (mMapperV2 != nullptr) {
|
||||
return lockYCbCrInternal<IMapper, MapperErrorV2>(mMapperV2, buf, cpuUsage, accessRegion);
|
||||
}
|
||||
|
||||
ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__);
|
||||
return {};
|
||||
}
|
||||
|
||||
status_t HandleImporter::getMonoPlanarStrideBytes(buffer_handle_t& buf, uint32_t* stride /*out*/) {
|
||||
if (stride == nullptr) {
|
||||
return BAD_VALUE;
|
||||
@@ -444,35 +182,26 @@ status_t HandleImporter::getMonoPlanarStrideBytes(buffer_handle_t& buf, uint32_t
|
||||
initializeLocked();
|
||||
}
|
||||
|
||||
if (mMapperV4 != nullptr) {
|
||||
std::vector<PlaneLayout> planeLayouts = getPlaneLayouts(mMapperV4, buf);
|
||||
if (planeLayouts.size() != 1) {
|
||||
ALOGE("%s: Unexpected number of planes %zu!", __FUNCTION__, planeLayouts.size());
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
*stride = planeLayouts[0].strideInBytes;
|
||||
} else {
|
||||
ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
|
||||
return NO_INIT;
|
||||
std::vector<PlaneLayout> planeLayouts = getPlaneLayouts(buf);
|
||||
if (planeLayouts.size() != 1) {
|
||||
ALOGE("%s: Unexpected number of planes %zu!", __FUNCTION__, planeLayouts.size());
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
*stride = planeLayouts[0].strideInBytes;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int HandleImporter::unlock(buffer_handle_t& buf) {
|
||||
if (mMapperV4 != nullptr) {
|
||||
return unlockInternal<IMapperV4, MapperErrorV4>(mMapperV4, buf);
|
||||
}
|
||||
if (mMapperV3 != nullptr) {
|
||||
return unlockInternal<IMapperV3, MapperErrorV3>(mMapperV3, buf);
|
||||
}
|
||||
if (mMapperV2 != nullptr) {
|
||||
return unlockInternal<IMapper, MapperErrorV2>(mMapperV2, buf);
|
||||
int releaseFence = -1;
|
||||
|
||||
status_t status = GraphicBufferMapper::get().unlockAsync(buf, &releaseFence);
|
||||
if (status != OK) {
|
||||
ALOGE("%s: failed to unlock error %d!", __FUNCTION__, status);
|
||||
}
|
||||
|
||||
ALOGE("%s: mMapperV4, mMapperV3 and mMapperV2 are all null!", __FUNCTION__);
|
||||
return -1;
|
||||
return releaseFence;
|
||||
}
|
||||
|
||||
bool HandleImporter::isSmpte2086Present(const buffer_handle_t& buf) {
|
||||
@@ -481,14 +210,14 @@ bool HandleImporter::isSmpte2086Present(const buffer_handle_t& buf) {
|
||||
if (!mInitialized) {
|
||||
initializeLocked();
|
||||
}
|
||||
|
||||
if (mMapperV4 != nullptr) {
|
||||
return isMetadataPesent(mMapperV4, buf, gralloc4::MetadataType_Smpte2086);
|
||||
} else {
|
||||
ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
|
||||
std::optional<ui::Smpte2086> metadata;
|
||||
status_t status = GraphicBufferMapper::get().getSmpte2086(buf, &metadata);
|
||||
if (status != OK) {
|
||||
ALOGE("%s: Mapper failed to get Smpte2094_40 metadata! Status: %d", __FUNCTION__, status);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return metadata.has_value();
|
||||
}
|
||||
|
||||
bool HandleImporter::isSmpte2094_10Present(const buffer_handle_t& buf) {
|
||||
@@ -498,13 +227,14 @@ bool HandleImporter::isSmpte2094_10Present(const buffer_handle_t& buf) {
|
||||
initializeLocked();
|
||||
}
|
||||
|
||||
if (mMapperV4 != nullptr) {
|
||||
return isMetadataPesent(mMapperV4, buf, gralloc4::MetadataType_Smpte2094_10);
|
||||
} else {
|
||||
ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
|
||||
std::optional<std::vector<uint8_t>> metadata;
|
||||
status_t status = GraphicBufferMapper::get().getSmpte2094_10(buf, &metadata);
|
||||
if (status != OK) {
|
||||
ALOGE("%s: Mapper failed to get Smpte2094_40 metadata! Status: %d", __FUNCTION__, status);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return metadata.has_value();
|
||||
}
|
||||
|
||||
bool HandleImporter::isSmpte2094_40Present(const buffer_handle_t& buf) {
|
||||
@@ -514,13 +244,14 @@ bool HandleImporter::isSmpte2094_40Present(const buffer_handle_t& buf) {
|
||||
initializeLocked();
|
||||
}
|
||||
|
||||
if (mMapperV4 != nullptr) {
|
||||
return isMetadataPesent(mMapperV4, buf, gralloc4::MetadataType_Smpte2094_40);
|
||||
} else {
|
||||
ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
|
||||
std::optional<std::vector<uint8_t>> metadata;
|
||||
status_t status = GraphicBufferMapper::get().getSmpte2094_40(buf, &metadata);
|
||||
if (status != OK) {
|
||||
ALOGE("%s: Mapper failed to get Smpte2094_40 metadata! Status: %d", __FUNCTION__, status);
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return metadata.has_value();
|
||||
}
|
||||
|
||||
} // namespace helper
|
||||
|
||||
@@ -17,15 +17,11 @@
|
||||
#ifndef CAMERA_COMMON_1_0_HANDLEIMPORTED_H
|
||||
#define CAMERA_COMMON_1_0_HANDLEIMPORTED_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 <cutils/native_handle.h>
|
||||
#include <system/graphics.h>
|
||||
#include <ui/Rect.h>
|
||||
#include <utils/Mutex.h>
|
||||
|
||||
using android::hardware::graphics::mapper::V2_0::IMapper;
|
||||
using android::hardware::graphics::mapper::V2_0::YCbCrLayout;
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace camera {
|
||||
@@ -49,11 +45,11 @@ class HandleImporter {
|
||||
void* lock(buffer_handle_t& buf, uint64_t cpuUsage, size_t size);
|
||||
|
||||
// Locks 2-D buffer. Assumes caller has waited for acquire fences.
|
||||
void* lock(buffer_handle_t& buf, uint64_t cpuUsage, const IMapper::Rect& accessRegion);
|
||||
void* lock(buffer_handle_t& buf, uint64_t cpuUsage, const android::Rect& accessRegion);
|
||||
|
||||
// Assumes caller has waited for acquire fences.
|
||||
YCbCrLayout lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
|
||||
const IMapper::Rect& accessRegion);
|
||||
android_ycbcr lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
|
||||
const android::Rect& accessRegion);
|
||||
|
||||
// Query the stride of the first plane in bytes.
|
||||
status_t getMonoPlanarStrideBytes(buffer_handle_t& buf, uint32_t* stride /*out*/);
|
||||
@@ -69,19 +65,11 @@ class HandleImporter {
|
||||
void initializeLocked();
|
||||
void cleanup();
|
||||
|
||||
template <class M, class E>
|
||||
bool importBufferInternal(const sp<M> mapper, buffer_handle_t& handle);
|
||||
template <class M, class E>
|
||||
YCbCrLayout lockYCbCrInternal(const sp<M> mapper, buffer_handle_t& buf, uint64_t cpuUsage,
|
||||
const IMapper::Rect& accessRegion);
|
||||
template <class M, class E>
|
||||
int unlockInternal(const sp<M> mapper, buffer_handle_t& buf);
|
||||
bool importBufferInternal(buffer_handle_t& handle);
|
||||
int unlockInternal(buffer_handle_t& buf);
|
||||
|
||||
Mutex mLock;
|
||||
bool mInitialized;
|
||||
sp<IMapper> mMapperV2;
|
||||
sp<graphics::mapper::V3_0::IMapper> mMapperV3;
|
||||
sp<graphics::mapper::V4_0::IMapper> mMapperV4;
|
||||
};
|
||||
|
||||
} // namespace helper
|
||||
|
||||
@@ -32,6 +32,7 @@ cc_library_shared {
|
||||
"libgralloctypes",
|
||||
"libhardware",
|
||||
"libcamera_metadata",
|
||||
"libui",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.camera.common@1.0-helper",
|
||||
|
||||
@@ -30,6 +30,7 @@ cc_library_shared {
|
||||
"libhardware",
|
||||
"libcamera_metadata",
|
||||
"libfmq",
|
||||
"libui",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.camera.common@1.0-helper",
|
||||
|
||||
@@ -106,6 +106,7 @@ cc_library_shared {
|
||||
"libjpeg",
|
||||
"libexif",
|
||||
"libtinyxml2",
|
||||
"libui",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.camera.common@1.0-helper",
|
||||
|
||||
@@ -1574,14 +1574,23 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
|
||||
} break;
|
||||
case PixelFormat::YCBCR_420_888:
|
||||
case PixelFormat::YV12: {
|
||||
IMapper::Rect outRect {0, 0,
|
||||
static_cast<int32_t>(halBuf.width),
|
||||
static_cast<int32_t>(halBuf.height)};
|
||||
YCbCrLayout outLayout = sHandleImporter.lockYCbCr(
|
||||
*(halBuf.bufPtr), 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);
|
||||
android::Rect outRect{0, 0, static_cast<int32_t>(halBuf.width),
|
||||
static_cast<int32_t>(halBuf.height)};
|
||||
android_ycbcr result =
|
||||
sHandleImporter.lockYCbCr(*(halBuf.bufPtr), halBuf.usage, outRect);
|
||||
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);
|
||||
|
||||
@@ -46,6 +46,7 @@ cc_library_shared {
|
||||
],
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libui",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
"camera.device@3.2-impl",
|
||||
@@ -81,6 +82,7 @@ cc_library_shared {
|
||||
],
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libui",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
"camera.device@3.2-impl",
|
||||
|
||||
@@ -41,6 +41,7 @@ cc_library_shared {
|
||||
],
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libui",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
"camera.device@3.2-impl",
|
||||
|
||||
@@ -222,14 +222,23 @@ bool ExternalCameraOfflineSession::OutputThread::threadLoop() {
|
||||
} break;
|
||||
case PixelFormat::YCBCR_420_888:
|
||||
case PixelFormat::YV12: {
|
||||
IMapper::Rect outRect {0, 0,
|
||||
static_cast<int32_t>(halBuf.width),
|
||||
static_cast<int32_t>(halBuf.height)};
|
||||
YCbCrLayout outLayout = sHandleImporter.lockYCbCr(
|
||||
*(halBuf.bufPtr), 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);
|
||||
android::Rect outRect{0, 0, static_cast<int32_t>(halBuf.width),
|
||||
static_cast<int32_t>(halBuf.height)};
|
||||
android_ycbcr result =
|
||||
sHandleImporter.lockYCbCr(*(halBuf.bufPtr), halBuf.usage, outRect);
|
||||
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 = V3_4::implementation::getFourCcFromLayout(outLayout);
|
||||
|
||||
@@ -40,7 +40,7 @@ cc_library_shared {
|
||||
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 @@ cc_library_shared {
|
||||
"libsync",
|
||||
"libtinyxml2",
|
||||
"libutils",
|
||||
"libui",
|
||||
"libyuv",
|
||||
],
|
||||
static_libs: [
|
||||
|
||||
@@ -2882,13 +2882,23 @@ bool ExternalCameraDeviceSession::OutputThread::threadLoop() {
|
||||
} 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);
|
||||
|
||||
@@ -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::base::unique_fd;
|
||||
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 {
|
||||
|
||||
@@ -486,13 +486,23 @@ bool ExternalCameraOfflineSession::OutputThread::threadLoop() {
|
||||
} 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 @@ bool ExternalCameraOfflineSession::OutputThread::threadLoop() {
|
||||
} // namespace device
|
||||
} // namespace camera
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace android
|
||||
|
||||
@@ -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::BufferUsage;
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user