OSDN Git Service

Add Wayland support.
[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_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                 4
45
46 #define INTEL_STR_DRIVER_VENDOR                 "Intel"
47 #define INTEL_STR_DRIVER_NAME                   "i965"
48
49 struct i965_kernel 
50 {
51     char *name;
52     int interface;
53     const uint32_t (*bin)[4];
54     int size;
55     dri_bo *bo;
56 };
57
58 struct buffer_store
59 {
60     unsigned char *buffer;
61     dri_bo *bo;
62     int ref_count;
63     int num_elements;
64 };
65     
66 struct object_config 
67 {
68     struct object_base base;
69     VAProfile profile;
70     VAEntrypoint entrypoint;
71     VAConfigAttrib attrib_list[I965_MAX_CONFIG_ATTRIBUTES];
72     int num_attribs;
73 };
74
75 #define NUM_SLICES     10
76
77 struct decode_state
78 {
79     struct buffer_store *pic_param;
80     struct buffer_store **slice_params;
81     struct buffer_store *iq_matrix;
82     struct buffer_store *bit_plane;
83     struct buffer_store *huffman_table;
84     struct buffer_store **slice_datas;
85     VASurfaceID current_render_target;
86     int max_slice_params;
87     int max_slice_datas;
88     int num_slice_params;
89     int num_slice_datas;
90 };
91
92 struct encode_state
93 {
94     struct buffer_store *seq_param;
95     struct buffer_store *pic_param;
96     struct buffer_store *pic_control;
97     struct buffer_store *iq_matrix;
98     struct buffer_store *q_matrix;
99     struct buffer_store **slice_params;
100     VASurfaceID current_render_target;
101     int max_slice_params;
102     int num_slice_params;
103 };
104
105 #define CODEC_DEC       0
106 #define CODEC_ENC       1
107
108 union codec_state
109 {
110     struct decode_state decode;
111     struct encode_state encode;
112 };
113
114 struct hw_context
115 {
116     void (*run)(VADriverContextP ctx, 
117                 VAProfile profile, 
118                 union codec_state *codec_state,
119                 struct hw_context *hw_context);
120     void (*destroy)(void *);
121     struct intel_batchbuffer *batch;
122 };
123
124 struct object_context 
125 {
126     struct object_base base;
127     VAContextID context_id;
128     VAConfigID config_id;
129     VASurfaceID *render_targets;                //input->encode, output->decode
130     int num_render_targets;
131     int picture_width;
132     int picture_height;
133     int flags;
134     int codec_type;
135     union codec_state codec_state;
136     struct hw_context *hw_context;
137 };
138
139 #define SURFACE_REFERENCED      (1 << 0)
140 #define SURFACE_DISPLAYED       (1 << 1)
141 #define SURFACE_DERIVED         (1 << 2)
142 #define SURFACE_REF_DIS_MASK    ((SURFACE_REFERENCED) | \
143                                  (SURFACE_DISPLAYED))
144 #define SURFACE_ALL_MASK        ((SURFACE_REFERENCED) | \
145                                  (SURFACE_DISPLAYED) |  \
146                                  (SURFACE_DERIVED))
147
148 struct object_surface 
149 {
150     struct object_base base;
151     VASurfaceStatus status;
152     VASubpictureID subpic;
153     int width;
154     int height;
155     int size;
156     int orig_width;
157     int orig_height;
158     int flags;
159     unsigned int fourcc;    
160     dri_bo *bo;
161     VAImageID locked_image_id;
162     void (*free_private_data)(void **data);
163     void *private_data;
164     unsigned int subsampling;
165     int x_cb_offset;
166     int y_cb_offset;
167     int x_cr_offset;
168     int y_cr_offset;
169     int cb_cr_width;
170     int cb_cr_height;
171     int cb_cr_pitch;
172 };
173
174 struct object_buffer 
175 {
176     struct object_base base;
177     struct buffer_store *buffer_store;
178     int max_num_elements;
179     int num_elements;
180     int size_element;
181     VABufferType type;
182 };
183
184 struct object_image 
185 {
186     struct object_base base;
187     VAImage image;
188     dri_bo *bo;
189     unsigned int *palette;
190     VASurfaceID derived_surface;
191 };
192
193 struct object_subpic 
194 {
195     struct object_base base;
196     VAImageID image;
197     VARectangle src_rect;
198     VARectangle dst_rect;
199     unsigned int format;
200     int width;
201     int height;
202     int pitch;
203     dri_bo *bo;
204     unsigned int flags;
205 };
206
207 struct hw_codec_info
208 {
209     struct hw_context *(*dec_hw_context_init)(VADriverContextP, VAProfile);
210     struct hw_context *(*enc_hw_context_init)(VADriverContextP, VAProfile);
211     int max_width;
212     int max_height;
213 };
214
215
216 #include "i965_render.h"
217
218 struct i965_driver_data 
219 {
220     struct intel_driver_data intel;
221     struct object_heap config_heap;
222     struct object_heap context_heap;
223     struct object_heap surface_heap;
224     struct object_heap buffer_heap;
225     struct object_heap image_heap;
226     struct object_heap subpic_heap;
227     struct hw_codec_info *codec_info;
228
229     _I965Mutex render_mutex;
230     struct intel_batchbuffer *batch;
231     struct i965_render_state render_state;
232     void *pp_context;
233     char va_vendor[256];
234  
235     VADisplayAttribute *display_attributes;
236     unsigned int num_display_attributes;
237     VADisplayAttribute *rotation_attrib;
238
239     /* VA/DRI (X11) specific data */
240     struct va_dri_output *dri_output;
241
242     /* VA/Wayland specific data */
243     struct va_wl_output *wl_output;
244 };
245
246 #define NEW_CONFIG_ID() object_heap_allocate(&i965->config_heap);
247 #define NEW_CONTEXT_ID() object_heap_allocate(&i965->context_heap);
248 #define NEW_SURFACE_ID() object_heap_allocate(&i965->surface_heap);
249 #define NEW_BUFFER_ID() object_heap_allocate(&i965->buffer_heap);
250 #define NEW_IMAGE_ID() object_heap_allocate(&i965->image_heap);
251 #define NEW_SUBPIC_ID() object_heap_allocate(&i965->subpic_heap);
252
253 #define CONFIG(id) ((struct object_config *)object_heap_lookup(&i965->config_heap, id))
254 #define CONTEXT(id) ((struct object_context *)object_heap_lookup(&i965->context_heap, id))
255 #define SURFACE(id) ((struct object_surface *)object_heap_lookup(&i965->surface_heap, id))
256 #define BUFFER(id) ((struct object_buffer *)object_heap_lookup(&i965->buffer_heap, id))
257 #define IMAGE(id) ((struct object_image *)object_heap_lookup(&i965->image_heap, id))
258 #define SUBPIC(id) ((struct object_subpic *)object_heap_lookup(&i965->subpic_heap, id))
259
260 #define FOURCC_IA44 0x34344149
261 #define FOURCC_AI44 0x34344941
262
263 #define STRIDE(w)               (((w) + 0xf) & ~0xf)
264 #define SIZE_YUV420(w, h)       (h * (STRIDE(w) + STRIDE(w >> 1)))
265
266 static INLINE struct i965_driver_data *
267 i965_driver_data(VADriverContextP ctx)
268 {
269     return (struct i965_driver_data *)(ctx->pDriverData);
270 }
271
272 void 
273 i965_check_alloc_surface_bo(VADriverContextP ctx,
274                             struct object_surface *obj_surface,
275                             int tiled,
276                             unsigned int fourcc,
277                             unsigned int subsampling);
278
279 #endif /* _I965_DRV_VIDEO_H_ */