Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 1 | /* |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2019, 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 | |
Naseer Ahmed | 7a2b09c | 2017-05-11 13:03:17 -0400 | [diff] [blame] | 30 | #define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) |
Naseer Ahmed | fcad05e | 2018-03-06 20:41:14 -0500 | [diff] [blame] | 31 | #include <log/log.h> |
Naseer Ahmed | 7a2b09c | 2017-05-11 13:03:17 -0400 | [diff] [blame] | 32 | #include <cutils/trace.h> |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 33 | #include <sync/sync.h> |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 34 | #include <utils/Trace.h> |
Naseer Ahmed | dc91813 | 2017-03-07 15:25:14 -0500 | [diff] [blame] | 35 | #include <algorithm> |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 36 | #include <sstream> |
| 37 | #include <string> |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 38 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 39 | #include "gr_buf_descriptor.h" |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 40 | #include "gr_device_impl.h" |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 41 | #include "gr_utils.h" |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 42 | #include "gralloc_priv.h" |
| 43 | #include "qdMetaData.h" |
| 44 | #include "qd_utils.h" |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 45 | |
| 46 | int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device); |
| 47 | |
| 48 | int gralloc_device_close(struct hw_device_t *device); |
| 49 | |
| 50 | static struct hw_module_methods_t gralloc_module_methods = {.open = gralloc_device_open}; |
| 51 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 52 | struct gralloc_module_t HAL_MODULE_INFO_SYM = { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 53 | // clang-format off |
| 54 | .common = { |
| 55 | .tag = HARDWARE_MODULE_TAG, |
| 56 | .module_api_version = GRALLOC_MODULE_API_VERSION_1_0, |
| 57 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
| 58 | .id = GRALLOC_HARDWARE_MODULE_ID, |
| 59 | .name = "Graphics Memory Module", |
| 60 | .author = "Code Aurora Forum", |
| 61 | .methods = &gralloc_module_methods, |
| 62 | .dso = 0, |
| 63 | .reserved = {0}, |
| 64 | }, |
| 65 | // clang-format on |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) { |
| 69 | int status = -EINVAL; |
Rohit Kulkarni | 511602d | 2017-09-26 16:56:41 -0700 | [diff] [blame] | 70 | if (module && device && !strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 71 | gralloc::GrallocImpl * /*gralloc1_device_t*/ dev = gralloc::GrallocImpl::GetInstance(module); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 72 | *device = reinterpret_cast<hw_device_t *>(dev); |
Naseer Ahmed | 7df1e40 | 2017-03-16 15:13:34 -0400 | [diff] [blame] | 73 | if (dev) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 74 | status = 0; |
| 75 | } else { |
Naseer Ahmed | 7df1e40 | 2017-03-16 15:13:34 -0400 | [diff] [blame] | 76 | ALOGE("Fatal error opening gralloc1 device"); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 77 | } |
| 78 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 79 | return status; |
| 80 | } |
| 81 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 82 | namespace gralloc { |
| 83 | |
| 84 | std::atomic<uint64_t> GrallocImpl::next_descriptor_id_(1); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 85 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 86 | GrallocImpl::GrallocImpl(const hw_module_t *module) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 87 | common.tag = HARDWARE_DEVICE_TAG; |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 88 | common.version = GRALLOC_MODULE_API_VERSION_1_0; |
| 89 | common.module = const_cast<hw_module_t *>(module); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 90 | common.close = CloseDevice; |
| 91 | getFunction = GetFunction; |
| 92 | getCapabilities = GetCapabilities; |
Naseer Ahmed | 7df1e40 | 2017-03-16 15:13:34 -0400 | [diff] [blame] | 93 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 94 | initialized_ = Init(); |
| 95 | } |
| 96 | |
| 97 | inline gralloc1_error_t ToError(Error error) { |
| 98 | switch (error) { |
| 99 | case Error::NONE: |
| 100 | return GRALLOC1_ERROR_NONE; |
| 101 | case Error::BAD_DESCRIPTOR: |
| 102 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 103 | case Error::BAD_BUFFER: |
| 104 | return GRALLOC1_ERROR_BAD_HANDLE; |
| 105 | case Error::BAD_VALUE: |
| 106 | return GRALLOC1_ERROR_BAD_VALUE; |
| 107 | case Error::NO_RESOURCES: |
| 108 | return GRALLOC1_ERROR_NO_RESOURCES; |
| 109 | case Error::UNSUPPORTED: |
| 110 | default: |
| 111 | return GRALLOC1_ERROR_UNSUPPORTED; |
| 112 | } |
| 113 | } |
| 114 | |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 115 | static uint64_t ProducerUsageToBufferUsage(uint64_t /*gralloc1_producer_usage_t*/ producer_usage) { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 116 | uint64_t usage = producer_usage & ~(GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN | |
| 117 | GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN); |
| 118 | if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN) == |
| 119 | GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN) { |
| 120 | usage |= BufferUsage::CPU_READ_OFTEN; |
| 121 | } else if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ) == |
| 122 | GRALLOC1_PRODUCER_USAGE_CPU_READ) { |
| 123 | usage |= BufferUsage::CPU_READ_RARELY; |
| 124 | } |
| 125 | |
| 126 | if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN) == |
| 127 | GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN) { |
| 128 | usage |= BufferUsage::CPU_WRITE_OFTEN; |
| 129 | } else if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE) == |
| 130 | GRALLOC1_PRODUCER_USAGE_CPU_WRITE) { |
| 131 | usage |= BufferUsage::CPU_WRITE_RARELY; |
| 132 | } |
| 133 | return usage; |
| 134 | } |
| 135 | |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 136 | static uint64_t ConsumerUsageToBufferUsage(uint64_t /*gralloc1_consumer_usage_t*/ consumer_usage) { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 137 | uint64_t usage = consumer_usage & ~(GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN); |
| 138 | if ((consumer_usage & GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN) == |
| 139 | GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN) { |
| 140 | usage |= BufferUsage::CPU_READ_OFTEN; |
| 141 | } else if ((consumer_usage & GRALLOC1_CONSUMER_USAGE_CPU_READ) == |
| 142 | GRALLOC1_CONSUMER_USAGE_CPU_READ) { |
| 143 | usage |= BufferUsage::CPU_READ_RARELY; |
| 144 | } |
| 145 | return usage; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | bool GrallocImpl::Init() { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 149 | buf_mgr_ = BufferManager::GetInstance(); |
Naseer Ahmed | 7df1e40 | 2017-03-16 15:13:34 -0400 | [diff] [blame] | 150 | return buf_mgr_ != nullptr; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 151 | } |
| 152 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 153 | GrallocImpl::~GrallocImpl() {} |
| 154 | |
| 155 | gralloc1_error_t GrallocImpl::CreateBufferDescriptorLocked( |
| 156 | gralloc1_buffer_descriptor_t *descriptor_id) { |
| 157 | std::lock_guard<std::mutex> lock(descriptor_lock_); |
| 158 | auto descriptor = std::make_shared<BufferDescriptor>(next_descriptor_id_++); |
| 159 | *descriptor_id = static_cast<gralloc1_buffer_descriptor_t>(descriptor->GetId()); |
| 160 | descriptors_map_.emplace(*descriptor_id, descriptor); |
| 161 | return GRALLOC1_ERROR_NONE; |
| 162 | } |
| 163 | |
| 164 | gralloc1_error_t GrallocImpl::DestroyBufferDescriptorLocked( |
| 165 | gralloc1_buffer_descriptor_t descriptor_id) { |
| 166 | std::lock_guard<std::mutex> lock(descriptor_lock_); |
| 167 | const auto descriptor = descriptors_map_.find(descriptor_id); |
| 168 | if (descriptor == descriptors_map_.end()) { |
| 169 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 170 | } |
| 171 | descriptors_map_.erase(descriptor); |
| 172 | return GRALLOC1_ERROR_NONE; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 173 | } |
| 174 | |
Naseer Ahmed | 7df1e40 | 2017-03-16 15:13:34 -0400 | [diff] [blame] | 175 | int GrallocImpl::CloseDevice(hw_device_t *device __unused) { |
| 176 | // No-op since the gralloc device is a singleton |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | void GrallocImpl::GetCapabilities(struct gralloc1_device *device, uint32_t *out_count, |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 181 | int32_t /*gralloc1_capability_t*/ *out_capabilities) { |
Rohit Kulkarni | 511602d | 2017-09-26 16:56:41 -0700 | [diff] [blame] | 182 | if (device != nullptr && out_count != nullptr) { |
Naseer Ahmed | 6733070 | 2017-05-02 15:00:26 -0400 | [diff] [blame] | 183 | if (out_capabilities != nullptr && *out_count >= 3) { |
Naseer Ahmed | 8f9c7c3 | 2017-02-21 16:45:14 -0500 | [diff] [blame] | 184 | out_capabilities[0] = GRALLOC1_CAPABILITY_TEST_ALLOCATE; |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 185 | out_capabilities[1] = GRALLOC1_CAPABILITY_LAYERED_BUFFERS; |
Naseer Ahmed | 6733070 | 2017-05-02 15:00:26 -0400 | [diff] [blame] | 186 | out_capabilities[2] = GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 187 | } |
Naseer Ahmed | 6733070 | 2017-05-02 15:00:26 -0400 | [diff] [blame] | 188 | *out_count = 3; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 189 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 190 | return; |
| 191 | } |
| 192 | |
| 193 | gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device, int32_t function) { |
| 194 | if (!device) { |
| 195 | return NULL; |
| 196 | } |
| 197 | |
| 198 | switch (function) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 199 | case GRALLOC1_FUNCTION_DUMP: |
| 200 | return reinterpret_cast<gralloc1_function_pointer_t>(Dump); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 201 | case GRALLOC1_FUNCTION_CREATE_DESCRIPTOR: |
| 202 | return reinterpret_cast<gralloc1_function_pointer_t>(CreateBufferDescriptor); |
| 203 | case GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR: |
| 204 | return reinterpret_cast<gralloc1_function_pointer_t>(DestroyBufferDescriptor); |
| 205 | case GRALLOC1_FUNCTION_SET_CONSUMER_USAGE: |
| 206 | return reinterpret_cast<gralloc1_function_pointer_t>(SetConsumerUsage); |
| 207 | case GRALLOC1_FUNCTION_SET_DIMENSIONS: |
| 208 | return reinterpret_cast<gralloc1_function_pointer_t>(SetBufferDimensions); |
| 209 | case GRALLOC1_FUNCTION_SET_FORMAT: |
| 210 | return reinterpret_cast<gralloc1_function_pointer_t>(SetColorFormat); |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 211 | case GRALLOC1_FUNCTION_SET_LAYER_COUNT: |
| 212 | return reinterpret_cast<gralloc1_function_pointer_t>(SetLayerCount); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 213 | case GRALLOC1_FUNCTION_SET_PRODUCER_USAGE: |
| 214 | return reinterpret_cast<gralloc1_function_pointer_t>(SetProducerUsage); |
| 215 | case GRALLOC1_FUNCTION_GET_BACKING_STORE: |
| 216 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBackingStore); |
| 217 | case GRALLOC1_FUNCTION_GET_CONSUMER_USAGE: |
| 218 | return reinterpret_cast<gralloc1_function_pointer_t>(GetConsumerUsage); |
| 219 | case GRALLOC1_FUNCTION_GET_DIMENSIONS: |
| 220 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferDimensions); |
| 221 | case GRALLOC1_FUNCTION_GET_FORMAT: |
| 222 | return reinterpret_cast<gralloc1_function_pointer_t>(GetColorFormat); |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 223 | case GRALLOC1_FUNCTION_GET_LAYER_COUNT: |
| 224 | return reinterpret_cast<gralloc1_function_pointer_t>(GetLayerCount); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 225 | case GRALLOC1_FUNCTION_GET_PRODUCER_USAGE: |
| 226 | return reinterpret_cast<gralloc1_function_pointer_t>(GetProducerUsage); |
| 227 | case GRALLOC1_FUNCTION_GET_STRIDE: |
| 228 | return reinterpret_cast<gralloc1_function_pointer_t>(GetBufferStride); |
| 229 | case GRALLOC1_FUNCTION_ALLOCATE: |
| 230 | return reinterpret_cast<gralloc1_function_pointer_t>(AllocateBuffers); |
| 231 | case GRALLOC1_FUNCTION_RETAIN: |
| 232 | return reinterpret_cast<gralloc1_function_pointer_t>(RetainBuffer); |
| 233 | case GRALLOC1_FUNCTION_RELEASE: |
| 234 | return reinterpret_cast<gralloc1_function_pointer_t>(ReleaseBuffer); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 235 | case GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES: |
| 236 | return reinterpret_cast<gralloc1_function_pointer_t>(GetNumFlexPlanes); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 237 | case GRALLOC1_FUNCTION_LOCK: |
| 238 | return reinterpret_cast<gralloc1_function_pointer_t>(LockBuffer); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 239 | case GRALLOC1_FUNCTION_LOCK_FLEX: |
| 240 | return reinterpret_cast<gralloc1_function_pointer_t>(LockFlex); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 241 | case GRALLOC1_FUNCTION_UNLOCK: |
| 242 | return reinterpret_cast<gralloc1_function_pointer_t>(UnlockBuffer); |
| 243 | case GRALLOC1_FUNCTION_PERFORM: |
| 244 | return reinterpret_cast<gralloc1_function_pointer_t>(Gralloc1Perform); |
| 245 | default: |
| 246 | ALOGE("%s:Gralloc Error. Client Requested for unsupported function", __FUNCTION__); |
| 247 | return NULL; |
| 248 | } |
| 249 | |
| 250 | return NULL; |
| 251 | } |
| 252 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 253 | void GrallocImpl::Dump(gralloc1_device_t *device, uint32_t *out_size, |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 254 | char *out_buffer) { |
Rohit Kulkarni | 511602d | 2017-09-26 16:56:41 -0700 | [diff] [blame] | 255 | if (!device || !out_size) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 256 | ALOGE("Gralloc Error : device=%p", (void *)device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 257 | return; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 258 | } |
Naseer Ahmed | dc91813 | 2017-03-07 15:25:14 -0500 | [diff] [blame] | 259 | const size_t max_dump_size = 8192; |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 260 | if (out_buffer == nullptr) { |
Naseer Ahmed | dc91813 | 2017-03-07 15:25:14 -0500 | [diff] [blame] | 261 | *out_size = max_dump_size; |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 262 | } else { |
| 263 | std::ostringstream os; |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 264 | os << "-------------------------------" << std::endl; |
| 265 | os << "QTI gralloc dump:" << std::endl; |
| 266 | os << "-------------------------------" << std::endl; |
Naseer Ahmed | dc91813 | 2017-03-07 15:25:14 -0500 | [diff] [blame] | 267 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 268 | dev->buf_mgr_->Dump(&os); |
| 269 | os << "-------------------------------" << std::endl; |
| 270 | auto copied = os.str().copy(out_buffer, std::min(os.str().size(), max_dump_size), 0); |
| 271 | *out_size = UINT(copied); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 272 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 273 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 274 | return; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | gralloc1_error_t GrallocImpl::CheckDeviceAndHandle(gralloc1_device_t *device, |
| 278 | buffer_handle_t buffer) { |
| 279 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 280 | if (!device || (private_handle_t::validate(hnd) != 0)) { |
| 281 | ALOGE("Gralloc Error : device= %p, buffer-handle=%p", (void *)device, (void *)buffer); |
| 282 | return GRALLOC1_ERROR_BAD_HANDLE; |
| 283 | } |
| 284 | |
| 285 | return GRALLOC1_ERROR_NONE; |
| 286 | } |
| 287 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 288 | int32_t GrallocImpl::CreateBufferDescriptor(gralloc1_device_t *device, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 289 | gralloc1_buffer_descriptor_t *out_descriptor) { |
Rohit Kulkarni | 511602d | 2017-09-26 16:56:41 -0700 | [diff] [blame] | 290 | if (!device || !out_descriptor) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 291 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 292 | } |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 293 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 294 | return static_cast<int32_t>(dev->CreateBufferDescriptorLocked(out_descriptor)); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 295 | } |
| 296 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 297 | int32_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 298 | gralloc1_buffer_descriptor_t descriptor) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 299 | if (!device) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 300 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_DESCRIPTOR); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 301 | } |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 302 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 303 | return static_cast<int32_t>(dev->DestroyBufferDescriptorLocked(descriptor)); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 304 | } |
| 305 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 306 | int32_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 307 | gralloc1_buffer_descriptor_t descriptor, |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 308 | uint64_t /*gralloc1_consumer_usage_t*/ usage) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 309 | if (!device) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 310 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_DESCRIPTOR); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 311 | } else { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 312 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 313 | return static_cast<int32_t>(dev->CallBufferDescriptorFunction(descriptor, |
| 314 | &BufferDescriptor::SetUsage, |
| 315 | ConsumerUsageToBufferUsage(usage))); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 316 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 317 | } |
| 318 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 319 | int32_t GrallocImpl::SetBufferDimensions(gralloc1_device_t *device, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 320 | gralloc1_buffer_descriptor_t descriptor, |
| 321 | uint32_t width, uint32_t height) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 322 | if (!device) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 323 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_DESCRIPTOR); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 324 | } else { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 325 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 326 | return static_cast<int32_t>(dev->CallBufferDescriptorFunction(descriptor, |
| 327 | &BufferDescriptor::SetDimensions, |
| 328 | INT(width), INT(height))); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 329 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 330 | } |
| 331 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 332 | int32_t GrallocImpl::SetColorFormat(gralloc1_device_t *device, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 333 | gralloc1_buffer_descriptor_t descriptor, |
| 334 | int32_t format) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 335 | if (!device) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 336 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_DESCRIPTOR); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 337 | } else { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 338 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 339 | return static_cast<int32_t>(dev->CallBufferDescriptorFunction(descriptor, |
| 340 | &BufferDescriptor::SetColorFormat, format)); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 341 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 342 | } |
| 343 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 344 | int32_t GrallocImpl::SetLayerCount(gralloc1_device_t *device, |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 345 | gralloc1_buffer_descriptor_t descriptor, |
| 346 | uint32_t layer_count) { |
| 347 | if (!device) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 348 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_DESCRIPTOR); |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 349 | } else { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 350 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 351 | return static_cast<int32_t>(dev->CallBufferDescriptorFunction(descriptor, |
| 352 | &BufferDescriptor::SetLayerCount, layer_count)); |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 356 | int32_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 357 | gralloc1_buffer_descriptor_t descriptor, |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 358 | uint64_t /*gralloc1_producer_usage_t*/ usage) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 359 | if (!device) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 360 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_DESCRIPTOR); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 361 | } else { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 362 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 363 | return static_cast<int32_t>(dev->CallBufferDescriptorFunction(descriptor, |
| 364 | &BufferDescriptor::SetUsage, ProducerUsageToBufferUsage(usage))); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 365 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 366 | } |
| 367 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 368 | int32_t GrallocImpl::GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 369 | gralloc1_backing_store_t *out_backstore) { |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 370 | if (!out_backstore) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 371 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 372 | } |
| 373 | |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 374 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 375 | if (status == GRALLOC1_ERROR_NONE) { |
| 376 | *out_backstore = |
| 377 | static_cast<gralloc1_backing_store_t>(PRIV_HANDLE_CONST(buffer)->GetBackingstore()); |
| 378 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 379 | |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 380 | return status; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 381 | } |
| 382 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 383 | int32_t GrallocImpl::GetConsumerUsage(gralloc1_device_t *device, buffer_handle_t buffer, |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 384 | uint64_t /*gralloc1_consumer_usage_t*/ *outUsage) { |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 385 | if (!outUsage) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 386 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 389 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 390 | if (status == GRALLOC1_ERROR_NONE) { |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 391 | *outUsage = static_cast<uint64_t>(PRIV_HANDLE_CONST(buffer)->GetUsage()); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 392 | } |
| 393 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 394 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 395 | } |
| 396 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 397 | int32_t GrallocImpl::GetBufferDimensions(gralloc1_device_t *device, buffer_handle_t buffer, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 398 | uint32_t *outWidth, uint32_t *outHeight) { |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 399 | if (!outWidth || !outHeight) { |
| 400 | return GRALLOC1_ERROR_BAD_VALUE; |
| 401 | } |
| 402 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 403 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 404 | if (status == GRALLOC1_ERROR_NONE) { |
| 405 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
Ramkumar Radhakrishnan | ba55eac | 2016-08-26 22:33:48 -0700 | [diff] [blame] | 406 | *outWidth = UINT(hnd->GetUnalignedWidth()); |
| 407 | *outHeight = UINT(hnd->GetUnalignedHeight()); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 408 | } |
| 409 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 410 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 411 | } |
| 412 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 413 | int32_t GrallocImpl::GetColorFormat(gralloc1_device_t *device, buffer_handle_t buffer, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 414 | int32_t *outFormat) { |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 415 | if (!outFormat) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 416 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 419 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 420 | if (status == GRALLOC1_ERROR_NONE) { |
| 421 | *outFormat = PRIV_HANDLE_CONST(buffer)->GetColorFormat(); |
| 422 | } |
| 423 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 424 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 425 | } |
| 426 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 427 | int32_t GrallocImpl::GetLayerCount(gralloc1_device_t *device, buffer_handle_t buffer, |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 428 | uint32_t *outLayerCount) { |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 429 | if (!outLayerCount) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 430 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Varun Arora | 16911a9 | 2018-06-13 17:59:12 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 433 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 434 | if (status == GRALLOC1_ERROR_NONE) { |
| 435 | *outLayerCount = PRIV_HANDLE_CONST(buffer)->GetLayerCount(); |
| 436 | } |
| 437 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 438 | return static_cast<int32_t>(status); |
Naseer Ahmed | baa39c5 | 2017-03-27 14:00:07 -0400 | [diff] [blame] | 439 | } |
| 440 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 441 | int32_t GrallocImpl::GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer, |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 442 | uint64_t /*gralloc1_producer_usage_t*/ *outUsage) { |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 443 | if (!outUsage) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 444 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 447 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 448 | if (status == GRALLOC1_ERROR_NONE) { |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 449 | *outUsage = static_cast<uint64_t>(PRIV_HANDLE_CONST(buffer)->GetUsage()); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 450 | } |
| 451 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 452 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 453 | } |
| 454 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 455 | int32_t GrallocImpl::GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 456 | uint32_t *outStride) { |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 457 | if (!outStride) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 458 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 461 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 462 | if (status == GRALLOC1_ERROR_NONE) { |
| 463 | *outStride = UINT(PRIV_HANDLE_CONST(buffer)->GetStride()); |
| 464 | } |
| 465 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 466 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 467 | } |
| 468 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 469 | gralloc1_error_t GrallocImpl::AllocateBuffer(const gralloc1_buffer_descriptor_t *descriptor_ids, |
| 470 | buffer_handle_t *out_buffers) { |
| 471 | gralloc1_error_t status = GRALLOC1_ERROR_NONE; |
| 472 | |
| 473 | // Validate descriptor |
| 474 | std::lock_guard<std::mutex> descriptor_lock(descriptor_lock_); |
| 475 | std::shared_ptr<gralloc::BufferDescriptor> descriptor; |
| 476 | const auto map_descriptor = descriptors_map_.find(descriptor_ids[0]); |
| 477 | if (map_descriptor == descriptors_map_.end()) { |
| 478 | return GRALLOC1_ERROR_BAD_DESCRIPTOR; |
| 479 | } else { |
| 480 | descriptor = map_descriptor->second; |
| 481 | } |
| 482 | |
| 483 | // Allocate separate buffer for each descriptor |
| 484 | if (buf_mgr_->AllocateBuffer(*descriptor, &out_buffers[0]) != Error::NONE) { |
| 485 | return GRALLOC1_ERROR_NO_RESOURCES; |
| 486 | } |
| 487 | |
| 488 | return status; |
| 489 | } |
| 490 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 491 | int32_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_descriptors, |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 492 | const gralloc1_buffer_descriptor_t *descriptors, |
| 493 | buffer_handle_t *out_buffers) { |
| 494 | if (!num_descriptors || !descriptors) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 495 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_DESCRIPTOR); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 496 | } |
| 497 | |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 498 | if (!device) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 499 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 502 | if (num_descriptors != 1) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 503 | return static_cast<int32_t>(GRALLOC1_ERROR_UNSUPPORTED); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
| 507 | gralloc1_error_t status = dev->AllocateBuffer(descriptors, out_buffers); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 508 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 509 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 510 | } |
| 511 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 512 | int32_t GrallocImpl::RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 513 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 514 | if (status == GRALLOC1_ERROR_NONE) { |
| 515 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 516 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 517 | status = ToError(dev->buf_mgr_->RetainBuffer(hnd)); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 518 | } |
| 519 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 520 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 521 | } |
| 522 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 523 | int32_t GrallocImpl::ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { |
Naseer Ahmed | a186b47 | 2017-07-07 18:50:49 -0400 | [diff] [blame] | 524 | if (!device || !buffer) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 525 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_DESCRIPTOR); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 526 | } |
| 527 | |
Naseer Ahmed | a186b47 | 2017-07-07 18:50:49 -0400 | [diff] [blame] | 528 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 529 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 530 | return static_cast<int32_t>((ToError(dev->buf_mgr_->ReleaseBuffer(hnd)))); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 531 | } |
| 532 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 533 | int32_t GrallocImpl::GetFlexLayout(const private_handle_t *hnd, |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 534 | struct android_flex_layout *layout) { |
Saurabh Dubey | b28b82b | 2018-05-29 09:46:41 +0530 | [diff] [blame] | 535 | if (!IsYuvFormat(hnd->format)) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 536 | return static_cast<int32_t>(GRALLOC1_ERROR_UNSUPPORTED); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | android_ycbcr yuvPlaneInfo[2]; |
| 540 | int err = GetYUVPlaneInfo(hnd, yuvPlaneInfo); |
| 541 | |
| 542 | if (err != 0) { |
| 543 | return GRALLOC1_ERROR_BAD_HANDLE; |
| 544 | } |
| 545 | |
| 546 | layout->format = FLEX_FORMAT_YCbCr; |
| 547 | layout->num_planes = 3; |
| 548 | |
| 549 | for (uint32_t i = 0; i < layout->num_planes; i++) { |
| 550 | layout->planes[i].bits_per_component = 8; |
| 551 | layout->planes[i].bits_used = 8; |
| 552 | layout->planes[i].h_increment = 1; |
| 553 | layout->planes[i].v_increment = 1; |
| 554 | layout->planes[i].h_subsampling = 2; |
| 555 | layout->planes[i].v_subsampling = 2; |
| 556 | } |
| 557 | |
| 558 | // We are only returning flex layout for progressive or single field formats. |
| 559 | struct android_ycbcr ycbcr = yuvPlaneInfo[0]; |
| 560 | layout->planes[0].top_left = static_cast<uint8_t *>(ycbcr.y); |
| 561 | layout->planes[0].component = FLEX_COMPONENT_Y; |
| 562 | layout->planes[0].v_increment = static_cast<int32_t>(ycbcr.ystride); |
| 563 | |
| 564 | layout->planes[1].top_left = static_cast<uint8_t *>(ycbcr.cb); |
| 565 | layout->planes[1].component = FLEX_COMPONENT_Cb; |
| 566 | layout->planes[1].h_increment = static_cast<int32_t>(ycbcr.chroma_step); |
| 567 | layout->planes[1].v_increment = static_cast<int32_t>(ycbcr.cstride); |
| 568 | |
| 569 | layout->planes[2].top_left = static_cast<uint8_t *>(ycbcr.cr); |
| 570 | layout->planes[2].component = FLEX_COMPONENT_Cr; |
| 571 | layout->planes[2].h_increment = static_cast<int32_t>(ycbcr.chroma_step); |
| 572 | layout->planes[2].v_increment = static_cast<int32_t>(ycbcr.cstride); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 573 | return static_cast<int32_t>(GRALLOC1_ERROR_NONE); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 574 | } |
| 575 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 576 | int32_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer, |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 577 | uint32_t *out_num_planes) { |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 578 | if (!out_num_planes) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 579 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 582 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
| 583 | if (status == GRALLOC1_ERROR_NONE) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 584 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
Saurabh Dubey | b28b82b | 2018-05-29 09:46:41 +0530 | [diff] [blame] | 585 | if (!IsYuvFormat(hnd->format)) { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 586 | status = GRALLOC1_ERROR_UNSUPPORTED; |
| 587 | } else { |
| 588 | *out_num_planes = 3; |
| 589 | } |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 590 | } |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 591 | return static_cast<int32_t>(status); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 592 | } |
| 593 | |
Naseer Ahmed | 8651417 | 2017-03-29 10:07:43 -0400 | [diff] [blame] | 594 | static inline void CloseFdIfValid(int fd) { |
| 595 | if (fd > 0) { |
| 596 | close(fd); |
| 597 | } |
| 598 | } |
| 599 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 600 | int32_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 601 | uint64_t /*gralloc1_producer_usage_t*/ prod_usage, |
| 602 | uint64_t /*gralloc1_consumer_usage_t*/ cons_usage, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 603 | const gralloc1_rect_t *region, void **out_data, |
| 604 | int32_t acquire_fence) { |
Naseer Ahmed | 7a2b09c | 2017-05-11 13:03:17 -0400 | [diff] [blame] | 605 | ATRACE_CALL(); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 606 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 607 | if (status != GRALLOC1_ERROR_NONE || !out_data || |
| 608 | !region) { // currently we ignore the region/rect client wants to lock |
Naseer Ahmed | 8651417 | 2017-03-29 10:07:43 -0400 | [diff] [blame] | 609 | CloseFdIfValid(acquire_fence); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 610 | return static_cast<int32_t>(status); |
Naseer Ahmed | 8651417 | 2017-03-29 10:07:43 -0400 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | if (acquire_fence > 0) { |
Naseer Ahmed | 7a2b09c | 2017-05-11 13:03:17 -0400 | [diff] [blame] | 614 | ATRACE_BEGIN("fence wait"); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 615 | int error = sync_wait(acquire_fence, 1000); |
Naseer Ahmed | 7a2b09c | 2017-05-11 13:03:17 -0400 | [diff] [blame] | 616 | ATRACE_END(); |
Naseer Ahmed | 8651417 | 2017-03-29 10:07:43 -0400 | [diff] [blame] | 617 | CloseFdIfValid(acquire_fence); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 618 | if (error < 0) { |
| 619 | ALOGE("%s: sync_wait timedout! error = %s", __FUNCTION__, strerror(errno)); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 620 | return static_cast<int32_t>(GRALLOC1_ERROR_UNDEFINED); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| 624 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 625 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 626 | |
| 627 | // Either producer usage or consumer usage must be *_USAGE_NONE |
| 628 | if ((prod_usage != GRALLOC1_PRODUCER_USAGE_NONE) && |
| 629 | (cons_usage != GRALLOC1_CONSUMER_USAGE_NONE)) { |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 630 | // Current gralloc1 clients do not satisfy this restriction. |
| 631 | // See b/33588773 for details |
| 632 | // return GRALLOC1_ERROR_BAD_VALUE; |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 633 | } |
| 634 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 635 | status = ToError(dev->buf_mgr_->LockBuffer( |
| 636 | hnd, ProducerUsageToBufferUsage(prod_usage) | ConsumerUsageToBufferUsage(cons_usage))); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 637 | *out_data = reinterpret_cast<void *>(hnd->base); |
| 638 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 639 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 640 | } |
| 641 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 642 | int32_t GrallocImpl::LockFlex(gralloc1_device_t *device, buffer_handle_t buffer, |
Mahesh Aia | b932518 | 2019-07-09 10:27:55 -0700 | [diff] [blame] | 643 | uint64_t /*gralloc1_producer_usage_t*/ prod_usage, |
| 644 | uint64_t /*gralloc1_consumer_usage_t*/ cons_usage, |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 645 | const gralloc1_rect_t *region, |
| 646 | struct android_flex_layout *out_flex_layout, |
| 647 | int32_t acquire_fence) { |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 648 | if (!out_flex_layout) { |
| 649 | CloseFdIfValid(acquire_fence); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 650 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 653 | void *out_data{}; |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 654 | int32_t status = GrallocImpl::LockBuffer(device, buffer, prod_usage, cons_usage, region, |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 655 | &out_data, acquire_fence); |
| 656 | if (status != GRALLOC1_ERROR_NONE) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 657 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 658 | } |
| 659 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 660 | auto *dev = reinterpret_cast<GrallocImpl *>(device); |
Naseer Ahmed | e69031e | 2016-11-22 20:05:16 -0500 | [diff] [blame] | 661 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 662 | dev->GetFlexLayout(hnd, out_flex_layout); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 663 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 664 | } |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 665 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 666 | int32_t GrallocImpl::UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 667 | int32_t *release_fence) { |
| 668 | gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 669 | if (status != GRALLOC1_ERROR_NONE) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 670 | return static_cast<int32_t>(status); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 671 | } |
| 672 | |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 673 | if (!release_fence) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 674 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 677 | const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); |
| 678 | GrallocImpl const *dev = GRALLOC_IMPL(device); |
| 679 | |
| 680 | *release_fence = -1; |
| 681 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 682 | return static_cast<int32_t>(ToError(dev->buf_mgr_->UnlockBuffer(hnd))); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 683 | } |
| 684 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 685 | static int32_t Perform(int operation, va_list args) { |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 686 | switch (operation) { |
| 687 | case GRALLOC_MODULE_PERFORM_GET_STRIDE: { |
| 688 | int width = va_arg(args, int); |
| 689 | int format = va_arg(args, int); |
| 690 | int *stride = va_arg(args, int *); |
| 691 | unsigned int alignedw = 0, alignedh = 0; |
| 692 | |
| 693 | if (!stride) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 694 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | BufferInfo info(width, width, format); |
| 698 | GetAlignedWidthAndHeight(info, &alignedw, &alignedh); |
| 699 | *stride = INT(alignedw); |
| 700 | } break; |
| 701 | |
| 702 | case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE: { |
| 703 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 704 | int *stride = va_arg(args, int *); |
| 705 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 706 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | if (!stride) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 710 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | BufferDim_t buffer_dim; |
| 714 | if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) { |
| 715 | *stride = buffer_dim.sliceWidth; |
| 716 | } else { |
| 717 | *stride = hnd->width; |
| 718 | } |
| 719 | } break; |
| 720 | |
| 721 | case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE: { |
| 722 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 723 | int *stride = va_arg(args, int *); |
| 724 | int *height = va_arg(args, int *); |
| 725 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 726 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | if (!stride || !height) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 730 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | GetCustomDimensions(hnd, stride, height); |
| 734 | } break; |
| 735 | |
| 736 | case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES: { |
| 737 | int width = va_arg(args, int); |
| 738 | int height = va_arg(args, int); |
| 739 | int format = va_arg(args, int); |
| 740 | uint64_t usage = va_arg(args, uint64_t); |
| 741 | usage |= va_arg(args, uint64_t); |
| 742 | |
| 743 | int *aligned_width = va_arg(args, int *); |
| 744 | int *aligned_height = va_arg(args, int *); |
| 745 | int *tile_enabled = va_arg(args, int *); |
| 746 | if (!aligned_width || !aligned_height || !tile_enabled) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 747 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | unsigned int alignedw, alignedh; |
| 751 | BufferInfo info(width, height, format, usage); |
| 752 | *tile_enabled = IsUBwcEnabled(format, usage); |
| 753 | GetAlignedWidthAndHeight(info, &alignedw, &alignedh); |
| 754 | *aligned_width = INT(alignedw); |
| 755 | *aligned_height = INT(alignedh); |
| 756 | } break; |
| 757 | |
| 758 | case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE: { |
| 759 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 760 | int *color_space = va_arg(args, int *); |
| 761 | |
| 762 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 763 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | if (!color_space) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 767 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | *color_space = 0; |
| 771 | GetColorSpaceFromMetadata(hnd, color_space); |
| 772 | } break; |
| 773 | case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO: { |
| 774 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 775 | android_ycbcr *ycbcr = va_arg(args, struct android_ycbcr *); |
| 776 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 777 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | if (!ycbcr) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 781 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | if (GetYUVPlaneInfo(hnd, ycbcr)) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 785 | return static_cast<int32_t>(GRALLOC1_ERROR_UNDEFINED); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 786 | } |
| 787 | } break; |
| 788 | |
| 789 | case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO: { |
| 790 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 791 | int *map_secure_buffer = va_arg(args, int *); |
| 792 | |
| 793 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 794 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | if (!map_secure_buffer) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 798 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) { |
| 802 | *map_secure_buffer = 0; |
| 803 | } |
| 804 | } break; |
| 805 | |
| 806 | case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG: { |
| 807 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 808 | int *flag = va_arg(args, int *); |
| 809 | |
| 810 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 811 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | if (!flag) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 815 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | *flag = hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED; |
| 819 | int linear_format = 0; |
| 820 | if (getMetaData(hnd, GET_LINEAR_FORMAT, &linear_format) == 0) { |
| 821 | if (linear_format) { |
| 822 | *flag = 0; |
| 823 | } |
| 824 | } |
| 825 | } break; |
| 826 | |
| 827 | case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS: { |
| 828 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 829 | void **rgb_data = va_arg(args, void **); |
| 830 | |
| 831 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 832 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | if (!rgb_data) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 836 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | if (GetRgbDataAddress(hnd, rgb_data)) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 840 | return static_cast<int32_t>(GRALLOC1_ERROR_UNDEFINED); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 841 | } |
| 842 | } break; |
| 843 | |
| 844 | case GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG: { |
| 845 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 846 | int *flag = va_arg(args, int *); |
| 847 | |
| 848 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 849 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | if (!flag) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 853 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_VALUE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, flag) != 0) { |
| 857 | *flag = 0; |
| 858 | } |
| 859 | } break; |
| 860 | |
| 861 | case GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE: { |
| 862 | private_handle_t *hnd = va_arg(args, private_handle_t *); |
| 863 | uint32_t *enable = va_arg(args, uint32_t *); |
| 864 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 865 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 866 | } |
| 867 | if (setMetaData(hnd, SET_SINGLE_BUFFER_MODE, enable) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 868 | return static_cast<int32_t>(GRALLOC1_ERROR_UNSUPPORTED); |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 869 | } |
| 870 | } break; |
| 871 | |
Saurabh Dubey | b28b82b | 2018-05-29 09:46:41 +0530 | [diff] [blame] | 872 | case GRALLOC_MODULE_PERFORM_GET_GRAPHICS_METADATA: { |
| 873 | private_handle_t* hnd = va_arg(args, private_handle_t *); |
| 874 | |
| 875 | if (private_handle_t::validate(hnd) != 0) { |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 876 | return static_cast<int32_t>(GRALLOC1_ERROR_BAD_HANDLE); |
Saurabh Dubey | b28b82b | 2018-05-29 09:46:41 +0530 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | void* graphic_metadata = va_arg(args, void*); |
| 880 | |
| 881 | if (getMetaData(hnd, GET_GRAPHICS_METADATA, graphic_metadata) != 0) { |
| 882 | graphic_metadata = NULL; |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 883 | return static_cast<int32_t>(GRALLOC1_ERROR_UNSUPPORTED); |
Saurabh Dubey | b28b82b | 2018-05-29 09:46:41 +0530 | [diff] [blame] | 884 | } |
| 885 | } break; |
| 886 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 887 | default: |
| 888 | break; |
| 889 | } |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 890 | return static_cast<int32_t>(GRALLOC1_ERROR_NONE); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 891 | } |
| 892 | |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 893 | int32_t GrallocImpl::Gralloc1Perform(gralloc1_device_t *device, int operation, ...) { |
Saurabh Shah | 6e4b376 | 2017-09-21 15:30:15 -0700 | [diff] [blame] | 894 | if (!device) { |
| 895 | return GRALLOC1_ERROR_BAD_VALUE; |
| 896 | } |
| 897 | |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 898 | va_list args; |
| 899 | va_start(args, operation); |
Mahesh Aia | bb82812 | 2019-01-16 13:07:42 -0800 | [diff] [blame] | 900 | int32_t err = Perform(operation, args); |
Prabhanjan Kandula | 96e9234 | 2016-03-24 21:03:35 +0530 | [diff] [blame] | 901 | va_end(args); |
| 902 | |
| 903 | return err; |
| 904 | } |
| 905 | |
Naseer Ahmed | e36f224 | 2017-12-01 15:33:56 -0500 | [diff] [blame] | 906 | } // namespace gralloc |