Merge "Refine freeBuffer in Mapper 2.0"
am: 9b2431d02a
Change-Id: Ia35e361e2b8343b3ad6205f30b1571547e7bdb3f
This commit is contained in:
commit
f6e09b2ff5
2 changed files with 27 additions and 8 deletions
|
@ -80,17 +80,21 @@ class MapperImpl : public Interface {
|
|||
}
|
||||
|
||||
Return<Error> freeBuffer(void* buffer) override {
|
||||
native_handle_t* bufferHandle = removeImportedBuffer(buffer);
|
||||
native_handle_t* bufferHandle = getImportedBuffer(buffer);
|
||||
if (!bufferHandle) {
|
||||
return Error::BAD_BUFFER;
|
||||
}
|
||||
|
||||
return mHal->freeBuffer(bufferHandle);
|
||||
Error error = mHal->freeBuffer(bufferHandle);
|
||||
if (error == Error::NONE) {
|
||||
removeImportedBuffer(buffer);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
Return<void> lock(void* buffer, uint64_t cpuUsage, const V2_0::IMapper::Rect& accessRegion,
|
||||
const hidl_handle& acquireFence, IMapper::lock_cb hidl_cb) override {
|
||||
const native_handle_t* bufferHandle = getImportedBuffer(buffer);
|
||||
const native_handle_t* bufferHandle = getConstImportedBuffer(buffer);
|
||||
if (!bufferHandle) {
|
||||
hidl_cb(Error::BAD_BUFFER, nullptr);
|
||||
return Void();
|
||||
|
@ -112,7 +116,7 @@ class MapperImpl : public Interface {
|
|||
Return<void> lockYCbCr(void* buffer, uint64_t cpuUsage, const V2_0::IMapper::Rect& accessRegion,
|
||||
const hidl_handle& acquireFence,
|
||||
IMapper::lockYCbCr_cb hidl_cb) override {
|
||||
const native_handle_t* bufferHandle = getImportedBuffer(buffer);
|
||||
const native_handle_t* bufferHandle = getConstImportedBuffer(buffer);
|
||||
if (!bufferHandle) {
|
||||
hidl_cb(Error::BAD_BUFFER, YCbCrLayout{});
|
||||
return Void();
|
||||
|
@ -132,7 +136,7 @@ class MapperImpl : public Interface {
|
|||
}
|
||||
|
||||
Return<void> unlock(void* buffer, IMapper::unlock_cb hidl_cb) override {
|
||||
const native_handle_t* bufferHandle = getImportedBuffer(buffer);
|
||||
const native_handle_t* bufferHandle = getConstImportedBuffer(buffer);
|
||||
if (!bufferHandle) {
|
||||
hidl_cb(Error::BAD_BUFFER, nullptr);
|
||||
return Void();
|
||||
|
@ -160,7 +164,11 @@ class MapperImpl : public Interface {
|
|||
return static_cast<native_handle_t*>(buffer);
|
||||
}
|
||||
|
||||
virtual const native_handle_t* getImportedBuffer(void* buffer) const {
|
||||
virtual native_handle_t* getImportedBuffer(void* buffer) const {
|
||||
return static_cast<native_handle_t*>(buffer);
|
||||
}
|
||||
|
||||
virtual const native_handle_t* getConstImportedBuffer(void* buffer) const {
|
||||
return static_cast<const native_handle_t*>(buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,14 @@ class GrallocImportedBufferPool {
|
|||
return mBufferHandles.erase(bufferHandle) == 1 ? bufferHandle : nullptr;
|
||||
}
|
||||
|
||||
const native_handle_t* get(void* buffer) {
|
||||
native_handle_t* get(void* buffer) {
|
||||
auto bufferHandle = static_cast<native_handle_t*>(buffer);
|
||||
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
return mBufferHandles.count(bufferHandle) == 1 ? bufferHandle : nullptr;
|
||||
}
|
||||
|
||||
const native_handle_t* getConst(void* buffer) {
|
||||
auto bufferHandle = static_cast<const native_handle_t*>(buffer);
|
||||
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
|
@ -92,9 +99,13 @@ class GrallocMapper : public T {
|
|||
return GrallocImportedBufferPool::getInstance().remove(buffer);
|
||||
}
|
||||
|
||||
const native_handle_t* getImportedBuffer(void* buffer) const override {
|
||||
native_handle_t* getImportedBuffer(void* buffer) const override {
|
||||
return GrallocImportedBufferPool::getInstance().get(buffer);
|
||||
}
|
||||
|
||||
const native_handle_t* getConstImportedBuffer(void* buffer) const override {
|
||||
return GrallocImportedBufferPool::getInstance().getConst(buffer);
|
||||
}
|
||||
};
|
||||
|
||||
class GrallocLoader {
|
||||
|
|
Loading…
Reference in a new issue