[g3dvl] rework video buffer format handling
[mesa.git] / src / gallium / include / pipe / p_video_context.h
1 /**************************************************************************
2 *
3 * Copyright 2009 Younes Manton.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef PIPE_VIDEO_CONTEXT_H
29 #define PIPE_VIDEO_CONTEXT_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #include <pipe/p_video_state.h>
36
37 struct pipe_screen;
38 struct pipe_surface;
39 struct pipe_macroblock;
40 struct pipe_picture_desc;
41 struct pipe_fence_handle;
42
43 /**
44 * Gallium video rendering context
45 */
46 struct pipe_video_context
47 {
48 struct pipe_screen *screen;
49
50 void *priv; /**< context private data (for DRI for example) */
51
52 /**
53 * destroy context, all objects created from this context
54 * (buffers, decoders, compositors etc...) must be freed before calling this
55 */
56 void (*destroy)(struct pipe_video_context *context);
57
58 /**
59 * Query an integer-valued capability/parameter/limit
60 * \param param one of PIPE_CAP_x
61 */
62 int (*get_param)(struct pipe_video_context *context, int param);
63
64 /**
65 * Check if the given pipe_format is supported as a video buffer
66 */
67 boolean (*is_format_supported)(struct pipe_video_context *context,
68 enum pipe_format format,
69 enum pipe_video_profile profile);
70
71 /**
72 * create a surface of a texture
73 */
74 struct pipe_surface *(*create_surface)(struct pipe_video_context *context,
75 struct pipe_resource *resource,
76 const struct pipe_surface *templ);
77
78 /**
79 * sampler view handling, used for subpictures for example
80 */
81 /*@{*/
82
83 /**
84 * create a sampler view of a texture, for subpictures for example
85 */
86 struct pipe_sampler_view *(*create_sampler_view)(struct pipe_video_context *context,
87 struct pipe_resource *resource,
88 const struct pipe_sampler_view *templ);
89
90 /**
91 * upload image data to a sampler
92 */
93 void (*upload_sampler)(struct pipe_video_context *context,
94 struct pipe_sampler_view *dst,
95 const struct pipe_box *dst_box,
96 const void *src, unsigned src_stride,
97 unsigned src_x, unsigned src_y);
98
99 /**
100 * clear a sampler with a specific rgba color
101 */
102 void (*clear_sampler)(struct pipe_video_context *context,
103 struct pipe_sampler_view *dst,
104 const struct pipe_box *dst_box,
105 const float *rgba);
106
107 /*}@*/
108
109 /**
110 * create a decoder for a specific video profile
111 */
112 struct pipe_video_decoder *(*create_decoder)(struct pipe_video_context *context,
113 enum pipe_video_profile profile,
114 enum pipe_video_entrypoint entrypoint,
115 enum pipe_video_chroma_format chroma_format,
116 unsigned width, unsigned height);
117
118 /**
119 * Creates a buffer as decoding target
120 */
121 struct pipe_video_buffer *(*create_buffer)(struct pipe_video_context *context,
122 enum pipe_format buffer_format,
123 enum pipe_video_chroma_format chroma_format,
124 unsigned width, unsigned height);
125
126 /**
127 * Creates a video compositor
128 */
129 struct pipe_video_compositor *(*create_compositor)(struct pipe_video_context *context);
130 };
131
132 /**
133 * decoder for a specific video codec
134 */
135 struct pipe_video_decoder
136 {
137 struct pipe_video_context *context;
138
139 enum pipe_video_profile profile;
140 enum pipe_video_entrypoint entrypoint;
141 enum pipe_video_chroma_format chroma_format;
142 unsigned width;
143 unsigned height;
144
145 /**
146 * destroy this video decoder
147 */
148 void (*destroy)(struct pipe_video_decoder *decoder);
149
150 /**
151 * Creates a buffer as decoding input
152 */
153 struct pipe_video_decode_buffer *(*create_buffer)(struct pipe_video_decoder *decoder);
154
155 /**
156 * flush decoder buffer to video hardware
157 */
158 void (*flush_buffer)(struct pipe_video_decode_buffer *decbuf,
159 unsigned num_ycbcr_blocks[3],
160 struct pipe_video_buffer *ref_frames[2],
161 struct pipe_video_buffer *dst);
162 };
163
164 /**
165 * input buffer for a decoder
166 */
167 struct pipe_video_decode_buffer
168 {
169 struct pipe_video_decoder *decoder;
170
171 /**
172 * destroy this decode buffer
173 */
174 void (*destroy)(struct pipe_video_decode_buffer *decbuf);
175
176 /**
177 * map the input buffer into memory before starting decoding
178 */
179 void (*begin_frame)(struct pipe_video_decode_buffer *decbuf);
180
181 /**
182 * set the quantification matrixes
183 */
184 void (*set_quant_matrix)(struct pipe_video_decode_buffer *decbuf,
185 const uint8_t intra_matrix[64],
186 const uint8_t non_intra_matrix[64]);
187
188 /**
189 * get the pointer where to put the ycbcr blocks of a component
190 */
191 struct pipe_ycbcr_block *(*get_ycbcr_stream)(struct pipe_video_decode_buffer *, int component);
192
193 /**
194 * get the pointer where to put the ycbcr dct block data of a component
195 */
196 short *(*get_ycbcr_buffer)(struct pipe_video_decode_buffer *, int component);
197
198 /**
199 * get the stride of the mv buffer
200 */
201 unsigned (*get_mv_stream_stride)(struct pipe_video_decode_buffer *decbuf);
202
203 /**
204 * get the pointer where to put the motion vectors of a ref frame
205 */
206 struct pipe_motionvector *(*get_mv_stream)(struct pipe_video_decode_buffer *decbuf, int ref_frame);
207
208 /**
209 * decode a bitstream
210 */
211 void (*decode_bitstream)(struct pipe_video_decode_buffer *decbuf,
212 unsigned num_bytes, const void *data,
213 struct pipe_mpeg12_picture_desc *picture,
214 unsigned num_ycbcr_blocks[3]);
215
216 /**
217 * unmap decoder buffer before flushing
218 */
219 void (*end_frame)(struct pipe_video_decode_buffer *decbuf);
220 };
221
222 /**
223 * output for decoding / input for displaying
224 */
225 struct pipe_video_buffer
226 {
227 struct pipe_video_context *context;
228
229 enum pipe_format buffer_format;
230 enum pipe_video_chroma_format chroma_format;
231 unsigned width;
232 unsigned height;
233
234 /**
235 * destroy this video buffer
236 */
237 void (*destroy)(struct pipe_video_buffer *buffer);
238
239 /**
240 * get a individual sampler view for each plane
241 */
242 struct pipe_sampler_view **(*get_sampler_view_planes)(struct pipe_video_buffer *buffer);
243
244 /**
245 * get a individual sampler view for each component
246 */
247 struct pipe_sampler_view **(*get_sampler_view_components)(struct pipe_video_buffer *buffer);
248
249 /**
250 * get a individual surfaces for each plane
251 */
252 struct pipe_surface **(*get_surfaces)(struct pipe_video_buffer *buffer);
253 };
254
255 /**
256 * composing and displaying of image data
257 */
258 struct pipe_video_compositor
259 {
260 struct pipe_video_context *context;
261
262 /**
263 * destroy this compositor
264 */
265 void (*destroy)(struct pipe_video_compositor *compositor);
266
267 /**
268 * set yuv -> rgba conversion matrix
269 */
270 void (*set_csc_matrix)(struct pipe_video_compositor *compositor, const float mat[16]);
271
272 /**
273 * reset dirty area, so it's cleared with the clear colour
274 */
275 void (*reset_dirty_area)(struct pipe_video_compositor *compositor);
276
277 /**
278 * set the clear color
279 */
280 void (*set_clear_color)(struct pipe_video_compositor *compositor, float color[4]);
281
282 /**
283 * set overlay samplers
284 */
285 /*@{*/
286
287 /**
288 * reset all currently set layers
289 */
290 void (*clear_layers)(struct pipe_video_compositor *compositor);
291
292 /**
293 * set a video buffer as a layer to render
294 */
295 void (*set_buffer_layer)(struct pipe_video_compositor *compositor,
296 unsigned layer,
297 struct pipe_video_buffer *buffer,
298 struct pipe_video_rect *src_rect,
299 struct pipe_video_rect *dst_rect);
300
301 /**
302 * set a paletted sampler as a layer to render
303 */
304 void (*set_palette_layer)(struct pipe_video_compositor *compositor,
305 unsigned layer,
306 struct pipe_sampler_view *indexes,
307 struct pipe_sampler_view *palette,
308 struct pipe_video_rect *src_rect,
309 struct pipe_video_rect *dst_rect);
310
311 /**
312 * set a rgba sampler as a layer to render
313 */
314 void (*set_rgba_layer)(struct pipe_video_compositor *compositor,
315 unsigned layer,
316 struct pipe_sampler_view *rgba,
317 struct pipe_video_rect *src_rect,
318 struct pipe_video_rect *dst_rect);
319
320 /*@}*/
321
322 /**
323 * render the layers to the frontbuffer
324 */
325 void (*render_picture)(struct pipe_video_compositor *compositor,
326 enum pipe_mpeg12_picture_type picture_type,
327 struct pipe_surface *dst_surface,
328 struct pipe_video_rect *dst_area,
329 struct pipe_fence_handle **fence);
330
331 };
332
333 #ifdef __cplusplus
334 }
335 #endif
336
337 #endif /* PIPE_VIDEO_CONTEXT_H */