OSDN Git Service

89ce9061051c6d3857226da9076d311cd9d3b26d
[android-x86/hardware-intel-common-vaapi.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_enc_h264.h>
35 #include <va/va_vpp.h>
36 #include <va/va_backend.h>
37 #include <va/va_backend_vpp.h>
38
39 #include "i965_mutext.h"
40 #include "object_heap.h"
41 #include "intel_driver.h"
42
43 #define I965_MAX_PROFILES                       11
44 #define I965_MAX_ENTRYPOINTS                    5
45 #define I965_MAX_CONFIG_ATTRIBUTES              10
46 #define I965_MAX_IMAGE_FORMATS                  10
47 #define I965_MAX_SUBPIC_FORMATS                 4
48
49 #define INTEL_STR_DRIVER_VENDOR                 "Intel"
50 #define INTEL_STR_DRIVER_NAME                   "i965"
51
52 #define I965_SURFACE_TYPE_IMAGE                 0
53 #define I965_SURFACE_TYPE_SURFACE               1
54
55 #define I965_SURFACE_FLAG_FRAME                 0x00000000
56 #define I965_SURFACE_FLAG_TOP_FIELD_FIRST       0x00000001
57 #define I965_SURFACE_FLAG_BOTTOME_FIELD_FIRST   0x00000002
58
59 struct i965_surface
60 {
61     VAGenericID id;
62     int type;
63     int flags;
64 };
65
66 struct i965_kernel 
67 {
68     char *name;
69     int interface;
70     const uint32_t (*bin)[4];
71     int size;
72     dri_bo *bo;
73 };
74
75 struct buffer_store
76 {
77     unsigned char *buffer;
78     dri_bo *bo;
79     int ref_count;
80     int num_elements;
81 };
82     
83 struct object_config 
84 {
85     struct object_base base;
86     VAProfile profile;
87     VAEntrypoint entrypoint;
88     VAConfigAttrib attrib_list[I965_MAX_CONFIG_ATTRIBUTES];
89     int num_attribs;
90 };
91
92 #define NUM_SLICES     10
93
94 struct decode_state
95 {
96     struct buffer_store *pic_param;
97     struct buffer_store **slice_params;
98     struct buffer_store *iq_matrix;
99     struct buffer_store *bit_plane;
100     struct buffer_store *huffman_table;
101     struct buffer_store **slice_datas;
102     VASurfaceID current_render_target;
103     int max_slice_params;
104     int max_slice_datas;
105     int num_slice_params;
106     int num_slice_datas;
107 };
108
109 struct encode_state
110 {
111     struct buffer_store *seq_param;
112     struct buffer_store *pic_param;
113     struct buffer_store *pic_control;
114     struct buffer_store *iq_matrix;
115     struct buffer_store *q_matrix;
116     struct buffer_store **slice_params;
117     int max_slice_params;
118     int num_slice_params;
119
120     /* for ext */
121     struct buffer_store *seq_param_ext;
122     struct buffer_store *pic_param_ext;
123     struct buffer_store *packed_header_param[4];
124     struct buffer_store *packed_header_data[4];
125     struct buffer_store **slice_params_ext;
126     int max_slice_params_ext;
127     int num_slice_params_ext;
128     int last_packed_header_type;
129
130     struct buffer_store *misc_param[8];
131
132     VASurfaceID current_render_target;
133 };
134
135 struct proc_state
136 {
137     struct buffer_store *pipeline_param;
138
139     VASurfaceID current_render_target;
140 };
141
142 #define CODEC_DEC       0
143 #define CODEC_ENC       1
144 #define CODEC_PROC      2
145
146 union codec_state
147 {
148     struct decode_state decode;
149     struct encode_state encode;
150     struct proc_state proc;
151 };
152
153 struct hw_context
154 {
155     void (*run)(VADriverContextP ctx, 
156                 VAProfile profile, 
157                 union codec_state *codec_state,
158                 struct hw_context *hw_context);
159     void (*destroy)(void *);
160     struct intel_batchbuffer *batch;
161 };
162
163 struct object_context 
164 {
165     struct object_base base;
166     VAContextID context_id;
167     VAConfigID config_id;
168     VASurfaceID *render_targets;                //input->encode, output->decode
169     int num_render_targets;
170     int picture_width;
171     int picture_height;
172     int flags;
173     int codec_type;
174     union codec_state codec_state;
175     struct hw_context *hw_context;
176 };
177
178 #define SURFACE_REFERENCED      (1 << 0)
179 #define SURFACE_DISPLAYED       (1 << 1)
180 #define SURFACE_DERIVED         (1 << 2)
181 #define SURFACE_REF_DIS_MASK    ((SURFACE_REFERENCED) | \
182                                  (SURFACE_DISPLAYED))
183 #define SURFACE_ALL_MASK        ((SURFACE_REFERENCED) | \
184                                  (SURFACE_DISPLAYED) |  \
185                                  (SURFACE_DERIVED))
186
187 struct object_surface 
188 {
189     struct object_base base;
190     VASurfaceStatus status;
191     VASubpictureID subpic;
192     int width;
193     int height;
194     int size;
195     int orig_width;
196     int orig_height;
197     int flags;
198     unsigned int fourcc;    
199     dri_bo *bo;
200     VAImageID locked_image_id;
201     void (*free_private_data)(void **data);
202     void *private_data;
203     unsigned int subsampling;
204     int x_cb_offset;
205     int y_cb_offset;
206     int x_cr_offset;
207     int y_cr_offset;
208     int cb_cr_width;
209     int cb_cr_height;
210     int cb_cr_pitch;
211 };
212
213 struct object_buffer 
214 {
215     struct object_base base;
216     struct buffer_store *buffer_store;
217     int max_num_elements;
218     int num_elements;
219     int size_element;
220     VABufferType type;
221 };
222
223 struct object_image 
224 {
225     struct object_base base;
226     VAImage image;
227     dri_bo *bo;
228     unsigned int *palette;
229     VASurfaceID derived_surface;
230 };
231
232 struct object_subpic 
233 {
234     struct object_base base;
235     VAImageID image;
236     VARectangle src_rect;
237     VARectangle dst_rect;
238     unsigned int format;
239     int width;
240     int height;
241     int pitch;
242     dri_bo *bo;
243     unsigned int flags;
244 };
245
246 struct hw_codec_info
247 {
248     struct hw_context *(*dec_hw_context_init)(VADriverContextP, struct object_config *);
249     struct hw_context *(*enc_hw_context_init)(VADriverContextP, struct object_config *);
250     struct hw_context *(*proc_hw_context_init)(VADriverContextP, struct object_config *);
251     int max_width;
252     int max_height;
253 };
254
255
256 #include "i965_render.h"
257
258 struct i965_driver_data 
259 {
260     struct intel_driver_data intel;
261     struct object_heap config_heap;
262     struct object_heap context_heap;
263     struct object_heap surface_heap;
264     struct object_heap buffer_heap;
265     struct object_heap image_heap;
266     struct object_heap subpic_heap;
267     struct hw_codec_info *codec_info;
268
269     _I965Mutex render_mutex;
270     _I965Mutex pp_mutex;
271     struct intel_batchbuffer *batch;
272     struct i965_render_state render_state;
273     void *pp_context;
274     char va_vendor[256];
275  
276     VADisplayAttribute *display_attributes;
277     unsigned int num_display_attributes;
278     
279     VAContextID current_context_id;
280
281     /* VA/DRI (X11) specific data */
282     struct va_dri_output *dri_output;
283
284     /* VA/Wayland specific data */
285     struct va_wl_output *wl_output;
286 };
287
288 #define NEW_CONFIG_ID() object_heap_allocate(&i965->config_heap);
289 #define NEW_CONTEXT_ID() object_heap_allocate(&i965->context_heap);
290 #define NEW_SURFACE_ID() object_heap_allocate(&i965->surface_heap);
291 #define NEW_BUFFER_ID() object_heap_allocate(&i965->buffer_heap);
292 #define NEW_IMAGE_ID() object_heap_allocate(&i965->image_heap);
293 #define NEW_SUBPIC_ID() object_heap_allocate(&i965->subpic_heap);
294
295 #define CONFIG(id) ((struct object_config *)object_heap_lookup(&i965->config_heap, id))
296 #define CONTEXT(id) ((struct object_context *)object_heap_lookup(&i965->context_heap, id))
297 #define SURFACE(id) ((struct object_surface *)object_heap_lookup(&i965->surface_heap, id))
298 #define BUFFER(id) ((struct object_buffer *)object_heap_lookup(&i965->buffer_heap, id))
299 #define IMAGE(id) ((struct object_image *)object_heap_lookup(&i965->image_heap, id))
300 #define SUBPIC(id) ((struct object_subpic *)object_heap_lookup(&i965->subpic_heap, id))
301
302 #define FOURCC_IA44 0x34344149
303 #define FOURCC_AI44 0x34344941
304
305 #define STRIDE(w)               (((w) + 0xf) & ~0xf)
306 #define SIZE_YUV420(w, h)       (h * (STRIDE(w) + STRIDE(w >> 1)))
307
308 static INLINE struct i965_driver_data *
309 i965_driver_data(VADriverContextP ctx)
310 {
311     return (struct i965_driver_data *)(ctx->pDriverData);
312 }
313
314 void 
315 i965_check_alloc_surface_bo(VADriverContextP ctx,
316                             struct object_surface *obj_surface,
317                             int tiled,
318                             unsigned int fourcc,
319                             unsigned int subsampling);
320
321 int
322 va_enc_packed_type_to_idx(int packed_type);
323
324 /* reserve 1 byte for internal using */
325 #define I965_CODEDBUFFER_SIZE   ALIGN(sizeof(VACodedBufferSegment) + 1, 64)
326
327 #endif /* _I965_DRV_VIDEO_H_ */