1 /* 2 * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved. 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 * Changes from Qualcomm Innovation Center are provided under the following license: 30 * 31 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted (subject to the limitations in the 35 * disclaimer below) provided that the following conditions are met: 36 * 37 * * Redistributions of source code must retain the above copyright 38 * notice, this list of conditions and the following disclaimer. 39 * 40 * * Redistributions in binary form must reproduce the above 41 * copyright notice, this list of conditions and the following 42 * disclaimer in the documentation and/or other materials provided 43 * with the distribution. 44 * 45 * * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its 46 * contributors may be used to endorse or promote products derived 47 * from this software without specific prior written permission. 48 * 49 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE 50 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 51 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 52 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 53 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 54 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 55 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 57 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 58 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 59 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 61 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 */ 63 64 #ifndef __GR_CAMERA_INFO_H__ 65 #define __GR_CAMERA_INFO_H__ 66 67 #include "gr_utils.h" 68 69 // Plane types supported by the camera format 70 typedef enum { 71 CAMERA_PLANE_TYPE_RAW, // RAW plane for Single planar formats including UYVY and thier variants 72 CAMERA_PLANE_TYPE_Y, // Y only 73 CAMERA_PLANE_TYPE_UV, // UV, VU, Cb, Cr planes for YUV variants 74 CAMERA_PLANE_TYPE_U, // U plane only 75 CAMERA_PLANE_TYPE_V, // V plane only 76 CAMERA_PLANE_TYPE_META_Y, // Metadata plane for Y 77 CAMERA_PLANE_TYPE_META_VU, // Metadata plane for VU and UV 78 } CamxPlaneType; 79 80 // External camera pixel formats that are allocated by gralloc 81 typedef enum : unsigned int { 82 CAMERA_PIXEL_FORMAT_NV21_ZSL = 0x113, // NV21 format with alignment requirements for 83 // YUV reprocessing 84 CAMERA_PIXEL_FORMAT_YUV_FLEX = 0x125, // YUV format with fliexible alignment defined by 85 // individual APIs 86 CAMERA_PIXEL_FORMAT_UBWC_FLEX = 0x126, // YUV format with fliexible alignment defined by 87 // individual APIs 88 CAMERA_PIXEL_FORMAT_MULTIPLANAR_FLEX = 0x127, // YUV format with fliexible alignment defined by 89 // individual APIs 90 CAMERA_PIXEL_FORMAT_UBWC_FLEX_2_BATCH = 0x128, // YUV format with fliexible alignment defined by 91 // individual APIs 92 CAMERA_PIXEL_FORMAT_UBWC_FLEX_4_BATCH = 0x129, // YUV format with fliexible alignment defined by 93 // individual APIs 94 CAMERA_PIXEL_FORMAT_UBWC_FLEX_8_BATCH = 0x130, // YUV format with fliexible alignment defined by 95 // individual APIs 96 CAMERA_PIXEL_FORMAT_NV12_VENUS = 0x7FA30C04, // NV12 video format 97 CAMERA_PIXEL_FORMAT_NV12_HEIF = 0x00000116, // HEIF video YUV420 format 98 CAMERA_PIXEL_FORMAT_YCbCr_420_SP_UBWC = 0x7FA30C06, // 8 bit YUV 420 semi-planar UBWC format 99 CAMERA_PIXEL_FORMAT_YCbCr_420_TP10_UBWC = 0x7FA30C09, // TP10 YUV 420 semi-planar UBWC format 100 CAMERA_PIXEL_FORMAT_YCbCr_420_P010_UBWC = 0x124, // P010 YUV 420 semi-planar UBWC format 101 CAMERA_PIXEL_FORMAT_RAW_OPAQUE = 0x24, // Opaque RAW format 102 CAMERA_PIXEL_FORMAT_RAW10 = 0x25, // Opaque RAW10 bit format 103 CAMERA_PIXEL_FORMAT_RAW12 = 0x26, // Opaque RAW12 bit format 104 } CamxPixelFormat; 105 106 // Camera Result Codes 107 typedef enum : int { 108 CamxFormatResultSuccess = 0, // Operation was successful 109 CamxFormatResultEFailed = 1, // Operation encountered unspecified error 110 CamxFormatResultEUnsupported = 2, // Operation is not supported 111 CamxFormatResultEInvalidState = 3, // Invalid state 112 CamxFormatResultEInvalidArg = 4, // Invalid argument 113 CamxFormatResultEInvalidPointer = 5, // Invalid memory pointer 114 CamxFormatResultENoSuch = 6, // No such item exists or is valid 115 CamxFormatResultEOutOfBounds = 7, // Out of bounds 116 CamxFormatResultENoMemory = 8, // Out of memory 117 CamxFormatResultENoMore = 10, // No more items available 118 CamxFormatResultENeedMore = 11, // Operation requires more 119 CamxFormatResultEPrivLevel = 13, // Privileges are insufficient for requested operation 120 CamxFormatResultENotImplemented = 26, // Function or method is not implemented 121 } CamxFormatResult; 122 123 namespace gralloc { 124 125 class CameraInfo { 126 public: IsCameraUtilsPresent()127 bool IsCameraUtilsPresent() { return libcamera_utils_ != nullptr; } 128 129 int GetUBWCInfo(int format, bool *is_Supported, bool *is_PI, int *version); 130 131 int GetPlaneAlignment(int format, int plane_type, unsigned int *alignment); 132 133 int IsPerPlaneFdNeeded(int format, bool *is_per_plane_fd_needed); 134 135 int GetBpp(int format, int *bpp); 136 137 int GetPerPlaneBpp(int format, int plane_type, int *bpp); 138 139 int GetPlaneStartAddressAlignment(int format, int plane_type, int *alignment); 140 141 int GetBufferSize(int format, int width, int height, unsigned int *size); 142 143 int GetStrideInBytes(int format, int plane_type, int width, int *stride_bytes); 144 145 int GetStrideInPixels(int format, int plane_type, int width, float *stride_pixel); 146 147 int GetPixelIncrement(int format, int plane_type, int *pixel_increment); 148 149 int GetPlaneOffset(int format, int plane_type, int width, int height, int *offset); 150 151 int GetSubsamplingFactor(int format, int plane_type, bool isHorizontal, int *subsampling_factor); 152 153 int GetPlaneTypes(int format, PlaneComponent *plane_component_array, int *plane_count); 154 155 int GetScanline(int format, int plane_type, int height, int *scanlines); 156 157 int GetPlaneSize(int format, int plane_type, int width, int height, unsigned int *size); 158 159 int GetCameraFormatPlaneInfo(int format, int width, int height, int *plane_count, 160 PlaneLayoutInfo *plane_info); 161 162 CamxPixelFormat GetCameraPixelFormat(int hal_format); 163 164 static CameraInfo *GetInstance(); 165 166 private: 167 CameraInfo(); 168 ~CameraInfo(); 169 170 PlaneComponent GetPlaneComponent(CamxPlaneType plane_type); 171 172 CamxPlaneType GetCamxPlaneType(int plane_type); 173 174 CamxFormatResult (*LINK_camera_get_stride_in_bytes)(CamxPixelFormat format, 175 CamxPlaneType plane_type, int width, 176 int *stride) = nullptr; 177 178 CamxFormatResult (*LINK_camera_get_stride_in_pixels)(CamxPixelFormat format, 179 CamxPlaneType plane_type, int width, 180 float *stride) = nullptr; 181 182 CamxFormatResult (*LINK_camera_get_scanline)(CamxPixelFormat format, CamxPlaneType plane_type, 183 int height, int *scanLine) = nullptr; 184 185 CamxFormatResult (*LINK_camera_get_plane_size)(CamxPixelFormat format, CamxPlaneType plane_type, 186 int width, int height, 187 unsigned int *aligned_size) = nullptr; 188 189 CamxFormatResult (*LINK_camera_get_buffer_size)(CamxPixelFormat format, int width, int height, 190 unsigned int *buffer_size) = nullptr; 191 192 CamxFormatResult (*LINK_camera_get_ubwc_info)(CamxPixelFormat format, bool *isSupported, 193 bool *isPI, int *version) = nullptr; 194 195 CamxFormatResult (*LINK_camera_get_plane_alignment)(CamxPixelFormat format, 196 CamxPlaneType plane_type, 197 unsigned int *alignment) = nullptr; 198 199 CamxFormatResult (*LINK_camera_get_plane_offset)(CamxPixelFormat format, CamxPlaneType plane_type, 200 int *offset, int width, int height) = nullptr; 201 202 CamxFormatResult (*LINK_camera_get_plane_types)(CamxPixelFormat format, 203 CamxPlaneType *plane_types_array, 204 int *plane_count) = nullptr; 205 206 CamxFormatResult (*LINK_camera_is_per_plane_fd_needed)(CamxPixelFormat format, 207 bool *is_perplane_fd_needed) = nullptr; 208 209 CamxFormatResult (*LINK_camera_get_bpp)(CamxPixelFormat format, int *bpp) = nullptr; 210 211 CamxFormatResult (*LINK_camera_get_per_plane_bpp)(CamxPixelFormat format, 212 CamxPlaneType plane_type, int *bpp) = nullptr; 213 214 CamxFormatResult (*LINK_camera_get_subsampling_factor)(CamxPixelFormat format, 215 CamxPlaneType plane_type, 216 bool is_horizontal, 217 int *subsampling_factor) = nullptr; 218 219 CamxFormatResult (*LINK_camera_get_plane_count)(CamxPixelFormat format, 220 int *plane_count) = nullptr; 221 222 CamxFormatResult (*LINK_camera_get_pixel_increment)(CamxPixelFormat format, 223 CamxPlaneType plane_type, 224 int *pixel_increment) = nullptr; 225 226 CamxFormatResult (*LINK_camera_get_plane_start_address_alignment)(CamxPixelFormat format, 227 CamxPlaneType planeType, 228 int *pAlignment) = nullptr; 229 230 void *libcamera_utils_ = nullptr; 231 static CameraInfo *s_instance; 232 }; 233 234 } // namespace gralloc 235 236 #endif // __GR_CAMERA_INFO_H__ 237