diff options
author | Peng Xu <pengxu@google.com> | 2017-06-21 12:39:08 -0700 |
---|---|---|
committer | Peng Xu <pengxu@google.com> | 2017-06-21 12:39:08 -0700 |
commit | 64ede7da77e9f8aa74a99185464bde4080d677bc (patch) | |
tree | b7b74d109ebcb388d43ea7fccad62e3a84d010ae | |
parent | b3f7e05044eb5237f500c082e7db102ce0bb4475 (diff) | |
download | contexthub-64ede7da77e9f8aa74a99185464bde4080d677bc.tar.gz |
Honor gralloc1 cap RELEASE_IMPLY_DELETE in nanohub
Test: sensor CTS SensorDirectReportTest pass
Bug: 62805387
Change-Id: Id32251619ec14de88d878a71ed071fdfe3ecd702
-rw-r--r-- | sensorhal/directchannel.cpp | 24 | ||||
-rw-r--r-- | sensorhal/directchannel.h | 2 |
2 files changed, 22 insertions, 4 deletions
diff --git a/sensorhal/directchannel.cpp b/sensorhal/directchannel.cpp index d0e719d6..8d87782d 100644 --- a/sensorhal/directchannel.cpp +++ b/sensorhal/directchannel.cpp @@ -79,7 +79,8 @@ ANDROID_SINGLETON_STATIC_INSTANCE(GrallocHalWrapper); GrallocHalWrapper::GrallocHalWrapper() : mError(NO_INIT), mVersion(-1), mGrallocModule(nullptr), mAllocDevice(nullptr), mGralloc1Device(nullptr), - mPfnRetain(nullptr), mPfnRelease(nullptr), mPfnLock(nullptr), mPfnUnlock(nullptr) { + mPfnRetain(nullptr), mPfnRelease(nullptr), mPfnLock(nullptr), mPfnUnlock(nullptr), + mUnregisterImplyDelete(false) { const hw_module_t *module; status_t err = ::hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); ALOGE_IF(err, "couldn't load %s module (%s)", GRALLOC_HARDWARE_MODULE_ID, strerror(-err)); @@ -106,7 +107,7 @@ GrallocHalWrapper::GrallocHalWrapper() mGrallocModule = (gralloc_module_t *)module; mVersion = 0; break; - case 1: + case 1: { err = ::gralloc1_open(module, &mGralloc1Device); if (err != NO_ERROR) { ALOGE("cannot open gralloc1 device (%s)", strerror(-err)); @@ -135,10 +136,23 @@ GrallocHalWrapper::GrallocHalWrapper() break; } + + int32_t caps[GRALLOC1_LAST_CAPABILITY]; + uint32_t n_cap = GRALLOC1_LAST_CAPABILITY; + mGralloc1Device->getCapabilities(mGralloc1Device, &n_cap, caps); + for (size_t i = 0; i < n_cap; ++i) { + if (caps[i] == GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE) { + mUnregisterImplyDelete = true; + } + } + ALOGI("gralloc hal %ssupport RELEASE_IMPLY_DELETE", + mUnregisterImplyDelete ? "" : "does not "); + // successfully initialized gralloc1 mGrallocModule = (gralloc_module_t *)module; mVersion = 1; break; + } default: ALOGE("Unknown version, not supported"); break; @@ -280,8 +294,10 @@ GrallocDirectChannel::~GrallocDirectChannel() { mBase = nullptr; } GrallocHalWrapper::getInstance().unregisterBuffer(mNativeHandle); - ::native_handle_close(mNativeHandle); - ::native_handle_delete(mNativeHandle); + if (!GrallocHalWrapper::getInstance().unregisterImplyDelete()) { + ::native_handle_close(mNativeHandle); + ::native_handle_delete(mNativeHandle); + } mNativeHandle = nullptr; } } diff --git a/sensorhal/directchannel.h b/sensorhal/directchannel.h index 192e35dc..4842ffcc 100644 --- a/sensorhal/directchannel.h +++ b/sensorhal/directchannel.h @@ -58,6 +58,7 @@ public: int unregisterBuffer(const native_handle_t *handle); int lock(const native_handle_t *handle, int usage, int l, int t, int w, int h, void **vaddr); int unlock(const native_handle_t *handle); + bool unregisterImplyDelete() { return mUnregisterImplyDelete; } private: friend class Singleton<GrallocHalWrapper>; GrallocHalWrapper(); @@ -76,6 +77,7 @@ private: GRALLOC1_PFN_RELEASE mPfnRelease; GRALLOC1_PFN_LOCK mPfnLock; GRALLOC1_PFN_UNLOCK mPfnUnlock; + bool mUnregisterImplyDelete; }; class GrallocDirectChannel : public DirectChannelBase { |