1 /* 2 * Copyright (c) 2014, 2016-2019, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are permitted 5 * provided that the following conditions are met: 6 * * Redistributions of source code must retain the above copyright notice, this list of 7 * conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright notice, this list of 9 * conditions and the following disclaimer in the documentation and/or other materials provided 10 * with the distribution. 11 * * Neither the name of The Linux Foundation nor the names of its contributors may be used to 12 * endorse or promote products derived from this software without specific prior written 13 * permission. 14 * 15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25 /*! @file layer_buffer.h 26 @brief File for layer buffer structure. 27 28 */ 29 #ifndef __LAYER_BUFFER_H__ 30 #define __LAYER_BUFFER_H__ 31 32 #include <stdint.h> 33 #include <color_metadata.h> 34 #include <utility> 35 #include <vector> 36 37 #include "sdm_types.h" 38 39 namespace sdm { 40 41 #define NUM_UBWC_CR_STATS_LAYERS 2 42 typedef std::vector<std::pair<int, int>> UbwcCrStatsVector; 43 44 /*! @brief This enum represents display layer inverse gamma correction (IGC) types. 45 46 @sa Layer 47 */ 48 enum LayerIGC { 49 kIGCNotSpecified, //!< IGC is not specified. 50 kIGCsRGB, //!< sRGB IGC type. 51 }; 52 53 /*! @brief This enum represents different buffer formats supported by display manager. 54 55 @sa LayerBuffer 56 */ 57 enum LayerBufferFormat { 58 /* All RGB formats, Any new format will be added towards end of this group to maintain backward 59 compatibility. 60 */ 61 kFormatARGB8888, //!< 8-bits Alpha, Red, Green, Blue interleaved in ARGB order. 62 kFormatRGBA8888, //!< 8-bits Red, Green, Blue, Alpha interleaved in RGBA order. 63 kFormatBGRA8888, //!< 8-bits Blue, Green, Red, Alpha interleaved in BGRA order. 64 kFormatXRGB8888, //!< 8-bits Padding, Red, Green, Blue interleaved in XRGB order. No Alpha. 65 kFormatRGBX8888, //!< 8-bits Red, Green, Blue, Padding interleaved in RGBX order. No Alpha. 66 kFormatBGRX8888, //!< 8-bits Blue, Green, Red, Padding interleaved in BGRX order. No Alpha. 67 kFormatRGBA5551, //!< 5-bits Red, Green, Blue, and 1 bit Alpha interleaved in RGBA order. 68 kFormatRGBA4444, //!< 4-bits Red, Green, Blue, Alpha interleaved in RGBA order. 69 kFormatRGB888, //!< 8-bits Red, Green, Blue interleaved in RGB order. No Alpha. 70 kFormatBGR888, //!< 8-bits Blue, Green, Red interleaved in BGR order. No Alpha. 71 kFormatRGB565, //!< 5-bit Red, 6-bit Green, 5-bit Blue interleaved in RGB order. No Alpha. 72 kFormatBGR565, //!< 5-bit Blue, 6-bit Green, 5-bit Red interleaved in BGR order. No Alpha. 73 kFormatRGBA8888Ubwc, //!< UBWC aligned RGBA8888 format 74 kFormatRGBX8888Ubwc, //!< UBWC aligned RGBX8888 format 75 kFormatBGR565Ubwc, //!< UBWC aligned BGR565 format 76 kFormatRGBA1010102, //!< 10-bits Red, Green, Blue, Alpha interleaved in RGBA order. 77 kFormatARGB2101010, //!< 10-bits Alpha, Red, Green, Blue interleaved in ARGB order. 78 kFormatRGBX1010102, //!< 10-bits Red, Green, Blue, Padding interleaved in RGBX order. No Alpha. 79 kFormatXRGB2101010, //!< 10-bits Padding, Red, Green, Blue interleaved in XRGB order. No Alpha. 80 kFormatBGRA1010102, //!< 10-bits Blue, Green, Red, Alpha interleaved in BGRA order. 81 kFormatABGR2101010, //!< 10-bits Alpha, Blue, Green, Red interleaved in ABGR order. 82 kFormatBGRX1010102, //!< 10-bits Blue, Green, Red, Padding interleaved in BGRX order. No Alpha. 83 kFormatXBGR2101010, //!< 10-bits Padding, Blue, Green, Red interleaved in XBGR order. No Alpha. 84 kFormatRGBA1010102Ubwc, //!< UBWC aligned RGBA1010102 format 85 kFormatRGBX1010102Ubwc, //!< UBWC aligned RGBX1010102 format 86 kFormatRGB101010, // 10-bits Red, Green, Blue, interleaved in RGB order. No Alpha. 87 88 /* All YUV-Planar formats, Any new format will be added towards end of this group to maintain 89 backward compatibility. 90 */ 91 kFormatYCbCr420Planar = 0x100, //!< Y-plane: y(0), y(1), y(2) ... y(n) 92 //!< 2x2 subsampled U-plane: u(0), u(2) ... u(n-1) 93 //!< 2x2 subsampled V-plane: v(0), v(2) ... v(n-1) 94 95 kFormatYCrCb420Planar, //!< Y-plane: y(0), y(1), y(2) ... y(n) 96 //!< 2x2 subsampled V-plane: v(0), v(2) ... v(n-1) 97 //!< 2x2 subsampled U-plane: u(0), u(2) ... u(n-1) 98 99 kFormatYCrCb420PlanarStride16, //!< kFormatYCrCb420Planar with stride aligned to 16 bytes 100 101 /* All YUV-Semiplanar formats, Any new format will be added towards end of this group to 102 maintain backward compatibility. 103 */ 104 kFormatYCbCr420SemiPlanar = 0x200, //!< Y-plane: y(0), y(1), y(2) ... y(n) 105 //!< 2x2 subsampled interleaved UV-plane: 106 //!< u(0), v(0), u(2), v(2) ... u(n-1), v(n-1) 107 //!< aka NV12. 108 109 kFormatYCrCb420SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) 110 //!< 2x2 subsampled interleaved VU-plane: 111 //!< v(0), u(0), v(2), u(2) ... v(n-1), u(n-1) 112 //!< aka NV21. 113 114 kFormatYCbCr420SemiPlanarVenus, //!< Y-plane: y(0), y(1), y(2) ... y(n) 115 //!< 2x2 subsampled interleaved UV-plane: 116 //!< u(0), v(0), u(2), v(2) ... u(n-1), v(n-1) 117 118 kFormatYCbCr422H1V2SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) 119 //!< vertically subsampled interleaved UV-plane: 120 //!< u(0), v(1), u(2), v(3) ... u(n-1), v(n) 121 122 kFormatYCrCb422H1V2SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) 123 //!< vertically subsampled interleaved VU-plane: 124 //!< v(0), u(1), v(2), u(3) ... v(n-1), u(n) 125 126 kFormatYCbCr422H2V1SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) 127 //!< horizontally subsampled interleaved UV-plane: 128 //!< u(0), v(1), u(2), v(3) ... u(n-1), v(n) 129 130 kFormatYCrCb422H2V1SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) 131 //!< horizontally subsampled interleaved VU-plane: 132 //!< v(0), u(1), v(2), u(3) ... v(n-1), u(n) 133 134 kFormatYCbCr420SPVenusUbwc, //!< UBWC aligned YCbCr420SemiPlanarVenus format 135 136 kFormatYCrCb420SemiPlanarVenus, //!< Y-plane: y(0), y(1), y(2) ... y(n) 137 //!< 2x2 subsampled interleaved UV-plane: 138 //!< v(0), u(0), v(2), u(2) ... v(n-1), u(n-1) 139 140 kFormatYCbCr420P010, //!< 16 bit Y-plane with 5 MSB bits set to 0: 141 //!< y(0), y(1), y(2) ... y(n) 142 //!< 2x2 subsampled interleaved 10 bit UV-plane with 143 //!< 5 MSB bits set to 0: 144 //!< u(0), v(0), u(2), v(2) ... u(n-1), v(n-1) 145 //!< aka P010. 146 147 kFormatYCbCr420TP10Ubwc, //!< UBWC aligned YCbCr420TP10 format. 148 149 kFormatYCbCr420P010Ubwc, //!< UBWC aligned YCbCr420P010 format. 150 151 kFormatYCbCr420P010Venus, //!< Venus aligned YCbCr420P010 format. 152 //! 153 kFormatYCbCr420SPVenusTile, //!< Tiled & uncompressed YCbCr420SemiPlanarVenus format 154 kFormatYCbCr420TP10Tile, //!< Tiled & uncompressed YCbCr420TP10 format. 155 kFormatYCbCr420P010Tile, //!< Tiled & uncompressed YCbCr420P010 format. 156 157 /* All YUV-Packed formats, Any new format will be added towards end of this group to maintain 158 backward compatibility. 159 */ 160 kFormatYCbCr422H2V1Packed = 0x300, //!< Y-plane interleaved with horizontally subsampled U/V by 161 //!< factor of 2 162 //!< y(0), u(0), y(1), v(0), y(2), u(2), y(3), v(2) 163 //!< y(n-1), u(n-1), y(n), v(n-1) 164 165 kFormatCbYCrY422H2V1Packed, 166 kFormatInvalid = 0xFFFFFFFF, 167 }; 168 169 170 /*! @brief This enum represents different types of 3D formats supported. 171 172 @sa LayerBufferS3DFormat 173 */ 174 enum LayerBufferS3DFormat { 175 kS3dFormatNone, //!< Layer buffer content is not 3D content. 176 kS3dFormatLeftRight, //!< Left and Right view of a 3D content stitched left and right. 177 kS3dFormatRightLeft, //!< Right and Left view of a 3D content stitched left and right. 178 kS3dFormatTopBottom, //!< Left and RightView of a 3D content stitched top and bottom. 179 kS3dFormatFramePacking //!< Left and right view of 3D content coded in consecutive frames. 180 }; 181 182 /*! @brief This structure defines a color sample plane belonging to a buffer format. RGB buffer 183 formats have 1 plane whereas YUV buffer formats may have upto 4 planes. 184 185 @sa LayerBuffer 186 */ 187 struct LayerBufferPlane { 188 int fd = -1; //!< File descriptor referring to the buffer associated with this plane. 189 uint32_t offset = 0; //!< Offset of the plane in bytes from beginning of the buffer. 190 uint32_t stride = 0; //!< Stride in bytes i.e. length of a scanline including padding. 191 }; 192 193 /*! @brief This structure defines flags associated with a layer buffer. The 1-bit flag can be set 194 to ON(1) or OFF(0). 195 196 @sa LayerBuffer 197 */ 198 struct LayerBufferFlags { 199 union { 200 struct { 201 uint32_t secure : 1; //!< This flag shall be set by client to indicate that the 202 //!< buffer need to be handled securely. 203 204 uint32_t video : 1; //!< This flag shall be set by client to indicate that the 205 //!< buffer is video/ui buffer. 206 207 uint32_t macro_tile : 1; //!< This flag shall be set by client to indicate that the 208 //!< buffer format is macro tiled. 209 210 uint32_t interlace : 1; //!< This flag shall be set by the client to indicate that 211 //!< the buffer has interlaced content. 212 213 uint32_t secure_display : 1; //!< This flag shall be set by the client to indicate that the 214 //!< secure display session is in progress. Secure display 215 //!< session can not coexist with non-secure session. 216 217 uint32_t secure_camera : 1; //!< This flag shall be set by the client to indicate that the 218 //!< buffer is associated with secure camera session. A secure 219 //!< camera layer can co-exist with non-secure layer(s). 220 221 uint32_t hdr : 1; //!< This flag shall be set by the client to indicate that the 222 //!< the content is HDR. 223 224 uint32_t mask_layer : 1; //!< This flag shall be set by client to indicate that the layer 225 //!< is union of solid fill regions typically transparent pixels 226 //!< and black pixels. 227 }; 228 229 uint32_t flags = 0; //!< For initialization purpose only. 230 //!< Client shall not refer to it directly. 231 }; 232 }; 233 234 /*! @brief This structure defines a layer buffer handle which contains raw buffer and its associated 235 properties. 236 237 @sa LayerBuffer 238 @sa LayerStack 239 */ 240 struct LayerBuffer { 241 uint32_t width = 0; //!< Aligned width of the Layer that this buffer is for. 242 uint32_t height = 0; //!< Aligned height of the Layer that this buffer is for. 243 uint32_t unaligned_width = 0; 244 //!< Unaligned width of the Layer that this buffer is for. 245 uint32_t unaligned_height = 0; 246 //!< Unaligned height of the Layer that this buffer is for. 247 uint32_t size = 0; //!< Size of a single buffer (even if multiple clubbed together) 248 LayerBufferFormat format = kFormatRGBA8888; //!< Format of the buffer content. 249 ColorMetaData color_metadata = {}; //!< CSC + Range + Transfer + Matrix + HDR Info 250 LayerIGC igc = kIGCNotSpecified; //!< IGC that will be applied on this layer. 251 LayerBufferPlane planes[4] = {}; 252 //!< Array of planes that this buffer contains. RGB buffer formats 253 //!< have 1 plane whereas YUV buffer formats may have upto 4 planes 254 //!< Total number of planes for the buffer will be interpreted based 255 //!< on the buffer format specified. 256 257 int acquire_fence_fd = -1; //!< File descriptor referring to a sync fence object which will be 258 //!< signaled when buffer can be read/write by display manager. 259 //!< This fence object is set by the client during Commit(). For 260 //!< input buffers client shall signal this fence when buffer 261 //!< content is available and can be read by display manager. For 262 //!< output buffers, client shall signal fence when buffer is ready 263 //!< to be written by display manager. 264 265 //!< This field is used only during Commit() and shall be set to -1 266 //!< by the client when buffer is already available for read/write. 267 268 int release_fence_fd = -1; //!< File descriptor referring to a sync fence object which will be 269 //!< signaled when buffer has been read/written by display manager. 270 //!< This fence object is set by display manager during Commit(). 271 //!< For input buffers display manager will signal this fence when 272 //!< buffer has been consumed. For output buffers, display manager 273 //!< will signal this fence when buffer is produced. 274 275 //!< This field is used only during Commit() and will be set to -1 276 //!< by display manager when buffer is already available for 277 //!< read/write. 278 279 LayerBufferFlags flags; //!< Flags associated with this buffer. 280 281 LayerBufferS3DFormat s3d_format = kS3dFormatNone; 282 //!< Represents the format of the buffer content in 3D. This field 283 //!< could be modified by both client and SDM. 284 uint64_t buffer_id __attribute__((aligned(8))) = 0; 285 //!< Specifies the buffer id. 286 UbwcCrStatsVector ubwc_crstats[NUM_UBWC_CR_STATS_LAYERS] = {}; 287 //! < UBWC Compression ratio,stats. Stored as a vector of pair of 288 //! of (tile size, #of tiles) LayerBufferLayerBuffer289 LayerBuffer() { 290 color_metadata.colorPrimaries = ColorPrimaries_BT709_5; 291 color_metadata.transfer = Transfer_sRGB; 292 } 293 294 uint64_t handle_id = 0; 295 }; 296 297 // This enum represents buffer layout types. 298 enum BufferLayout { 299 kLinear, //!< Linear data 300 kUBWC, //!< UBWC aligned data 301 kTPTiled //!< Tightly Packed data 302 }; 303 304 class LayerBufferObject { 305 public: ~LayerBufferObject()306 virtual ~LayerBufferObject() {} 307 }; 308 309 } // namespace sdm 310 311 #endif // __LAYER_BUFFER_H__ 312 313