Home | History | Annotate | Download | only in media
      1 #ifndef __MEDIA_INFO_H__
      2 #define __MEDIA_INFO_H__
      3 
      4 #ifndef MSM_MEDIA_ALIGN
      5 #define MSM_MEDIA_ALIGN(__sz, __align) (((__sz) + (__align-1)) & (~(__align-1)))
      6 #endif
      7 
      8 #ifndef MSM_MEDIA_ROUNDUP
      9 #define MSM_MEDIA_ROUNDUP(__sz, __r) (((__sz) + ((__r) - 1)) / (__r))
     10 #endif
     11 
     12 #ifndef MSM_MEDIA_MAX
     13 #define MSM_MEDIA_MAX(__a, __b) ((__a) > (__b)?(__a):(__b))
     14 #endif
     15 
     16 enum color_fmts {
     17 	/* Venus NV12:
     18 	 * YUV 4:2:0 image with a plane of 8 bit Y samples followed
     19 	 * by an interleaved U/V plane containing 8 bit 2x2 subsampled
     20 	 * colour difference samples.
     21 	 *
     22 	 * <-------- Y/UV_Stride -------->
     23 	 * <------- Width ------->
     24 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  ^           ^
     25 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |
     26 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  Height      |
     27 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |          Y_Scanlines
     28 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |
     29 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |
     30 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |
     31 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  V           |
     32 	 * . . . . . . . . . . . . . . . .              |
     33 	 * . . . . . . . . . . . . . . . .              |
     34 	 * . . . . . . . . . . . . . . . .              |
     35 	 * . . . . . . . . . . . . . . . .              V
     36 	 * U V U V U V U V U V U V . . . .  ^
     37 	 * U V U V U V U V U V U V . . . .  |
     38 	 * U V U V U V U V U V U V . . . .  |
     39 	 * U V U V U V U V U V U V . . . .  UV_Scanlines
     40 	 * . . . . . . . . . . . . . . . .  |
     41 	 * . . . . . . . . . . . . . . . .  V
     42 	 * . . . . . . . . . . . . . . . .  --> Buffer size alignment
     43 	 *
     44 	 * Y_Stride : Width aligned to 128
     45 	 * UV_Stride : Width aligned to 128
     46 	 * Y_Scanlines: Height aligned to 32
     47 	 * UV_Scanlines: Height/2 aligned to 16
     48 	 * Extradata: Arbitrary (software-imposed) padding
     49 	 * Total size = align((Y_Stride * Y_Scanlines
     50 	 *          + UV_Stride * UV_Scanlines
     51 	 *          + max(Extradata, Y_Stride * 8), 4096)
     52 	 */
     53 	COLOR_FMT_NV12,
     54 
     55 	/* Venus NV21:
     56 	 * YUV 4:2:0 image with a plane of 8 bit Y samples followed
     57 	 * by an interleaved V/U plane containing 8 bit 2x2 subsampled
     58 	 * colour difference samples.
     59 	 *
     60 	 * <-------- Y/UV_Stride -------->
     61 	 * <------- Width ------->
     62 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  ^           ^
     63 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |
     64 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  Height      |
     65 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |          Y_Scanlines
     66 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |
     67 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |
     68 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |
     69 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  V           |
     70 	 * . . . . . . . . . . . . . . . .              |
     71 	 * . . . . . . . . . . . . . . . .              |
     72 	 * . . . . . . . . . . . . . . . .              |
     73 	 * . . . . . . . . . . . . . . . .              V
     74 	 * V U V U V U V U V U V U . . . .  ^
     75 	 * V U V U V U V U V U V U . . . .  |
     76 	 * V U V U V U V U V U V U . . . .  |
     77 	 * V U V U V U V U V U V U . . . .  UV_Scanlines
     78 	 * . . . . . . . . . . . . . . . .  |
     79 	 * . . . . . . . . . . . . . . . .  V
     80 	 * . . . . . . . . . . . . . . . .  --> Padding & Buffer size alignment
     81 	 *
     82 	 * Y_Stride : Width aligned to 128
     83 	 * UV_Stride : Width aligned to 128
     84 	 * Y_Scanlines: Height aligned to 32
     85 	 * UV_Scanlines: Height/2 aligned to 16
     86 	 * Extradata: Arbitrary (software-imposed) padding
     87 	 * Total size = align((Y_Stride * Y_Scanlines
     88 	 *          + UV_Stride * UV_Scanlines
     89 	 *          + max(Extradata, Y_Stride * 8), 4096)
     90 	 */
     91 	COLOR_FMT_NV21,
     92 	/* Venus NV12_MVTB:
     93 	 * Two YUV 4:2:0 images/views one after the other
     94 	 * in a top-bottom layout, same as NV12
     95 	 * with a plane of 8 bit Y samples followed
     96 	 * by an interleaved U/V plane containing 8 bit 2x2 subsampled
     97 	 * colour difference samples.
     98 	 *
     99 	 *
    100 	 * <-------- Y/UV_Stride -------->
    101 	 * <------- Width ------->
    102 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  ^           ^               ^
    103 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |               |
    104 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  Height      |               |
    105 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |          Y_Scanlines      |
    106 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |               |
    107 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |               |
    108 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |               |
    109 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  V           |               |
    110 	 * . . . . . . . . . . . . . . . .              |             View_1
    111 	 * . . . . . . . . . . . . . . . .              |               |
    112 	 * . . . . . . . . . . . . . . . .              |               |
    113 	 * . . . . . . . . . . . . . . . .              V               |
    114 	 * U V U V U V U V U V U V . . . .  ^                           |
    115 	 * U V U V U V U V U V U V . . . .  |                           |
    116 	 * U V U V U V U V U V U V . . . .  |                           |
    117 	 * U V U V U V U V U V U V . . . .  UV_Scanlines                |
    118 	 * . . . . . . . . . . . . . . . .  |                           |
    119 	 * . . . . . . . . . . . . . . . .  V                           V
    120 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  ^           ^               ^
    121 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |               |
    122 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  Height      |               |
    123 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |          Y_Scanlines      |
    124 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |               |
    125 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |               |
    126 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  |           |               |
    127 	 * Y Y Y Y Y Y Y Y Y Y Y Y . . . .  V           |               |
    128 	 * . . . . . . . . . . . . . . . .              |             View_2
    129 	 * . . . . . . . . . . . . . . . .              |               |
    130 	 * . . . . . . . . . . . . . . . .              |               |
    131 	 * . . . . . . . . . . . . . . . .              V               |
    132 	 * U V U V U V U V U V U V . . . .  ^                           |
    133 	 * U V U V U V U V U V U V . . . .  |                           |
    134 	 * U V U V U V U V U V U V . . . .  |                           |
    135 	 * U V U V U V U V U V U V . . . .  UV_Scanlines                |
    136 	 * . . . . . . . . . . . . . . . .  |                           |
    137 	 * . . . . . . . . . . . . . . . .  V                           V
    138 	 * . . . . . . . . . . . . . . . .  --> Buffer size alignment
    139 	 *
    140 	 * Y_Stride : Width aligned to 128
    141 	 * UV_Stride : Width aligned to 128
    142 	 * Y_Scanlines: Height aligned to 32
    143 	 * UV_Scanlines: Height/2 aligned to 16
    144 	 * View_1 begin at: 0 (zero)
    145 	 * View_2 begin at: Y_Stride * Y_Scanlines + UV_Stride * UV_Scanlines
    146 	 * Extradata: Arbitrary (software-imposed) padding
    147 	 * Total size = align((2*(Y_Stride * Y_Scanlines)
    148 	 *          + 2*(UV_Stride * UV_Scanlines) + Extradata), 4096)
    149 	 */
    150 	COLOR_FMT_NV12_MVTB,
    151 	/* Venus NV12 UBWC:
    152 	 * Compressed Macro-tile format for NV12.
    153 	 * Contains 4 planes in the following order -
    154 	 * (A) Y_Meta_Plane
    155 	 * (B) Y_UBWC_Plane
    156 	 * (C) UV_Meta_Plane
    157 	 * (D) UV_UBWC_Plane
    158 	 *
    159 	 * Y_Meta_Plane consists of meta information to decode compressed
    160 	 * tile data in Y_UBWC_Plane.
    161 	 * Y_UBWC_Plane consists of Y data in compressed macro-tile format.
    162 	 * UBWC decoder block will use the Y_Meta_Plane data together with
    163 	 * Y_UBWC_Plane data to produce loss-less uncompressed 8 bit Y samples.
    164 	 *
    165 	 * UV_Meta_Plane consists of meta information to decode compressed
    166 	 * tile data in UV_UBWC_Plane.
    167 	 * UV_UBWC_Plane consists of UV data in compressed macro-tile format.
    168 	 * UBWC decoder block will use UV_Meta_Plane data together with
    169 	 * UV_UBWC_Plane data to produce loss-less uncompressed 8 bit 2x2
    170 	 * subsampled color difference samples.
    171 	 *
    172 	 * Each tile in Y_UBWC_Plane/UV_UBWC_Plane is independently decodable
    173 	 * and randomly accessible. There is no dependency between tiles.
    174 	 *
    175 	 * <----- Y_Meta_Stride ---->
    176 	 * <-------- Width ------>
    177 	 * M M M M M M M M M M M M . .      ^           ^
    178 	 * M M M M M M M M M M M M . .      |           |
    179 	 * M M M M M M M M M M M M . .      Height      |
    180 	 * M M M M M M M M M M M M . .      |         Meta_Y_Scanlines
    181 	 * M M M M M M M M M M M M . .      |           |
    182 	 * M M M M M M M M M M M M . .      |           |
    183 	 * M M M M M M M M M M M M . .      |           |
    184 	 * M M M M M M M M M M M M . .      V           |
    185 	 * . . . . . . . . . . . . . .                  |
    186 	 * . . . . . . . . . . . . . .                  |
    187 	 * . . . . . . . . . . . . . .      -------> Buffer size aligned to 4k
    188 	 * . . . . . . . . . . . . . .                  V
    189 	 * <--Compressed tile Y Stride--->
    190 	 * <------- Width ------->
    191 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  ^           ^
    192 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |           |
    193 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  Height      |
    194 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |        Macro_tile_Y_Scanlines
    195 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |           |
    196 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |           |
    197 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |           |
    198 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  V           |
    199 	 * . . . . . . . . . . . . . . . .              |
    200 	 * . . . . . . . . . . . . . . . .              |
    201 	 * . . . . . . . . . . . . . . . .  -------> Buffer size aligned to 4k
    202 	 * . . . . . . . . . . . . . . . .              V
    203 	 * <----- UV_Meta_Stride ---->
    204 	 * M M M M M M M M M M M M . .      ^
    205 	 * M M M M M M M M M M M M . .      |
    206 	 * M M M M M M M M M M M M . .      |
    207 	 * M M M M M M M M M M M M . .      M_UV_Scanlines
    208 	 * . . . . . . . . . . . . . .      |
    209 	 * . . . . . . . . . . . . . .      V
    210 	 * . . . . . . . . . . . . . .      -------> Buffer size aligned to 4k
    211 	 * <--Compressed tile UV Stride--->
    212 	 * U* V* U* V* U* V* U* V* . . . .  ^
    213 	 * U* V* U* V* U* V* U* V* . . . .  |
    214 	 * U* V* U* V* U* V* U* V* . . . .  |
    215 	 * U* V* U* V* U* V* U* V* . . . .  UV_Scanlines
    216 	 * . . . . . . . . . . . . . . . .  |
    217 	 * . . . . . . . . . . . . . . . .  V
    218 	 * . . . . . . . . . . . . . . . .  -------> Buffer size aligned to 4k
    219 	 *
    220 	 * Y_Stride = align(Width, 128)
    221 	 * UV_Stride = align(Width, 128)
    222 	 * Y_Scanlines = align(Height, 32)
    223 	 * UV_Scanlines = align(Height/2, 16)
    224 	 * Y_UBWC_Plane_size = align(Y_Stride * Y_Scanlines, 4096)
    225 	 * UV_UBWC_Plane_size = align(UV_Stride * UV_Scanlines, 4096)
    226 	 * Y_Meta_Stride = align(roundup(Width, Y_TileWidth), 64)
    227 	 * Y_Meta_Scanlines = align(roundup(Height, Y_TileHeight), 16)
    228 	 * Y_Meta_Plane_size = align(Y_Meta_Stride * Y_Meta_Scanlines, 4096)
    229 	 * UV_Meta_Stride = align(roundup(Width, UV_TileWidth), 64)
    230 	 * UV_Meta_Scanlines = align(roundup(Height, UV_TileHeight), 16)
    231 	 * UV_Meta_Plane_size = align(UV_Meta_Stride * UV_Meta_Scanlines, 4096)
    232 	 * Extradata = 8k
    233 	 *
    234 	 * Total size = align( Y_UBWC_Plane_size + UV_UBWC_Plane_size +
    235 	 *           Y_Meta_Plane_size + UV_Meta_Plane_size
    236 	 *           + max(Extradata, Y_Stride * 48), 4096)
    237 	 */
    238 	COLOR_FMT_NV12_UBWC,
    239 	/* Venus NV12 10-bit UBWC:
    240 	 * Compressed Macro-tile format for NV12.
    241 	 * Contains 4 planes in the following order -
    242 	 * (A) Y_Meta_Plane
    243 	 * (B) Y_UBWC_Plane
    244 	 * (C) UV_Meta_Plane
    245 	 * (D) UV_UBWC_Plane
    246 	 *
    247 	 * Y_Meta_Plane consists of meta information to decode compressed
    248 	 * tile data in Y_UBWC_Plane.
    249 	 * Y_UBWC_Plane consists of Y data in compressed macro-tile format.
    250 	 * UBWC decoder block will use the Y_Meta_Plane data together with
    251 	 * Y_UBWC_Plane data to produce loss-less uncompressed 10 bit Y samples.
    252 	 *
    253 	 * UV_Meta_Plane consists of meta information to decode compressed
    254 	 * tile data in UV_UBWC_Plane.
    255 	 * UV_UBWC_Plane consists of UV data in compressed macro-tile format.
    256 	 * UBWC decoder block will use UV_Meta_Plane data together with
    257 	 * UV_UBWC_Plane data to produce loss-less uncompressed 10 bit 2x2
    258 	 * subsampled color difference samples.
    259 	 *
    260 	 * Each tile in Y_UBWC_Plane/UV_UBWC_Plane is independently decodable
    261 	 * and randomly accessible. There is no dependency between tiles.
    262 	 *
    263 	 * <----- Y_Meta_Stride ----->
    264 	 * <-------- Width ------>
    265 	 * M M M M M M M M M M M M . .      ^           ^
    266 	 * M M M M M M M M M M M M . .      |           |
    267 	 * M M M M M M M M M M M M . .      Height      |
    268 	 * M M M M M M M M M M M M . .      |         Meta_Y_Scanlines
    269 	 * M M M M M M M M M M M M . .      |           |
    270 	 * M M M M M M M M M M M M . .      |           |
    271 	 * M M M M M M M M M M M M . .      |           |
    272 	 * M M M M M M M M M M M M . .      V           |
    273 	 * . . . . . . . . . . . . . .                  |
    274 	 * . . . . . . . . . . . . . .                  |
    275 	 * . . . . . . . . . . . . . .      -------> Buffer size aligned to 4k
    276 	 * . . . . . . . . . . . . . .                  V
    277 	 * <--Compressed tile Y Stride--->
    278 	 * <------- Width ------->
    279 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  ^           ^
    280 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |           |
    281 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  Height      |
    282 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |        Macro_tile_Y_Scanlines
    283 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |           |
    284 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |           |
    285 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  |           |
    286 	 * Y* Y* Y* Y* Y* Y* Y* Y* . . . .  V           |
    287 	 * . . . . . . . . . . . . . . . .              |
    288 	 * . . . . . . . . . . . . . . . .              |
    289 	 * . . . . . . . . . . . . . . . .  -------> Buffer size aligned to 4k
    290 	 * . . . . . . . . . . . . . . . .              V
    291 	 * <----- UV_Meta_Stride ---->
    292 	 * M M M M M M M M M M M M . .      ^
    293 	 * M M M M M M M M M M M M . .      |
    294 	 * M M M M M M M M M M M M . .      |
    295 	 * M M M M M M M M M M M M . .      M_UV_Scanlines
    296 	 * . . . . . . . . . . . . . .      |
    297 	 * . . . . . . . . . . . . . .      V
    298 	 * . . . . . . . . . . . . . .      -------> Buffer size aligned to 4k
    299 	 * <--Compressed tile UV Stride--->
    300 	 * U* V* U* V* U* V* U* V* . . . .  ^
    301 	 * U* V* U* V* U* V* U* V* . . . .  |
    302 	 * U* V* U* V* U* V* U* V* . . . .  |
    303 	 * U* V* U* V* U* V* U* V* . . . .  UV_Scanlines
    304 	 * . . . . . . . . . . . . . . . .  |
    305 	 * . . . . . . . . . . . . . . . .  V
    306 	 * . . . . . . . . . . . . . . . .  -------> Buffer size aligned to 4k
    307 	 *
    308 	 *
    309 	 * Y_Stride = align(Width * 4/3, 128)
    310 	 * UV_Stride = align(Width * 4/3, 128)
    311 	 * Y_Scanlines = align(Height, 32)
    312 	 * UV_Scanlines = align(Height/2, 16)
    313 	 * Y_UBWC_Plane_Size = align(Y_Stride * Y_Scanlines, 4096)
    314 	 * UV_UBWC_Plane_Size = align(UV_Stride * UV_Scanlines, 4096)
    315 	 * Y_Meta_Stride = align(roundup(Width, Y_TileWidth), 64)
    316 	 * Y_Meta_Scanlines = align(roundup(Height, Y_TileHeight), 16)
    317 	 * Y_Meta_Plane_size = align(Y_Meta_Stride * Y_Meta_Scanlines, 4096)
    318 	 * UV_Meta_Stride = align(roundup(Width, UV_TileWidth), 64)
    319 	 * UV_Meta_Scanlines = align(roundup(Height, UV_TileHeight), 16)
    320 	 * UV_Meta_Plane_size = align(UV_Meta_Stride * UV_Meta_Scanlines, 4096)
    321 	 * Extradata = 8k
    322 	 *
    323 	 * Total size = align(Y_UBWC_Plane_size + UV_UBWC_Plane_size +
    324 	 *           Y_Meta_Plane_size + UV_Meta_Plane_size
    325 	 *           + max(Extradata, Y_Stride * 48), 4096)
    326 	 */
    327 	COLOR_FMT_NV12_BPP10_UBWC,
    328 	/* Venus RGBA8888 format:
    329 	 * Contains 1 plane in the following order -
    330 	 * (A) RGBA plane
    331 	 *
    332 	 * <-------- RGB_Stride -------->
    333 	 * <------- Width ------->
    334 	 * R R R R R R R R R R R R . . . .  ^           ^
    335 	 * R R R R R R R R R R R R . . . .  |           |
    336 	 * R R R R R R R R R R R R . . . .  Height      |
    337 	 * R R R R R R R R R R R R . . . .  |       RGB_Scanlines
    338 	 * R R R R R R R R R R R R . . . .  |           |
    339 	 * R R R R R R R R R R R R . . . .  |           |
    340 	 * R R R R R R R R R R R R . . . .  |           |
    341 	 * R R R R R R R R R R R R . . . .  V           |
    342 	 * . . . . . . . . . . . . . . . .              |
    343 	 * . . . . . . . . . . . . . . . .              |
    344 	 * . . . . . . . . . . . . . . . .              |
    345 	 * . . . . . . . . . . . . . . . .              V
    346 	 *
    347 	 * RGB_Stride = align(Width * 4, 128)
    348 	 * RGB_Scanlines = align(Height, 32)
    349 	 * RGB_Plane_size = align(RGB_Stride * RGB_Scanlines, 4096)
    350 	 * Extradata = 8k
    351 	 *
    352 	 * Total size = align(RGB_Plane_size + Extradata, 4096)
    353 	 */
    354 	COLOR_FMT_RGBA8888,
    355 	/* Venus RGBA8888 UBWC format:
    356 	 * Contains 2 planes in the following order -
    357 	 * (A) Meta plane
    358 	 * (B) RGBA plane
    359 	 *
    360 	 * <--- RGB_Meta_Stride ---->
    361 	 * <-------- Width ------>
    362 	 * M M M M M M M M M M M M . .      ^           ^
    363 	 * M M M M M M M M M M M M . .      |           |
    364 	 * M M M M M M M M M M M M . .      Height      |
    365 	 * M M M M M M M M M M M M . .      |       Meta_RGB_Scanlines
    366 	 * M M M M M M M M M M M M . .      |           |
    367 	 * M M M M M M M M M M M M . .      |           |
    368 	 * M M M M M M M M M M M M . .      |           |
    369 	 * M M M M M M M M M M M M . .      V           |
    370 	 * . . . . . . . . . . . . . .                  |
    371 	 * . . . . . . . . . . . . . .                  |
    372 	 * . . . . . . . . . . . . . .      -------> Buffer size aligned to 4k
    373 	 * . . . . . . . . . . . . . .                  V
    374 	 * <-------- RGB_Stride -------->
    375 	 * <------- Width ------->
    376 	 * R R R R R R R R R R R R . . . .  ^           ^
    377 	 * R R R R R R R R R R R R . . . .  |           |
    378 	 * R R R R R R R R R R R R . . . .  Height      |
    379 	 * R R R R R R R R R R R R . . . .  |       RGB_Scanlines
    380 	 * R R R R R R R R R R R R . . . .  |           |
    381 	 * R R R R R R R R R R R R . . . .  |           |
    382 	 * R R R R R R R R R R R R . . . .  |           |
    383 	 * R R R R R R R R R R R R . . . .  V           |
    384 	 * . . . . . . . . . . . . . . . .              |
    385 	 * . . . . . . . . . . . . . . . .              |
    386 	 * . . . . . . . . . . . . . . . .    -------> Buffer size aligned to 4k
    387 	 * . . . . . . . . . . . . . . . .              V
    388 	 *
    389 	 * RGB_Stride = align(Width * 4, 128)
    390 	 * RGB_Scanlines = align(Height, 32)
    391 	 * RGB_Plane_size = align(RGB_Stride * RGB_Scanlines, 4096)
    392 	 * RGB_Meta_Stride = align(roundup(Width, RGB_TileWidth), 64)
    393 	 * RGB_Meta_Scanline = align(roundup(Height, RGB_TileHeight), 16)
    394 	 * RGB_Meta_Plane_size = align(RGB_Meta_Stride *
    395 	 *		RGB_Meta_Scanlines, 4096)
    396 	 * Extradata = 8k
    397 	 *
    398 	 * Total size = align(RGB_Meta_Plane_size + RGB_Plane_size +
    399 	 *		Extradata, 4096)
    400 	 */
    401 	COLOR_FMT_RGBA8888_UBWC,
    402 };
    403 
    404 static inline unsigned int VENUS_EXTRADATA_SIZE(int width, int height)
    405 {
    406 	(void)height;
    407 	(void)width;
    408 
    409 	/*
    410 	 * In the future, calculate the size based on the w/h but just
    411 	 * hardcode it for now since 16K satisfies all current usecases.
    412 	 */
    413 	return 16 * 1024;
    414 }
    415 
    416 static inline unsigned int VENUS_Y_STRIDE(int color_fmt, int width)
    417 {
    418 	unsigned int alignment, stride = 0;
    419 	if (!width)
    420 		goto invalid_input;
    421 
    422 	switch (color_fmt) {
    423 	case COLOR_FMT_NV21:
    424 	case COLOR_FMT_NV12:
    425 	case COLOR_FMT_NV12_MVTB:
    426 	case COLOR_FMT_NV12_UBWC:
    427 		alignment = 128;
    428 		stride = MSM_MEDIA_ALIGN(width, alignment);
    429 		break;
    430 	case COLOR_FMT_NV12_BPP10_UBWC:
    431 		alignment = 256;
    432 		stride = MSM_MEDIA_ALIGN(width, 192);
    433 		stride = MSM_MEDIA_ALIGN(stride * 4/3, alignment);
    434 		break;
    435 	default:
    436 		break;
    437 	}
    438 invalid_input:
    439 	return stride;
    440 }
    441 
    442 static inline unsigned int VENUS_UV_STRIDE(int color_fmt, int width)
    443 {
    444 	unsigned int alignment, stride = 0;
    445 	if (!width)
    446 		goto invalid_input;
    447 
    448 	switch (color_fmt) {
    449 	case COLOR_FMT_NV21:
    450 	case COLOR_FMT_NV12:
    451 	case COLOR_FMT_NV12_MVTB:
    452 	case COLOR_FMT_NV12_UBWC:
    453 		alignment = 128;
    454 		stride = MSM_MEDIA_ALIGN(width, alignment);
    455 		break;
    456 	case COLOR_FMT_NV12_BPP10_UBWC:
    457 		alignment = 256;
    458 		stride = MSM_MEDIA_ALIGN(width, 192);
    459 		stride = MSM_MEDIA_ALIGN(stride * 4/3, alignment);
    460 		break;
    461 	default:
    462 		break;
    463 	}
    464 invalid_input:
    465 	return stride;
    466 }
    467 
    468 static inline unsigned int VENUS_Y_SCANLINES(int color_fmt, int height)
    469 {
    470 	unsigned int alignment, sclines = 0;
    471 	if (!height)
    472 		goto invalid_input;
    473 
    474 	switch (color_fmt) {
    475 	case COLOR_FMT_NV21:
    476 	case COLOR_FMT_NV12:
    477 	case COLOR_FMT_NV12_MVTB:
    478 	case COLOR_FMT_NV12_UBWC:
    479 		alignment = 32;
    480 		break;
    481 	case COLOR_FMT_NV12_BPP10_UBWC:
    482 		alignment = 16;
    483 		break;
    484 	default:
    485 		return 0;
    486 	}
    487 	sclines = MSM_MEDIA_ALIGN(height, alignment);
    488 invalid_input:
    489 	return sclines;
    490 }
    491 
    492 static inline unsigned int VENUS_UV_SCANLINES(int color_fmt, int height)
    493 {
    494 	unsigned int alignment, sclines = 0;
    495 	if (!height)
    496 		goto invalid_input;
    497 
    498 	switch (color_fmt) {
    499 	case COLOR_FMT_NV21:
    500 	case COLOR_FMT_NV12:
    501 	case COLOR_FMT_NV12_MVTB:
    502 	case COLOR_FMT_NV12_BPP10_UBWC:
    503 		alignment = 16;
    504 		break;
    505 	case COLOR_FMT_NV12_UBWC:
    506 		alignment = 32;
    507 		break;
    508 	default:
    509 		goto invalid_input;
    510 	}
    511 
    512 	sclines = MSM_MEDIA_ALIGN(height / 2, alignment);
    513 
    514 invalid_input:
    515 	return sclines;
    516 }
    517 
    518 static inline unsigned int VENUS_Y_META_STRIDE(int color_fmt, int width)
    519 {
    520 	int y_tile_width = 0, y_meta_stride = 0;
    521 
    522 	if (!width)
    523 		goto invalid_input;
    524 
    525 	switch (color_fmt) {
    526 	case COLOR_FMT_NV12_UBWC:
    527 		y_tile_width = 32;
    528 		break;
    529 	case COLOR_FMT_NV12_BPP10_UBWC:
    530 		y_tile_width = 48;
    531 		break;
    532 	default:
    533 		goto invalid_input;
    534 	}
    535 
    536 	y_meta_stride = MSM_MEDIA_ROUNDUP(width, y_tile_width);
    537 	y_meta_stride = MSM_MEDIA_ALIGN(y_meta_stride, 64);
    538 
    539 invalid_input:
    540 	return y_meta_stride;
    541 }
    542 
    543 static inline unsigned int VENUS_Y_META_SCANLINES(int color_fmt, int height)
    544 {
    545 	int y_tile_height = 0, y_meta_scanlines = 0;
    546 
    547 	if (!height)
    548 		goto invalid_input;
    549 
    550 	switch (color_fmt) {
    551 	case COLOR_FMT_NV12_UBWC:
    552 		y_tile_height = 8;
    553 		break;
    554 	case COLOR_FMT_NV12_BPP10_UBWC:
    555 		y_tile_height = 4;
    556 		break;
    557 	default:
    558 		goto invalid_input;
    559 	}
    560 
    561 	y_meta_scanlines = MSM_MEDIA_ROUNDUP(height, y_tile_height);
    562 	y_meta_scanlines = MSM_MEDIA_ALIGN(y_meta_scanlines, 16);
    563 
    564 invalid_input:
    565 	return y_meta_scanlines;
    566 }
    567 
    568 static inline unsigned int VENUS_UV_META_STRIDE(int color_fmt, int width)
    569 {
    570 	int uv_tile_width = 0, uv_meta_stride = 0;
    571 
    572 	if (!width)
    573 		goto invalid_input;
    574 
    575 	switch (color_fmt) {
    576 	case COLOR_FMT_NV12_UBWC:
    577 		uv_tile_width = 16;
    578 		break;
    579 	case COLOR_FMT_NV12_BPP10_UBWC:
    580 		uv_tile_width = 24;
    581 		break;
    582 	default:
    583 		goto invalid_input;
    584 	}
    585 
    586 	uv_meta_stride = MSM_MEDIA_ROUNDUP(width / 2, uv_tile_width);
    587 	uv_meta_stride = MSM_MEDIA_ALIGN(uv_meta_stride, 64);
    588 
    589 invalid_input:
    590 	return uv_meta_stride;
    591 }
    592 
    593 static inline unsigned int VENUS_UV_META_SCANLINES(int color_fmt, int height)
    594 {
    595 	int uv_tile_height = 0, uv_meta_scanlines = 0;
    596 
    597 	if (!height)
    598 		goto invalid_input;
    599 
    600 	switch (color_fmt) {
    601 	case COLOR_FMT_NV12_UBWC:
    602 		uv_tile_height = 8;
    603 		break;
    604 	case COLOR_FMT_NV12_BPP10_UBWC:
    605 		uv_tile_height = 4;
    606 		break;
    607 	default:
    608 		goto invalid_input;
    609 	}
    610 
    611 	uv_meta_scanlines = MSM_MEDIA_ROUNDUP(height / 2, uv_tile_height);
    612 	uv_meta_scanlines = MSM_MEDIA_ALIGN(uv_meta_scanlines, 16);
    613 
    614 invalid_input:
    615 	return uv_meta_scanlines;
    616 }
    617 
    618 static inline unsigned int VENUS_RGB_STRIDE(int color_fmt, int width)
    619 {
    620 	unsigned int alignment = 0, stride = 0;
    621 	if (!width)
    622 		goto invalid_input;
    623 
    624 	switch (color_fmt) {
    625 	case COLOR_FMT_RGBA8888:
    626 		alignment = 128;
    627 		break;
    628 	case COLOR_FMT_RGBA8888_UBWC:
    629 		alignment = 256;
    630 		break;
    631 	default:
    632 		goto invalid_input;
    633 	}
    634 
    635 	stride = MSM_MEDIA_ALIGN(width * 4, alignment);
    636 
    637 invalid_input:
    638 	return stride;
    639 }
    640 
    641 static inline unsigned int VENUS_RGB_SCANLINES(int color_fmt, int height)
    642 {
    643 	unsigned int alignment = 0, scanlines = 0;
    644 
    645 	if (!height)
    646 		goto invalid_input;
    647 
    648 	switch (color_fmt) {
    649 	case COLOR_FMT_RGBA8888:
    650 		alignment = 32;
    651 		break;
    652 	case COLOR_FMT_RGBA8888_UBWC:
    653 		alignment = 16;
    654 		break;
    655 	default:
    656 		goto invalid_input;
    657 	}
    658 
    659 	scanlines = MSM_MEDIA_ALIGN(height, alignment);
    660 
    661 invalid_input:
    662 	return scanlines;
    663 }
    664 
    665 static inline unsigned int VENUS_RGB_META_STRIDE(int color_fmt, int width)
    666 {
    667 	int rgb_tile_width = 0, rgb_meta_stride = 0;
    668 
    669 	if (!width)
    670 		goto invalid_input;
    671 
    672 	switch (color_fmt) {
    673 	case COLOR_FMT_RGBA8888_UBWC:
    674 		rgb_tile_width = 16;
    675 		break;
    676 	default:
    677 		goto invalid_input;
    678 	}
    679 
    680 	rgb_meta_stride = MSM_MEDIA_ROUNDUP(width, rgb_tile_width);
    681 	rgb_meta_stride = MSM_MEDIA_ALIGN(rgb_meta_stride, 64);
    682 
    683 invalid_input:
    684 	return rgb_meta_stride;
    685 }
    686 
    687 static inline unsigned int VENUS_RGB_META_SCANLINES(int color_fmt, int height)
    688 {
    689 	int rgb_tile_height = 0, rgb_meta_scanlines = 0;
    690 
    691 	if (!height)
    692 		goto invalid_input;
    693 
    694 	switch (color_fmt) {
    695 	case COLOR_FMT_RGBA8888_UBWC:
    696 		rgb_tile_height = 4;
    697 		break;
    698 	default:
    699 		goto invalid_input;
    700 	}
    701 
    702 	rgb_meta_scanlines = MSM_MEDIA_ROUNDUP(height, rgb_tile_height);
    703 	rgb_meta_scanlines = MSM_MEDIA_ALIGN(rgb_meta_scanlines, 16);
    704 
    705 invalid_input:
    706 	return rgb_meta_scanlines;
    707 }
    708 
    709 static inline unsigned int VENUS_BUFFER_SIZE(
    710 	int color_fmt, int width, int height)
    711 {
    712 	const unsigned int extra_size = VENUS_EXTRADATA_SIZE(width, height);
    713 	unsigned int uv_alignment = 0, size = 0;
    714 	unsigned int y_plane, uv_plane, y_stride,
    715 		uv_stride, y_sclines, uv_sclines;
    716 	unsigned int y_ubwc_plane = 0, uv_ubwc_plane = 0;
    717 	unsigned int y_meta_stride = 0, y_meta_scanlines = 0;
    718 	unsigned int uv_meta_stride = 0, uv_meta_scanlines = 0;
    719 	unsigned int y_meta_plane = 0, uv_meta_plane = 0;
    720 	unsigned int rgb_stride = 0, rgb_scanlines = 0;
    721 	unsigned int rgb_plane = 0, rgb_ubwc_plane = 0, rgb_meta_plane = 0;
    722 	unsigned int rgb_meta_stride = 0, rgb_meta_scanlines = 0;
    723 
    724 	if (!width || !height)
    725 		goto invalid_input;
    726 
    727 	y_stride = VENUS_Y_STRIDE(color_fmt, width);
    728 	uv_stride = VENUS_UV_STRIDE(color_fmt, width);
    729 	y_sclines = VENUS_Y_SCANLINES(color_fmt, height);
    730 	uv_sclines = VENUS_UV_SCANLINES(color_fmt, height);
    731 	rgb_stride = VENUS_RGB_STRIDE(color_fmt, width);
    732 	rgb_scanlines = VENUS_RGB_SCANLINES(color_fmt, height);
    733 
    734 	switch (color_fmt) {
    735 	case COLOR_FMT_NV21:
    736 	case COLOR_FMT_NV12:
    737 		uv_alignment = 4096;
    738 		y_plane = y_stride * y_sclines;
    739 		uv_plane = uv_stride * uv_sclines + uv_alignment;
    740 		size = y_plane + uv_plane +
    741 				MSM_MEDIA_MAX(extra_size, 8 * y_stride);
    742 		size = MSM_MEDIA_ALIGN(size, 4096);
    743 		break;
    744 	case COLOR_FMT_NV12_MVTB:
    745 		uv_alignment = 4096;
    746 		y_plane = y_stride * y_sclines;
    747 		uv_plane = uv_stride * uv_sclines + uv_alignment;
    748 		size = y_plane + uv_plane;
    749 		size = 2 * size + extra_size;
    750 		size = MSM_MEDIA_ALIGN(size, 4096);
    751 		break;
    752 	case COLOR_FMT_NV12_UBWC:
    753 	case COLOR_FMT_NV12_BPP10_UBWC:
    754 		y_ubwc_plane = MSM_MEDIA_ALIGN(y_stride * y_sclines, 4096);
    755 		uv_ubwc_plane = MSM_MEDIA_ALIGN(uv_stride * uv_sclines, 4096);
    756 		y_meta_stride = VENUS_Y_META_STRIDE(color_fmt, width);
    757 		y_meta_scanlines = VENUS_Y_META_SCANLINES(color_fmt, height);
    758 		y_meta_plane = MSM_MEDIA_ALIGN(
    759 				y_meta_stride * y_meta_scanlines, 4096);
    760 		uv_meta_stride = VENUS_UV_META_STRIDE(color_fmt, width);
    761 		uv_meta_scanlines = VENUS_UV_META_SCANLINES(color_fmt, height);
    762 		uv_meta_plane = MSM_MEDIA_ALIGN(uv_meta_stride *
    763 					uv_meta_scanlines, 4096);
    764 
    765 		size = y_ubwc_plane + uv_ubwc_plane + y_meta_plane +
    766 			uv_meta_plane +
    767 			MSM_MEDIA_MAX(extra_size + 8192, 48 * y_stride);
    768 		size = MSM_MEDIA_ALIGN(size, 4096);
    769 		break;
    770 	case COLOR_FMT_RGBA8888:
    771 		rgb_plane = MSM_MEDIA_ALIGN(rgb_stride  * rgb_scanlines, 4096);
    772 		size = rgb_plane;
    773 		size =  MSM_MEDIA_ALIGN(size, 4096);
    774 		break;
    775 	case COLOR_FMT_RGBA8888_UBWC:
    776 		rgb_ubwc_plane = MSM_MEDIA_ALIGN(rgb_stride * rgb_scanlines,
    777 							4096);
    778 		rgb_meta_stride = VENUS_RGB_META_STRIDE(color_fmt, width);
    779 		rgb_meta_scanlines = VENUS_RGB_META_SCANLINES(color_fmt,
    780 					height);
    781 		rgb_meta_plane = MSM_MEDIA_ALIGN(rgb_meta_stride *
    782 					rgb_meta_scanlines, 4096);
    783 		size = rgb_ubwc_plane + rgb_meta_plane;
    784 		size = MSM_MEDIA_ALIGN(size, 4096);
    785 		break;
    786 	default:
    787 		break;
    788 	}
    789 invalid_input:
    790 	return size;
    791 }
    792 
    793 static inline unsigned int VENUS_VIEW2_OFFSET(
    794 	int color_fmt, int width, int height)
    795 {
    796 	unsigned int offset = 0;
    797 	unsigned int y_plane, uv_plane, y_stride,
    798 		uv_stride, y_sclines, uv_sclines;
    799 	if (!width || !height)
    800 		goto invalid_input;
    801 
    802 	y_stride = VENUS_Y_STRIDE(color_fmt, width);
    803 	uv_stride = VENUS_UV_STRIDE(color_fmt, width);
    804 	y_sclines = VENUS_Y_SCANLINES(color_fmt, height);
    805 	uv_sclines = VENUS_UV_SCANLINES(color_fmt, height);
    806 	switch (color_fmt) {
    807 	case COLOR_FMT_NV12_MVTB:
    808 		y_plane = y_stride * y_sclines;
    809 		uv_plane = uv_stride * uv_sclines;
    810 		offset = y_plane + uv_plane;
    811 		break;
    812 	default:
    813 		break;
    814 	}
    815 invalid_input:
    816 	return offset;
    817 }
    818 
    819 #endif
    820