1 /*
2  * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3  * Copyright (c) Imagination Technologies Limited, UK
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Authors:
26  *    Shengquan Yuan  <shengquan.yuan@intel.com>
27  *    Zhaohan Ren  <zhaohan.ren@intel.com>
28  */
29 
30 #ifndef _PSB_XVVA_H
31 #define _PSB_XVVA_H
32 
33 #include <pthread.h>
34 #include <stdint.h>
35 
36 
37 #ifndef MAKEFOURCC
38 
39 #define MAKEFOURCC(ch0, ch1, ch2, ch3)                                  \
40     ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
41     ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
42 
43 /* a few common FourCCs */
44 #define VA_FOURCC_AI44         0x34344149
45 #define VA_FOURCC_UYVY          0x59565955
46 #define VA_FOURCC_YUY2          0x32595559
47 #define VA_FOURCC_AYUV          0x56555941
48 #define VA_FOURCC_NV11          0x3131564e
49 #define VA_FOURCC_YV12          0x32315659
50 #define VA_FOURCC_P208          0x38303250
51 #define VA_FOURCC_IYUV          0x56555949
52 #define VA_FOURCC_I420          0x30323449
53 
54 #endif
55 
56 /* XvDrawable information */
57 #define XVDRAWABLE_NORMAL       0x00
58 #define XVDRAWABLE_PIXMAP       0x01
59 #define XVDRAWABLE_ROTATE_90    0x02
60 #define XVDRAWABLE_ROTATE_180   0x04
61 #define XVDRAWABLE_ROTATE_270   0x08
62 #define XVDRAWABLE_REDIRECT_WINDOW 0x10
63 #define XVDRAWABLE_SCALE        0x20
64 
65 #define XVDRAWABLE_INVALID_DRAWABLE     0x8000
66 
67 typedef struct _PsbAYUVSample8 {
68     unsigned char     Cr;
69     unsigned char     Cb;
70     unsigned char     Y;
71     unsigned char     Alpha;
72 } PsbAYUVSample8;
73 
74 typedef struct _VaClipBox {
75     short x;
76     short y;
77     unsigned short width;
78     unsigned short height;
79 } VaClipBox;
80 
81 
82 struct _PsbVASurface {
83     struct _PsbVASurface *next; /* next subpicture, only used by client */
84 
85     struct _WsbmBufferObject *bo;
86     uint32_t bufid;
87     uint64_t pl_flags; /* placement */
88     uint32_t size;
89 
90     unsigned int fourcc;
91     unsigned int planar;
92     unsigned int width;
93     unsigned int height;
94     unsigned int bytes_pp;
95     unsigned int stride;
96     unsigned int pre_add;
97     unsigned int reserved_phyaddr; /* for reserved memory, e.g. CI/RAR */
98 
99     unsigned int clear_color;
100 
101     unsigned int subpic_id; /* subpic id, only used by client */
102     unsigned int subpic_flags;/* flags for subpictures
103                                * #define VA_SUBPICTURE_CHROMA_KEYING    0x0001
104                                * #define VA_SUBPICTURE_GLOBAL_ALPHA     0x0002
105                                 *#define VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD 0x0004
106                                */
107     float global_alpha;
108     unsigned int chromakey_min;
109     unsigned int chromakey_max;
110     unsigned int chromakey_mask;
111 
112     PsbAYUVSample8 *palette_ptr; /* point to image palette */
113     union {
114         uint32_t  palette[16]; /* used to pass palette to server */
115         PsbAYUVSample8  constant[16]; /* server convert palette into SGX constants */
116     };
117     int subpic_srcx;
118     int subpic_srcy;
119     int subpic_srcw;
120     int subpic_srch;
121 
122     int subpic_dstx;
123     int subpic_dsty;
124     int subpic_dstw;
125     int subpic_dsth;
126 
127     /* only used by server side */
128     unsigned int num_constant;
129     unsigned int *constants;
130 
131     unsigned int mem_layout;
132     unsigned int tex_fmt;
133     unsigned int pack_mode;
134 
135     unsigned int fragment_start;
136     unsigned int fragment_end;
137 };
138 
139 typedef struct _PsbVASurface PsbVASurfaceRec;
140 typedef struct _PsbVASurface *PsbVASurfacePtr;
141 
142 
143 #ifndef VA_FRAME_PICTURE
144 
145 /* de-interlace flags for vaPutSurface */
146 #define VA_FRAME_PICTURE        0x00000000
147 #define VA_TOP_FIELD            0x00000001
148 #define VA_BOTTOM_FIELD         0x00000002
149 /*
150  * clears the drawable with background color.
151  * for hardware overlay based implementation this flag
152  * can be used to turn off the overlay
153  */
154 #define VA_CLEAR_DRAWABLE       0x00000008
155 
156 /* color space conversion flags for vaPutSurface */
157 #define VA_SRC_BT601            0x00000010
158 #define VA_SRC_BT709            0x00000020
159 
160 #endif /* end for _VA_X11_H_ */
161 
162 
163 
164 #define PSB_SUBPIC_MAX_NUM      6
165 #define PSB_CLIPBOX_MAX_NUM     6
166 
167 typedef struct _PsbXvVAPutSurface {
168     uint32_t flags;/* #define VA_FRAME_PICTURE 0x00000000
169                     * #define VA_TOP_FIELD     0x00000001
170                     * #define VA_BOTTOM_FIELD  0x00000002
171                     */
172     unsigned int num_subpicture;
173     unsigned int num_clipbox;
174 
175     PsbVASurfaceRec dst_srf; /* filled by Xserver */
176     PsbVASurfaceRec src_srf; /* provided by VA client */
177     PsbVASurfaceRec subpic_srf[PSB_SUBPIC_MAX_NUM];
178     VaClipBox clipbox[PSB_CLIPBOX_MAX_NUM];
179 } PsbXvVAPutSurfaceRec, *PsbXvVAPutSurfacePtr;
180 
181 #endif
182