Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 1 | /* |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 3 | |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #include <cutils/log.h> |
| 31 | #include <sync/sync.h> |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 32 | #include <sstream> |
| 33 | #include <string> |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 34 | |
| 35 | #include "gr_device_impl.h" |
| 36 | #include "gr_buf_descriptor.h" |
| 37 | #include "gralloc_priv.h" |
| 38 | #include "qd_utils.h" |
| 39 | #include "qdMetaData.h" |
| 40 | #include "gr_utils.h" |
| 41 | |
| 42 | int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device); |
| 43 | |
| 44 | int gralloc_device_close(struct hw_device_t *device); |
| 45 | |
| 46 | static struct hw_module_methods_t gralloc_module_methods = {.open = gralloc_device_open}; |
| 47 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 48 | struct gralloc_module_t HAL_MODULE_INFO_SYM = { |
| 49 | .common = { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 50 | .tag = HARDWARE_MODULE_TAG, |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 51 | .module_api_version = GRALLOC_MODULE_API_VERSION_1_0, |
| 52 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 53 | .id = GRALLOC_HARDWARE_MODULE_ID, |
| 54 | .name = "Graphics Memory Module", |
| 55 | .author = "Code Aurora Forum", |
| 56 | .methods = &gralloc_module_methods, |
| 57 | .dso = 0, |
| 58 | .reserved = {0}, |
| 59 | }, |
| 60 | }; |
| 61 | |
| 62 | int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) { |
| 63 | int status = -EINVAL; |
| 64 | if (!strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 65 | gralloc1::GrallocImpl * /*gralloc1_device_t*/ dev = gralloc1::GrallocImpl::GetInstance(module); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 66 | *device = reinterpret_cast<hw_device_t *>(dev); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 67 | if (dev->Init()) { |
| 68 | status = 0; |
| 69 | } else { |
| 70 | ALOGE(" Error in opening gralloc1 device"); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 71 | } |
| 72 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 73 | return status; |
| 74 | } |
| 75 | |
| 76 | namespace gralloc1 { |
| 77 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 78 | GrallocImpl::GrallocImpl(const hw_module_t *module) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 79 | common.tag = HARDWARE_DEVICE_TAG; |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 80 | common.version = GRALLOC_MODULE_API_VERSION_1_0; |
| 81 | common.module = const_cast<hw_module_t *>(module); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 82 | common.close = CloseDevice; |
| 83 | getFunction = GetFunction; |
| 84 | getCapabilities = GetCapabilities; |
| 85 | } |
| 86 | |
| 87 | bool GrallocImpl::Init() { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 88 | buf_mgr_ = BufferManager::GetInstance(); |
| 89 | return true; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | GrallocImpl::~GrallocImpl() { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | int GrallocImpl::CloseDevice(hw_device_t *device) { |
| 96 | GrallocImpl *impl = reinterpret_cast<GrallocImpl *>(device); |
| 97 | delete impl; |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | void GrallocImpl::GetCapabilities(struct gralloc1_device *device, uint32_t *out_count, |
| 103 | int32_t /*gralloc1_capability_t*/ *out_capabilities) { |
| 104 | if (!device) { |
| 105 | // Need to plan for adding more capabilities |
| 106 | if (out_capabilities == NULL) { |
| 107 | *out_count = 1; |
| 108 | } else { |
| 109 | *out_capabilities = GRALLOC1_CAPABILITY_TEST_ALLOCATE; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device, int32_t function) { |
| 117 | if (!device) { |
| 118 | return NULL; |
| 119 | } |
| 120 | |
| 121 | switch (function) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 122 | case GRALLOC1_FUNCTION_DUMP: |
| 123 | return reinterpret_cast<gralloc1_function_pointer_t>(Dump); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 124 | case GRALLOC1_FUNCTION_CREATE_DESCRIPTOR: |
| 125 | return reinterpret_cast<gralloc1_function_pointer_t>(CreateBufferDescriptor); |
| 126 | case GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR: |
| 127 | return reinterpret_cast<gralloc1_function_pointer_t>(DestroyBufferDescriptor); |
| 128 | case GRALLOC1_FUNCTION_SET_CONSUMER_USAGE: |
| 129 | return reinterpret_cast<gralloc1_function_pointer_t>(SetConsumerUsage); |
| 130 | case GRALLOC1_FUNCTION_SET_DIMENSIONS: |
| 131 | return reinterpret_cast<gralloc1_function_pointer_t>(SetBufferDimensions); |
| 132 | case GRALLOC1_FUNCTION_SET_FORMAT: |
| 133 | return reinterpret_cast<gralloc1_function_pointer_t>(SetColorFormat); |
| 134 | case GRALLOC1_FUNCTION_SET_PRODUCER_USAGE: |
| 135 | return reinterpret_cast<gralloc1_function_pointer_t>(SetProducerUsage); |
| 136 | case GRALLOC1_FUNCTION_GET_BACKING_STORE: |
| 137 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBackingStore); |
| 138 | case GRALLOC1_FUNCTION_GET_CONSUMER_USAGE: |
| 139 | return reinterpret_cast<gralloc1_function_pointer_t>(GetConsumerUsage); |
| 140 | case GRALLOC1_FUNCTION_GET_DIMENSIONS: |
| 141 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferDimensions); |
| 142 | case GRALLOC1_FUNCTION_GET_FORMAT: |
| 143 | return reinterpret_cast<gralloc1_function_pointer_t>(GetColorFormat); |
| 144 | case GRALLOC1_FUNCTION_GET_PRODUCER_USAGE: |
| 145 | return reinterpret_cast<gralloc1_function_pointer_t>(GetProducerUsage); |
| 146 | case GRALLOC1_FUNCTION_GET_STRIDE: |
| 147 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferStride); |
| 148 | case GRALLOC1_FUNCTION_ALLOCATE: |
| 149 | return reinterpret_cast<gralloc1_function_pointer_t>(AllocateBuffers); |
| 150 | case GRALLOC1_FUNCTION_RETAIN: |
| 151 | return reinterpret_cast<gralloc1_function_pointer_t>(RetainBuffer); |
| 152 | case GRALLOC1_FUNCTION_RELEASE: |
| 153 | return reinterpret_cast<gralloc1_function_pointer_t>(ReleaseBuffer); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 154 | case GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES: |
| 155 | return reinterpret_cast<gralloc1_function_pointer_t>(GetNumFlexPlanes); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 156 | case GRALLOC1_FUNCTION_LOCK: |
| 157 | return reinterpret_cast<gralloc1_function_pointer_t>(LockBuffer); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 158 | case GRALLOC1_FUNCTION_LOCK_FLEX: |
| 159 | return reinterpret_cast<gralloc1_function_pointer_t>(LockFlex); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 160 | case GRALLOC1_FUNCTION_UNLOCK: |
| 161 | return reinterpret_cast<gralloc1_function_pointer_t>(UnlockBuffer); |
| 162 | case GRALLOC1_FUNCTION_PERFORM: |
| 163 | return reinterpret_cast<gralloc1_function_pointer_t>(Gralloc1Perform); |
| 164 | default: |
| 165 | ALOGE("%s:Gralloc Error. Client Requested for unsupported function", __FUNCTION__); |
| 166 | return NULL; |
| 167 | } |
| 168 | |
| 169 | return NULL; |
| 170 | } |
| 171 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 172 | gralloc1_error_t GrallocImpl::Dump(gralloc1_device_t *device, uint32_t *out_size, |
| 173 | char *out_buffer) { |
| 174 | if (!device) { |
| 175 | ALOGE("Gralloc Error : device=%p", (void *)device); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 176 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 177 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 178 | if (out_buffer == nullptr) { |
| 179 | *out_size = 1024; |
| 180 | } else { |
| 181 | std::ostringstream os; |
| 182 | // TODO(user): implement in buffer manager |
| 183 | os << "-------------------------------" << std::endl; |
| 184 | os << "QTI gralloc dump:" << std::endl; |
| 185 | os << "-------------------------------" << std::endl; |
| 186 | auto copy_size = os.str().size() < *out_size ? os.str().size() : *out_size; |
| 187 | std::copy_n(out_buffer, copy_size, os.str().begin()); |
| 188 | *out_size = static_cast<uint32_t>(copy_size); |
| 189 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 190 | |
| 191 | return GRALLOC1_ERROR_NONE; |
| 192 | } |
| 193 | |
| 194 | gralloc1_error_t GrallocImpl::CheckDeviceAndHandle(gralloc1_device_t *device, |
| 195 | buffer_handle_t buffer) { |
| 196 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 197 | if (!device || (private_handle_t::validate(hnd) != 0)) { |
| 198 | ALOGE("Gralloc Error : device= %p, buffer-handle=%p", (void *)device, (void *)buffer); |
| 199 | return GRALLOC1_ERROR_BAD_HANDLE; |
| 200 | } |
| 201 | |
| 202 | return GRALLOC1_ERROR_NONE; |
| 203 | } |
| 204 | |
| 205 | gralloc1_error_t GrallocImpl::CreateBufferDescriptor(gralloc1_device_t *device, |
| 206 | gralloc1_buffer_descriptor_t *out_descriptor) { |
| 207 | if (!device) { |
| 208 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 209 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 210 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 211 | return dev->buf_mgr_->CreateBufferDescriptor(out_descriptor); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device, |
| 215 | gralloc1_buffer_descriptor_t descriptor) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 216 | if (!device) { |
| 217 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 218 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 219 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 220 | return dev->buf_mgr_->DestroyBufferDescriptor(descriptor); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device, |
| 224 | gralloc1_buffer_descriptor_t descriptor, |
| 225 | gralloc1_consumer_usage_t usage) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 226 | if (!device) { |
| 227 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 228 | } else { |
| 229 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 230 | return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor, |
| 231 | &BufferDescriptor::SetConsumerUsage, usage); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 232 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | gralloc1_error_t GrallocImpl::SetBufferDimensions(gralloc1_device_t *device, |
| 236 | gralloc1_buffer_descriptor_t descriptor, |
| 237 | uint32_t width, uint32_t height) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 238 | if (!device) { |
| 239 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 240 | } else { |
| 241 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 242 | return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor, |
| 243 | &BufferDescriptor::SetDimensions, |
| 244 | INT(width), INT(height)); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 245 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | gralloc1_error_t GrallocImpl::SetColorFormat(gralloc1_device_t *device, |
| 249 | gralloc1_buffer_descriptor_t descriptor, |
| 250 | int32_t format) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 251 | if (!device) { |
| 252 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 253 | } else { |
| 254 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 255 | return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor, |
| 256 | &BufferDescriptor::SetColorFormat, format); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 257 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device, |
| 261 | gralloc1_buffer_descriptor_t descriptor, |
| 262 | gralloc1_producer_usage_t usage) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 263 | if (!device) { |
| 264 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 265 | } else { |
| 266 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 267 | return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor, |
| 268 | &BufferDescriptor::SetProducerUsage, usage); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 269 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | gralloc1_error_t GrallocImpl::GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer, |
| 273 | gralloc1_backing_store_t *out_backstore) { |
| 274 | if (!device || !buffer) { |
| 275 | return GRALLOC1_ERROR_BAD_HANDLE; |
| 276 | } |
| 277 | |
| 278 | *out_backstore = |
| 279 | static_cast<gralloc1_backing_store_t>(PRIV_HANDLE_CONST(buffer)->GetBackingstore()); |
| 280 | |
| 281 | return GRALLOC1_ERROR_NONE; |
| 282 | } |
| 283 | |
| 284 | gralloc1_error_t GrallocImpl::GetConsumerUsage(gralloc1_device_t *device, buffer_handle_t buffer, |
| 285 | gralloc1_consumer_usage_t *outUsage) { |
| 286 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 287 | if (status == GRALLOC1_ERROR_NONE) { |
| 288 | *outUsage = PRIV_HANDLE_CONST(buffer)->GetConsumerUsage(); |
| 289 | } |
| 290 | |
| 291 | return status; |
| 292 | } |
| 293 | |
| 294 | gralloc1_error_t GrallocImpl::GetBufferDimensions(gralloc1_device_t *device, buffer_handle_t buffer, |
| 295 | uint32_t *outWidth, uint32_t *outHeight) { |
| 296 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 297 | if (status == GRALLOC1_ERROR_NONE) { |
| 298 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
Ramkumar Radhakrishnan | ba55eac | 2016-08-26 22:33:48 -0700 | [diff] [blame] | 299 | *outWidth = UINT(hnd->GetUnalignedWidth()); |
| 300 | *outHeight = UINT(hnd->GetUnalignedHeight()); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | return status; |
| 304 | } |
| 305 | |
| 306 | gralloc1_error_t GrallocImpl::GetColorFormat(gralloc1_device_t *device, buffer_handle_t buffer, |
| 307 | int32_t *outFormat) { |
| 308 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 309 | if (status == GRALLOC1_ERROR_NONE) { |
| 310 | *outFormat = PRIV_HANDLE_CONST(buffer)->GetColorFormat(); |
| 311 | } |
| 312 | |
| 313 | return status; |
| 314 | } |
| 315 | |
| 316 | gralloc1_error_t GrallocImpl::GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer, |
| 317 | gralloc1_producer_usage_t *outUsage) { |
| 318 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 319 | if (status == GRALLOC1_ERROR_NONE) { |
| 320 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 321 | *outUsage = hnd->GetProducerUsage(); |
| 322 | } |
| 323 | |
| 324 | return status; |
| 325 | } |
| 326 | |
| 327 | gralloc1_error_t GrallocImpl::GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer, |
| 328 | uint32_t *outStride) { |
| 329 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 330 | if (status == GRALLOC1_ERROR_NONE) { |
| 331 | *outStride = UINT(PRIV_HANDLE_CONST(buffer)->GetStride()); |
| 332 | } |
| 333 | |
| 334 | return status; |
| 335 | } |
| 336 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 337 | gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_descriptors, |
| 338 | const gralloc1_buffer_descriptor_t *descriptors, |
| 339 | buffer_handle_t *out_buffers) { |
| 340 | if (!num_descriptors || !descriptors) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 341 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 342 | } |
| 343 | |
| 344 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 345 | gralloc1_error_t status = dev->buf_mgr_->AllocateBuffers(num_descriptors, descriptors, |
| 346 | out_buffers); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 347 | |
| 348 | return status; |
| 349 | } |
| 350 | |
| 351 | gralloc1_error_t GrallocImpl::RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { |
| 352 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 353 | if (status == GRALLOC1_ERROR_NONE) { |
| 354 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 355 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 356 | status = dev->buf_mgr_->RetainBuffer(hnd); |
| 357 | } |
| 358 | |
| 359 | return status; |
| 360 | } |
| 361 | |
| 362 | gralloc1_error_t GrallocImpl::ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { |
| 363 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 364 | if (status == GRALLOC1_ERROR_NONE) { |
| 365 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 366 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 367 | status = dev->buf_mgr_->ReleaseBuffer(hnd); |
| 368 | } |
| 369 | |
| 370 | return status; |
| 371 | } |
| 372 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 373 | gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer, |
| 374 | uint32_t *out_num_planes) { |
| 375 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 376 | if (status == GRALLOC1_ERROR_NONE) { |
| 377 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 378 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 379 | status = dev->buf_mgr_->GetNumFlexPlanes(hnd, out_num_planes); |
| 380 | } |
| 381 | return status; |
| 382 | } |
| 383 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 384 | gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, |
| 385 | gralloc1_producer_usage_t prod_usage, |
| 386 | gralloc1_consumer_usage_t cons_usage, |
| 387 | const gralloc1_rect_t *region, void **out_data, |
| 388 | int32_t acquire_fence) { |
| 389 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 390 | if (status == GRALLOC1_ERROR_NONE && (acquire_fence > 0)) { |
| 391 | int error = sync_wait(acquire_fence, 1000); |
| 392 | if (error < 0) { |
| 393 | ALOGE("%s: sync_wait timedout! error = %s", __FUNCTION__, strerror(errno)); |
| 394 | return GRALLOC1_ERROR_UNDEFINED; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 399 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 400 | |
| 401 | // Either producer usage or consumer usage must be *_USAGE_NONE |
| 402 | if ((prod_usage != GRALLOC1_PRODUCER_USAGE_NONE) && |
| 403 | (cons_usage != GRALLOC1_CONSUMER_USAGE_NONE)) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 404 | // Current gralloc1 clients do not satisfy this restriction. |
| 405 | // See b/33588773 for details |
| 406 | // return GRALLOC1_ERROR_BAD_VALUE; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | // currently we ignore the region/rect client wants to lock |
| 410 | if (region == NULL) { |
| 411 | return GRALLOC1_ERROR_BAD_VALUE; |
| 412 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 413 | // TODO(user): Need to check if buffer was allocated with the same flags |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 414 | status = dev->buf_mgr_->LockBuffer(hnd, prod_usage, cons_usage); |
| 415 | |
| 416 | *out_data = reinterpret_cast<void *>(hnd->base); |
| 417 | |
| 418 | return status; |
| 419 | } |
| 420 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 421 | gralloc1_error_t GrallocImpl::LockFlex(gralloc1_device_t *device, buffer_handle_t buffer, |
| 422 | gralloc1_producer_usage_t prod_usage, |
| 423 | gralloc1_consumer_usage_t cons_usage, |
| 424 | const gralloc1_rect_t *region, |
| 425 | struct android_flex_layout *out_flex_layout, |
| 426 | int32_t acquire_fence) { |
| 427 | void *out_data; |
| 428 | gralloc1_error_t status = GrallocImpl::LockBuffer(device, buffer, prod_usage, cons_usage, region, |
| 429 | &out_data, acquire_fence); |
| 430 | if (status != GRALLOC1_ERROR_NONE) { |
| 431 | return status; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 432 | } |
| 433 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 434 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 435 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 436 | dev->buf_mgr_->GetFlexLayout(hnd, out_flex_layout); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 437 | return status; |
| 438 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 439 | |
| 440 | gralloc1_error_t GrallocImpl::UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, |
| 441 | int32_t *release_fence) { |
| 442 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 443 | |
| 444 | if (status != GRALLOC1_ERROR_NONE) { |
| 445 | return status; |
| 446 | } |
| 447 | |
| 448 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 449 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 450 | |
| 451 | *release_fence = -1; |
| 452 | |
| 453 | return dev->buf_mgr_->UnlockBuffer(hnd); |
| 454 | } |
| 455 | |
| 456 | gralloc1_error_t GrallocImpl::Gralloc1Perform(gralloc1_device_t *device, int operation, ...) { |
| 457 | va_list args; |
| 458 | va_start(args, operation); |
| 459 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 460 | gralloc1_error_t err = dev->buf_mgr_->Perform(operation, args); |
| 461 | va_end(args); |
| 462 | |
| 463 | return err; |
| 464 | } |
| 465 | |
| 466 | } // namespace gralloc1 |