Merge "Ensure AIMapper and underlying IMPL outlive IMapperProvider" into main am: b8c23a8a7d
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2781709 Change-Id: I671d08ada9a43dd869add540dfceb05ee22a6fcb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
4c11b51986
1 changed files with 7 additions and 6 deletions
|
@ -106,15 +106,15 @@ class IMapperProvider {
|
|||
static_assert(std::is_constructible_v<IMPL>, "Implementation must have a no-args constructor");
|
||||
|
||||
std::once_flag mLoadOnceFlag;
|
||||
std::optional<IMPL> mImpl;
|
||||
AIMapper mMapper = {};
|
||||
IMPL* _Nullable mImpl;
|
||||
AIMapper* _Nullable mMapper;
|
||||
|
||||
static IMPL& impl() {
|
||||
return *reinterpret_cast<IMapperProvider<IMPL>*>(provider::sIMapperInstance)->mImpl;
|
||||
}
|
||||
|
||||
void bindV5() {
|
||||
mMapper.v5 = {
|
||||
mMapper->v5 = {
|
||||
.importBuffer = [](const native_handle_t* _Nonnull handle,
|
||||
buffer_handle_t _Nullable* _Nonnull outBufferHandle)
|
||||
-> AIMapper_Error { return impl().importBuffer(handle, outBufferHandle); },
|
||||
|
@ -208,13 +208,14 @@ class IMapperProvider {
|
|||
LOG_ALWAYS_FATAL_IF(provider::sIMapperInstance != nullptr,
|
||||
"AIMapper implementation already loaded!");
|
||||
provider::sIMapperInstance = this;
|
||||
mImpl.emplace();
|
||||
mMapper.version = IMPL::version;
|
||||
mImpl = new IMPL();
|
||||
mMapper = new AIMapper();
|
||||
mMapper->version = IMPL::version;
|
||||
if (IMPL::version >= AIMAPPER_VERSION_5) {
|
||||
bindV5();
|
||||
}
|
||||
});
|
||||
*outImplementation = &mMapper;
|
||||
*outImplementation = mMapper;
|
||||
return AIMAPPER_ERROR_NONE;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue