diff options
author | Praveen Chavan <pchavan@codeaurora.org> | 2018-07-06 18:19:46 -0700 |
---|---|---|
committer | Praveen Chavan <pchavan@codeaurora.org> | 2018-07-10 23:15:56 -0700 |
commit | 0957bedef83c372238cd71388fab11de8e5feb1b (patch) | |
tree | f6e19061fca0bf227f3f47c893bc7750236a47f9 | |
parent | 8aefef0b385405f689a0eea1e80f1c67f441787c (diff) | |
download | display-0957bedef83c372238cd71388fab11de8e5feb1b.tar.gz |
qdMetaData: Add get/setMetaData variants that unmap metadata
Add get/setMetaDataAndUnmap(..) api that remove the meta-data
mapping and reset the mapped pointer in handle.
Use these versions in setMetaData called during alloc to
ensure allocating process does not duplicate invalid
base address of metadata (i.e when native_handle is cloned
without importing)
CRs-Fixed: 2265196
Change-Id: I0481ad8d59950256723871a089aeb3d143afac5a
-rw-r--r-- | gralloc/gr_buf_mgr.cpp | 4 | ||||
-rw-r--r-- | libqdutils/qdMetaData.cpp | 22 | ||||
-rw-r--r-- | libqdutils/qdMetaData.h | 8 |
3 files changed, 32 insertions, 2 deletions
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp index 8c8c66f8..c8309525 100644 --- a/gralloc/gr_buf_mgr.cpp +++ b/gralloc/gr_buf_mgr.cpp @@ -359,11 +359,11 @@ Error BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_h hnd->layer_count = layer_count; ColorSpace_t colorSpace = ITU_R_601; - setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace)); + setMetaDataAndUnmap(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace)); bool use_adreno_for_size = CanUseAdrenoForSize(buffer_type, usage); if (use_adreno_for_size) { - setMetaData(hnd, SET_GRAPHICS_METADATA, reinterpret_cast<void *>(&graphics_metadata)); + setMetaDataAndUnmap(hnd, SET_GRAPHICS_METADATA, reinterpret_cast<void *>(&graphics_metadata)); } *handle = hnd; diff --git a/libqdutils/qdMetaData.cpp b/libqdutils/qdMetaData.cpp index 3259ee23..a40ea629 100644 --- a/libqdutils/qdMetaData.cpp +++ b/libqdutils/qdMetaData.cpp @@ -64,6 +64,13 @@ static int validateAndMap(private_handle_t* handle) { return 0; } +static void unmapAndReset(private_handle_t *handle) { + if (private_handle_t::validate(handle) == 0 && handle->base_metadata) { + munmap(reinterpret_cast<void *>(handle->base_metadata), getMetaDataSize()); + handle->base_metadata = 0; + } +} + int setMetaData(private_handle_t *handle, DispParamType paramType, void *param) { auto err = validateAndMap(handle); @@ -346,3 +353,18 @@ int copyMetaDataVaToVa(MetaData_t *src_data, MetaData_t *dst_data) { return 0; } +int setMetaDataAndUnmap(struct private_handle_t *handle, enum DispParamType paramType, + void *param) { + auto ret = setMetaData(handle, paramType, param); + unmapAndReset(handle); + return ret; +} + +int getMetaDataAndUnmap(struct private_handle_t *handle, + enum DispFetchParamType paramType, + void *param) { + auto ret = getMetaData(handle, paramType, param); + unmapAndReset(handle); + return ret; +} + diff --git a/libqdutils/qdMetaData.h b/libqdutils/qdMetaData.h index 195fdd20..5739ceea 100644 --- a/libqdutils/qdMetaData.h +++ b/libqdutils/qdMetaData.h @@ -208,6 +208,14 @@ int clearMetaDataVa(struct MetaData_t *data, enum DispParamType paramType); unsigned long getMetaDataSize(); +// Map, access metadata and unmap. Used by clients that do not import/free but +// clone and delete native_handle +int setMetaDataAndUnmap(struct private_handle_t *handle, enum DispParamType paramType, + void *param); +int getMetaDataAndUnmap(struct private_handle_t *handle, + enum DispFetchParamType paramType, + void *param); + #ifdef __cplusplus } #endif |