1fb635f17560ad86b9c27bc36305c617943e5398
[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 * Check if the given pipe_format is supported as a video buffer
60 */
61 boolean (*is_format_supported)(struct pipe_video_context *context,
62 enum pipe_format format,
63 enum pipe_video_profile profile);
64
65 /**
66 * create a surface of a texture
67 */
68 struct pipe_surface *(*create_surface)(struct pipe_video_context *context,
69 struct pipe_resource *resource,
70 const struct pipe_surface *templ);
71
72 /**
73 * sampler view handling, used for subpictures for example
74 */
75 /*@{*/
76
77 /**
78 * create a sampler view of a texture, for subpictures for example
79 */
80 struct pipe_sampler_view *(*create_sampler_view)(struct pipe_video_context *context,
81 struct pipe_resource *resource,
82 const struct pipe_sampler_view *templ);
83
84 /**
85 * upload image data to a sampler
86 */
87 void (*upload_sampler)(struct pipe_video_context *context,
88 struct pipe_sampler_view *dst,
89 const struct pipe_box *dst_box,
90 const void *src, unsigned src_stride,
91 unsigned src_x, unsigned src_y);
92
93 /**
94 * clear a sampler with a specific rgba color
95 */
96 void (*clear_sampler)(struct pipe_video_context *context,
97 struct pipe_sampler_view *dst,
98 const struct pipe_box *dst_box,
99 const float *rgba);
100
101 /*}@*/
102
103 /**
104 * create a decoder for a specific video profile
105 */
106 struct pipe_video_decoder *(*create_decoder)(struct pipe_video_context *context,
107 enum pipe_video_profile profile,
108 enum pipe_video_entrypoint entrypoint,
109 enum pipe_video_chroma_format chroma_format,
110 unsigned width, unsigned height);
111
112 /**
113 * Creates a buffer as decoding target
114 */
115 struct pipe_video_buffer *(*create_buffer)(struct pipe_video_context *context,
116 enum pipe_format buffer_format,
117 enum pipe_video_chroma_format chroma_format,
118 unsigned width, unsigned height);
119
120 /**
121 * Creates a video compositor
122 */
123 struct pipe_video_compositor *(*create_compositor)(struct pipe_video_context *context);
124 };
125
126 /**
127 * decoder for a specific video codec
128 */
129 struct pipe_video_decoder
130 {
131 struct pipe_video_context *context;
132
133 enum pipe_video_profile profile;
134 enum pipe_video_entrypoint entrypoint;
135 enum pipe_video_chroma_format chroma_format;
136 unsigned width;
137 unsigned height;
138
139 /**
140 * destroy this video decoder
141 */
142 void (*destroy)(struct pipe_video_decoder *decoder);
143
144 /**
145 * Creates a buffer as decoding input
146 */
147 struct pipe_video_decode_buffer *(*create_buffer)(struct pipe_video_decoder *decoder);
148
149 /**
150 * flush decoder buffer to video hardware
151 */
152 void (*flush_buffer)(struct pipe_video_decode_buffer *decbuf,
153 unsigned num_ycbcr_blocks[3],
154 struct pipe_video_buffer *ref_frames[2],
155 struct pipe_video_buffer *dst);
156 };
157
158 /**
159 * input buffer for a decoder
160 */
161 struct pipe_video_decode_buffer
162 {
163 struct pipe_video_decoder *decoder;
164
165 /**
166 * destroy this decode buffer
167 */
168 void (*destroy)(struct pipe_video_decode_buffer *decbuf);
169
170 /**
171 * map the input buffer into memory before starting decoding
172 */
173 void (*begin_frame)(struct pipe_video_decode_buffer *decbuf);
174
175 /**
176 * set the quantification matrixes
177 */
178 void (*set_quant_matrix)(struct pipe_video_decode_buffer *decbuf,
179 const uint8_t intra_matrix[64],
180 const uint8_t non_intra_matrix[64]);
181
182 /**
183 * get the pointer where to put the ycbcr blocks of a component
184 */
185 struct pipe_ycbcr_block *(*get_ycbcr_stream)(struct pipe_video_decode_buffer *, int component);
186
187 /**
188 * get the pointer where to put the ycbcr dct block data of a component
189 */
190 short *(*get_ycbcr_buffer)(struct pipe_video_decode_buffer *, int component);
191
192 /**
193 * get the stride of the mv buffer
194 */
195 unsigned (*get_mv_stream_stride)(struct pipe_video_decode_buffer *decbuf);
196
197 /**
198 * get the pointer where to put the motion vectors of a ref frame
199 */
200 struct pipe_motionvector *(*get_mv_stream)(struct pipe_video_decode_buffer *decbuf, int ref_frame);
201
202 /**
203 * decode a bitstream
204 */
205 void (*decode_bitstream)(struct pipe_video_decode_buffer *decbuf,
206 unsigned num_bytes, const void *data,
207 struct pipe_mpeg12_picture_desc *picture,
208 unsigned num_ycbcr_blocks[3]);
209
210 /**
211 * unmap decoder buffer before flushing
212 */
213 void (*end_frame)(struct pipe_video_decode_buffer *decbuf);
214 };
215
216 /**
217 * output for decoding / input for displaying
218 */
219 struct pipe_video_buffer
220 {
221 struct pipe_video_context *context;
222
223 enum pipe_format buffer_format;
224 enum pipe_video_chroma_format chroma_format;
225 unsigned width;
226 unsigned height;
227
228 /**
229 * destroy this video buffer
230 */
231 void (*destroy)(struct pipe_video_buffer *buffer);
232
233 /**
234 * get a individual sampler view for each plane
235 */
236 struct pipe_sampler_view **(*get_sampler_view_planes)(struct pipe_video_buffer *buffer);
237
238 /**
239 * get a individual sampler view for each component
240 */
241 struct pipe_sampler_view **(*get_sampler_view_components)(struct pipe_video_buffer *buffer);
242
243 /**
244 * get a individual surfaces for each plane
245 */
246 struct pipe_surface **(*get_surfaces)(struct pipe_video_buffer *buffer);
247 };
248
249 /**
250 * composing and displaying of image data
251 */
252 struct pipe_video_compositor
253 {
254 struct pipe_video_context *context;
255
256 /**
257 * destroy this compositor
258 */
259 void (*destroy)(struct pipe_video_compositor *compositor);
260
261 /**
262 * set yuv -> rgba conversion matrix
263 */
264 void (*set_csc_matrix)(struct pipe_video_compositor *compositor, const float mat[16]);
265
266 /**
267 * reset dirty area, so it's cleared with the clear colour
268 */
269 void (*reset_dirty_area)(struct pipe_video_compositor *compositor);
270
271 /**
272 * set the clear color
273 */
274 void (*set_clear_color)(struct pipe_video_compositor *compositor, float color[4]);
275
276 /**
277 * set overlay samplers
278 */
279 /*@{*/
280
281 /**
282 * reset all currently set layers
283 */
284 void (*clear_layers)(struct pipe_video_compositor *compositor);
285
286 /**
287 * set a video buffer as a layer to render
288 */
289 void (*set_buffer_layer)(struct pipe_video_compositor *compositor,
290 unsigned layer,
291 struct pipe_video_buffer *buffer,
292 struct pipe_video_rect *src_rect,
293 struct pipe_video_rect *dst_rect);
294
295 /**
296 * set a paletted sampler as a layer to render
297 */
298 void (*set_palette_layer)(struct pipe_video_compositor *compositor,
299 unsigned layer,
300 struct pipe_sampler_view *indexes,
301 struct pipe_sampler_view *palette,
302 struct pipe_video_rect *src_rect,
303 struct pipe_video_rect *dst_rect);
304
305 /**
306 * set a rgba sampler as a layer to render
307 */
308 void (*set_rgba_layer)(struct pipe_video_compositor *compositor,
309 unsigned layer,
310 struct pipe_sampler_view *rgba,
311 struct pipe_video_rect *src_rect,
312 struct pipe_video_rect *dst_rect);
313
314 /*@}*/
315
316 /**
317 * render the layers to the frontbuffer
318 */
319 void (*render_picture)(struct pipe_video_compositor *compositor,
320 enum pipe_mpeg12_picture_type picture_type,
321 struct pipe_surface *dst_surface,
322 struct pipe_video_rect *dst_area,
323 struct pipe_fence_handle **fence);
324
325 };
326
327 #ifdef __cplusplus
328 }
329 #endif
330
331 #endif /* PIPE_VIDEO_CONTEXT_H */