Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The Android Open Source Project |
| 3 | * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #define LOG_TAG "GrallocMapperPassthrough" |
| 17 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 18 | #include "GrallocMapper.h" |
| 19 | |
| 20 | #include <vector> |
| 21 | |
| 22 | #include <string.h> |
| 23 | |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 24 | #include <hardware/gralloc1.h> |
| 25 | #include <log/log.h> |
| 26 | |
| 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | namespace graphics { |
| 30 | namespace mapper { |
| 31 | namespace V2_0 { |
| 32 | namespace implementation { |
| 33 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 34 | namespace { |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 35 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 36 | using android::hardware::graphics::allocator::V2_0::Error; |
| 37 | using android::hardware::graphics::common::V1_0::PixelFormat; |
| 38 | |
| 39 | class GrallocMapperHal : public IMapper { |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 40 | public: |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 41 | GrallocMapperHal(const hw_module_t* module); |
| 42 | ~GrallocMapperHal(); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 43 | |
| 44 | // IMapper interface |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 45 | Return<Error> retain(const hidl_handle& bufferHandle) override; |
| 46 | Return<Error> release(const hidl_handle& bufferHandle) override; |
| 47 | Return<void> getDimensions(const hidl_handle& bufferHandle, |
| 48 | getDimensions_cb hidl_cb) override; |
| 49 | Return<void> getFormat(const hidl_handle& bufferHandle, |
| 50 | getFormat_cb hidl_cb) override; |
| 51 | Return<void> getLayerCount(const hidl_handle& bufferHandle, |
| 52 | getLayerCount_cb hidl_cb) override; |
| 53 | Return<void> getProducerUsageMask(const hidl_handle& bufferHandle, |
| 54 | getProducerUsageMask_cb hidl_cb) override; |
| 55 | Return<void> getConsumerUsageMask(const hidl_handle& bufferHandle, |
| 56 | getConsumerUsageMask_cb hidl_cb) override; |
| 57 | Return<void> getBackingStore(const hidl_handle& bufferHandle, |
| 58 | getBackingStore_cb hidl_cb) override; |
| 59 | Return<void> getStride(const hidl_handle& bufferHandle, |
| 60 | getStride_cb hidl_cb) override; |
| 61 | Return<void> lock(const hidl_handle& bufferHandle, |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 62 | uint64_t producerUsageMask, uint64_t consumerUsageMask, |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 63 | const IMapper::Rect& accessRegion, const hidl_handle& acquireFence, |
| 64 | lock_cb hidl_cb) override; |
| 65 | Return<void> lockFlex(const hidl_handle& bufferHandle, |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 66 | uint64_t producerUsageMask, uint64_t consumerUsageMask, |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 67 | const IMapper::Rect& accessRegion, const hidl_handle& acquireFence, |
| 68 | lockFlex_cb hidl_cb) override; |
| 69 | Return<void> unlock(const hidl_handle& bufferHandle, |
| 70 | unlock_cb hidl_cb) override; |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 71 | |
| 72 | private: |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 73 | void initCapabilities(); |
| 74 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 75 | template<typename T> |
| 76 | void initDispatch(gralloc1_function_descriptor_t desc, T* outPfn); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 77 | void initDispatch(); |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 78 | |
| 79 | static gralloc1_rect_t asGralloc1Rect(const IMapper::Rect& rect); |
| 80 | static bool dupFence(const hidl_handle& fenceHandle, int* outFd); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 81 | |
| 82 | gralloc1_device_t* mDevice; |
| 83 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 84 | struct { |
| 85 | bool layeredBuffers; |
| 86 | } mCapabilities; |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 87 | |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 88 | struct { |
| 89 | GRALLOC1_PFN_RETAIN retain; |
| 90 | GRALLOC1_PFN_RELEASE release; |
| 91 | GRALLOC1_PFN_GET_DIMENSIONS getDimensions; |
| 92 | GRALLOC1_PFN_GET_FORMAT getFormat; |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 93 | GRALLOC1_PFN_GET_LAYER_COUNT getLayerCount; |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 94 | GRALLOC1_PFN_GET_PRODUCER_USAGE getProducerUsage; |
| 95 | GRALLOC1_PFN_GET_CONSUMER_USAGE getConsumerUsage; |
| 96 | GRALLOC1_PFN_GET_BACKING_STORE getBackingStore; |
| 97 | GRALLOC1_PFN_GET_STRIDE getStride; |
| 98 | GRALLOC1_PFN_GET_NUM_FLEX_PLANES getNumFlexPlanes; |
| 99 | GRALLOC1_PFN_LOCK lock; |
| 100 | GRALLOC1_PFN_LOCK_FLEX lockFlex; |
| 101 | GRALLOC1_PFN_UNLOCK unlock; |
| 102 | } mDispatch; |
| 103 | }; |
| 104 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 105 | GrallocMapperHal::GrallocMapperHal(const hw_module_t* module) |
| 106 | : mDevice(nullptr), mCapabilities(), mDispatch() |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 107 | { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 108 | int status = gralloc1_open(module, &mDevice); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 109 | if (status) { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 110 | LOG_ALWAYS_FATAL("failed to open gralloc1 device: %s", |
| 111 | strerror(-status)); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 112 | } |
| 113 | |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 114 | initCapabilities(); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 115 | initDispatch(); |
| 116 | } |
| 117 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 118 | GrallocMapperHal::~GrallocMapperHal() |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 119 | { |
| 120 | gralloc1_close(mDevice); |
| 121 | } |
| 122 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 123 | void GrallocMapperHal::initCapabilities() |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 124 | { |
| 125 | uint32_t count; |
| 126 | mDevice->getCapabilities(mDevice, &count, nullptr); |
| 127 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 128 | std::vector<int32_t> caps(count); |
| 129 | mDevice->getCapabilities(mDevice, &count, caps.data()); |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 130 | caps.resize(count); |
| 131 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 132 | for (auto cap : caps) { |
| 133 | switch (cap) { |
| 134 | case GRALLOC1_CAPABILITY_LAYERED_BUFFERS: |
| 135 | mCapabilities.layeredBuffers = true; |
| 136 | break; |
| 137 | default: |
| 138 | break; |
| 139 | } |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 140 | } |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 141 | } |
| 142 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 143 | template<typename T> |
| 144 | void GrallocMapperHal::initDispatch(gralloc1_function_descriptor_t desc, |
| 145 | T* outPfn) |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 146 | { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 147 | auto pfn = mDevice->getFunction(mDevice, desc); |
| 148 | if (!pfn) { |
| 149 | LOG_ALWAYS_FATAL("failed to get gralloc1 function %d", desc); |
| 150 | } |
| 151 | |
| 152 | *outPfn = reinterpret_cast<T>(pfn); |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 155 | void GrallocMapperHal::initDispatch() |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 156 | { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 157 | initDispatch(GRALLOC1_FUNCTION_RETAIN, &mDispatch.retain); |
| 158 | initDispatch(GRALLOC1_FUNCTION_RELEASE, &mDispatch.release); |
| 159 | initDispatch(GRALLOC1_FUNCTION_GET_DIMENSIONS, &mDispatch.getDimensions); |
| 160 | initDispatch(GRALLOC1_FUNCTION_GET_FORMAT, &mDispatch.getFormat); |
| 161 | if (mCapabilities.layeredBuffers) { |
| 162 | initDispatch(GRALLOC1_FUNCTION_GET_LAYER_COUNT, |
| 163 | &mDispatch.getLayerCount); |
| 164 | } |
| 165 | initDispatch(GRALLOC1_FUNCTION_GET_PRODUCER_USAGE, |
| 166 | &mDispatch.getProducerUsage); |
| 167 | initDispatch(GRALLOC1_FUNCTION_GET_CONSUMER_USAGE, |
| 168 | &mDispatch.getConsumerUsage); |
| 169 | initDispatch(GRALLOC1_FUNCTION_GET_BACKING_STORE, |
| 170 | &mDispatch.getBackingStore); |
| 171 | initDispatch(GRALLOC1_FUNCTION_GET_STRIDE, &mDispatch.getStride); |
| 172 | initDispatch(GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES, |
| 173 | &mDispatch.getNumFlexPlanes); |
| 174 | initDispatch(GRALLOC1_FUNCTION_LOCK, &mDispatch.lock); |
| 175 | initDispatch(GRALLOC1_FUNCTION_LOCK_FLEX, &mDispatch.lockFlex); |
| 176 | initDispatch(GRALLOC1_FUNCTION_UNLOCK, &mDispatch.unlock); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 177 | } |
| 178 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 179 | gralloc1_rect_t GrallocMapperHal::asGralloc1Rect(const IMapper::Rect& rect) |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 180 | { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 181 | return gralloc1_rect_t{rect.left, rect.top, rect.width, rect.height}; |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 182 | } |
| 183 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 184 | bool GrallocMapperHal::dupFence(const hidl_handle& fenceHandle, int* outFd) |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 185 | { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 186 | auto handle = fenceHandle.getNativeHandle(); |
| 187 | if (!handle || handle->numFds == 0) { |
| 188 | *outFd = -1; |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | if (handle->numFds > 1) { |
| 193 | ALOGE("invalid fence handle with %d fds", handle->numFds); |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | *outFd = dup(handle->data[0]); |
| 198 | return (*outFd >= 0); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 199 | } |
| 200 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 201 | Return<Error> GrallocMapperHal::retain(const hidl_handle& bufferHandle) |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 202 | { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 203 | int32_t err = mDispatch.retain(mDevice, bufferHandle); |
| 204 | return static_cast<Error>(err); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 205 | } |
| 206 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 207 | Return<Error> GrallocMapperHal::release(const hidl_handle& bufferHandle) |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 208 | { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 209 | int32_t err = mDispatch.release(mDevice, bufferHandle); |
| 210 | return static_cast<Error>(err); |
| 211 | } |
| 212 | |
| 213 | Return<void> GrallocMapperHal::getDimensions(const hidl_handle& bufferHandle, |
| 214 | getDimensions_cb hidl_cb) |
| 215 | { |
| 216 | uint32_t width = 0; |
| 217 | uint32_t height = 0; |
| 218 | int32_t err = mDispatch.getDimensions(mDevice, bufferHandle, |
| 219 | &width, &height); |
| 220 | |
| 221 | hidl_cb(static_cast<Error>(err), width, height); |
| 222 | return Void(); |
| 223 | } |
| 224 | |
| 225 | Return<void> GrallocMapperHal::getFormat(const hidl_handle& bufferHandle, |
| 226 | getFormat_cb hidl_cb) |
| 227 | { |
| 228 | int32_t format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED; |
| 229 | int32_t err = mDispatch.getFormat(mDevice, bufferHandle, &format); |
| 230 | |
| 231 | hidl_cb(static_cast<Error>(err), static_cast<PixelFormat>(format)); |
| 232 | return Void(); |
| 233 | } |
| 234 | |
| 235 | Return<void> GrallocMapperHal::getLayerCount(const hidl_handle& bufferHandle, |
| 236 | getLayerCount_cb hidl_cb) |
| 237 | { |
| 238 | int32_t err = GRALLOC1_ERROR_NONE; |
| 239 | uint32_t count = 1; |
| 240 | if (mCapabilities.layeredBuffers) { |
| 241 | err = mDispatch.getLayerCount(mDevice, bufferHandle, &count); |
| 242 | } |
| 243 | |
| 244 | hidl_cb(static_cast<Error>(err), count); |
| 245 | return Void(); |
| 246 | } |
| 247 | |
| 248 | Return<void> GrallocMapperHal::getProducerUsageMask( |
| 249 | const hidl_handle& bufferHandle, getProducerUsageMask_cb hidl_cb) |
| 250 | { |
| 251 | uint64_t mask = 0x0; |
| 252 | int32_t err = mDispatch.getProducerUsage(mDevice, bufferHandle, &mask); |
| 253 | |
| 254 | hidl_cb(static_cast<Error>(err), mask); |
| 255 | return Void(); |
| 256 | } |
| 257 | |
| 258 | Return<void> GrallocMapperHal::getConsumerUsageMask( |
| 259 | const hidl_handle& bufferHandle, getConsumerUsageMask_cb hidl_cb) |
| 260 | { |
| 261 | uint64_t mask = 0x0; |
| 262 | int32_t err = mDispatch.getConsumerUsage(mDevice, bufferHandle, &mask); |
| 263 | |
| 264 | hidl_cb(static_cast<Error>(err), mask); |
| 265 | return Void(); |
| 266 | } |
| 267 | |
| 268 | Return<void> GrallocMapperHal::getBackingStore( |
| 269 | const hidl_handle& bufferHandle, getBackingStore_cb hidl_cb) |
| 270 | { |
| 271 | uint64_t store = 0; |
| 272 | int32_t err = mDispatch.getBackingStore(mDevice, bufferHandle, &store); |
| 273 | |
| 274 | hidl_cb(static_cast<Error>(err), store); |
| 275 | return Void(); |
| 276 | } |
| 277 | |
| 278 | Return<void> GrallocMapperHal::getStride(const hidl_handle& bufferHandle, |
| 279 | getStride_cb hidl_cb) |
| 280 | { |
| 281 | uint32_t stride = 0; |
| 282 | int32_t err = mDispatch.getStride(mDevice, bufferHandle, &stride); |
| 283 | |
| 284 | hidl_cb(static_cast<Error>(err), stride); |
| 285 | return Void(); |
| 286 | } |
| 287 | |
| 288 | Return<void> GrallocMapperHal::lock(const hidl_handle& bufferHandle, |
| 289 | uint64_t producerUsageMask, uint64_t consumerUsageMask, |
| 290 | const IMapper::Rect& accessRegion, const hidl_handle& acquireFence, |
| 291 | lock_cb hidl_cb) |
| 292 | { |
| 293 | gralloc1_rect_t rect = asGralloc1Rect(accessRegion); |
| 294 | |
| 295 | int fence = -1; |
| 296 | if (!dupFence(acquireFence, &fence)) { |
| 297 | hidl_cb(Error::NO_RESOURCES, nullptr); |
| 298 | return Void(); |
| 299 | } |
| 300 | |
| 301 | void* data = nullptr; |
| 302 | int32_t err = mDispatch.lock(mDevice, bufferHandle, producerUsageMask, |
| 303 | consumerUsageMask, &rect, &data, fence); |
| 304 | if (err != GRALLOC1_ERROR_NONE) { |
| 305 | close(fence); |
| 306 | } |
| 307 | |
| 308 | hidl_cb(static_cast<Error>(err), data); |
| 309 | return Void(); |
| 310 | } |
| 311 | |
| 312 | Return<void> GrallocMapperHal::lockFlex(const hidl_handle& bufferHandle, |
| 313 | uint64_t producerUsageMask, uint64_t consumerUsageMask, |
| 314 | const IMapper::Rect& accessRegion, const hidl_handle& acquireFence, |
| 315 | lockFlex_cb hidl_cb) |
| 316 | { |
| 317 | FlexLayout layout_reply{}; |
| 318 | |
| 319 | uint32_t planeCount = 0; |
| 320 | int32_t err = mDispatch.getNumFlexPlanes(mDevice, bufferHandle, |
| 321 | &planeCount); |
| 322 | if (err != GRALLOC1_ERROR_NONE) { |
| 323 | hidl_cb(static_cast<Error>(err), layout_reply); |
| 324 | return Void(); |
| 325 | } |
| 326 | |
| 327 | gralloc1_rect_t rect = asGralloc1Rect(accessRegion); |
| 328 | |
| 329 | int fence = -1; |
| 330 | if (!dupFence(acquireFence, &fence)) { |
| 331 | hidl_cb(Error::NO_RESOURCES, layout_reply); |
| 332 | return Void(); |
| 333 | } |
| 334 | |
| 335 | std::vector<android_flex_plane_t> planes(planeCount); |
| 336 | android_flex_layout_t layout{}; |
| 337 | layout.num_planes = planes.size(); |
| 338 | layout.planes = planes.data(); |
| 339 | |
| 340 | err = mDispatch.lockFlex(mDevice, bufferHandle, producerUsageMask, |
| 341 | consumerUsageMask, &rect, &layout, fence); |
| 342 | if (err == GRALLOC1_ERROR_NONE) { |
| 343 | layout_reply.format = static_cast<FlexFormat>(layout.format); |
| 344 | |
| 345 | planes.resize(layout.num_planes); |
| 346 | layout_reply.planes.setToExternal( |
| 347 | reinterpret_cast<FlexPlane*>(planes.data()), planes.size()); |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 348 | } else { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 349 | close(fence); |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 350 | } |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 351 | |
| 352 | hidl_cb(static_cast<Error>(err), layout_reply); |
| 353 | return Void(); |
Craig Donner | 0b00adf | 2016-10-20 17:12:58 -0700 | [diff] [blame] | 354 | } |
| 355 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 356 | Return<void> GrallocMapperHal::unlock(const hidl_handle& bufferHandle, |
| 357 | unlock_cb hidl_cb) |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 358 | { |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 359 | int32_t fence = -1; |
| 360 | int32_t err = mDispatch.unlock(mDevice, bufferHandle, &fence); |
| 361 | |
| 362 | NATIVE_HANDLE_DECLARE_STORAGE(fenceStorage, 1, 0); |
| 363 | hidl_handle fenceHandle; |
| 364 | if (err == GRALLOC1_ERROR_NONE && fence >= 0) { |
| 365 | auto nativeHandle = native_handle_init(fenceStorage, 1, 0); |
| 366 | nativeHandle->data[0] = fence; |
| 367 | |
| 368 | fenceHandle = nativeHandle; |
| 369 | } |
| 370 | |
| 371 | hidl_cb(static_cast<Error>(err), fenceHandle); |
| 372 | return Void(); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 373 | } |
| 374 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 375 | } // anonymous namespace |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 376 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 377 | IMapper* HIDL_FETCH_IMapper(const char* /* name */) { |
| 378 | const hw_module_t* module = nullptr; |
| 379 | int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); |
| 380 | if (err) { |
| 381 | ALOGE("failed to get gralloc module"); |
| 382 | return nullptr; |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 383 | } |
| 384 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 385 | uint8_t major = (module->module_api_version >> 8) & 0xff; |
| 386 | if (major != 1) { |
| 387 | ALOGE("unknown gralloc module major version %d", major); |
| 388 | return nullptr; |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 389 | } |
| 390 | |
Chia-I Wu | 158d530 | 2016-10-04 06:00:12 +0800 | [diff] [blame] | 391 | return new GrallocMapperHal(module); |
Chia-I Wu | 0f215c5 | 2016-10-11 11:48:21 +0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | } // namespace implementation |
| 395 | } // namespace V2_0 |
| 396 | } // namespace mapper |
| 397 | } // namespace graphics |
| 398 | } // namespace hardware |
| 399 | } // namespace android |