Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 17 | #include <aidlcommonsupport/NativeHandle.h> |
Alec Mouri | 1833999 | 2022-04-04 21:53:57 +0000 | [diff] [blame] | 18 | #include <android-base/properties.h> |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 19 | #include <android/binder_manager.h> |
Marissa Wall | 88d87fa | 2019-11-05 14:57:51 -0800 | [diff] [blame] | 20 | #include <gralloctypes/Gralloc4.h> |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 21 | #include <mapper-vts/4.0/MapperVts.h> |
| 22 | |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace graphics { |
| 26 | namespace mapper { |
| 27 | namespace V4_0 { |
| 28 | namespace vts { |
| 29 | |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 30 | Gralloc::Gralloc(const std::string& aidlAllocatorServiceName, |
| 31 | const std::string& hidlAllocatorServiceName, const std::string& mapperServiceName, |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 32 | bool errOnFailure) { |
| 33 | if (errOnFailure) { |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 34 | init(aidlAllocatorServiceName, hidlAllocatorServiceName, mapperServiceName); |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 35 | } else { |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 36 | initNoErr(aidlAllocatorServiceName, hidlAllocatorServiceName, mapperServiceName); |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 40 | void Gralloc::init(const std::string& aidlAllocatorServiceName, |
| 41 | const std::string& hidlAllocatorServiceName, |
| 42 | const std::string& mapperServiceName) { |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 43 | mAidlAllocator = aidl::android::hardware::graphics::allocator::IAllocator::fromBinder( |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 44 | ndk::SpAIBinder(AServiceManager_checkService(aidlAllocatorServiceName.c_str()))); |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 45 | |
| 46 | if (mAidlAllocator == nullptr) { |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 47 | mHidlAllocator = IAllocator::getService(hidlAllocatorServiceName); |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 48 | } |
| 49 | ASSERT_TRUE(nullptr != mAidlAllocator || mHidlAllocator != nullptr) |
| 50 | << "failed to get allocator service"; |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 51 | |
Dan Shi | 46245c5 | 2019-12-06 16:12:53 -0800 | [diff] [blame] | 52 | mMapper = IMapper::getService(mapperServiceName); |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 53 | ASSERT_NE(nullptr, mMapper.get()) << "failed to get mapper service"; |
| 54 | ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; |
| 55 | } |
| 56 | |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 57 | void Gralloc::initNoErr(const std::string& aidlAllocatorServiceName, |
| 58 | const std::string& hidlAllocatorServiceName, |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 59 | const std::string& mapperServiceName) { |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 60 | mAidlAllocator = aidl::android::hardware::graphics::allocator::IAllocator::fromBinder( |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 61 | ndk::SpAIBinder(AServiceManager_checkService(aidlAllocatorServiceName.c_str()))); |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 62 | |
| 63 | if (mAidlAllocator == nullptr) { |
ramindani | b2b747f | 2022-06-04 00:16:44 +0000 | [diff] [blame] | 64 | mHidlAllocator = IAllocator::getService(hidlAllocatorServiceName); |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 65 | } |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 66 | |
Dan Shi | 46245c5 | 2019-12-06 16:12:53 -0800 | [diff] [blame] | 67 | mMapper = IMapper::getService(mapperServiceName); |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 68 | if (mMapper.get()) { |
| 69 | ASSERT_FALSE(mMapper->isRemote()) << "mapper is not in passthrough mode"; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | Gralloc::~Gralloc() { |
| 74 | for (auto bufferHandle : mClonedBuffers) { |
| 75 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 76 | native_handle_close(buffer); |
| 77 | native_handle_delete(buffer); |
| 78 | } |
| 79 | mClonedBuffers.clear(); |
| 80 | |
| 81 | for (auto bufferHandle : mImportedBuffers) { |
| 82 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 83 | EXPECT_EQ(Error::NONE, mMapper->freeBuffer(buffer)) << "failed to free buffer " << buffer; |
| 84 | } |
| 85 | mImportedBuffers.clear(); |
| 86 | } |
| 87 | |
Yichi Chen | c6394ff | 2020-05-12 08:58:08 +0800 | [diff] [blame] | 88 | const native_handle_t* Gralloc::cloneBuffer(const hidl_handle& rawHandle, |
| 89 | enum Tolerance /*tolerance*/) { |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 90 | const native_handle_t* bufferHandle = native_handle_clone(rawHandle.getNativeHandle()); |
| 91 | EXPECT_NE(nullptr, bufferHandle); |
| 92 | |
| 93 | if (bufferHandle) { |
| 94 | mClonedBuffers.insert(bufferHandle); |
| 95 | } |
| 96 | |
| 97 | return bufferHandle; |
| 98 | } |
| 99 | |
| 100 | std::vector<const native_handle_t*> Gralloc::allocate(const BufferDescriptor& descriptor, |
| 101 | uint32_t count, bool import, |
Yichi Chen | c6394ff | 2020-05-12 08:58:08 +0800 | [diff] [blame] | 102 | enum Tolerance tolerance, |
| 103 | uint32_t* outStride) { |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 104 | std::vector<const native_handle_t*> bufferHandles; |
| 105 | bufferHandles.reserve(count); |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 106 | |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 107 | auto callback = [&](Error error, uint32_t stride, |
| 108 | const hidl_vec<hidl_handle>& buffers) -> void { |
| 109 | if (canTolerate(tolerance, error)) { |
| 110 | return; |
| 111 | } |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 112 | |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 113 | if (error != Error::NONE) { |
| 114 | if (base::GetIntProperty("ro.vendor.build.version.sdk", 0, 0, INT_MAX) < 33) { |
| 115 | GTEST_SKIP() << "Old vendor grallocs may not support P010"; |
| 116 | } else { |
| 117 | GTEST_FAIL() << "failed to allocate buffers"; |
| 118 | } |
| 119 | } |
| 120 | ASSERT_EQ(count, buffers.size()) << "invalid buffer array"; |
Yichi Chen | c6394ff | 2020-05-12 08:58:08 +0800 | [diff] [blame] | 121 | |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 122 | for (uint32_t i = 0; i < count; i++) { |
| 123 | const native_handle_t* bufferHandle = nullptr; |
| 124 | if (import) { |
| 125 | ASSERT_NO_FATAL_FAILURE(bufferHandle = importBuffer(buffers[i], tolerance)); |
| 126 | } else { |
| 127 | ASSERT_NO_FATAL_FAILURE(bufferHandle = cloneBuffer(buffers[i], tolerance)); |
| 128 | } |
| 129 | if (bufferHandle) { |
| 130 | bufferHandles.push_back(bufferHandle); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | if (outStride) { |
| 135 | *outStride = stride; |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | rawAllocate(descriptor, count, callback); |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 140 | |
| 141 | if (::testing::Test::HasFatalFailure()) { |
| 142 | bufferHandles.clear(); |
| 143 | } |
| 144 | |
| 145 | return bufferHandles; |
| 146 | } |
| 147 | |
| 148 | const native_handle_t* Gralloc::allocate(const IMapper::BufferDescriptorInfo& descriptorInfo, |
Yichi Chen | c6394ff | 2020-05-12 08:58:08 +0800 | [diff] [blame] | 149 | bool import, enum Tolerance tolerance, |
| 150 | uint32_t* outStride) { |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 151 | BufferDescriptor descriptor = createDescriptor(descriptorInfo); |
| 152 | if (::testing::Test::HasFatalFailure()) { |
| 153 | return nullptr; |
| 154 | } |
| 155 | |
Yichi Chen | c6394ff | 2020-05-12 08:58:08 +0800 | [diff] [blame] | 156 | auto buffers = allocate(descriptor, 1, import, tolerance, outStride); |
Alec Mouri | 1833999 | 2022-04-04 21:53:57 +0000 | [diff] [blame] | 157 | if (::testing::Test::HasFatalFailure() || ::testing::Test::IsSkipped() || buffers.size() != 1) { |
Marissa Wall | 88d87fa | 2019-11-05 14:57:51 -0800 | [diff] [blame] | 158 | return nullptr; |
| 159 | } |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 160 | return buffers[0]; |
| 161 | } |
| 162 | |
Alec Mouri | 38ccfd7 | 2022-05-16 20:20:28 +0000 | [diff] [blame] | 163 | void Gralloc::rawAllocate( |
| 164 | const BufferDescriptor& descriptor, uint32_t count, |
| 165 | std::function<void(Error, uint32_t, const hidl_vec<hidl_handle>&)> callback) { |
| 166 | if (mAidlAllocator) { |
| 167 | aidl::android::hardware::graphics::allocator::AllocationResult result; |
| 168 | auto status = mAidlAllocator->allocate(descriptor, count, &result); |
| 169 | const Error error = toHidlError(status); |
| 170 | std::vector<hidl_handle> handles; |
| 171 | for (const auto& aidlHandle : result.buffers) { |
| 172 | handles.push_back(hidl_handle(makeFromAidl(aidlHandle))); |
| 173 | } |
| 174 | callback(error, result.stride, handles); |
| 175 | } else { |
| 176 | mHidlAllocator->allocate(descriptor, count, callback); |
| 177 | } |
| 178 | } |
| 179 | |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 180 | sp<IMapper> Gralloc::getMapper() const { |
| 181 | return mMapper; |
| 182 | } |
| 183 | |
| 184 | BufferDescriptor Gralloc::createDescriptor(const IMapper::BufferDescriptorInfo& descriptorInfo) { |
| 185 | BufferDescriptor descriptor; |
| 186 | mMapper->createDescriptor(descriptorInfo, [&](const auto& tmpError, const auto& tmpDescriptor) { |
| 187 | ASSERT_EQ(Error::NONE, tmpError) << "failed to create descriptor"; |
| 188 | descriptor = tmpDescriptor; |
| 189 | }); |
| 190 | |
| 191 | return descriptor; |
| 192 | } |
| 193 | |
Yichi Chen | c6394ff | 2020-05-12 08:58:08 +0800 | [diff] [blame] | 194 | const native_handle_t* Gralloc::importBuffer(const hidl_handle& rawHandle, |
| 195 | enum Tolerance tolerance) { |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 196 | const native_handle_t* bufferHandle = nullptr; |
| 197 | mMapper->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBuffer) { |
Yichi Chen | c6394ff | 2020-05-12 08:58:08 +0800 | [diff] [blame] | 198 | if (!canTolerate(tolerance, tmpError)) { |
| 199 | ASSERT_EQ(Error::NONE, tmpError) |
| 200 | << "failed to import buffer %p" << rawHandle.getNativeHandle(); |
| 201 | } |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 202 | bufferHandle = static_cast<const native_handle_t*>(tmpBuffer); |
| 203 | }); |
| 204 | |
| 205 | if (bufferHandle) { |
| 206 | mImportedBuffers.insert(bufferHandle); |
| 207 | } |
| 208 | |
| 209 | return bufferHandle; |
| 210 | } |
| 211 | |
| 212 | void Gralloc::freeBuffer(const native_handle_t* bufferHandle) { |
Marissa Wall | 88d87fa | 2019-11-05 14:57:51 -0800 | [diff] [blame] | 213 | if (bufferHandle == nullptr) { |
| 214 | return; |
| 215 | } |
| 216 | |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 217 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 218 | |
| 219 | if (mImportedBuffers.erase(bufferHandle)) { |
| 220 | Error error = mMapper->freeBuffer(buffer); |
| 221 | ASSERT_EQ(Error::NONE, error) << "failed to free buffer " << buffer; |
| 222 | } else { |
| 223 | mClonedBuffers.erase(bufferHandle); |
| 224 | native_handle_close(buffer); |
| 225 | native_handle_delete(buffer); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | void* Gralloc::lock(const native_handle_t* bufferHandle, uint64_t cpuUsage, |
Marissa Wall | 9c5ebfc | 2019-11-05 14:59:27 -0800 | [diff] [blame] | 230 | const IMapper::Rect& accessRegion, int acquireFence) { |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 231 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 232 | |
| 233 | NATIVE_HANDLE_DECLARE_STORAGE(acquireFenceStorage, 1, 0); |
| 234 | hidl_handle acquireFenceHandle; |
| 235 | if (acquireFence >= 0) { |
| 236 | auto h = native_handle_init(acquireFenceStorage, 1, 0); |
| 237 | h->data[0] = acquireFence; |
| 238 | acquireFenceHandle = h; |
| 239 | } |
| 240 | |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 241 | void* data = nullptr; |
| 242 | mMapper->lock(buffer, cpuUsage, accessRegion, acquireFenceHandle, |
Marissa Wall | 9c5ebfc | 2019-11-05 14:59:27 -0800 | [diff] [blame] | 243 | [&](const auto& tmpError, const auto& tmpData) { |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 244 | ASSERT_EQ(Error::NONE, tmpError) << "failed to lock buffer " << buffer; |
| 245 | data = tmpData; |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 246 | }); |
| 247 | |
| 248 | if (acquireFence >= 0) { |
| 249 | close(acquireFence); |
| 250 | } |
| 251 | |
| 252 | return data; |
| 253 | } |
| 254 | |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 255 | int Gralloc::unlock(const native_handle_t* bufferHandle) { |
| 256 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 257 | |
| 258 | int releaseFence = -1; |
| 259 | mMapper->unlock(buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) { |
| 260 | ASSERT_EQ(Error::NONE, tmpError) << "failed to unlock buffer " << buffer; |
| 261 | |
| 262 | auto fenceHandle = tmpReleaseFence.getNativeHandle(); |
| 263 | if (fenceHandle) { |
| 264 | ASSERT_EQ(0, fenceHandle->numInts) << "invalid fence handle " << fenceHandle; |
| 265 | if (fenceHandle->numFds == 1) { |
| 266 | releaseFence = dup(fenceHandle->data[0]); |
| 267 | ASSERT_LT(0, releaseFence) << "failed to dup fence fd"; |
| 268 | } else { |
| 269 | ASSERT_EQ(0, fenceHandle->numFds) << " invalid fence handle " << fenceHandle; |
| 270 | } |
| 271 | } |
| 272 | }); |
| 273 | |
| 274 | return releaseFence; |
| 275 | } |
| 276 | |
Marissa Wall | 2c45bb1 | 2019-10-18 13:31:36 -0700 | [diff] [blame] | 277 | int Gralloc::flushLockedBuffer(const native_handle_t* bufferHandle) { |
| 278 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 279 | |
| 280 | int releaseFence = -1; |
| 281 | mMapper->flushLockedBuffer(buffer, [&](const auto& tmpError, const auto& tmpReleaseFence) { |
| 282 | ASSERT_EQ(Error::NONE, tmpError) << "failed to flush locked buffer " << buffer; |
| 283 | |
| 284 | auto fenceHandle = tmpReleaseFence.getNativeHandle(); |
| 285 | if (fenceHandle) { |
| 286 | ASSERT_EQ(0, fenceHandle->numInts) << "invalid fence handle " << fenceHandle; |
| 287 | if (fenceHandle->numFds == 1) { |
| 288 | releaseFence = dup(fenceHandle->data[0]); |
| 289 | ASSERT_LT(0, releaseFence) << "failed to dup fence fd"; |
| 290 | } else { |
| 291 | ASSERT_EQ(0, fenceHandle->numFds) << " invalid fence handle " << fenceHandle; |
| 292 | } |
| 293 | } |
| 294 | }); |
| 295 | |
| 296 | return releaseFence; |
| 297 | } |
| 298 | |
| 299 | void Gralloc::rereadLockedBuffer(const native_handle_t* bufferHandle) { |
| 300 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 301 | |
| 302 | ASSERT_EQ(Error::NONE, mMapper->rereadLockedBuffer(buffer)); |
| 303 | } |
| 304 | |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 305 | bool Gralloc::validateBufferSize(const native_handle_t* bufferHandle, |
| 306 | const IMapper::BufferDescriptorInfo& descriptorInfo, |
| 307 | uint32_t stride) { |
| 308 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 309 | |
| 310 | Error error = mMapper->validateBufferSize(buffer, descriptorInfo, stride); |
| 311 | return error == Error::NONE; |
| 312 | } |
| 313 | |
| 314 | void Gralloc::getTransportSize(const native_handle_t* bufferHandle, uint32_t* outNumFds, |
| 315 | uint32_t* outNumInts) { |
| 316 | auto buffer = const_cast<native_handle_t*>(bufferHandle); |
| 317 | |
| 318 | *outNumFds = 0; |
| 319 | *outNumInts = 0; |
| 320 | mMapper->getTransportSize(buffer, [&](const auto& tmpError, const auto& tmpNumFds, |
| 321 | const auto& tmpNumInts) { |
| 322 | ASSERT_EQ(Error::NONE, tmpError) << "failed to get transport size"; |
| 323 | ASSERT_GE(bufferHandle->numFds, int(tmpNumFds)) << "invalid numFds " << tmpNumFds; |
| 324 | ASSERT_GE(bufferHandle->numInts, int(tmpNumInts)) << "invalid numInts " << tmpNumInts; |
| 325 | |
| 326 | *outNumFds = tmpNumFds; |
| 327 | *outNumInts = tmpNumInts; |
| 328 | }); |
| 329 | } |
| 330 | |
| 331 | bool Gralloc::isSupported(const IMapper::BufferDescriptorInfo& descriptorInfo) { |
| 332 | bool supported = false; |
| 333 | mMapper->isSupported(descriptorInfo, [&](const auto& tmpError, const auto& tmpSupported) { |
| 334 | ASSERT_EQ(Error::NONE, tmpError) << "failed to check is supported"; |
| 335 | supported = tmpSupported; |
| 336 | }); |
| 337 | return supported; |
| 338 | } |
| 339 | |
Leon Scroggins III | cd5e469 | 2022-02-16 16:36:27 -0500 | [diff] [blame] | 340 | bool Gralloc::isSupportedNoFailure(const IMapper::BufferDescriptorInfo& descriptorInfo) { |
| 341 | bool supported = false; |
| 342 | mMapper->isSupported(descriptorInfo, [&](const auto& tmpError, const auto& tmpSupported) { |
| 343 | supported = tmpSupported && tmpError == Error::NONE; |
| 344 | }); |
| 345 | return supported; |
| 346 | } |
| 347 | |
Marissa Wall | 88d87fa | 2019-11-05 14:57:51 -0800 | [diff] [blame] | 348 | Error Gralloc::get(const native_handle_t* bufferHandle, const IMapper::MetadataType& metadataType, |
| 349 | hidl_vec<uint8_t>* outVec) { |
| 350 | Error err; |
| 351 | mMapper->get(const_cast<native_handle_t*>(bufferHandle), metadataType, |
| 352 | [&](const auto& tmpError, const hidl_vec<uint8_t>& tmpVec) { |
| 353 | err = tmpError; |
| 354 | *outVec = tmpVec; |
| 355 | }); |
| 356 | return err; |
| 357 | } |
| 358 | |
| 359 | Error Gralloc::set(const native_handle_t* bufferHandle, const IMapper::MetadataType& metadataType, |
| 360 | const hidl_vec<uint8_t>& vec) { |
| 361 | return mMapper->set(const_cast<native_handle_t*>(bufferHandle), metadataType, vec); |
| 362 | } |
| 363 | |
| 364 | Error Gralloc::getFromBufferDescriptorInfo(const IMapper::BufferDescriptorInfo& descriptorInfo, |
| 365 | const IMapper::MetadataType& metadataType, |
| 366 | hidl_vec<uint8_t>* outVec) { |
| 367 | Error err; |
| 368 | mMapper->getFromBufferDescriptorInfo( |
| 369 | descriptorInfo, metadataType, |
| 370 | [&](const auto& tmpError, const hidl_vec<uint8_t>& tmpVec) { |
| 371 | err = tmpError; |
| 372 | *outVec = tmpVec; |
| 373 | }); |
| 374 | return err; |
| 375 | } |
| 376 | |
Marissa Wall | d36e127 | 2019-11-26 11:33:32 -0800 | [diff] [blame] | 377 | Error Gralloc::getReservedRegion(const native_handle_t* bufferHandle, void** outReservedRegion, |
| 378 | uint64_t* outReservedSize) { |
| 379 | Error err; |
| 380 | mMapper->getReservedRegion( |
| 381 | const_cast<native_handle_t*>(bufferHandle), |
| 382 | [&](const auto& tmpError, const auto& tmpReservedRegion, const auto& tmpReservedSize) { |
| 383 | err = tmpError; |
| 384 | *outReservedRegion = tmpReservedRegion; |
| 385 | *outReservedSize = tmpReservedSize; |
| 386 | }); |
| 387 | return err; |
| 388 | } |
| 389 | |
Marissa Wall | 6534164 | 2019-06-20 13:21:06 -0700 | [diff] [blame] | 390 | } // namespace vts |
| 391 | } // namespace V4_0 |
| 392 | } // namespace mapper |
| 393 | } // namespace graphics |
| 394 | } // namespace hardware |
| 395 | } // namespace android |