Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 1 | /* |
Tharaga Balachandran | a6480a4 | 2020-01-20 13:58:43 -0500 | [diff] [blame] | 2 | * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved. |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [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 | |
Tharaga Balachandran | a069a7e | 2020-01-08 17:22:12 -0500 | [diff] [blame] | 30 | #include "qdMetaData.h" |
| 31 | |
| 32 | #include <QtiGrallocPriv.h> |
Ray Zhang | 566adac | 2014-04-14 15:32:04 +0800 | [diff] [blame] | 33 | #include <errno.h> |
Tharaga Balachandran | a069a7e | 2020-01-08 17:22:12 -0500 | [diff] [blame] | 34 | #include <gralloc_priv.h> |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 35 | #include <gralloctypes/Gralloc4.h> |
Tharaga Balachandran | a069a7e | 2020-01-08 17:22:12 -0500 | [diff] [blame] | 36 | #include <log/log.h> |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 37 | #include <string.h> |
| 38 | #include <sys/mman.h> |
Tharaga Balachandran | a069a7e | 2020-01-08 17:22:12 -0500 | [diff] [blame] | 39 | |
Naseer Ahmed | 08c3e40 | 2017-03-16 15:51:54 -0400 | [diff] [blame] | 40 | #include <cinttypes> |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 41 | |
Tharaga Balachandran | a6480a4 | 2020-01-20 13:58:43 -0500 | [diff] [blame] | 42 | static int colorMetaDataToColorSpace(ColorMetaData in, ColorSpace_t *out) { |
| 43 | if (in.colorPrimaries == ColorPrimaries_BT601_6_525 || |
| 44 | in.colorPrimaries == ColorPrimaries_BT601_6_625) { |
| 45 | if (in.range == Range_Full) { |
| 46 | *out = ITU_R_601_FR; |
| 47 | } else { |
| 48 | *out = ITU_R_601; |
| 49 | } |
| 50 | } else if (in.colorPrimaries == ColorPrimaries_BT2020) { |
| 51 | if (in.range == Range_Full) { |
| 52 | *out = ITU_R_2020_FR; |
| 53 | } else { |
| 54 | *out = ITU_R_2020; |
| 55 | } |
| 56 | } else if (in.colorPrimaries == ColorPrimaries_BT709_5) { |
| 57 | *out = ITU_R_709; |
| 58 | } else { |
Yichi Chen | bddad07 | 2020-03-23 12:50:12 +0800 | [diff] [blame] | 59 | ALOGE( |
| 60 | "Cannot convert ColorMetaData to ColorSpace_t. " |
| 61 | "Primaries = %d, Range = %d", |
| 62 | in.colorPrimaries, in.range); |
Tharaga Balachandran | a6480a4 | 2020-01-20 13:58:43 -0500 | [diff] [blame] | 63 | return -1; |
| 64 | } |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static int colorSpaceToColorMetadata(ColorSpace_t in, ColorMetaData *out) { |
| 70 | out->transfer = Transfer_sRGB; |
| 71 | switch (in) { |
| 72 | case ITU_R_601: |
| 73 | out->colorPrimaries = ColorPrimaries_BT601_6_525; |
| 74 | out->range = Range_Limited; |
| 75 | break; |
| 76 | case ITU_R_601_FR: |
| 77 | out->colorPrimaries = ColorPrimaries_BT601_6_525; |
| 78 | out->range = Range_Full; |
| 79 | break; |
| 80 | case ITU_R_709: |
| 81 | out->colorPrimaries = ColorPrimaries_BT709_5; |
| 82 | out->range = Range_Limited; |
| 83 | break; |
| 84 | case ITU_R_2020: |
| 85 | out->colorPrimaries = ColorPrimaries_BT2020; |
| 86 | out->range = Range_Limited; |
| 87 | break; |
| 88 | case ITU_R_2020_FR: |
| 89 | out->colorPrimaries = ColorPrimaries_BT2020; |
| 90 | out->range = Range_Full; |
| 91 | break; |
| 92 | default: |
Yichi Chen | bddad07 | 2020-03-23 12:50:12 +0800 | [diff] [blame] | 93 | ALOGE("Cannot convert ColorSpace_t %d to ColorMetaData", in); |
Tharaga Balachandran | a6480a4 | 2020-01-20 13:58:43 -0500 | [diff] [blame] | 94 | return -1; |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | return 0; |
| 99 | } |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 100 | |
| 101 | static bool getGralloc4Array(MetaData_t *metadata, int32_t paramType) { |
| 102 | switch (paramType) { |
| 103 | case SET_VT_TIMESTAMP: |
| 104 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_VT_TIMESTAMP)]; |
| 105 | case COLOR_METADATA: |
| 106 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_COLOR_METADATA)]; |
| 107 | case PP_PARAM_INTERLACED: |
| 108 | return metadata |
| 109 | ->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_PP_PARAM_INTERLACED)]; |
| 110 | case SET_VIDEO_PERF_MODE: |
| 111 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_VIDEO_PERF_MODE)]; |
| 112 | case SET_GRAPHICS_METADATA: |
| 113 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_GRAPHICS_METADATA)]; |
| 114 | case SET_UBWC_CR_STATS_INFO: |
| 115 | return metadata |
| 116 | ->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_UBWC_CR_STATS_INFO)]; |
| 117 | case UPDATE_BUFFER_GEOMETRY: |
| 118 | return metadata->isStandardMetadataSet[GET_STANDARD_METADATA_STATUS_INDEX( |
| 119 | ::android::gralloc4::MetadataType_Crop.value)]; |
| 120 | case UPDATE_REFRESH_RATE: |
| 121 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_REFRESH_RATE)]; |
| 122 | case UPDATE_COLOR_SPACE: |
| 123 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_COLOR_METADATA)]; |
| 124 | case MAP_SECURE_BUFFER: |
| 125 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_MAP_SECURE_BUFFER)]; |
| 126 | case LINEAR_FORMAT: |
| 127 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_LINEAR_FORMAT)]; |
| 128 | case SET_SINGLE_BUFFER_MODE: |
| 129 | return metadata |
| 130 | ->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_SINGLE_BUFFER_MODE)]; |
| 131 | case SET_CVP_METADATA: |
| 132 | return metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_CVP_METADATA)]; |
| 133 | case SET_VIDEO_HISTOGRAM_STATS: |
| 134 | return metadata |
| 135 | ->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_VIDEO_HISTOGRAM_STATS)]; |
| 136 | default: |
| 137 | ALOGE("paramType %d not supported", paramType); |
| 138 | return false; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | static void setGralloc4Array(MetaData_t *metadata, int32_t paramType, bool isSet) { |
| 143 | switch (paramType) { |
| 144 | case SET_VT_TIMESTAMP: |
| 145 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_VT_TIMESTAMP)] = isSet; |
| 146 | break; |
| 147 | case COLOR_METADATA: |
| 148 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_COLOR_METADATA)] = isSet; |
| 149 | break; |
| 150 | case PP_PARAM_INTERLACED: |
| 151 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_PP_PARAM_INTERLACED)] = |
| 152 | isSet; |
| 153 | break; |
| 154 | case SET_VIDEO_PERF_MODE: |
| 155 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_VIDEO_PERF_MODE)] = isSet; |
| 156 | break; |
| 157 | case SET_GRAPHICS_METADATA: |
| 158 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_GRAPHICS_METADATA)] = |
| 159 | isSet; |
| 160 | break; |
| 161 | case SET_UBWC_CR_STATS_INFO: |
| 162 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_UBWC_CR_STATS_INFO)] = |
| 163 | isSet; |
| 164 | break; |
| 165 | case UPDATE_BUFFER_GEOMETRY: |
| 166 | metadata->isStandardMetadataSet[GET_STANDARD_METADATA_STATUS_INDEX( |
| 167 | ::android::gralloc4::MetadataType_Crop.value)] = isSet; |
| 168 | break; |
| 169 | case UPDATE_REFRESH_RATE: |
| 170 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_REFRESH_RATE)] = isSet; |
| 171 | break; |
| 172 | case UPDATE_COLOR_SPACE: |
| 173 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_COLOR_METADATA)] = isSet; |
| 174 | break; |
| 175 | case MAP_SECURE_BUFFER: |
| 176 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_MAP_SECURE_BUFFER)] = |
| 177 | isSet; |
| 178 | break; |
| 179 | case LINEAR_FORMAT: |
| 180 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_LINEAR_FORMAT)] = isSet; |
| 181 | break; |
| 182 | case SET_SINGLE_BUFFER_MODE: |
| 183 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_SINGLE_BUFFER_MODE)] = |
| 184 | isSet; |
| 185 | break; |
| 186 | case SET_CVP_METADATA: |
| 187 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_CVP_METADATA)] = isSet; |
| 188 | break; |
| 189 | case SET_VIDEO_HISTOGRAM_STATS: |
| 190 | metadata->isVendorMetadataSet[GET_VENDOR_METADATA_STATUS_INDEX(QTI_VIDEO_HISTOGRAM_STATS)] = |
| 191 | isSet; |
| 192 | break; |
| 193 | default: |
| 194 | ALOGE("paramType %d not supported in Gralloc4", paramType); |
| 195 | } |
| 196 | } |
| 197 | |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 198 | unsigned long getMetaDataSize() { |
| 199 | return static_cast<unsigned long>(ROUND_UP_PAGESIZE(sizeof(MetaData_t))); |
| 200 | } |
| 201 | |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 202 | // Cannot add default argument to existing function |
| 203 | unsigned long getMetaDataSizeWithReservedRegion(uint64_t reserved_size) { |
| 204 | return static_cast<unsigned long>(ROUND_UP_PAGESIZE(sizeof(MetaData_t) + reserved_size)); |
| 205 | } |
| 206 | |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 207 | static int validateAndMap(private_handle_t* handle) { |
Prabhanjan Kandula | 1ef8e6e | 2016-08-19 11:46:47 +0530 | [diff] [blame] | 208 | if (private_handle_t::validate(handle)) { |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 209 | ALOGE("%s: Private handle is invalid - handle:%p", __func__, handle); |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 210 | return -1; |
| 211 | } |
Naseer Ahmed | 7aff261 | 2017-10-05 20:39:05 -0400 | [diff] [blame] | 212 | if (handle->fd_metadata < 0) { |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 213 | // Metadata cannot be used |
| 214 | return -1; |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 215 | } |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 216 | |
| 217 | if (!handle->base_metadata) { |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 218 | auto size = getMetaDataSize(); |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 219 | void *base = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, |
| 220 | handle->fd_metadata, 0); |
| 221 | if (base == reinterpret_cast<void*>(MAP_FAILED)) { |
| 222 | ALOGE("%s: metadata mmap failed - handle:%p fd: %d err: %s", |
| 223 | __func__, handle, handle->fd_metadata, strerror(errno)); |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 224 | return -1; |
| 225 | } |
| 226 | handle->base_metadata = (uintptr_t) base; |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 227 | auto metadata = reinterpret_cast<MetaData_t *>(handle->base_metadata); |
| 228 | if (metadata->reservedSize) { |
| 229 | auto reserved_size = metadata->reservedSize; |
| 230 | munmap(reinterpret_cast<void *>(handle->base_metadata), getMetaDataSize()); |
| 231 | handle->base_metadata = 0; |
| 232 | size = getMetaDataSizeWithReservedRegion(reserved_size); |
| 233 | void *new_base = |
| 234 | mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd_metadata, 0); |
| 235 | if (new_base == reinterpret_cast<void *>(MAP_FAILED)) { |
| 236 | ALOGE("%s: metadata mmap failed - handle:%p fd: %d err: %s", __func__, handle, |
| 237 | handle->fd_metadata, strerror(errno)); |
| 238 | return -1; |
| 239 | } |
| 240 | handle->base_metadata = (uintptr_t)new_base; |
| 241 | } |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 242 | } |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | |
Praveen Chavan | 5e5679a | 2018-11-18 11:14:19 -0800 | [diff] [blame] | 246 | static void unmapAndReset(private_handle_t *handle) { |
| 247 | if (private_handle_t::validate(handle) == 0 && handle->base_metadata) { |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 248 | // If reservedSize is 0, the return value will be the same as getMetaDataSize |
| 249 | auto metadata = reinterpret_cast<MetaData_t *>(handle->base_metadata); |
| 250 | auto size = getMetaDataSizeWithReservedRegion(metadata->reservedSize); |
| 251 | munmap(reinterpret_cast<void *>(handle->base_metadata), size); |
| 252 | handle->base_metadata = 0; |
Praveen Chavan | 5e5679a | 2018-11-18 11:14:19 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 256 | int setMetaData(private_handle_t *handle, DispParamType paramType, |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 257 | void *param) { |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 258 | auto err = validateAndMap(handle); |
| 259 | if (err != 0) |
| 260 | return err; |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 261 | return setMetaDataVa(reinterpret_cast<MetaData_t*>(handle->base_metadata), |
| 262 | paramType, param); |
| 263 | } |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 264 | |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 265 | int setMetaDataVa(MetaData_t *data, DispParamType paramType, |
| 266 | void *param) { |
| 267 | if (data == nullptr) |
| 268 | return -EINVAL; |
Prabhanjan Kandula | 1ef8e6e | 2016-08-19 11:46:47 +0530 | [diff] [blame] | 269 | // If parameter is NULL reset the specific MetaData Key |
| 270 | if (!param) { |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 271 | setGralloc4Array(data, paramType, false); |
| 272 | switch (paramType) { |
| 273 | case SET_VIDEO_PERF_MODE: |
| 274 | data->isVideoPerfMode = 0; |
| 275 | break; |
| 276 | case SET_CVP_METADATA: |
| 277 | data->cvpMetadata.size = 0; |
| 278 | break; |
| 279 | case SET_VIDEO_HISTOGRAM_STATS: |
| 280 | data->video_histogram_stats.stat_len = 0; |
| 281 | break; |
| 282 | default: |
| 283 | ALOGE("Unknown paramType %d", paramType); |
| 284 | break; |
| 285 | } |
Naseer Ahmed | 8d1434a | 2017-03-31 15:31:18 -0400 | [diff] [blame] | 286 | // param unset |
| 287 | return 0; |
Prabhanjan Kandula | 1ef8e6e | 2016-08-19 11:46:47 +0530 | [diff] [blame] | 288 | } |
| 289 | |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 290 | setGralloc4Array(data, paramType, true); |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 291 | switch (paramType) { |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 292 | case PP_PARAM_INTERLACED: |
| 293 | data->interlaced = *((int32_t *)param); |
| 294 | break; |
Tharaga Balachandran | a069a7e | 2020-01-08 17:22:12 -0500 | [diff] [blame] | 295 | case UPDATE_BUFFER_GEOMETRY: { |
| 296 | BufferDim_t in = *((BufferDim_t *)param); |
| 297 | data->crop = {0, 0, in.sliceWidth, in.sliceHeight}; |
| 298 | break; |
| 299 | } |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 300 | case UPDATE_REFRESH_RATE: |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 301 | data->refreshrate = *((float *)param); |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 302 | break; |
Tharaga Balachandran | a6480a4 | 2020-01-20 13:58:43 -0500 | [diff] [blame] | 303 | case UPDATE_COLOR_SPACE: { |
Tharaga Balachandran | c20aa83 | 2020-04-07 19:26:54 -0400 | [diff] [blame] | 304 | ColorMetaData color = {}; |
Tharaga Balachandran | a6480a4 | 2020-01-20 13:58:43 -0500 | [diff] [blame] | 305 | if (!colorSpaceToColorMetadata(*((ColorSpace_t *)param), &color)) { |
| 306 | data->color = color; |
Yichi Chen | bddad07 | 2020-03-23 12:50:12 +0800 | [diff] [blame] | 307 | break; |
Tharaga Balachandran | a6480a4 | 2020-01-20 13:58:43 -0500 | [diff] [blame] | 308 | } |
Yichi Chen | bddad07 | 2020-03-23 12:50:12 +0800 | [diff] [blame] | 309 | return -EINVAL; |
Tharaga Balachandran | a6480a4 | 2020-01-20 13:58:43 -0500 | [diff] [blame] | 310 | } |
Arun Kumar K.R | da2f69b | 2014-09-30 15:45:37 -0700 | [diff] [blame] | 311 | case MAP_SECURE_BUFFER: |
| 312 | data->mapSecureBuffer = *((int32_t *)param); |
| 313 | break; |
Naseer Ahmed | 3324ff7 | 2015-01-21 17:14:44 -0500 | [diff] [blame] | 314 | case S3D_FORMAT: |
| 315 | data->s3dFormat = *((uint32_t *)param); |
| 316 | break; |
Sushil Chauhan | e7acc3c | 2015-06-23 16:22:30 -0700 | [diff] [blame] | 317 | case LINEAR_FORMAT: |
| 318 | data->linearFormat = *((uint32_t *)param); |
| 319 | break; |
Saurabh Shah | 95f8368 | 2015-10-16 10:30:04 -0700 | [diff] [blame] | 320 | case SET_SINGLE_BUFFER_MODE: |
Saurabh Shah | b8067a4 | 2015-11-06 16:52:02 -0800 | [diff] [blame] | 321 | data->isSingleBufferMode = *((uint32_t *)param); |
Saurabh Shah | 95f8368 | 2015-10-16 10:30:04 -0700 | [diff] [blame] | 322 | break; |
Naseer Ahmed | e8f254d | 2016-08-02 20:06:40 -0400 | [diff] [blame] | 323 | case SET_VT_TIMESTAMP: |
| 324 | data->vtTimeStamp = *((uint64_t *)param); |
| 325 | break; |
Arun Kumar K.R | b2771bf | 2016-10-03 21:38:23 -0700 | [diff] [blame] | 326 | case COLOR_METADATA: |
| 327 | data->color = *((ColorMetaData *)param); |
Arun Kumar K.R | b2771bf | 2016-10-03 21:38:23 -0700 | [diff] [blame] | 328 | break; |
Gurunath Ramaswamy | b494c02 | 2017-07-04 13:47:46 -0700 | [diff] [blame] | 329 | case SET_UBWC_CR_STATS_INFO: { |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 330 | struct UBWCStats *stats = (struct UBWCStats *)param; |
| 331 | int numelems = sizeof(data->ubwcCRStats) / sizeof(struct UBWCStats); |
| 332 | for (int i = 0; i < numelems; i++) { |
| 333 | data->ubwcCRStats[i] = stats[i]; |
| 334 | } |
| 335 | break; |
Gurunath Ramaswamy | b494c02 | 2017-07-04 13:47:46 -0700 | [diff] [blame] | 336 | } |
Ashwini Rao | 6e61696 | 2017-11-28 12:12:46 -0800 | [diff] [blame] | 337 | case SET_VIDEO_PERF_MODE: |
| 338 | data->isVideoPerfMode = *((uint32_t *)param); |
| 339 | break; |
Mohan Pallaka | 5d81443 | 2018-08-01 10:40:13 -0700 | [diff] [blame] | 340 | case SET_GRAPHICS_METADATA: { |
| 341 | GraphicsMetadata payload = *((GraphicsMetadata*)(param)); |
| 342 | data->graphics_metadata.size = payload.size; |
| 343 | memcpy(data->graphics_metadata.data, payload.data, |
| 344 | sizeof(data->graphics_metadata.data)); |
| 345 | break; |
| 346 | } |
Maheshwar Ajja | 1069072 | 2019-01-30 14:12:45 -0800 | [diff] [blame] | 347 | case SET_CVP_METADATA: { |
| 348 | struct CVPMetadata *cvpMetadata = (struct CVPMetadata *)param; |
Maheshwar Ajja | 0de87d7 | 2019-03-11 11:44:30 -0700 | [diff] [blame] | 349 | if (cvpMetadata->size <= CVP_METADATA_SIZE) { |
Maheshwar Ajja | 1069072 | 2019-01-30 14:12:45 -0800 | [diff] [blame] | 350 | data->cvpMetadata.size = cvpMetadata->size; |
| 351 | memcpy(data->cvpMetadata.payload, cvpMetadata->payload, |
| 352 | cvpMetadata->size); |
Akshata Sahukar | aab1e56 | 2019-07-30 13:57:25 -0700 | [diff] [blame] | 353 | data->cvpMetadata.capture_frame_rate = cvpMetadata->capture_frame_rate; |
| 354 | data->cvpMetadata.cvp_frame_rate = cvpMetadata->cvp_frame_rate; |
Akshata Sahukar | 8a8657c | 2019-10-04 20:29:25 -0700 | [diff] [blame] | 355 | data->cvpMetadata.flags = cvpMetadata->flags; |
| 356 | memcpy(data->cvpMetadata.reserved, cvpMetadata->reserved, |
| 357 | (8 * sizeof(uint32_t))); |
Maheshwar Ajja | 1069072 | 2019-01-30 14:12:45 -0800 | [diff] [blame] | 358 | } else { |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 359 | setGralloc4Array(data, paramType, false); |
| 360 | ALOGE("%s: cvp metadata length %d is more than max size %d", __func__, |
| 361 | cvpMetadata->size, CVP_METADATA_SIZE); |
| 362 | return -EINVAL; |
Maheshwar Ajja | 1069072 | 2019-01-30 14:12:45 -0800 | [diff] [blame] | 363 | } |
| 364 | break; |
| 365 | } |
Mihir Ganu | 3d40154 | 2019-04-03 11:08:06 -0700 | [diff] [blame] | 366 | case SET_VIDEO_HISTOGRAM_STATS: { |
| 367 | struct VideoHistogramMetadata *vidstats = (struct VideoHistogramMetadata *)param; |
| 368 | if (vidstats->stat_len <= VIDEO_HISTOGRAM_STATS_SIZE) { |
| 369 | memcpy(data->video_histogram_stats.stats_info, |
| 370 | vidstats->stats_info, VIDEO_HISTOGRAM_STATS_SIZE); |
| 371 | data->video_histogram_stats.stat_len = vidstats->stat_len; |
| 372 | data->video_histogram_stats.frame_type = vidstats->frame_type; |
| 373 | data->video_histogram_stats.display_width = vidstats->display_width; |
| 374 | data->video_histogram_stats.display_height = vidstats->display_height; |
| 375 | data->video_histogram_stats.decode_width = vidstats->decode_width; |
| 376 | data->video_histogram_stats.decode_height = vidstats->decode_height; |
| 377 | } else { |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 378 | setGralloc4Array(data, paramType, false); |
| 379 | ALOGE("%s: video stats length %u is more than max size %u", __func__, |
| 380 | vidstats->stat_len, VIDEO_HISTOGRAM_STATS_SIZE); |
| 381 | return -EINVAL; |
Mihir Ganu | 3d40154 | 2019-04-03 11:08:06 -0700 | [diff] [blame] | 382 | } |
| 383 | break; |
| 384 | } |
| 385 | default: |
Ray Zhang | 8ace84d | 2016-08-08 19:36:03 +0800 | [diff] [blame] | 386 | ALOGE("Unknown paramType %d", paramType); |
| 387 | break; |
| 388 | } |
Ray Zhang | 8ace84d | 2016-08-08 19:36:03 +0800 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | int clearMetaData(private_handle_t *handle, DispParamType paramType) { |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 393 | auto err = validateAndMap(handle); |
| 394 | if (err != 0) |
| 395 | return err; |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 396 | return clearMetaDataVa(reinterpret_cast<MetaData_t *>(handle->base_metadata), |
| 397 | paramType); |
| 398 | } |
Ray Zhang | 8ace84d | 2016-08-08 19:36:03 +0800 | [diff] [blame] | 399 | |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 400 | int clearMetaDataVa(MetaData_t *data, DispParamType paramType) { |
| 401 | if (data == nullptr) |
| 402 | return -EINVAL; |
Ray Zhang | 8ace84d | 2016-08-08 19:36:03 +0800 | [diff] [blame] | 403 | data->operation &= ~paramType; |
| 404 | switch (paramType) { |
Priyanka Gujjula | 1db7471 | 2018-11-27 17:38:26 +0530 | [diff] [blame] | 405 | case SET_VIDEO_PERF_MODE: |
| 406 | data->isVideoPerfMode = 0; |
| 407 | break; |
Maheshwar Ajja | 1069072 | 2019-01-30 14:12:45 -0800 | [diff] [blame] | 408 | case SET_CVP_METADATA: |
| 409 | data->cvpMetadata.size = 0; |
| 410 | break; |
Mihir Ganu | 3d40154 | 2019-04-03 11:08:06 -0700 | [diff] [blame] | 411 | case SET_VIDEO_HISTOGRAM_STATS: |
| 412 | data->video_histogram_stats.stat_len = 0; |
| 413 | break; |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 414 | default: |
| 415 | ALOGE("Unknown paramType %d", paramType); |
| 416 | break; |
| 417 | } |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 418 | return 0; |
| 419 | } |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 420 | |
| 421 | int getMetaData(private_handle_t *handle, DispFetchParamType paramType, |
| 422 | void *param) { |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 423 | int ret = validateAndMap(handle); |
| 424 | if (ret != 0) |
| 425 | return ret; |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 426 | return getMetaDataVa(reinterpret_cast<MetaData_t *>(handle->base_metadata), |
| 427 | paramType, param); |
| 428 | } |
| 429 | |
| 430 | int getMetaDataVa(MetaData_t *data, DispFetchParamType paramType, |
| 431 | void *param) { |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 432 | // Make sure we send 0 only if the operation queried is present |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 433 | int ret = -EINVAL; |
| 434 | if (data == nullptr) |
| 435 | return ret; |
Gurunath Ramaswamy | b494c02 | 2017-07-04 13:47:46 -0700 | [diff] [blame] | 436 | if (param == nullptr) |
| 437 | return ret; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 438 | |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 439 | if (!getGralloc4Array(data, paramType)) { |
| 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | ret = 0; |
| 444 | |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 445 | switch (paramType) { |
| 446 | case GET_PP_PARAM_INTERLACED: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 447 | *((int32_t *)param) = data->interlaced; |
| 448 | break; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 449 | case GET_BUFFER_GEOMETRY: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 450 | *((BufferDim_t *)param) = {data->crop.right, data->crop.bottom}; |
| 451 | break; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 452 | case GET_REFRESH_RATE: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 453 | *((float *)param) = data->refreshrate; |
| 454 | break; |
| 455 | case GET_COLOR_SPACE: { |
| 456 | ColorSpace_t color_space; |
| 457 | if (!colorMetaDataToColorSpace(data->color, &color_space)) { |
| 458 | *((ColorSpace_t *)param) = color_space; |
| 459 | } else { |
| 460 | ret = -EINVAL; |
| 461 | } |
| 462 | break; |
| 463 | } |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 464 | case GET_MAP_SECURE_BUFFER: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 465 | *((int32_t *)param) = data->mapSecureBuffer; |
| 466 | break; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 467 | case GET_S3D_FORMAT: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 468 | *((uint32_t *)param) = data->s3dFormat; |
| 469 | break; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 470 | case GET_LINEAR_FORMAT: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 471 | *((uint32_t *)param) = data->linearFormat; |
| 472 | break; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 473 | case GET_SINGLE_BUFFER_MODE: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 474 | *((uint32_t *)param) = data->isSingleBufferMode; |
| 475 | break; |
Naseer Ahmed | e8f254d | 2016-08-02 20:06:40 -0400 | [diff] [blame] | 476 | case GET_VT_TIMESTAMP: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 477 | *((uint64_t *)param) = data->vtTimeStamp; |
| 478 | break; |
Arun Kumar K.R | b2771bf | 2016-10-03 21:38:23 -0700 | [diff] [blame] | 479 | case GET_COLOR_METADATA: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 480 | *((ColorMetaData *)param) = data->color; |
| 481 | break; |
| 482 | case GET_UBWC_CR_STATS_INFO: { |
| 483 | struct UBWCStats *stats = (struct UBWCStats *)param; |
| 484 | int numelems = sizeof(data->ubwcCRStats) / sizeof(struct UBWCStats); |
| 485 | for (int i = 0; i < numelems; i++) { |
| 486 | stats[i] = data->ubwcCRStats[i]; |
| 487 | } |
| 488 | break; |
| 489 | } |
Ashwini Rao | 6e61696 | 2017-11-28 12:12:46 -0800 | [diff] [blame] | 490 | case GET_VIDEO_PERF_MODE: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 491 | *((uint32_t *)param) = data->isVideoPerfMode; |
| 492 | break; |
Mohan Pallaka | 5d81443 | 2018-08-01 10:40:13 -0700 | [diff] [blame] | 493 | case GET_GRAPHICS_METADATA: |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 494 | memcpy(param, data->graphics_metadata.data, sizeof(data->graphics_metadata.data)); |
| 495 | break; |
| 496 | case GET_CVP_METADATA: { |
| 497 | struct CVPMetadata *cvpMetadata = (struct CVPMetadata *)param; |
| 498 | cvpMetadata->size = 0; |
| 499 | if (data->cvpMetadata.size <= CVP_METADATA_SIZE) { |
| 500 | cvpMetadata->size = data->cvpMetadata.size; |
| 501 | memcpy(cvpMetadata->payload, data->cvpMetadata.payload, data->cvpMetadata.size); |
| 502 | cvpMetadata->capture_frame_rate = data->cvpMetadata.capture_frame_rate; |
| 503 | cvpMetadata->cvp_frame_rate = data->cvpMetadata.cvp_frame_rate; |
| 504 | cvpMetadata->flags = data->cvpMetadata.flags; |
| 505 | memcpy(cvpMetadata->reserved, data->cvpMetadata.reserved, (8 * sizeof(uint32_t))); |
| 506 | } else { |
| 507 | ret = -EINVAL; |
| 508 | } |
| 509 | break; |
| 510 | } |
| 511 | case GET_VIDEO_HISTOGRAM_STATS: { |
| 512 | struct VideoHistogramMetadata *vidstats = (struct VideoHistogramMetadata *)param; |
| 513 | vidstats->stat_len = 0; |
| 514 | if (data->video_histogram_stats.stat_len <= VIDEO_HISTOGRAM_STATS_SIZE) { |
| 515 | memcpy(vidstats->stats_info, data->video_histogram_stats.stats_info, |
| 516 | VIDEO_HISTOGRAM_STATS_SIZE); |
| 517 | vidstats->stat_len = data->video_histogram_stats.stat_len; |
| 518 | vidstats->frame_type = data->video_histogram_stats.frame_type; |
| 519 | vidstats->display_width = data->video_histogram_stats.display_width; |
| 520 | vidstats->display_height = data->video_histogram_stats.display_height; |
| 521 | vidstats->decode_width = data->video_histogram_stats.decode_width; |
| 522 | vidstats->decode_height = data->video_histogram_stats.decode_height; |
| 523 | } else { |
| 524 | ret = -EINVAL; |
| 525 | } |
| 526 | break; |
| 527 | } |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 528 | default: |
| 529 | ALOGE("Unknown paramType %d", paramType); |
Tharaga Balachandran | df242cf | 2020-06-16 09:34:34 -0400 | [diff] [blame] | 530 | ret = -EINVAL; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 531 | break; |
| 532 | } |
Arun Kumar K.R | 3e45ac4 | 2017-03-08 19:00:02 -0800 | [diff] [blame] | 533 | return ret; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | int copyMetaData(struct private_handle_t *src, struct private_handle_t *dst) { |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 537 | auto err = validateAndMap(src); |
| 538 | if (err != 0) |
| 539 | return err; |
| 540 | |
| 541 | err = validateAndMap(dst); |
| 542 | if (err != 0) |
| 543 | return err; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 544 | |
Naseer Ahmed | 3b3a19c | 2017-03-28 15:17:27 -0400 | [diff] [blame] | 545 | MetaData_t *src_data = reinterpret_cast <MetaData_t *>(src->base_metadata); |
| 546 | MetaData_t *dst_data = reinterpret_cast <MetaData_t *>(dst->base_metadata); |
Naseer Ahmed | e9b8762 | 2017-07-06 12:53:15 -0400 | [diff] [blame] | 547 | *dst_data = *src_data; |
feifanz | 9cc2303 | 2016-03-23 18:48:56 +0800 | [diff] [blame] | 548 | return 0; |
| 549 | } |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 550 | |
| 551 | int copyMetaDataVaToHandle(MetaData_t *src_data, struct private_handle_t *dst) { |
| 552 | int err = -EINVAL; |
| 553 | if (src_data == nullptr) |
| 554 | return err; |
| 555 | |
| 556 | err = validateAndMap(dst); |
| 557 | if (err != 0) |
| 558 | return err; |
| 559 | |
| 560 | MetaData_t *dst_data = reinterpret_cast <MetaData_t *>(dst->base_metadata); |
Naseer Ahmed | e9b8762 | 2017-07-06 12:53:15 -0400 | [diff] [blame] | 561 | *dst_data = *src_data; |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | int copyMetaDataHandleToVa(struct private_handle_t *src, MetaData_t *dst_data) { |
| 566 | int err = -EINVAL; |
| 567 | if (dst_data == nullptr) |
| 568 | return err; |
| 569 | |
| 570 | err = validateAndMap(src); |
| 571 | if (err != 0) |
| 572 | return err; |
| 573 | |
| 574 | MetaData_t *src_data = reinterpret_cast <MetaData_t *>(src->base_metadata); |
Naseer Ahmed | e9b8762 | 2017-07-06 12:53:15 -0400 | [diff] [blame] | 575 | *dst_data = *src_data; |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | int copyMetaDataVaToVa(MetaData_t *src_data, MetaData_t *dst_data) { |
| 580 | int err = -EINVAL; |
| 581 | if (src_data == nullptr) |
| 582 | return err; |
| 583 | |
| 584 | if (dst_data == nullptr) |
| 585 | return err; |
| 586 | |
Naseer Ahmed | e9b8762 | 2017-07-06 12:53:15 -0400 | [diff] [blame] | 587 | *dst_data = *src_data; |
Naseer Ahmed | 2e6bee1 | 2017-04-13 22:45:54 -0400 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
Praveen Chavan | 5e5679a | 2018-11-18 11:14:19 -0800 | [diff] [blame] | 591 | int setMetaDataAndUnmap(struct private_handle_t *handle, enum DispParamType paramType, |
| 592 | void *param) { |
| 593 | auto ret = setMetaData(handle, paramType, param); |
| 594 | unmapAndReset(handle); |
| 595 | return ret; |
| 596 | } |
| 597 | |
| 598 | int getMetaDataAndUnmap(struct private_handle_t *handle, |
| 599 | enum DispFetchParamType paramType, |
| 600 | void *param) { |
| 601 | auto ret = getMetaData(handle, paramType, param); |
| 602 | unmapAndReset(handle); |
| 603 | return ret; |
| 604 | } |