Render: Add AI88/IA88 surface foramt support for subpicture
[platform/upstream/libva-intel-driver.git] / src / i965_drv_video.h
1 /*
2  * Copyright © 2009 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *    Xiang Haihao <haihao.xiang@intel.com>
26  *    Zou Nan hai <nanhai.zou@intel.com>
27  *
28  */
29
30 #ifndef _I965_DRV_VIDEO_H_
31 #define _I965_DRV_VIDEO_H_
32
33 #include <va/va.h>
34 #include <va/va_backend.h>
35
36 #include "i965_mutext.h"
37 #include "object_heap.h"
38 #include "intel_driver.h"
39
40 #define I965_MAX_PROFILES                       11
41 #define I965_MAX_ENTRYPOINTS                    5
42 #define I965_MAX_CONFIG_ATTRIBUTES              10
43 #define I965_MAX_IMAGE_FORMATS                  3
44 #define I965_MAX_SUBPIC_FORMATS                 6
45
46 #define INTEL_STR_DRIVER_VENDOR                 "Intel"
47 #define INTEL_STR_DRIVER_NAME                   "i965"
48
49 #define I965_SURFACE_TYPE_IMAGE                   0
50 #define I965_SURFACE_TYPE_SURFACE                 1
51
52 #define I965_SURFACE_FLAG_FRAME                  0x00000000
53 #define I965_SURFACE_FLAG_TOP_FIELD_FIRST        0x00000001
54 #define I965_SURFACE_FLAG_BOTTOM_FIELD_FIRST     0x00000002
55
56 struct i965_surface
57 {
58     VAGenericID id;
59     int type;
60     int flags;
61 };
62
63 struct i965_kernel 
64 {
65     char *name;
66     int interface;
67     const uint32_t (*bin)[4];
68     int size;
69     dri_bo *bo;
70 };
71
72 struct buffer_store
73 {
74     unsigned char *buffer;
75     dri_bo *bo;
76     int ref_count;
77     int num_elements;
78 };
79     
80 struct object_config 
81 {
82     struct object_base base;
83     VAProfile profile;
84     VAEntrypoint entrypoint;
85     VAConfigAttrib attrib_list[I965_MAX_CONFIG_ATTRIBUTES];
86     int num_attribs;
87 };
88
89 #define NUM_SLICES     10
90
91 struct decode_state
92 {
93     struct buffer_store *pic_param;
94     struct buffer_store **slice_params;
95     struct buffer_store *iq_matrix;
96     struct buffer_store *bit_plane;
97     struct buffer_store *huffman_table;
98     struct buffer_store **slice_datas;
99     VASurfaceID current_render_target;
100     int max_slice_params;
101     int max_slice_datas;
102     int num_slice_params;
103     int num_slice_datas;
104 };
105
106 struct encode_state
107 {
108     struct buffer_store *seq_param;
109     struct buffer_store *pic_param;
110     struct buffer_store *pic_control;
111     struct buffer_store *iq_matrix;
112     struct buffer_store *q_matrix;
113     struct buffer_store **slice_params;
114     VASurfaceID current_render_target;
115     int max_slice_params;
116     int num_slice_params;
117 };
118
119 #define CODEC_DEC       0
120 #define CODEC_ENC       1
121
122 union codec_state
123 {
124     struct decode_state decode;
125     struct encode_state encode;
126 };
127
128 struct hw_context
129 {
130     void (*run)(VADriverContextP ctx, 
131                 VAProfile profile, 
132                 union codec_state *codec_state,
133                 struct hw_context *hw_context);
134     void (*destroy)(void *);
135     struct intel_batchbuffer *batch;
136 };
137
138 struct object_context 
139 {
140     struct object_base base;
141     VAContextID context_id;
142     VAConfigID config_id;
143     VASurfaceID *render_targets;                //input->encode, output->decode
144     int num_render_targets;
145     int picture_width;
146     int picture_height;
147     int flags;
148     int codec_type;
149     union codec_state codec_state;
150     struct hw_context *hw_context;
151 };
152
153 #define SURFACE_REFERENCED      (1 << 0)
154 #define SURFACE_DISPLAYED       (1 << 1)
155 #define SURFACE_DERIVED         (1 << 2)
156 #define SURFACE_REF_DIS_MASK    ((SURFACE_REFERENCED) | \
157                                  (SURFACE_DISPLAYED))
158 #define SURFACE_ALL_MASK        ((SURFACE_REFERENCED) | \
159                                  (SURFACE_DISPLAYED) |  \
160                                  (SURFACE_DERIVED))
161
162 struct object_surface 
163 {
164     struct object_base base;
165     VASurfaceStatus status;
166     VASubpictureID subpic;
167     int width;
168     int height;
169     int size;
170     int orig_width;
171     int orig_height;
172     int flags;
173     unsigned int fourcc;    
174     dri_bo *bo;
175     VAImageID locked_image_id;
176     void (*free_private_data)(void **data);
177     void *private_data;
178     unsigned int subsampling;
179     int x_cb_offset;
180     int y_cb_offset;
181     int x_cr_offset;
182     int y_cr_offset;
183     int cb_cr_width;
184     int cb_cr_height;
185     int cb_cr_pitch;
186 };
187
188 struct object_buffer 
189 {
190     struct object_base base;
191     struct buffer_store *buffer_store;
192     int max_num_elements;
193     int num_elements;
194     int size_element;
195     VABufferType type;
196 };
197
198 struct object_image 
199 {
200     struct object_base base;
201     VAImage image;
202     dri_bo *bo;
203     unsigned int *palette;
204     VASurfaceID derived_surface;
205 };
206
207 struct object_subpic 
208 {
209     struct object_base base;
210     VAImageID image;
211     VARectangle src_rect;
212     VARectangle dst_rect;
213     unsigned int format;
214     int width;
215     int height;
216     int pitch;
217     float global_alpha;
218     dri_bo *bo;
219     unsigned int flags;
220 };
221
222 struct hw_codec_info
223 {
224     struct hw_context *(*dec_hw_context_init)(VADriverContextP, VAProfile);
225     struct hw_context *(*enc_hw_context_init)(VADriverContextP, VAProfile);
226     int max_width;
227     int max_height;
228 };
229
230
231 #include "i965_render.h"
232
233 struct i965_driver_data 
234 {
235     struct intel_driver_data intel;
236     struct object_heap config_heap;
237     struct object_heap context_heap;
238     struct object_heap surface_heap;
239     struct object_heap buffer_heap;
240     struct object_heap image_heap;
241     struct object_heap subpic_heap;
242     struct hw_codec_info *codec_info;
243
244     _I965Mutex render_mutex;
245     struct intel_batchbuffer *batch;
246     struct i965_render_state render_state;
247     void *pp_context;
248     char va_vendor[256];
249  
250     VADisplayAttribute *display_attributes;
251     unsigned int num_display_attributes;
252     VADisplayAttribute *rotation_attrib;
253
254     /* VA/DRI (X11) specific data */
255     struct va_dri_output *dri_output;
256
257     /* VA/Wayland specific data */
258     struct va_wl_output *wl_output;
259 };
260
261 #define NEW_CONFIG_ID() object_heap_allocate(&i965->config_heap);
262 #define NEW_CONTEXT_ID() object_heap_allocate(&i965->context_heap);
263 #define NEW_SURFACE_ID() object_heap_allocate(&i965->surface_heap);
264 #define NEW_BUFFER_ID() object_heap_allocate(&i965->buffer_heap);
265 #define NEW_IMAGE_ID() object_heap_allocate(&i965->image_heap);
266 #define NEW_SUBPIC_ID() object_heap_allocate(&i965->subpic_heap);
267
268 #define CONFIG(id) ((struct object_config *)object_heap_lookup(&i965->config_heap, id))
269 #define CONTEXT(id) ((struct object_context *)object_heap_lookup(&i965->context_heap, id))
270 #define SURFACE(id) ((struct object_surface *)object_heap_lookup(&i965->surface_heap, id))
271 #define BUFFER(id) ((struct object_buffer *)object_heap_lookup(&i965->buffer_heap, id))
272 #define IMAGE(id) ((struct object_image *)object_heap_lookup(&i965->image_heap, id))
273 #define SUBPIC(id) ((struct object_subpic *)object_heap_lookup(&i965->subpic_heap, id))
274
275 #define FOURCC_IA44 0x34344149
276 #define FOURCC_AI44 0x34344941
277
278 #define STRIDE(w)               (((w) + 0xf) & ~0xf)
279 #define SIZE_YUV420(w, h)       (h * (STRIDE(w) + STRIDE(w >> 1)))
280
281 static INLINE struct i965_driver_data *
282 i965_driver_data(VADriverContextP ctx)
283 {
284     return (struct i965_driver_data *)(ctx->pDriverData);
285 }
286
287 void 
288 i965_check_alloc_surface_bo(VADriverContextP ctx,
289                             struct object_surface *obj_surface,
290                             int tiled,
291                             unsigned int fourcc,
292                             unsigned int subsampling);
293
294
295 extern VAStatus i965_MapBuffer(VADriverContextP ctx,
296                 VABufferID buf_id,       /* in */
297                 void **pbuf);            /* out */
298
299 extern VAStatus i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id);
300
301 #endif /* _I965_DRV_VIDEO_H_ */