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 
30 #ifndef __GR_CAMERA_INFO_H__
31 #define __GR_CAMERA_INFO_H__
32 
33 #include "gr_utils.h"
34 
35 // Plane types supported by the camera format
36 typedef enum {
37   CAMERA_PLANE_TYPE_RAW,  // RAW plane for Single planar formats including UYVY and thier variants
38   CAMERA_PLANE_TYPE_Y,    // Y only
39   CAMERA_PLANE_TYPE_UV,   // UV, VU, Cb, Cr planes for YUV variants
40   CAMERA_PLANE_TYPE_U,    // U plane only
41   CAMERA_PLANE_TYPE_V,    // V plane only
42   CAMERA_PLANE_TYPE_META_Y,   // Metadata plane for Y
43   CAMERA_PLANE_TYPE_META_VU,  // Metadata plane for VU and UV
44 } CamxPlaneType;
45 
46 // External camera pixel formats that are allocated by gralloc
47 typedef enum : unsigned int {
48   CAMERA_PIXEL_FORMAT_NV21_ZSL = 0x113,  // NV21 format with alignment requirements for
49                                          // YUV reprocessing
50   CAMERA_PIXEL_FORMAT_YUV_FLEX = 0x125,  // YUV format with fliexible alignment defined by
51                                          // individual APIs
52   CAMERA_PIXEL_FORMAT_UBWC_FLEX = 0x126,  // YUV format with fliexible alignment defined by
53                                           // individual APIs
54   CAMERA_PIXEL_FORMAT_MULTIPLANAR_FLEX = 0x127,   // YUV format with fliexible alignment defined by
55                                                   // individual APIs
56   CAMERA_PIXEL_FORMAT_UBWC_FLEX_2_BATCH = 0x128,  // YUV format with fliexible alignment defined by
57                                                   // individual APIs
58   CAMERA_PIXEL_FORMAT_UBWC_FLEX_4_BATCH = 0x129,  // YUV format with fliexible alignment defined by
59                                                   // individual APIs
60   CAMERA_PIXEL_FORMAT_UBWC_FLEX_8_BATCH = 0x130,  // YUV format with fliexible alignment defined by
61                                                   // individual APIs
62   CAMERA_PIXEL_FORMAT_NV12_VENUS = 0x7FA30C04,           // NV12 video format
63   CAMERA_PIXEL_FORMAT_NV12_HEIF = 0x00000116,            // HEIF video YUV420 format
64   CAMERA_PIXEL_FORMAT_YCbCr_420_SP_UBWC = 0x7FA30C06,    // 8 bit YUV 420 semi-planar UBWC format
65   CAMERA_PIXEL_FORMAT_YCbCr_420_TP10_UBWC = 0x7FA30C09,  // TP10 YUV 420 semi-planar UBWC format
66   CAMERA_PIXEL_FORMAT_YCbCr_420_P010_UBWC = 0x124,       // P010 YUV 420 semi-planar UBWC format
67   CAMERA_PIXEL_FORMAT_RAW_OPAQUE = 0x24,                 // Opaque RAW format
68   CAMERA_PIXEL_FORMAT_RAW10 = 0x25,                      // Opaque RAW10 bit format
69   CAMERA_PIXEL_FORMAT_RAW12 = 0x26,                      // Opaque RAW12 bit format
70 } CamxPixelFormat;
71 
72 // Camera Result Codes
73 typedef enum : int {
74   CamxFormatResultSuccess = 0,           // Operation was successful
75   CamxFormatResultEFailed = 1,           // Operation encountered unspecified error
76   CamxFormatResultEUnsupported = 2,      // Operation is not supported
77   CamxFormatResultEInvalidState = 3,     // Invalid state
78   CamxFormatResultEInvalidArg = 4,       // Invalid argument
79   CamxFormatResultEInvalidPointer = 5,   // Invalid memory pointer
80   CamxFormatResultENoSuch = 6,           // No such item exists or is valid
81   CamxFormatResultEOutOfBounds = 7,      // Out of bounds
82   CamxFormatResultENoMemory = 8,         // Out of memory
83   CamxFormatResultENoMore = 10,          // No more items available
84   CamxFormatResultENeedMore = 11,        // Operation requires more
85   CamxFormatResultEPrivLevel = 13,       // Privileges are insufficient for requested operation
86   CamxFormatResultENotImplemented = 26,  // Function or method is not implemented
87 } CamxFormatResult;
88 
89 namespace gralloc {
90 
91 class CameraInfo {
92  public:
93   int GetUBWCInfo(int format, bool *is_Supported, bool *is_PI, int *version);
94 
95   int GetPlaneAlignment(int format, int plane_type, unsigned int *alignment);
96 
97   int IsPerPlaneFdNeeded(int format, bool *is_per_plane_fd_needed);
98 
99   int GetBpp(int format, int *bpp);
100 
101   int GetPerPlaneBpp(int format, int plane_type, int *bpp);
102 
103   int GetPlaneStartAddressAlignment(int format, int plane_type, int *alignment);
104 
105   int GetBufferSize(int format, int width, int height, unsigned int *size);
106 
107   int GetStrideInBytes(int format, int plane_type, int width, int *stride_bytes);
108 
109   int GetStrideInPixels(int format, int plane_type, int width, float *stride_pixel);
110 
111   int GetPixelIncrement(int format, int plane_type, int *pixel_increment);
112 
113   int GetPlaneOffset(int format, int plane_type, int width, int height, int *offset);
114 
115   int GetSubsamplingFactor(int format, int plane_type, bool isHorizontal, int *subsampling_factor);
116 
117   int GetPlaneTypes(int format, PlaneComponent *plane_component_array, int *plane_count);
118 
119   int GetScanline(int format, int plane_type, int height, int *scanlines);
120 
121   int GetPlaneSize(int format, int plane_type, int width, int height, unsigned int *size);
122 
123   int GetCameraFormatPlaneInfo(int format, int width, int height, int *plane_count,
124                                PlaneLayoutInfo *plane_info);
125 
126   CamxPixelFormat GetCameraPixelFormat(int hal_format);
127 
128   static CameraInfo *GetInstance();
129 
130  private:
131   CameraInfo();
132   ~CameraInfo();
133 
134   PlaneComponent GetPlaneComponent(CamxPlaneType plane_type);
135 
136   CamxPlaneType GetCamxPlaneType(int plane_type);
137 
138   CamxFormatResult (*LINK_camera_get_stride_in_bytes)(CamxPixelFormat format,
139                                                       CamxPlaneType plane_type, int width,
140                                                       int *stride) = nullptr;
141 
142   CamxFormatResult (*LINK_camera_get_stride_in_pixels)(CamxPixelFormat format,
143                                                        CamxPlaneType plane_type, int width,
144                                                        float *stride) = nullptr;
145 
146   CamxFormatResult (*LINK_camera_get_scanline)(CamxPixelFormat format, CamxPlaneType plane_type,
147                                                int height, int *scanLine) = nullptr;
148 
149   CamxFormatResult (*LINK_camera_get_plane_size)(CamxPixelFormat format, CamxPlaneType plane_type,
150                                                  int width, int height,
151                                                  unsigned int *aligned_size) = nullptr;
152 
153   CamxFormatResult (*LINK_camera_get_buffer_size)(CamxPixelFormat format, int width, int height,
154                                                   unsigned int *buffer_size) = nullptr;
155 
156   CamxFormatResult (*LINK_camera_get_ubwc_info)(CamxPixelFormat format, bool *isSupported,
157                                                 bool *isPI, int *version) = nullptr;
158 
159   CamxFormatResult (*LINK_camera_get_plane_alignment)(CamxPixelFormat format,
160                                                       CamxPlaneType plane_type,
161                                                       unsigned int *alignment) = nullptr;
162 
163   CamxFormatResult (*LINK_camera_get_plane_offset)(CamxPixelFormat format, CamxPlaneType plane_type,
164                                                    int *offset, int width, int height) = nullptr;
165 
166   CamxFormatResult (*LINK_camera_get_plane_types)(CamxPixelFormat format,
167                                                   CamxPlaneType *plane_types_array,
168                                                   int *plane_count) = nullptr;
169 
170   CamxFormatResult (*LINK_camera_is_per_plane_fd_needed)(CamxPixelFormat format,
171                                                          bool *is_perplane_fd_needed) = nullptr;
172 
173   CamxFormatResult (*LINK_camera_get_bpp)(CamxPixelFormat format, int *bpp) = nullptr;
174 
175   CamxFormatResult (*LINK_camera_get_per_plane_bpp)(CamxPixelFormat format,
176                                                     CamxPlaneType plane_type, int *bpp) = nullptr;
177 
178   CamxFormatResult (*LINK_camera_get_subsampling_factor)(CamxPixelFormat format,
179                                                          CamxPlaneType plane_type,
180                                                          bool is_horizontal,
181                                                          int *subsampling_factor) = nullptr;
182 
183   CamxFormatResult (*LINK_camera_get_plane_count)(CamxPixelFormat format,
184                                                   int *plane_count) = nullptr;
185 
186   CamxFormatResult (*LINK_camera_get_pixel_increment)(CamxPixelFormat format,
187                                                       CamxPlaneType plane_type,
188                                                       int *pixel_increment) = nullptr;
189 
190   CamxFormatResult (*LINK_camera_get_plane_start_address_alignment)(CamxPixelFormat format,
191                                                                     CamxPlaneType planeType,
192                                                                     int *pAlignment) = nullptr;
193 
194   void *libcamera_utils_ = nullptr;
195   static CameraInfo *s_instance;
196 };
197 
198 }  // namespace gralloc
199 
200 #endif  // __GR_CAMERA_INFO_H__
201