diff options
author | 2016-12-23 02:05:24 +0000 | |
---|---|---|
committer | 2016-12-23 02:05:24 +0000 | |
commit | 6fb6369693a89fbcbf86b13fce65454e2b7e50f9 (patch) | |
tree | 43c8026beb8e444b24867b605a4ff042ba248432 /libs/ui/GrallocMapper.cpp | |
parent | 064670efc4ce0fc7dcbe943b91d6d85b31025736 (diff) | |
parent | 316694751e5f20e24ad2eb3cb36d99f5498d373d (diff) |
Merge "libui: use HIDLized gralloc-mapper"
Diffstat (limited to 'libs/ui/GrallocMapper.cpp')
-rw-r--r-- | libs/ui/GrallocMapper.cpp | 171 |
1 files changed, 115 insertions, 56 deletions
diff --git a/libs/ui/GrallocMapper.cpp b/libs/ui/GrallocMapper.cpp index d568b68d7b..b444871e3b 100644 --- a/libs/ui/GrallocMapper.cpp +++ b/libs/ui/GrallocMapper.cpp @@ -26,85 +26,144 @@ namespace android { namespace Gralloc2 { -typedef const void*(*FetchInterface)(const char* name); +static constexpr Error kDefaultError = Error::NO_RESOURCES; -static FetchInterface loadHalLib(const char* pkg_name) +Mapper::Mapper() { - static const std::array<const char*, 3> sSearchDirs = {{ - HAL_LIBRARY_PATH_ODM, - HAL_LIBRARY_PATH_VENDOR, - HAL_LIBRARY_PATH_SYSTEM, - }}; - static const char sSymbolName[] = "HALLIB_FETCH_Interface"; - - void* handle = nullptr; - std::string path; - for (auto dir : sSearchDirs) { - path = dir; - path += pkg_name; - path += ".hallib.so"; - handle = dlopen(path.c_str(), RTLD_LOCAL | RTLD_NOW); - if (handle) { - break; - } - } - if (!handle) { - return nullptr; + mMapper = IMapper::getService("gralloc-mapper"); + if (mMapper != nullptr && mMapper->isRemote()) { + LOG_ALWAYS_FATAL("gralloc-mapper must be in passthrough mode"); } +} - void* symbol = dlsym(handle, sSymbolName); - if (!symbol) { - ALOGE("%s is missing from %s", sSymbolName, path.c_str()); - dlclose(handle); - return nullptr; - } +Error Mapper::retain(buffer_handle_t handle) const +{ + auto ret = mMapper->retain(handle); + return (ret.isOk()) ? static_cast<Error>(ret) : kDefaultError; +} - return reinterpret_cast<FetchInterface>(symbol); +void Mapper::release(buffer_handle_t handle) const +{ + auto ret = mMapper->release(handle); + + auto error = (ret.isOk()) ? static_cast<Error>(ret) : kDefaultError; + ALOGE_IF(error != Error::NONE, + "release(%p) failed with %d", handle, error); } -Mapper::Mapper() - : mMapper(nullptr), mDevice(nullptr) +Error Mapper::getStride(buffer_handle_t handle, uint32_t* outStride) const +{ + Error error = kDefaultError; + mMapper->getStride(handle, + [&](const auto& tmpError, const auto& tmpStride) + { + error = tmpError; + if (error != Error::NONE) { + return; + } + + *outStride = tmpStride; + }); + + return error; +} + +Error Mapper::lock(buffer_handle_t handle, + uint64_t producerUsageMask, + uint64_t consumerUsageMask, + const IMapper::Rect& accessRegion, + int acquireFence, void** outData) const { - static const char sHalLibName[] = "android.hardware.graphics.mapper"; - static const char sSupportedInterface[] = - "android.hardware.graphics.mapper@2.0::IMapper"; + hardware::hidl_handle acquireFenceHandle; - FetchInterface fetchInterface = loadHalLib(sHalLibName); - if (!fetchInterface) { - return; + NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0); + if (acquireFence >= 0) { + auto h = native_handle_init(acquireFenceStorage, 1, 0); + h->data[0] = acquireFence; + acquireFenceHandle = h; } - mMapper = static_cast<const IMapper*>( - fetchInterface(sSupportedInterface)); - if (!mMapper) { - ALOGE("%s is not supported", sSupportedInterface); - return; + Error error = kDefaultError; + mMapper->lock(handle, producerUsageMask, consumerUsageMask, + accessRegion, acquireFenceHandle, + [&](const auto& tmpError, const auto& tmpData) + { + error = tmpError; + if (error != Error::NONE) { + return; + } + + *outData = tmpData; + }); + + if (error == Error::NONE && acquireFence >= 0) { + close(acquireFence); } - if (mMapper->createDevice(&mDevice) != Error::NONE) { - ALOGE("failed to create mapper device"); - mMapper = nullptr; - } + return error; } -Mapper::~Mapper() +Error Mapper::lock(buffer_handle_t handle, + uint64_t producerUsageMask, + uint64_t consumerUsageMask, + const IMapper::Rect& accessRegion, + int acquireFence, FlexLayout* outLayout) const { - if (mMapper) { - mMapper->destroyDevice(mDevice); + hardware::hidl_handle acquireFenceHandle; + + NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0); + if (acquireFence >= 0) { + auto h = native_handle_init(acquireFenceStorage, 1, 0); + h->data[0] = acquireFence; + acquireFenceHandle = h; } -} -void Mapper::release(buffer_handle_t handle) const -{ - auto error = mMapper->release(mDevice, handle); - ALOGE_IF(error != Error::NONE, - "release(%p) failed with %d", handle, error); + Error error = kDefaultError; + mMapper->lockFlex(handle, producerUsageMask, consumerUsageMask, + accessRegion, acquireFenceHandle, + [&](const auto& tmpError, const auto& tmpLayout) + { + error = tmpError; + if (error != Error::NONE) { + return; + } + + *outLayout = tmpLayout; + }); + + if (error == Error::NONE && acquireFence >= 0) { + close(acquireFence); + } + + return error; } int Mapper::unlock(buffer_handle_t handle) const { int releaseFence; - auto error = mMapper->unlock(mDevice, handle, &releaseFence); + + Error error = kDefaultError; + mMapper->unlock(handle, + [&](const auto& tmpError, const auto& tmpReleaseFence) + { + error = tmpError; + if (error != Error::NONE) { + return; + } + + auto fenceHandle = tmpReleaseFence.getNativeHandle(); + if (fenceHandle && fenceHandle->numFds == 1) { + int fd = dup(fenceHandle->data[0]); + if (fd >= 0) { + releaseFence = fd; + } else { + error = Error::NO_RESOURCES; + } + } else { + releaseFence = -1; + } + }); + if (error != Error::NONE) { ALOGE("unlock(%p) failed with %d", handle, error); releaseFence = -1; |