| /* |
| * Copyright (c) 2020 The Linux Foundation. All rights reserved. |
| * |
| * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are |
| * met: |
| * * Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * * Redistributions in binary form must reproduce the above |
| * copyright notice, this list of conditions and the following |
| * disclaimer in the documentation and/or other materials provided |
| * with the distribution. |
| * * Neither the name of The Linux Foundation. nor the names of its |
| * contributors may be used to endorse or promote products derived |
| * from this software without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| /* |
| * Changes from Qualcomm Innovation Center are provided under the following license: |
| * |
| * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted (subject to the limitations in the |
| * disclaimer below) provided that the following conditions are met: |
| * |
| * * Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * |
| * * Redistributions in binary form must reproduce the above |
| * copyright notice, this list of conditions and the following |
| * disclaimer in the documentation and/or other materials provided |
| * with the distribution. |
| * |
| * * Neither the name of Qualcomm Innovation Center, Inc. nor the |
| * names of its contributors may be used to endorse or promote |
| * products derived from this software without specific prior |
| * written permission. |
| * |
| * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE |
| * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT |
| * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #ifndef __QTIGRALLOCPRIV_H__ |
| #define __QTIGRALLOCPRIV_H__ |
| |
| #include <color_metadata.h> |
| #include <cutils/native_handle.h> |
| #include <log/log.h> |
| |
| #include <cinttypes> |
| #include <string> |
| |
| #include "QtiGrallocMetadata.h" |
| |
| |
| /* |
| * |
| * DISCLAIMER: |
| * INTERNAL GRALLOC USE ONLY - THIS FILE SHOULD NOT BE INCLUDED BY GRALLOC CLIENTS |
| * The location will be changed and this file will not be exposed |
| * once qdMetaData copy functions are deprecated |
| * |
| */ |
| |
| #define METADATA_V2 |
| |
| // TODO: MetaData_t should be in qtigralloc namespace |
| struct MetaData_t { |
| int32_t operation; |
| int32_t interlaced; |
| float refreshrate; |
| int32_t mapSecureBuffer; |
| /* Deprecated */ |
| uint32_t s3dFormat; |
| /* VENUS output buffer is linear for UBWC Interlaced video */ |
| uint32_t linearFormat; |
| /* Set by graphics to indicate that this buffer will be written to but not |
| * swapped out */ |
| uint32_t isSingleBufferMode; |
| |
| /* Set by camera to program the VT Timestamp */ |
| uint64_t vtTimeStamp; |
| /* Color Aspects + HDR info */ |
| ColorMetaData color; |
| /* Consumer should read this data as follows based on |
| * Gralloc flag "interlaced" listed above. |
| * [0] : If it is progressive. |
| * [0] : Top field, if it is interlaced. |
| * [1] : Do not read, if it is progressive. |
| * [1] : Bottom field, if it is interlaced. |
| */ |
| struct UBWCStats ubwcCRStats[UBWC_STATS_ARRAY_SIZE]; |
| /* Set by camera to indicate that this buffer will be used for a High |
| * Performance Video Usecase */ |
| uint32_t isVideoPerfMode; |
| /* Populated and used by adreno during buffer size calculation. |
| * Set only for RGB formats. */ |
| GraphicsMetadata graphics_metadata; |
| /* Video histogram stats populated by video decoder */ |
| struct VideoHistogramMetadata video_histogram_stats; |
| /* |
| * Producer (camera) will set cvp metadata and consumer (video) will |
| * use it. The format of metadata is known to producer and consumer. |
| */ |
| CVPMetadata cvpMetadata; |
| CropRectangle_t crop; |
| int32_t blendMode; |
| char name[MAX_NAME_LEN]; |
| ReservedRegion reservedRegion; |
| bool isStandardMetadataSet[METADATA_SET_SIZE]; |
| bool isVendorMetadataSet[METADATA_SET_SIZE]; |
| uint64_t reservedSize; |
| VideoTimestampInfo videoTsInfo; |
| BufferPermission bufferPerm[BUFFER_CLIENT_MAX]; |
| int64_t memHandle; |
| |
| /* Set by clients to indicate that timed rendering will be enabled |
| * or disabled for this buffer. */ |
| uint32_t timedRendering; |
| /* Video transcode stat populated by video decoder */ |
| struct VideoTranscodeStatsMetadata video_transcode_stats; |
| int32_t videoEarlyNotifyLineCount; |
| char heapName[MAX_NAME_LEN]; |
| }; |
| |
| namespace qtigralloc { |
| #define QTI_HANDLE_CONST(exp) static_cast<const private_handle_t *>(exp) |
| |
| #pragma pack(push, 4) |
| struct private_handle_t : public native_handle_t { |
| // file-descriptors dup'd over IPC |
| int fd; |
| int fd_metadata; |
| |
| // values sent over IPC |
| int magic; |
| int flags; |
| int width; // holds width of the actual buffer allocated |
| int height; // holds height of the actual buffer allocated |
| int unaligned_width; // holds width client asked to allocate |
| int unaligned_height; // holds height client asked to allocate |
| int format; |
| int buffer_type; |
| unsigned int layer_count; |
| uint64_t id; |
| uint64_t usage; |
| |
| unsigned int size; |
| unsigned int offset; |
| unsigned int offset_metadata; |
| uint64_t base; |
| uint64_t base_metadata; |
| uint64_t gpuaddr; |
| unsigned int reserved_size; |
| unsigned int custom_content_md_reserved_size; |
| static const int kNumFds = 2; |
| static const int kMagic = 'gmsm'; |
| unsigned int linear_size; |
| int ubwcp_format; |
| |
| static inline int NumInts() { |
| return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int)) - kNumFds; |
| } |
| |
| private_handle_t(int fd, int meta_fd, int flags, int width, int height, int uw, int uh, |
| int format, int buf_type, unsigned int size, uint64_t usage = 0) |
| : fd(fd), |
| fd_metadata(meta_fd), |
| magic(kMagic), |
| flags(flags), |
| width(width), |
| height(height), |
| unaligned_width(uw), |
| unaligned_height(uh), |
| format(format), |
| buffer_type(buf_type), |
| layer_count(1), |
| id(0), |
| usage(usage), |
| size(size), |
| offset(0), |
| offset_metadata(0), |
| base(0), |
| base_metadata(0), |
| gpuaddr(0), |
| reserved_size(0), |
| linear_size(0), |
| ubwcp_format(format), |
| custom_content_md_reserved_size(0) { |
| version = static_cast<int>(sizeof(native_handle)); |
| numInts = NumInts(); |
| numFds = kNumFds; |
| } |
| |
| ~private_handle_t() { magic = 0; } |
| |
| static int validate(const native_handle *h) { |
| auto *hnd = static_cast<const private_handle_t *>(h); |
| if (!h || h->version != sizeof(native_handle) || h->numInts != NumInts() || |
| h->numFds != kNumFds) { |
| ALOGE("Invalid gralloc handle (at %p): ver(%d/%zu) ints(%d/%d) fds(%d/%d)", h, |
| h ? h->version : -1, sizeof(native_handle), h ? h->numInts : -1, NumInts(), |
| h ? h->numFds : -1, kNumFds); |
| return -1; |
| } |
| if (hnd->magic != kMagic) { |
| ALOGE("handle = %p invalid magic(%c%c%c%c/%c%c%c%c)", hnd, |
| hnd ? (((hnd->magic >> 24) & 0xFF) ? ((hnd->magic >> 24) & 0xFF) : '-') : '?', |
| hnd ? (((hnd->magic >> 16) & 0xFF) ? ((hnd->magic >> 16) & 0xFF) : '-') : '?', |
| hnd ? (((hnd->magic >> 8) & 0xFF) ? ((hnd->magic >> 8) & 0xFF) : '-') : '?', |
| hnd ? (((hnd->magic >> 0) & 0xFF) ? ((hnd->magic >> 0) & 0xFF) : '-') : '?', |
| (kMagic >> 24) & 0xFF, (kMagic >> 16) & 0xFF, (kMagic >> 8) & 0xFF, |
| (kMagic >> 0) & 0xFF); |
| return -1; |
| } |
| |
| return 0; |
| } |
| |
| static void Dump(const private_handle_t *hnd) { |
| ALOGD("handle id:%" PRIu64 |
| " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x " |
| "usage:0x%" PRIx64 " format:0x%x layer_count: %d reserved_size = %d " |
| "custom_content_md_reserved_size = %u", |
| hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size, |
| hnd->fd, hnd->fd_metadata, hnd->flags, hnd->usage, hnd->format, hnd->layer_count, |
| hnd->reserved_size, hnd->custom_content_md_reserved_size); |
| } |
| }; |
| #pragma pack(pop) |
| |
| } // namespace qtigralloc |
| |
| #endif //__QTIGRALLOCPRIV_H__ |