Home | History | Annotate | Download | only in core
      1 /*
      2 * Copyright (c) 2014, 2016, 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 
     34 #include "sdm_types.h"
     35 
     36 namespace sdm {
     37 
     38 /*! @brief This enum represents display layer color space conversion (CSC) matrix types.
     39 
     40   @sa Layer
     41 */
     42 enum LayerCSC {
     43   kCSCLimitedRange601,    //!< 601 limited range color space.
     44   kCSCFullRange601,       //!< 601 full range color space.
     45   kCSCLimitedRange709,    //!< 709 limited range color space.
     46 };
     47 
     48 /*! @brief This enum represents display layer inverse gamma correction (IGC) types.
     49 
     50   @sa Layer
     51 */
     52 enum LayerIGC {
     53   kIGCNotSpecified,       //!< IGC is not specified.
     54   kIGCsRGB,               //!< sRGB IGC type.
     55 };
     56 
     57 /*! @brief This enum represents different buffer formats supported by display manager.
     58 
     59   @sa LayerBuffer
     60 */
     61 enum LayerBufferFormat {
     62   /* All RGB formats, Any new format will be added towards end of this group to maintain backward
     63      compatibility.
     64   */
     65   kFormatARGB8888,      //!< 8-bits Alpha, Red, Green, Blue interleaved in ARGB order.
     66   kFormatRGBA8888,      //!< 8-bits Red, Green, Blue, Alpha interleaved in RGBA order.
     67   kFormatBGRA8888,      //!< 8-bits Blue, Green, Red, Alpha interleaved in BGRA order.
     68   kFormatXRGB8888,      //!< 8-bits Padding, Red, Green, Blue interleaved in XRGB order. No Alpha.
     69   kFormatRGBX8888,      //!< 8-bits Red, Green, Blue, Padding interleaved in RGBX order. No Alpha.
     70   kFormatBGRX8888,      //!< 8-bits Blue, Green, Red, Padding interleaved in BGRX order. No Alpha.
     71   kFormatRGBA5551,      //!< 5-bits Red, Green, Blue, and 1 bit Alpha interleaved in RGBA order.
     72   kFormatRGBA4444,      //!< 4-bits Red, Green, Blue, Alpha interleaved in RGBA order.
     73   kFormatRGB888,        //!< 8-bits Red, Green, Blue interleaved in RGB order. No Alpha.
     74   kFormatBGR888,        //!< 8-bits Blue, Green, Red interleaved in BGR order. No Alpha.
     75   kFormatRGB565,        //!< 5-bit Red, 6-bit Green, 5-bit Blue interleaved in RGB order. No Alpha.
     76   kFormatBGR565,        //!< 5-bit Blue, 6-bit Green, 5-bit Red interleaved in BGR order. No Alpha.
     77   kFormatRGBA8888Ubwc,  //!< UBWC aligned RGBA8888 format
     78   kFormatRGBX8888Ubwc,  //!< UBWC aligned RGBX8888 format
     79   kFormatBGR565Ubwc,    //!< UBWC aligned BGR565 format
     80   kFormatRGBA1010102,   //!< 10-bits Red, Green, Blue, Alpha interleaved in RGBA order.
     81   kFormatARGB2101010,   //!< 10-bits Alpha, Red, Green, Blue interleaved in ARGB order.
     82   kFormatRGBX1010102,   //!< 10-bits Red, Green, Blue, Padding interleaved in RGBX order. No Alpha.
     83   kFormatXRGB2101010,   //!< 10-bits Padding, Red, Green, Blue interleaved in XRGB order. No Alpha.
     84   kFormatBGRA1010102,   //!< 10-bits Blue, Green, Red, Alpha interleaved in BGRA order.
     85   kFormatABGR2101010,   //!< 10-bits Alpha, Blue, Green, Red interleaved in ABGR order.
     86   kFormatBGRX1010102,   //!< 10-bits Blue, Green, Red, Padding interleaved in BGRX order. No Alpha.
     87   kFormatXBGR2101010,   //!< 10-bits Padding, Blue, Green, Red interleaved in XBGR order. No Alpha.
     88   kFormatRGBA1010102Ubwc,  //!< UBWC aligned RGBA1010102 format
     89   kFormatRGBX1010102Ubwc,  //!< UBWC aligned RGBX1010102 format
     90   kFormatRGB101010,     // 10-bits Red, Green, Blue, interleaved in RGB order. No Alpha.
     91 
     92   /* All YUV-Planar formats, Any new format will be added towards end of this group to maintain
     93      backward compatibility.
     94   */
     95   kFormatYCbCr420Planar = 0x100,  //!< Y-plane: y(0), y(1), y(2) ... y(n)
     96                                   //!< 2x2 subsampled U-plane: u(0), u(2) ... u(n-1)
     97                                   //!< 2x2 subsampled V-plane: v(0), v(2) ... v(n-1)
     98 
     99   kFormatYCrCb420Planar,          //!< Y-plane: y(0), y(1), y(2) ... y(n)
    100                                   //!< 2x2 subsampled V-plane: v(0), v(2) ... v(n-1)
    101                                   //!< 2x2 subsampled U-plane: u(0), u(2) ... u(n-1)
    102 
    103   kFormatYCrCb420PlanarStride16,  //!< kFormatYCrCb420Planar with stride aligned to 16 bytes
    104 
    105   /* All YUV-Semiplanar formats, Any new format will be added towards end of this group to
    106      maintain backward compatibility.
    107   */
    108   kFormatYCbCr420SemiPlanar = 0x200,  //!< Y-plane: y(0), y(1), y(2) ... y(n)
    109                                       //!< 2x2 subsampled interleaved UV-plane:
    110                                       //!<    u(0), v(0), u(2), v(2) ... u(n-1), v(n-1)
    111                                       //!< aka NV12.
    112 
    113   kFormatYCrCb420SemiPlanar,          //!< Y-plane: y(0), y(1), y(2) ... y(n)
    114                                       //!< 2x2 subsampled interleaved VU-plane:
    115                                       //!<    v(0), u(0), v(2), u(2) ... v(n-1), u(n-1)
    116                                       //!< aka NV21.
    117 
    118   kFormatYCbCr420SemiPlanarVenus,     //!< Y-plane: y(0), y(1), y(2) ... y(n)
    119                                       //!< 2x2 subsampled interleaved UV-plane:
    120                                       //!<    u(0), v(0), u(2), v(2) ... u(n-1), v(n-1)
    121 
    122   kFormatYCbCr422H1V2SemiPlanar,      //!< Y-plane: y(0), y(1), y(2) ... y(n)
    123                                       //!< vertically subsampled interleaved UV-plane:
    124                                       //!<    u(0), v(1), u(2), v(3) ... u(n-1), v(n)
    125 
    126   kFormatYCrCb422H1V2SemiPlanar,      //!< Y-plane: y(0), y(1), y(2) ... y(n)
    127                                       //!< vertically subsampled interleaved VU-plane:
    128                                       //!<    v(0), u(1), v(2), u(3) ... v(n-1), u(n)
    129 
    130   kFormatYCbCr422H2V1SemiPlanar,      //!< Y-plane: y(0), y(1), y(2) ... y(n)
    131                                       //!< horizontally subsampled interleaved UV-plane:
    132                                       //!<    u(0), v(1), u(2), v(3) ... u(n-1), v(n)
    133 
    134   kFormatYCrCb422H2V1SemiPlanar,      //!< Y-plane: y(0), y(1), y(2) ... y(n)
    135                                       //!< horizontally subsampled interleaved VU-plane:
    136                                       //!<    v(0), u(1), v(2), u(3) ... v(n-1), u(n)
    137 
    138   kFormatYCbCr420SPVenusUbwc,         //!< UBWC aligned YCbCr420SemiPlanarVenus format
    139 
    140   kFormatYCrCb420SemiPlanarVenus,     //!< Y-plane: y(0), y(1), y(2) ... y(n)
    141                                       //!< 2x2 subsampled interleaved UV-plane:
    142                                       //!<    v(0), u(0), v(2), u(2) ... v(n-1), u(n-1)
    143 
    144   kFormatYCbCr420P010,                //!< 16 bit Y-plane with 5 MSB bits set to 0:
    145                                       //!< y(0), y(1), y(2) ... y(n)
    146                                       //!< 2x2 subsampled interleaved 10 bit UV-plane with
    147                                       //!< 5 MSB bits set to 0:
    148                                       //!<    u(0), v(0), u(2), v(2) ... u(n-1), v(n-1)
    149                                       //!< aka P010.
    150 
    151   kFormatYCbCr420TP10Ubwc,            //!< UBWC aligned YCbCr420TP10 format.
    152 
    153   /* All YUV-Packed formats, Any new format will be added towards end of this group to maintain
    154      backward compatibility.
    155   */
    156   kFormatYCbCr422H2V1Packed = 0x300,  //!< Y-plane interleaved with horizontally subsampled U/V by
    157                                       //!< factor of 2
    158                                       //!<    y(0), u(0), y(1), v(0), y(2), u(2), y(3), v(2)
    159                                       //!<    y(n-1), u(n-1), y(n), v(n-1)
    160 
    161   kFormatInvalid = 0xFFFFFFFF,
    162 };
    163 
    164 
    165 /*! @brief This enum represents different types of 3D formats supported.
    166 
    167   @sa LayerBufferS3DFormat
    168 */
    169 enum LayerBufferS3DFormat {
    170   kS3dFormatNone,            //!< Layer buffer content is not 3D content.
    171   kS3dFormatLeftRight,       //!< Left and Right view of a 3D content stitched left and right.
    172   kS3dFormatRightLeft,       //!< Right and Left view of a 3D content stitched left and right.
    173   kS3dFormatTopBottom,       //!< Left and RightView of a 3D content stitched top and bottom.
    174   kS3dFormatFramePacking     //!< Left and right view of 3D content coded in consecutive frames.
    175 };
    176 
    177 /*! @brief This structure defines a color sample plane belonging to a buffer format. RGB buffer
    178   formats have 1 plane whereas YUV buffer formats may have upto 4 planes.
    179 
    180   @sa LayerBuffer
    181 */
    182 struct LayerBufferPlane {
    183   int fd = -1;           //!< File descriptor referring to the buffer associated with this plane.
    184   uint32_t offset = 0;   //!< Offset of the plane in bytes from beginning of the buffer.
    185   uint32_t stride = 0;   //!< Stride in bytes i.e. length of a scanline including padding.
    186 };
    187 
    188 /*! @brief This structure defines flags associated with a layer buffer. The 1-bit flag can be set
    189   to ON(1) or OFF(0).
    190 
    191   @sa LayerBuffer
    192 */
    193 struct LayerBufferFlags {
    194   union {
    195     struct {
    196       uint32_t secure : 1;          //!< This flag shall be set by client to indicate that the
    197                                     //!< buffer need to be handled securely.
    198 
    199       uint32_t video  : 1;          //!< This flag shall be set by client to indicate that the
    200                                     //!< buffer is video/ui buffer.
    201 
    202       uint32_t macro_tile : 1;      //!< This flag shall be set by client to indicate that the
    203                                     //!< buffer format is macro tiled.
    204 
    205       uint32_t interlace : 1;       //!< This flag shall be set by the client to indicate that
    206                                     //!< the buffer has interlaced content.
    207 
    208       uint32_t secure_display : 1;  //!< This flag shall be set by the client to indicate that the
    209                                     //!< secure display session is in progress. Secure display
    210                                     //!< session can not coexist with non-secure session.
    211     };
    212 
    213     uint32_t flags = 0;             //!< For initialization purpose only.
    214                                     //!< Client shall not refer to it directly.
    215   };
    216 };
    217 
    218 /*! @brief This structure defines a layer buffer handle which contains raw buffer and its associated
    219   properties.
    220 
    221   @sa LayerBuffer
    222   @sa LayerStack
    223 */
    224 struct LayerBuffer {
    225   uint32_t width = 0;           //!< Actual width of the Layer that this buffer is for.
    226   uint32_t height = 0;          //!< Actual height of the Layer that this buffer is for.
    227   uint32_t size = 0;            //!< Size of a single buffer (even if multiple clubbed together)
    228   LayerBufferFormat format = kFormatRGBA8888;     //!< Format of the buffer content.
    229   LayerCSC csc = kCSCFullRange601;                //!< Color Space of the layer.
    230   LayerIGC igc = kIGCNotSpecified;                //!< IGC that will be applied on this layer.
    231   LayerBufferPlane planes[4] = {};
    232                                 //!< Array of planes that this buffer contains. RGB buffer formats
    233                                 //!< have 1 plane whereas YUV buffer formats may have upto 4 planes
    234                                 //!< Total number of planes for the buffer will be interpreted based
    235                                 //!< on the buffer format specified.
    236 
    237   int acquire_fence_fd = -1;    //!< File descriptor referring to a sync fence object which will be
    238                                 //!< signaled when buffer can be read/write by display manager.
    239                                 //!< This fence object is set by the client during Commit(). For
    240                                 //!< input buffers client shall signal this fence when buffer
    241                                 //!< content is available and can be read by display manager. For
    242                                 //!< output buffers, client shall signal fence when buffer is ready
    243                                 //!< to be written by display manager.
    244 
    245                                 //!< This field is used only during Commit() and shall be set to -1
    246                                 //!< by the client when buffer is already available for read/write.
    247 
    248   int release_fence_fd = -1;    //!< File descriptor referring to a sync fence object which will be
    249                                 //!< signaled when buffer has been read/written by display manager.
    250                                 //!< This fence object is set by display manager during Commit().
    251                                 //!< For input buffers display manager will signal this fence when
    252                                 //!< buffer has been consumed. For output buffers, display manager
    253                                 //!< will signal this fence when buffer is produced.
    254 
    255                                 //!< This field is used only during Commit() and will be set to -1
    256                                 //!< by display manager when buffer is already available for
    257                                 //!< read/write.
    258 
    259   LayerBufferFlags flags;       //!< Flags associated with this buffer.
    260 
    261   LayerBufferS3DFormat s3d_format = kS3dFormatNone;
    262                                 //!< Represents the format of the buffer content in 3D.
    263   uint64_t buffer_id __attribute__((aligned(8))) = 0;
    264                                 //!< Specifies the buffer id.
    265 };
    266 
    267 }  // namespace sdm
    268 
    269 #endif  // __LAYER_BUFFER_H__
    270 
    271