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 {
|
Return<Error> freeBuffer(void* buffer) override {
|
||||||
native_handle_t* bufferHandle = removeImportedBuffer(buffer);
|
native_handle_t* bufferHandle = getImportedBuffer(buffer);
|
||||||
if (!bufferHandle) {
|
if (!bufferHandle) {
|
||||||
return Error::BAD_BUFFER;
|
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,
|
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 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) {
|
if (!bufferHandle) {
|
||||||
hidl_cb(Error::BAD_BUFFER, nullptr);
|
hidl_cb(Error::BAD_BUFFER, nullptr);
|
||||||
return Void();
|
return Void();
|
||||||
|
@ -112,7 +116,7 @@ class MapperImpl : public Interface {
|
||||||
Return<void> lockYCbCr(void* buffer, uint64_t cpuUsage, const V2_0::IMapper::Rect& accessRegion,
|
Return<void> lockYCbCr(void* buffer, uint64_t cpuUsage, const V2_0::IMapper::Rect& accessRegion,
|
||||||
const hidl_handle& acquireFence,
|
const hidl_handle& acquireFence,
|
||||||
IMapper::lockYCbCr_cb hidl_cb) override {
|
IMapper::lockYCbCr_cb hidl_cb) override {
|
||||||
const native_handle_t* bufferHandle = getImportedBuffer(buffer);
|
const native_handle_t* bufferHandle = getConstImportedBuffer(buffer);
|
||||||
if (!bufferHandle) {
|
if (!bufferHandle) {
|
||||||
hidl_cb(Error::BAD_BUFFER, YCbCrLayout{});
|
hidl_cb(Error::BAD_BUFFER, YCbCrLayout{});
|
||||||
return Void();
|
return Void();
|
||||||
|
@ -132,7 +136,7 @@ class MapperImpl : public Interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> unlock(void* buffer, IMapper::unlock_cb hidl_cb) override {
|
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) {
|
if (!bufferHandle) {
|
||||||
hidl_cb(Error::BAD_BUFFER, nullptr);
|
hidl_cb(Error::BAD_BUFFER, nullptr);
|
||||||
return Void();
|
return Void();
|
||||||
|
@ -160,7 +164,11 @@ class MapperImpl : public Interface {
|
||||||
return static_cast<native_handle_t*>(buffer);
|
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);
|
return static_cast<const native_handle_t*>(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,14 @@ class GrallocImportedBufferPool {
|
||||||
return mBufferHandles.erase(bufferHandle) == 1 ? bufferHandle : nullptr;
|
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);
|
auto bufferHandle = static_cast<const native_handle_t*>(buffer);
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mMutex);
|
std::lock_guard<std::mutex> lock(mMutex);
|
||||||
|
@ -92,9 +99,13 @@ class GrallocMapper : public T {
|
||||||
return GrallocImportedBufferPool::getInstance().remove(buffer);
|
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);
|
return GrallocImportedBufferPool::getInstance().get(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const native_handle_t* getConstImportedBuffer(void* buffer) const override {
|
||||||
|
return GrallocImportedBufferPool::getInstance().getConst(buffer);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class GrallocLoader {
|
class GrallocLoader {
|
||||||
|
|
Loading…
Reference in a new issue