Loading audio/common/all-versions/util/include/common/all-versions/HidlSupport.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef android_hardware_audio_common_HidlSupport_H_ #define android_hardware_audio_common_HidlSupport_H_ #include <hidl/HidlSupport.h> #include <algorithm> namespace android::hardware::audio::common::utils { template <typename Enum> bool isValidHidlEnum(Enum e) { hidl_enum_range<Enum> values; return std::find(values.begin(), values.end(), e) != values.end(); } } // namespace android::hardware::audio::common::utils #endif // android_hardware_audio_common_HidlSupport_H_ audio/core/all-versions/default/StreamIn.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "core/default/StreamIn.h" #include "core/default/Conversions.h" #include "core/default/Util.h" #include "common/all-versions/HidlSupport.h" //#define LOG_NDEBUG 0 #define ATRACE_TAG ATRACE_TAG_AUDIO Loading @@ -27,6 +28,7 @@ #include <hardware/audio.h> #include <utils/Trace.h> #include <memory> #include <cmath> namespace android { namespace hardware { Loading Loading @@ -501,6 +503,10 @@ Return<Result> StreamIn::setMicrophoneDirection(MicrophoneDirection direction) { if (mStream->set_microphone_direction == nullptr) { return Result::NOT_SUPPORTED; } if (!common::utils::isValidHidlEnum(direction)) { ALOGE("%s: Invalid direction %d", __func__, direction); return Result::INVALID_ARGUMENTS; } return Stream::analyzeStatus( "set_microphone_direction", mStream->set_microphone_direction( Loading @@ -511,6 +517,10 @@ Return<Result> StreamIn::setMicrophoneFieldDimension(float zoom) { if (mStream->set_microphone_field_dimension == nullptr) { return Result::NOT_SUPPORTED; } if (std::isnan(zoom) || zoom < -1 || zoom > 1) { ALOGE("%s: Invalid zoom %f", __func__, zoom); return Result::INVALID_ARGUMENTS; } return Stream::analyzeStatus("set_microphone_field_dimension", mStream->set_microphone_field_dimension(mStream, zoom)); } Loading automotive/vehicle/2.0/types.hal +15 −1 Original line number Diff line number Diff line Loading @@ -641,7 +641,9 @@ enum VehicleProperty : int32_t { /** * Night mode * * True indicates that night mode is currently enabled. * True indicates that the night mode sensor has detected that the car cabin environment has * low light. The platform could use this, for example, to enable appropriate UI for * better viewing in dark or low light environments. * * @change_mode VehiclePropertyChangeMode:ON_CHANGE * @access VehiclePropertyAccess:READ Loading Loading @@ -983,6 +985,10 @@ enum VehicleProperty : int32_t { * * Indicates whether the vehicle is displaying temperature to the user as * Celsius or Fahrenheit. * VehiclePropConfig.configArray is used to indicate the supported temperature display units. * For example: configArray[0] = CELSIUS * configArray[1] = FAHRENHEIT * * This parameter MAY be used for displaying any HVAC temperature in the system. * Values must be one of VehicleUnit::CELSIUS or VehicleUnit::FAHRENHEIT * Note that internally, all temperatures are represented in floating point Celsius. Loading Loading @@ -2792,6 +2798,14 @@ struct VehicleAreaConfig { */ int32_t areaId; /** * If the property has @data_enum, leave the range to zero. * * Range will be ignored in the following cases: * - The VehiclePropertyType is not INT32, INT64 or FLOAT. * - Both of min value and max value are zero. */ int32_t minInt32Value; int32_t maxInt32Value; Loading camera/common/1.0/default/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ cc_library_static { "libhardware", "libcamera_metadata", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", "libexif", ], include_dirs: ["system/media/private/camera/include"], Loading camera/common/1.0/default/HandleImporter.cpp +157 −87 Original line number Diff line number Diff line Loading @@ -25,7 +25,9 @@ namespace common { namespace V1_0 { namespace helper { using MapperError = android::hardware::graphics::mapper::V2_0::Error; using MapperErrorV2 = android::hardware::graphics::mapper::V2_0::Error; using MapperErrorV3 = android::hardware::graphics::mapper::V3_0::Error; using IMapperV3 = android::hardware::graphics::mapper::V3_0::IMapper; HandleImporter::HandleImporter() : mInitialized(false) {} Loading @@ -34,8 +36,14 @@ void HandleImporter::initializeLocked() { return; } mMapper = IMapper::getService(); if (mMapper == nullptr) { mMapperV3 = IMapperV3::getService(); if (mMapperV3 != nullptr) { mInitialized = true; return; } mMapperV2 = IMapper::getService(); if (mMapperV2 == nullptr) { ALOGE("%s: cannnot acccess graphics mapper HAL!", __FUNCTION__); return; } Loading @@ -45,32 +53,16 @@ void HandleImporter::initializeLocked() { } void HandleImporter::cleanup() { mMapper.clear(); mMapperV3.clear(); mMapperV2.clear(); mInitialized = false; } // 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. bool HandleImporter::importBuffer(buffer_handle_t& handle) { if (!handle->numFds && !handle->numInts) { handle = nullptr; return true; } Mutex::Autolock lock(mLock); if (!mInitialized) { initializeLocked(); } if (mMapper == nullptr) { ALOGE("%s: mMapper is null!", __FUNCTION__); return false; } MapperError error; template<class M, class E> bool HandleImporter::importBufferInternal(const sp<M> mapper, buffer_handle_t& handle) { E error; buffer_handle_t importedHandle; auto ret = mMapper->importBuffer( auto ret = mapper->importBuffer( hidl_handle(handle), [&](const auto& tmpError, const auto& tmpBufferHandle) { error = tmpError; Loading @@ -83,32 +75,119 @@ bool HandleImporter::importBuffer(buffer_handle_t& handle) { return false; } if (error != MapperError::NONE) { if (error != E::NONE) { return false; } handle = importedHandle; 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 = {}; 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; } 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. bool HandleImporter::importBuffer(buffer_handle_t& handle) { if (!handle->numFds && !handle->numInts) { handle = nullptr; return true; } Mutex::Autolock lock(mLock); if (!mInitialized) { initializeLocked(); } if (mMapperV3 != nullptr) { return importBufferInternal<IMapperV3, MapperErrorV3>(mMapperV3, handle); } if (mMapperV2 != nullptr) { return importBufferInternal<IMapper, MapperErrorV2>(mMapperV2, handle); } ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return false; } void HandleImporter::freeBuffer(buffer_handle_t handle) { if (!handle) { return; } Mutex::Autolock lock(mLock); if (mMapper == nullptr) { ALOGE("%s: mMapper is null!", __FUNCTION__); if (mMapperV3 == nullptr && mMapperV2 == nullptr) { ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return; } auto ret = mMapper->freeBuffer(const_cast<native_handle_t*>(handle)); 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()); } } } bool HandleImporter::importFence(const native_handle_t* handle, int& fd) const { if (handle == nullptr || handle->numFds == 0) { Loading Loading @@ -138,91 +217,82 @@ void* HandleImporter::lock( buffer_handle_t& buf, uint64_t cpuUsage, size_t size) { Mutex::Autolock lock(mLock); void *ret = 0; IMapper::Rect accessRegion { 0, 0, static_cast<int>(size), 1 }; if (!mInitialized) { initializeLocked(); } if (mMapper == nullptr) { ALOGE("%s: mMapper is null!", __FUNCTION__); if (mMapperV3 == nullptr && mMapperV2 == nullptr) { ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return ret; } hidl_handle acquireFenceHandle; auto buffer = const_cast<native_handle_t*>(buf); mMapper->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle, 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); } }); } 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 == MapperError::NONE) { if (tmpError == MapperErrorV2::NONE) { ret = tmpPtr; } else { ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError); } }); } ALOGV("%s: ptr %p size: %zu", __FUNCTION__, ret, size); return ret; } YCbCrLayout HandleImporter::lockYCbCr( buffer_handle_t& buf, uint64_t cpuUsage, const IMapper::Rect& accessRegion) { Mutex::Autolock lock(mLock); YCbCrLayout layout = {}; if (!mInitialized) { initializeLocked(); } if (mMapper == nullptr) { ALOGE("%s: mMapper is null!", __FUNCTION__); return layout; if (mMapperV3 != nullptr) { return lockYCbCrInternal<IMapperV3, MapperErrorV3>( mMapperV3, buf, cpuUsage, accessRegion); } hidl_handle acquireFenceHandle; auto buffer = const_cast<native_handle_t*>(buf); mMapper->lockYCbCr(buffer, cpuUsage, accessRegion, acquireFenceHandle, [&](const auto& tmpError, const auto& tmpLayout) { if (tmpError == MapperError::NONE) { layout = tmpLayout; } else { ALOGE("%s: failed to lockYCbCr error %d!", __FUNCTION__, tmpError); if (mMapperV2 != nullptr) { return lockYCbCrInternal<IMapper, MapperErrorV2>( mMapperV2, buf, cpuUsage, accessRegion); } }); ALOGV("%s: layout y %p cb %p cr %p y_str %d c_str %d c_step %d", __FUNCTION__, layout.y, layout.cb, layout.cr, layout.yStride, layout.cStride, layout.chromaStep); return layout; ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return {}; } int HandleImporter::unlock(buffer_handle_t& buf) { int releaseFence = -1; auto buffer = const_cast<native_handle_t*>(buf); mMapper->unlock( buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) { if (tmpError == MapperError::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); if (mMapperV3 != nullptr) { return unlockInternal<IMapperV3, MapperErrorV3>(mMapperV3, buf); } if (mMapperV2 != nullptr) { return unlockInternal<IMapper, MapperErrorV2>(mMapperV2, buf); } } else { ALOGE("%s: failed to unlock error %d!", __FUNCTION__, tmpError); } }); return releaseFence; ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return -1; } } // namespace helper Loading Loading
audio/common/all-versions/util/include/common/all-versions/HidlSupport.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef android_hardware_audio_common_HidlSupport_H_ #define android_hardware_audio_common_HidlSupport_H_ #include <hidl/HidlSupport.h> #include <algorithm> namespace android::hardware::audio::common::utils { template <typename Enum> bool isValidHidlEnum(Enum e) { hidl_enum_range<Enum> values; return std::find(values.begin(), values.end(), e) != values.end(); } } // namespace android::hardware::audio::common::utils #endif // android_hardware_audio_common_HidlSupport_H_
audio/core/all-versions/default/StreamIn.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "core/default/StreamIn.h" #include "core/default/Conversions.h" #include "core/default/Util.h" #include "common/all-versions/HidlSupport.h" //#define LOG_NDEBUG 0 #define ATRACE_TAG ATRACE_TAG_AUDIO Loading @@ -27,6 +28,7 @@ #include <hardware/audio.h> #include <utils/Trace.h> #include <memory> #include <cmath> namespace android { namespace hardware { Loading Loading @@ -501,6 +503,10 @@ Return<Result> StreamIn::setMicrophoneDirection(MicrophoneDirection direction) { if (mStream->set_microphone_direction == nullptr) { return Result::NOT_SUPPORTED; } if (!common::utils::isValidHidlEnum(direction)) { ALOGE("%s: Invalid direction %d", __func__, direction); return Result::INVALID_ARGUMENTS; } return Stream::analyzeStatus( "set_microphone_direction", mStream->set_microphone_direction( Loading @@ -511,6 +517,10 @@ Return<Result> StreamIn::setMicrophoneFieldDimension(float zoom) { if (mStream->set_microphone_field_dimension == nullptr) { return Result::NOT_SUPPORTED; } if (std::isnan(zoom) || zoom < -1 || zoom > 1) { ALOGE("%s: Invalid zoom %f", __func__, zoom); return Result::INVALID_ARGUMENTS; } return Stream::analyzeStatus("set_microphone_field_dimension", mStream->set_microphone_field_dimension(mStream, zoom)); } Loading
automotive/vehicle/2.0/types.hal +15 −1 Original line number Diff line number Diff line Loading @@ -641,7 +641,9 @@ enum VehicleProperty : int32_t { /** * Night mode * * True indicates that night mode is currently enabled. * True indicates that the night mode sensor has detected that the car cabin environment has * low light. The platform could use this, for example, to enable appropriate UI for * better viewing in dark or low light environments. * * @change_mode VehiclePropertyChangeMode:ON_CHANGE * @access VehiclePropertyAccess:READ Loading Loading @@ -983,6 +985,10 @@ enum VehicleProperty : int32_t { * * Indicates whether the vehicle is displaying temperature to the user as * Celsius or Fahrenheit. * VehiclePropConfig.configArray is used to indicate the supported temperature display units. * For example: configArray[0] = CELSIUS * configArray[1] = FAHRENHEIT * * This parameter MAY be used for displaying any HVAC temperature in the system. * Values must be one of VehicleUnit::CELSIUS or VehicleUnit::FAHRENHEIT * Note that internally, all temperatures are represented in floating point Celsius. Loading Loading @@ -2792,6 +2798,14 @@ struct VehicleAreaConfig { */ int32_t areaId; /** * If the property has @data_enum, leave the range to zero. * * Range will be ignored in the following cases: * - The VehiclePropertyType is not INT32, INT64 or FLOAT. * - Both of min value and max value are zero. */ int32_t minInt32Value; int32_t maxInt32Value; Loading
camera/common/1.0/default/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ cc_library_static { "libhardware", "libcamera_metadata", "android.hardware.graphics.mapper@2.0", "android.hardware.graphics.mapper@3.0", "libexif", ], include_dirs: ["system/media/private/camera/include"], Loading
camera/common/1.0/default/HandleImporter.cpp +157 −87 Original line number Diff line number Diff line Loading @@ -25,7 +25,9 @@ namespace common { namespace V1_0 { namespace helper { using MapperError = android::hardware::graphics::mapper::V2_0::Error; using MapperErrorV2 = android::hardware::graphics::mapper::V2_0::Error; using MapperErrorV3 = android::hardware::graphics::mapper::V3_0::Error; using IMapperV3 = android::hardware::graphics::mapper::V3_0::IMapper; HandleImporter::HandleImporter() : mInitialized(false) {} Loading @@ -34,8 +36,14 @@ void HandleImporter::initializeLocked() { return; } mMapper = IMapper::getService(); if (mMapper == nullptr) { mMapperV3 = IMapperV3::getService(); if (mMapperV3 != nullptr) { mInitialized = true; return; } mMapperV2 = IMapper::getService(); if (mMapperV2 == nullptr) { ALOGE("%s: cannnot acccess graphics mapper HAL!", __FUNCTION__); return; } Loading @@ -45,32 +53,16 @@ void HandleImporter::initializeLocked() { } void HandleImporter::cleanup() { mMapper.clear(); mMapperV3.clear(); mMapperV2.clear(); mInitialized = false; } // 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. bool HandleImporter::importBuffer(buffer_handle_t& handle) { if (!handle->numFds && !handle->numInts) { handle = nullptr; return true; } Mutex::Autolock lock(mLock); if (!mInitialized) { initializeLocked(); } if (mMapper == nullptr) { ALOGE("%s: mMapper is null!", __FUNCTION__); return false; } MapperError error; template<class M, class E> bool HandleImporter::importBufferInternal(const sp<M> mapper, buffer_handle_t& handle) { E error; buffer_handle_t importedHandle; auto ret = mMapper->importBuffer( auto ret = mapper->importBuffer( hidl_handle(handle), [&](const auto& tmpError, const auto& tmpBufferHandle) { error = tmpError; Loading @@ -83,32 +75,119 @@ bool HandleImporter::importBuffer(buffer_handle_t& handle) { return false; } if (error != MapperError::NONE) { if (error != E::NONE) { return false; } handle = importedHandle; 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 = {}; 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; } 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. bool HandleImporter::importBuffer(buffer_handle_t& handle) { if (!handle->numFds && !handle->numInts) { handle = nullptr; return true; } Mutex::Autolock lock(mLock); if (!mInitialized) { initializeLocked(); } if (mMapperV3 != nullptr) { return importBufferInternal<IMapperV3, MapperErrorV3>(mMapperV3, handle); } if (mMapperV2 != nullptr) { return importBufferInternal<IMapper, MapperErrorV2>(mMapperV2, handle); } ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return false; } void HandleImporter::freeBuffer(buffer_handle_t handle) { if (!handle) { return; } Mutex::Autolock lock(mLock); if (mMapper == nullptr) { ALOGE("%s: mMapper is null!", __FUNCTION__); if (mMapperV3 == nullptr && mMapperV2 == nullptr) { ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return; } auto ret = mMapper->freeBuffer(const_cast<native_handle_t*>(handle)); 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()); } } } bool HandleImporter::importFence(const native_handle_t* handle, int& fd) const { if (handle == nullptr || handle->numFds == 0) { Loading Loading @@ -138,91 +217,82 @@ void* HandleImporter::lock( buffer_handle_t& buf, uint64_t cpuUsage, size_t size) { Mutex::Autolock lock(mLock); void *ret = 0; IMapper::Rect accessRegion { 0, 0, static_cast<int>(size), 1 }; if (!mInitialized) { initializeLocked(); } if (mMapper == nullptr) { ALOGE("%s: mMapper is null!", __FUNCTION__); if (mMapperV3 == nullptr && mMapperV2 == nullptr) { ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return ret; } hidl_handle acquireFenceHandle; auto buffer = const_cast<native_handle_t*>(buf); mMapper->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle, 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); } }); } 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 == MapperError::NONE) { if (tmpError == MapperErrorV2::NONE) { ret = tmpPtr; } else { ALOGE("%s: failed to lock error %d!", __FUNCTION__, tmpError); } }); } ALOGV("%s: ptr %p size: %zu", __FUNCTION__, ret, size); return ret; } YCbCrLayout HandleImporter::lockYCbCr( buffer_handle_t& buf, uint64_t cpuUsage, const IMapper::Rect& accessRegion) { Mutex::Autolock lock(mLock); YCbCrLayout layout = {}; if (!mInitialized) { initializeLocked(); } if (mMapper == nullptr) { ALOGE("%s: mMapper is null!", __FUNCTION__); return layout; if (mMapperV3 != nullptr) { return lockYCbCrInternal<IMapperV3, MapperErrorV3>( mMapperV3, buf, cpuUsage, accessRegion); } hidl_handle acquireFenceHandle; auto buffer = const_cast<native_handle_t*>(buf); mMapper->lockYCbCr(buffer, cpuUsage, accessRegion, acquireFenceHandle, [&](const auto& tmpError, const auto& tmpLayout) { if (tmpError == MapperError::NONE) { layout = tmpLayout; } else { ALOGE("%s: failed to lockYCbCr error %d!", __FUNCTION__, tmpError); if (mMapperV2 != nullptr) { return lockYCbCrInternal<IMapper, MapperErrorV2>( mMapperV2, buf, cpuUsage, accessRegion); } }); ALOGV("%s: layout y %p cb %p cr %p y_str %d c_str %d c_step %d", __FUNCTION__, layout.y, layout.cb, layout.cr, layout.yStride, layout.cStride, layout.chromaStep); return layout; ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return {}; } int HandleImporter::unlock(buffer_handle_t& buf) { int releaseFence = -1; auto buffer = const_cast<native_handle_t*>(buf); mMapper->unlock( buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) { if (tmpError == MapperError::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); if (mMapperV3 != nullptr) { return unlockInternal<IMapperV3, MapperErrorV3>(mMapperV3, buf); } if (mMapperV2 != nullptr) { return unlockInternal<IMapper, MapperErrorV2>(mMapperV2, buf); } } else { ALOGE("%s: failed to unlock error %d!", __FUNCTION__, tmpError); } }); return releaseFence; ALOGE("%s: mMapperV3 and mMapperV2 are both null!", __FUNCTION__); return -1; } } // namespace helper Loading