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, |
Naseer Ahmed | 8f9c7c3 | 2017-02-21 16:45:14 -0500 | [diff] [blame] | 103 | int32_t /*gralloc1_capability_t*/ *out_capabilities) { |
| 104 | if (device != nullptr) { |
| 105 | if (out_capabilities != nullptr && *out_count > 0) { |
| 106 | out_capabilities[0] = GRALLOC1_CAPABILITY_TEST_ALLOCATE; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 107 | } |
Naseer Ahmed | 8f9c7c3 | 2017-02-21 16:45:14 -0500 | [diff] [blame] | 108 | *out_count = 1; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 109 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 110 | return; |
| 111 | } |
| 112 | |
| 113 | gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device, int32_t function) { |
| 114 | if (!device) { |
| 115 | return NULL; |
| 116 | } |
| 117 | |
| 118 | switch (function) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 119 | case GRALLOC1_FUNCTION_DUMP: |
| 120 | return reinterpret_cast<gralloc1_function_pointer_t>(Dump); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 121 | case GRALLOC1_FUNCTION_CREATE_DESCRIPTOR: |
| 122 | return reinterpret_cast<gralloc1_function_pointer_t>(CreateBufferDescriptor); |
| 123 | case GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR: |
| 124 | return reinterpret_cast<gralloc1_function_pointer_t>(DestroyBufferDescriptor); |
| 125 | case GRALLOC1_FUNCTION_SET_CONSUMER_USAGE: |
| 126 | return reinterpret_cast<gralloc1_function_pointer_t>(SetConsumerUsage); |
| 127 | case GRALLOC1_FUNCTION_SET_DIMENSIONS: |
| 128 | return reinterpret_cast<gralloc1_function_pointer_t>(SetBufferDimensions); |
| 129 | case GRALLOC1_FUNCTION_SET_FORMAT: |
| 130 | return reinterpret_cast<gralloc1_function_pointer_t>(SetColorFormat); |
| 131 | case GRALLOC1_FUNCTION_SET_PRODUCER_USAGE: |
| 132 | return reinterpret_cast<gralloc1_function_pointer_t>(SetProducerUsage); |
| 133 | case GRALLOC1_FUNCTION_GET_BACKING_STORE: |
| 134 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBackingStore); |
| 135 | case GRALLOC1_FUNCTION_GET_CONSUMER_USAGE: |
| 136 | return reinterpret_cast<gralloc1_function_pointer_t>(GetConsumerUsage); |
| 137 | case GRALLOC1_FUNCTION_GET_DIMENSIONS: |
| 138 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferDimensions); |
| 139 | case GRALLOC1_FUNCTION_GET_FORMAT: |
| 140 | return reinterpret_cast<gralloc1_function_pointer_t>(GetColorFormat); |
| 141 | case GRALLOC1_FUNCTION_GET_PRODUCER_USAGE: |
| 142 | return reinterpret_cast<gralloc1_function_pointer_t>(GetProducerUsage); |
| 143 | case GRALLOC1_FUNCTION_GET_STRIDE: |
| 144 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferStride); |
| 145 | case GRALLOC1_FUNCTION_ALLOCATE: |
| 146 | return reinterpret_cast<gralloc1_function_pointer_t>(AllocateBuffers); |
| 147 | case GRALLOC1_FUNCTION_RETAIN: |
| 148 | return reinterpret_cast<gralloc1_function_pointer_t>(RetainBuffer); |
| 149 | case GRALLOC1_FUNCTION_RELEASE: |
| 150 | return reinterpret_cast<gralloc1_function_pointer_t>(ReleaseBuffer); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 151 | case GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES: |
| 152 | return reinterpret_cast<gralloc1_function_pointer_t>(GetNumFlexPlanes); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 153 | case GRALLOC1_FUNCTION_LOCK: |
| 154 | return reinterpret_cast<gralloc1_function_pointer_t>(LockBuffer); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 155 | case GRALLOC1_FUNCTION_LOCK_FLEX: |
| 156 | return reinterpret_cast<gralloc1_function_pointer_t>(LockFlex); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 157 | case GRALLOC1_FUNCTION_UNLOCK: |
| 158 | return reinterpret_cast<gralloc1_function_pointer_t>(UnlockBuffer); |
| 159 | case GRALLOC1_FUNCTION_PERFORM: |
| 160 | return reinterpret_cast<gralloc1_function_pointer_t>(Gralloc1Perform); |
| 161 | default: |
| 162 | ALOGE("%s:Gralloc Error. Client Requested for unsupported function", __FUNCTION__); |
| 163 | return NULL; |
| 164 | } |
| 165 | |
| 166 | return NULL; |
| 167 | } |
| 168 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 169 | gralloc1_error_t GrallocImpl::Dump(gralloc1_device_t *device, uint32_t *out_size, |
| 170 | char *out_buffer) { |
| 171 | if (!device) { |
| 172 | ALOGE("Gralloc Error : device=%p", (void *)device); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 173 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 174 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 175 | if (out_buffer == nullptr) { |
| 176 | *out_size = 1024; |
| 177 | } else { |
| 178 | std::ostringstream os; |
| 179 | // TODO(user): implement in buffer manager |
| 180 | os << "-------------------------------" << std::endl; |
| 181 | os << "QTI gralloc dump:" << std::endl; |
| 182 | os << "-------------------------------" << std::endl; |
| 183 | auto copy_size = os.str().size() < *out_size ? os.str().size() : *out_size; |
| 184 | std::copy_n(out_buffer, copy_size, os.str().begin()); |
| 185 | *out_size = static_cast<uint32_t>(copy_size); |
| 186 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 187 | |
| 188 | return GRALLOC1_ERROR_NONE; |
| 189 | } |
| 190 | |
| 191 | gralloc1_error_t GrallocImpl::CheckDeviceAndHandle(gralloc1_device_t *device, |
| 192 | buffer_handle_t buffer) { |
| 193 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 194 | if (!device || (private_handle_t::validate(hnd) != 0)) { |
| 195 | ALOGE("Gralloc Error : device= %p, buffer-handle=%p", (void *)device, (void *)buffer); |
| 196 | return GRALLOC1_ERROR_BAD_HANDLE; |
| 197 | } |
| 198 | |
| 199 | return GRALLOC1_ERROR_NONE; |
| 200 | } |
| 201 | |
| 202 | gralloc1_error_t GrallocImpl::CreateBufferDescriptor(gralloc1_device_t *device, |
| 203 | gralloc1_buffer_descriptor_t *out_descriptor) { |
| 204 | if (!device) { |
| 205 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 206 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 207 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 208 | return dev->buf_mgr_->CreateBufferDescriptor(out_descriptor); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device, |
| 212 | gralloc1_buffer_descriptor_t descriptor) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 213 | if (!device) { |
| 214 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 215 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 216 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 217 | return dev->buf_mgr_->DestroyBufferDescriptor(descriptor); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device, |
| 221 | gralloc1_buffer_descriptor_t descriptor, |
| 222 | gralloc1_consumer_usage_t usage) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 223 | if (!device) { |
| 224 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 225 | } else { |
| 226 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 227 | return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor, |
| 228 | &BufferDescriptor::SetConsumerUsage, usage); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 229 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | gralloc1_error_t GrallocImpl::SetBufferDimensions(gralloc1_device_t *device, |
| 233 | gralloc1_buffer_descriptor_t descriptor, |
| 234 | uint32_t width, uint32_t height) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 235 | if (!device) { |
| 236 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 237 | } else { |
| 238 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 239 | return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor, |
| 240 | &BufferDescriptor::SetDimensions, |
| 241 | INT(width), INT(height)); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 242 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | gralloc1_error_t GrallocImpl::SetColorFormat(gralloc1_device_t *device, |
| 246 | gralloc1_buffer_descriptor_t descriptor, |
| 247 | int32_t format) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 248 | if (!device) { |
| 249 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 250 | } else { |
| 251 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 252 | return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor, |
| 253 | &BufferDescriptor::SetColorFormat, format); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 254 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device, |
| 258 | gralloc1_buffer_descriptor_t descriptor, |
| 259 | gralloc1_producer_usage_t usage) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 260 | if (!device) { |
| 261 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 262 | } else { |
| 263 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 264 | return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor, |
| 265 | &BufferDescriptor::SetProducerUsage, usage); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 266 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | gralloc1_error_t GrallocImpl::GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer, |
| 270 | gralloc1_backing_store_t *out_backstore) { |
| 271 | if (!device || !buffer) { |
| 272 | return GRALLOC1_ERROR_BAD_HANDLE; |
| 273 | } |
| 274 | |
| 275 | *out_backstore = |
| 276 | static_cast<gralloc1_backing_store_t>(PRIV_HANDLE_CONST(buffer)->GetBackingstore()); |
| 277 | |
| 278 | return GRALLOC1_ERROR_NONE; |
| 279 | } |
| 280 | |
| 281 | gralloc1_error_t GrallocImpl::GetConsumerUsage(gralloc1_device_t *device, buffer_handle_t buffer, |
| 282 | gralloc1_consumer_usage_t *outUsage) { |
| 283 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 284 | if (status == GRALLOC1_ERROR_NONE) { |
| 285 | *outUsage = PRIV_HANDLE_CONST(buffer)->GetConsumerUsage(); |
| 286 | } |
| 287 | |
| 288 | return status; |
| 289 | } |
| 290 | |
| 291 | gralloc1_error_t GrallocImpl::GetBufferDimensions(gralloc1_device_t *device, buffer_handle_t buffer, |
| 292 | uint32_t *outWidth, uint32_t *outHeight) { |
| 293 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 294 | if (status == GRALLOC1_ERROR_NONE) { |
| 295 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
Ramkumar Radhakrishnan | ba55eac | 2016-08-26 22:33:48 -0700 | [diff] [blame] | 296 | *outWidth = UINT(hnd->GetUnalignedWidth()); |
| 297 | *outHeight = UINT(hnd->GetUnalignedHeight()); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | return status; |
| 301 | } |
| 302 | |
| 303 | gralloc1_error_t GrallocImpl::GetColorFormat(gralloc1_device_t *device, buffer_handle_t buffer, |
| 304 | int32_t *outFormat) { |
| 305 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 306 | if (status == GRALLOC1_ERROR_NONE) { |
| 307 | *outFormat = PRIV_HANDLE_CONST(buffer)->GetColorFormat(); |
| 308 | } |
| 309 | |
| 310 | return status; |
| 311 | } |
| 312 | |
| 313 | gralloc1_error_t GrallocImpl::GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer, |
| 314 | gralloc1_producer_usage_t *outUsage) { |
| 315 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 316 | if (status == GRALLOC1_ERROR_NONE) { |
| 317 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 318 | *outUsage = hnd->GetProducerUsage(); |
| 319 | } |
| 320 | |
| 321 | return status; |
| 322 | } |
| 323 | |
| 324 | gralloc1_error_t GrallocImpl::GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer, |
| 325 | uint32_t *outStride) { |
| 326 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 327 | if (status == GRALLOC1_ERROR_NONE) { |
| 328 | *outStride = UINT(PRIV_HANDLE_CONST(buffer)->GetStride()); |
| 329 | } |
| 330 | |
| 331 | return status; |
| 332 | } |
| 333 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 334 | gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_descriptors, |
| 335 | const gralloc1_buffer_descriptor_t *descriptors, |
| 336 | buffer_handle_t *out_buffers) { |
| 337 | if (!num_descriptors || !descriptors) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 338 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 339 | } |
| 340 | |
| 341 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 342 | gralloc1_error_t status = dev->buf_mgr_->AllocateBuffers(num_descriptors, descriptors, |
| 343 | out_buffers); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 344 | |
| 345 | return status; |
| 346 | } |
| 347 | |
| 348 | gralloc1_error_t GrallocImpl::RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { |
| 349 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 350 | if (status == GRALLOC1_ERROR_NONE) { |
| 351 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 352 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 353 | status = dev->buf_mgr_->RetainBuffer(hnd); |
| 354 | } |
| 355 | |
| 356 | return status; |
| 357 | } |
| 358 | |
| 359 | gralloc1_error_t GrallocImpl::ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { |
| 360 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 361 | if (status == GRALLOC1_ERROR_NONE) { |
| 362 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 363 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 364 | status = dev->buf_mgr_->ReleaseBuffer(hnd); |
| 365 | } |
| 366 | |
| 367 | return status; |
| 368 | } |
| 369 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 370 | gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer, |
| 371 | uint32_t *out_num_planes) { |
| 372 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 373 | if (status == GRALLOC1_ERROR_NONE) { |
| 374 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 375 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 376 | status = dev->buf_mgr_->GetNumFlexPlanes(hnd, out_num_planes); |
| 377 | } |
| 378 | return status; |
| 379 | } |
| 380 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 381 | gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, |
| 382 | gralloc1_producer_usage_t prod_usage, |
| 383 | gralloc1_consumer_usage_t cons_usage, |
| 384 | const gralloc1_rect_t *region, void **out_data, |
| 385 | int32_t acquire_fence) { |
| 386 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 387 | if (status == GRALLOC1_ERROR_NONE && (acquire_fence > 0)) { |
| 388 | int error = sync_wait(acquire_fence, 1000); |
| 389 | if (error < 0) { |
| 390 | ALOGE("%s: sync_wait timedout! error = %s", __FUNCTION__, strerror(errno)); |
| 391 | return GRALLOC1_ERROR_UNDEFINED; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 396 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 397 | |
| 398 | // Either producer usage or consumer usage must be *_USAGE_NONE |
| 399 | if ((prod_usage != GRALLOC1_PRODUCER_USAGE_NONE) && |
| 400 | (cons_usage != GRALLOC1_CONSUMER_USAGE_NONE)) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 401 | // Current gralloc1 clients do not satisfy this restriction. |
| 402 | // See b/33588773 for details |
| 403 | // return GRALLOC1_ERROR_BAD_VALUE; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | // currently we ignore the region/rect client wants to lock |
| 407 | if (region == NULL) { |
| 408 | return GRALLOC1_ERROR_BAD_VALUE; |
| 409 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 410 | // 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] | 411 | status = dev->buf_mgr_->LockBuffer(hnd, prod_usage, cons_usage); |
| 412 | |
| 413 | *out_data = reinterpret_cast<void *>(hnd->base); |
| 414 | |
| 415 | return status; |
| 416 | } |
| 417 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 418 | gralloc1_error_t GrallocImpl::LockFlex(gralloc1_device_t *device, buffer_handle_t buffer, |
| 419 | gralloc1_producer_usage_t prod_usage, |
| 420 | gralloc1_consumer_usage_t cons_usage, |
| 421 | const gralloc1_rect_t *region, |
| 422 | struct android_flex_layout *out_flex_layout, |
| 423 | int32_t acquire_fence) { |
| 424 | void *out_data; |
| 425 | gralloc1_error_t status = GrallocImpl::LockBuffer(device, buffer, prod_usage, cons_usage, region, |
| 426 | &out_data, acquire_fence); |
| 427 | if (status != GRALLOC1_ERROR_NONE) { |
| 428 | return status; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 429 | } |
| 430 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 431 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 432 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 433 | dev->buf_mgr_->GetFlexLayout(hnd, out_flex_layout); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 434 | return status; |
| 435 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 436 | |
| 437 | gralloc1_error_t GrallocImpl::UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, |
| 438 | int32_t *release_fence) { |
| 439 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 440 | |
| 441 | if (status != GRALLOC1_ERROR_NONE) { |
| 442 | return status; |
| 443 | } |
| 444 | |
| 445 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 446 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 447 | |
| 448 | *release_fence = -1; |
| 449 | |
| 450 | return dev->buf_mgr_->UnlockBuffer(hnd); |
| 451 | } |
| 452 | |
| 453 | gralloc1_error_t GrallocImpl::Gralloc1Perform(gralloc1_device_t *device, int operation, ...) { |
| 454 | va_list args; |
| 455 | va_start(args, operation); |
| 456 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 457 | gralloc1_error_t err = dev->buf_mgr_->Perform(operation, args); |
| 458 | va_end(args); |
| 459 | |
| 460 | return err; |
| 461 | } |
| 462 | |
| 463 | } // namespace gralloc1 |