1 /**************************************************************************
3 * Copyright 2009 Younes Manton.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "util/u_inlines.h"
29 #include "util/u_memory.h"
31 #include "vl_mpeg12_context.h"
32 #include "vl_defines.h"
33 #include <pipe/p_shader_tokens.h>
34 #include <util/u_inlines.h>
35 #include <util/u_memory.h>
36 #include <util/u_keymap.h>
37 #include <util/u_rect.h>
38 #include <util/u_video.h>
39 #include <util/u_surface.h>
40 #include <util/u_sampler.h>
42 static const unsigned const_empty_block_mask_420
[3][2][2] = {
43 { { 0x20, 0x10 }, { 0x08, 0x04 } },
44 { { 0x02, 0x02 }, { 0x02, 0x02 } },
45 { { 0x01, 0x01 }, { 0x01, 0x01 } }
49 upload_buffer(struct vl_mpeg12_context
*ctx
,
50 struct vl_mpeg12_buffer
*buffer
,
51 struct pipe_mpeg12_macroblock
*mb
)
62 for (y
= 0; y
< 2; ++y
) {
63 for (x
= 0; x
< 2; ++x
, ++tb
) {
64 if (mb
->cbp
& (*ctx
->empty_block_mask
)[0][y
][x
]) {
65 vl_idct_add_block(&buffer
->idct_y
, mb
->mbx
* 2 + x
, mb
->mby
* 2 + y
, blocks
);
66 blocks
+= BLOCK_WIDTH
* BLOCK_HEIGHT
;
71 /* TODO: Implement 422, 444 */
72 assert(ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
);
74 for (tb
= 1; tb
< 3; ++tb
) {
75 if (mb
->cbp
& (*ctx
->empty_block_mask
)[tb
][0][0]) {
77 vl_idct_add_block(&buffer
->idct_cb
, mb
->mbx
, mb
->mby
, blocks
);
79 vl_idct_add_block(&buffer
->idct_cr
, mb
->mbx
, mb
->mby
, blocks
);
80 blocks
+= BLOCK_WIDTH
* BLOCK_HEIGHT
;
86 vl_mpeg12_buffer_destroy(struct pipe_video_buffer
*buffer
)
88 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
89 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
92 vl_vb_cleanup(&buf
->vertex_stream
);
93 vl_idct_cleanup_buffer(&ctx
->idct_y
, &buf
->idct_y
);
94 vl_idct_cleanup_buffer(&ctx
->idct_cb
, &buf
->idct_cb
);
95 vl_idct_cleanup_buffer(&ctx
->idct_cr
, &buf
->idct_cr
);
96 vl_mpeg12_mc_cleanup_buffer(&buf
->mc
);
97 pipe_surface_reference(&buf
->surface
, NULL
);
98 pipe_sampler_view_reference(&buf
->sampler_view
, NULL
);
104 vl_mpeg12_buffer_map(struct pipe_video_buffer
*buffer
)
106 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
107 struct vl_mpeg12_context
*ctx
;
110 ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
113 vl_vb_map(&buf
->vertex_stream
, ctx
->pipe
);
114 vl_idct_map_buffers(&ctx
->idct_y
, &buf
->idct_y
);
115 vl_idct_map_buffers(&ctx
->idct_cr
, &buf
->idct_cr
);
116 vl_idct_map_buffers(&ctx
->idct_cb
, &buf
->idct_cb
);
120 vl_mpeg12_buffer_add_macroblocks(struct pipe_video_buffer
*buffer
,
121 unsigned num_macroblocks
,
122 struct pipe_macroblock
*macroblocks
)
124 struct pipe_mpeg12_macroblock
*mpeg12_macroblocks
= (struct pipe_mpeg12_macroblock
*)macroblocks
;
125 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
126 struct vl_mpeg12_context
*ctx
;
131 ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
134 assert(num_macroblocks
);
136 assert(macroblocks
->codec
== PIPE_VIDEO_CODEC_MPEG12
);
138 for ( i
= 0; i
< num_macroblocks
; ++i
) {
139 vl_vb_add_block(&buf
->vertex_stream
, &mpeg12_macroblocks
[i
], ctx
->empty_block_mask
);
140 upload_buffer(ctx
, buf
, &mpeg12_macroblocks
[i
]);
145 vl_mpeg12_buffer_unmap(struct pipe_video_buffer
*buffer
)
147 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
148 struct vl_mpeg12_context
*ctx
;
151 ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
154 vl_vb_unmap(&buf
->vertex_stream
, ctx
->pipe
);
155 vl_idct_unmap_buffers(&ctx
->idct_y
, &buf
->idct_y
);
156 vl_idct_unmap_buffers(&ctx
->idct_cr
, &buf
->idct_cr
);
157 vl_idct_unmap_buffers(&ctx
->idct_cb
, &buf
->idct_cb
);
161 vl_mpeg12_buffer_flush(struct pipe_video_buffer
*buffer
,
162 struct pipe_video_buffer
*refs
[2],
163 struct pipe_fence_handle
**fence
)
165 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)buffer
;
166 struct vl_mpeg12_buffer
*past
= (struct vl_mpeg12_buffer
*)refs
[0];
167 struct vl_mpeg12_buffer
*future
= (struct vl_mpeg12_buffer
*)refs
[1];
169 struct pipe_sampler_view
*sv_refs
[2];
170 unsigned ne_start
, ne_num
, e_start
, e_num
;
171 struct vl_mpeg12_context
*ctx
;
175 ctx
= (struct vl_mpeg12_context
*)buf
->base
.context
;
178 vl_vb_restart(&buf
->vertex_stream
, &ne_start
, &ne_num
, &e_start
, &e_num
);
180 ctx
->pipe
->set_vertex_buffers(ctx
->pipe
, 2, buf
->vertex_bufs
.all
);
181 ctx
->pipe
->bind_vertex_elements_state(ctx
->pipe
, ctx
->vertex_elems_state
);
182 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend
);
183 vl_idct_flush(&ctx
->idct_y
, &buf
->idct_y
, ne_num
);
184 vl_idct_flush(&ctx
->idct_cr
, &buf
->idct_cr
, ne_num
);
185 vl_idct_flush(&ctx
->idct_cb
, &buf
->idct_cb
, ne_num
);
187 sv_refs
[0] = past
? past
->sampler_view
: NULL
;
188 sv_refs
[1] = future
? future
->sampler_view
: NULL
;
190 vl_mpeg12_mc_renderer_flush(&ctx
->mc_renderer
, &buf
->mc
,
191 buf
->surface
, sv_refs
,
192 ne_start
, ne_num
, e_start
, e_num
,
197 vl_mpeg12_destroy(struct pipe_video_context
*vpipe
)
199 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
203 /* Asserted in softpipe_delete_fs_state() for some reason */
204 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
205 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
207 ctx
->pipe
->delete_blend_state(ctx
->pipe
, ctx
->blend
);
208 ctx
->pipe
->delete_rasterizer_state(ctx
->pipe
, ctx
->rast
);
209 ctx
->pipe
->delete_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
211 vl_compositor_cleanup(&ctx
->compositor
);
212 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
213 vl_idct_cleanup(&ctx
->idct_y
);
214 vl_idct_cleanup(&ctx
->idct_cr
);
215 vl_idct_cleanup(&ctx
->idct_cb
);
216 ctx
->pipe
->delete_vertex_elements_state(ctx
->pipe
, ctx
->vertex_elems_state
);
217 pipe_resource_reference(&ctx
->quads
.buffer
, NULL
);
218 ctx
->pipe
->destroy(ctx
->pipe
);
224 vl_mpeg12_get_param(struct pipe_video_context
*vpipe
, int param
)
226 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
231 case PIPE_CAP_NPOT_TEXTURES
:
232 return !ctx
->pot_buffers
;
233 case PIPE_CAP_DECODE_TARGET_PREFERRED_FORMAT
:
234 return ctx
->decode_format
;
237 debug_printf("vl_mpeg12_context: Unknown PIPE_CAP %d\n", param
);
243 static struct pipe_surface
*
244 vl_mpeg12_create_surface(struct pipe_video_context
*vpipe
,
245 struct pipe_resource
*resource
,
246 const struct pipe_surface
*templ
)
248 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
252 return ctx
->pipe
->create_surface(ctx
->pipe
, resource
, templ
);
255 static struct pipe_sampler_view
*
256 vl_mpeg12_create_sampler_view(struct pipe_video_context
*vpipe
,
257 struct pipe_resource
*resource
,
258 const struct pipe_sampler_view
*templ
)
260 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
264 return ctx
->pipe
->create_sampler_view(ctx
->pipe
, resource
, templ
);
267 static struct pipe_video_buffer
*
268 vl_mpeg12_create_buffer(struct pipe_video_context
*vpipe
)
270 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
271 struct pipe_resource
*y
, *cr
, *cb
;
272 struct vl_mpeg12_buffer
*buffer
;
274 struct pipe_resource res_template
, *resource
;
275 struct pipe_surface surf_template
;
276 struct pipe_sampler_view sv_template
;
280 buffer
= CALLOC_STRUCT(vl_mpeg12_buffer
);
284 buffer
->base
.context
= vpipe
;
285 buffer
->base
.destroy
= vl_mpeg12_buffer_destroy
;
286 buffer
->base
.map
= vl_mpeg12_buffer_map
;
287 buffer
->base
.add_macroblocks
= vl_mpeg12_buffer_add_macroblocks
;
288 buffer
->base
.unmap
= vl_mpeg12_buffer_unmap
;
289 buffer
->base
.flush
= vl_mpeg12_buffer_flush
;
291 memset(&res_template
, 0, sizeof(res_template
));
292 res_template
.target
= PIPE_TEXTURE_2D
;
293 res_template
.format
= ctx
->decode_format
;
294 res_template
.last_level
= 0;
295 res_template
.width0
= ctx
->buffer_width
;
296 res_template
.height0
= ctx
->buffer_height
;
297 res_template
.depth0
= 1;
298 res_template
.array_size
= 1;
299 res_template
.usage
= PIPE_USAGE_DEFAULT
;
300 res_template
.bind
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
301 res_template
.flags
= 0;
302 resource
= ctx
->pipe
->screen
->resource_create(ctx
->pipe
->screen
, &res_template
);
308 memset(&surf_template
, 0, sizeof(surf_template
));
309 surf_template
.format
= resource
->format
;
310 surf_template
.usage
= PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
;
311 buffer
->surface
= ctx
->pipe
->create_surface(ctx
->pipe
, resource
, &surf_template
);
312 if (!buffer
->surface
) {
317 u_sampler_view_default_template(&sv_template
, resource
, resource
->format
);
318 buffer
->sampler_view
= ctx
->pipe
->create_sampler_view(ctx
->pipe
, resource
, &sv_template
);
319 if (!buffer
->sampler_view
) {
324 pipe_resource_reference(&resource
, NULL
);
326 buffer
->vertex_bufs
.individual
.quad
.stride
= ctx
->quads
.stride
;
327 buffer
->vertex_bufs
.individual
.quad
.buffer_offset
= ctx
->quads
.buffer_offset
;
328 pipe_resource_reference(&buffer
->vertex_bufs
.individual
.quad
.buffer
, ctx
->quads
.buffer
);
330 buffer
->vertex_bufs
.individual
.stream
= vl_vb_init(&buffer
->vertex_stream
, ctx
->pipe
,
331 ctx
->vertex_buffer_size
);
332 if (!(y
= vl_idct_init_buffer(&ctx
->idct_y
, &buffer
->idct_y
))) {
337 if (!(cr
= vl_idct_init_buffer(&ctx
->idct_cr
, &buffer
->idct_cr
))) {
342 if (!(cb
= vl_idct_init_buffer(&ctx
->idct_cb
, &buffer
->idct_cb
))) {
347 if(!vl_mpeg12_mc_init_buffer(&ctx
->mc_renderer
, &buffer
->mc
, y
, cr
, cb
)) {
352 return &buffer
->base
;
356 vl_mpeg12_is_format_supported(struct pipe_video_context
*vpipe
,
357 enum pipe_format format
,
360 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
364 return ctx
->pipe
->screen
->is_format_supported(ctx
->pipe
->screen
, format
,
370 vl_mpeg12_clear_sampler(struct pipe_video_context
*vpipe
,
371 struct pipe_sampler_view
*dst
,
372 const struct pipe_box
*dst_box
,
375 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
376 struct pipe_transfer
*transfer
;
386 transfer
= ctx
->pipe
->get_transfer(ctx
->pipe
, dst
->texture
, 0, PIPE_TRANSFER_WRITE
, dst_box
);
390 map
= ctx
->pipe
->transfer_map(ctx
->pipe
, transfer
);
394 for ( i
= 0; i
< 4; ++i
)
397 util_fill_rect(map
, dst
->texture
->format
, transfer
->stride
, 0, 0,
398 dst_box
->width
, dst_box
->height
, &uc
);
400 ctx
->pipe
->transfer_unmap(ctx
->pipe
, transfer
);
403 ctx
->pipe
->transfer_destroy(ctx
->pipe
, transfer
);
407 vl_mpeg12_upload_sampler(struct pipe_video_context
*vpipe
,
408 struct pipe_sampler_view
*dst
,
409 const struct pipe_box
*dst_box
,
410 const void *src
, unsigned src_stride
,
411 unsigned src_x
, unsigned src_y
)
413 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
414 struct pipe_transfer
*transfer
;
422 transfer
= ctx
->pipe
->get_transfer(ctx
->pipe
, dst
->texture
, 0, PIPE_TRANSFER_WRITE
, dst_box
);
426 map
= ctx
->pipe
->transfer_map(ctx
->pipe
, transfer
);
430 util_copy_rect(map
, dst
->texture
->format
, transfer
->stride
, 0, 0,
431 dst_box
->width
, dst_box
->height
,
432 src
, src_stride
, src_x
, src_y
);
434 ctx
->pipe
->transfer_unmap(ctx
->pipe
, transfer
);
437 ctx
->pipe
->transfer_destroy(ctx
->pipe
, transfer
);
441 vl_mpeg12_render_picture(struct pipe_video_context
*vpipe
,
442 struct pipe_video_buffer
*src_surface
,
443 struct pipe_video_rect
*src_area
,
444 enum pipe_mpeg12_picture_type picture_type
,
445 struct pipe_surface
*dst_surface
,
446 struct pipe_video_rect
*dst_area
,
447 struct pipe_fence_handle
**fence
)
449 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
450 struct vl_mpeg12_buffer
*buf
= (struct vl_mpeg12_buffer
*)src_surface
;
458 vl_compositor_render(&ctx
->compositor
, buf
->sampler_view
,
459 picture_type
, src_area
,
460 dst_surface
, dst_area
, fence
);
464 vl_mpeg12_set_picture_layers(struct pipe_video_context
*vpipe
,
465 struct pipe_sampler_view
*layers
[],
466 struct pipe_sampler_view
*palettes
[],
467 struct pipe_video_rect
*src_rects
[],
468 struct pipe_video_rect
*dst_rects
[],
471 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
474 assert((layers
&& src_rects
&& dst_rects
) ||
475 (!layers
&& !src_rects
&& !dst_rects
));
477 vl_compositor_set_layers(&ctx
->compositor
, layers
, palettes
, src_rects
, dst_rects
, num_layers
);
481 vl_mpeg12_set_csc_matrix(struct pipe_video_context
*vpipe
, const float *mat
)
483 struct vl_mpeg12_context
*ctx
= (struct vl_mpeg12_context
*)vpipe
;
487 vl_compositor_set_csc_matrix(&ctx
->compositor
, mat
);
491 init_pipe_state(struct vl_mpeg12_context
*ctx
)
493 struct pipe_rasterizer_state rast
;
494 struct pipe_blend_state blend
;
495 struct pipe_depth_stencil_alpha_state dsa
;
500 memset(&rast
, 0, sizeof rast
);
502 rast
.flatshade_first
= 0;
503 rast
.light_twoside
= 0;
505 rast
.cull_face
= PIPE_FACE_NONE
;
506 rast
.fill_back
= PIPE_POLYGON_MODE_FILL
;
507 rast
.fill_front
= PIPE_POLYGON_MODE_FILL
;
508 rast
.offset_point
= 0;
509 rast
.offset_line
= 0;
511 rast
.poly_smooth
= 0;
512 rast
.poly_stipple_enable
= 0;
513 rast
.sprite_coord_enable
= 0;
514 rast
.point_size_per_vertex
= 0;
515 rast
.multisample
= 0;
516 rast
.line_smooth
= 0;
517 rast
.line_stipple_enable
= 0;
518 rast
.line_stipple_factor
= 0;
519 rast
.line_stipple_pattern
= 0;
520 rast
.line_last_pixel
= 0;
522 rast
.point_smooth
= 0;
523 rast
.point_quad_rasterization
= 0;
524 rast
.point_size_per_vertex
= 1;
525 rast
.offset_units
= 1;
526 rast
.offset_scale
= 1;
527 rast
.gl_rasterization_rules
= 1;
529 ctx
->rast
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &rast
);
530 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rast
);
532 memset(&blend
, 0, sizeof blend
);
534 blend
.independent_blend_enable
= 0;
535 blend
.rt
[0].blend_enable
= 0;
536 blend
.rt
[0].rgb_func
= PIPE_BLEND_ADD
;
537 blend
.rt
[0].rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
538 blend
.rt
[0].rgb_dst_factor
= PIPE_BLENDFACTOR_ONE
;
539 blend
.rt
[0].alpha_func
= PIPE_BLEND_ADD
;
540 blend
.rt
[0].alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
541 blend
.rt
[0].alpha_dst_factor
= PIPE_BLENDFACTOR_ONE
;
542 blend
.logicop_enable
= 0;
543 blend
.logicop_func
= PIPE_LOGICOP_CLEAR
;
544 /* Needed to allow color writes to FB, even if blending disabled */
545 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
547 ctx
->blend
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &blend
);
549 memset(&dsa
, 0, sizeof dsa
);
550 dsa
.depth
.enabled
= 0;
551 dsa
.depth
.writemask
= 0;
552 dsa
.depth
.func
= PIPE_FUNC_ALWAYS
;
553 for (i
= 0; i
< 2; ++i
) {
554 dsa
.stencil
[i
].enabled
= 0;
555 dsa
.stencil
[i
].func
= PIPE_FUNC_ALWAYS
;
556 dsa
.stencil
[i
].fail_op
= PIPE_STENCIL_OP_KEEP
;
557 dsa
.stencil
[i
].zpass_op
= PIPE_STENCIL_OP_KEEP
;
558 dsa
.stencil
[i
].zfail_op
= PIPE_STENCIL_OP_KEEP
;
559 dsa
.stencil
[i
].valuemask
= 0;
560 dsa
.stencil
[i
].writemask
= 0;
562 dsa
.alpha
.enabled
= 0;
563 dsa
.alpha
.func
= PIPE_FUNC_ALWAYS
;
564 dsa
.alpha
.ref_value
= 0;
565 ctx
->dsa
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
, &dsa
);
566 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
572 init_idct(struct vl_mpeg12_context
*ctx
, unsigned buffer_width
, unsigned buffer_height
)
574 unsigned chroma_width
, chroma_height
, chroma_blocks_x
, chroma_blocks_y
;
575 struct pipe_resource
*idct_matrix
;
577 /* TODO: Implement 422, 444 */
578 assert(ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
);
579 ctx
->empty_block_mask
= &const_empty_block_mask_420
;
581 if (!(idct_matrix
= vl_idct_upload_matrix(ctx
->pipe
)))
584 if (!vl_idct_init(&ctx
->idct_y
, ctx
->pipe
, buffer_width
, buffer_height
,
585 2, 2, TGSI_SWIZZLE_X
, idct_matrix
))
588 if (ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_420
) {
589 chroma_width
= buffer_width
/ 2;
590 chroma_height
= buffer_height
/ 2;
593 } else if (ctx
->base
.chroma_format
== PIPE_VIDEO_CHROMA_FORMAT_422
) {
594 chroma_width
= buffer_width
;
595 chroma_height
= buffer_height
/ 2;
599 chroma_width
= buffer_width
;
600 chroma_height
= buffer_height
;
605 if(!vl_idct_init(&ctx
->idct_cr
, ctx
->pipe
, chroma_width
, chroma_height
,
606 chroma_blocks_x
, chroma_blocks_y
, TGSI_SWIZZLE_Z
, idct_matrix
))
609 if(!vl_idct_init(&ctx
->idct_cb
, ctx
->pipe
, chroma_width
, chroma_height
,
610 chroma_blocks_x
, chroma_blocks_y
, TGSI_SWIZZLE_Y
, idct_matrix
))
616 struct pipe_video_context
*
617 vl_create_mpeg12_context(struct pipe_context
*pipe
,
618 enum pipe_video_profile profile
,
619 enum pipe_video_chroma_format chroma_format
,
620 unsigned width
, unsigned height
,
622 enum pipe_format decode_format
)
624 struct vl_mpeg12_context
*ctx
;
626 assert(u_reduce_video_profile(profile
) == PIPE_VIDEO_CODEC_MPEG12
);
628 ctx
= CALLOC_STRUCT(vl_mpeg12_context
);
633 ctx
->base
.profile
= profile
;
634 ctx
->base
.chroma_format
= chroma_format
;
635 ctx
->base
.width
= width
;
636 ctx
->base
.height
= height
;
638 ctx
->base
.screen
= pipe
->screen
;
640 ctx
->base
.destroy
= vl_mpeg12_destroy
;
641 ctx
->base
.get_param
= vl_mpeg12_get_param
;
642 ctx
->base
.is_format_supported
= vl_mpeg12_is_format_supported
;
643 ctx
->base
.create_surface
= vl_mpeg12_create_surface
;
644 ctx
->base
.create_sampler_view
= vl_mpeg12_create_sampler_view
;
645 ctx
->base
.create_buffer
= vl_mpeg12_create_buffer
;
646 ctx
->base
.render_picture
= vl_mpeg12_render_picture
;
647 ctx
->base
.clear_sampler
= vl_mpeg12_clear_sampler
;
648 ctx
->base
.upload_sampler
= vl_mpeg12_upload_sampler
;
649 ctx
->base
.set_picture_layers
= vl_mpeg12_set_picture_layers
;
650 ctx
->base
.set_csc_matrix
= vl_mpeg12_set_csc_matrix
;
653 ctx
->decode_format
= decode_format
;
654 ctx
->pot_buffers
= pot_buffers
;
656 ctx
->quads
= vl_vb_upload_quads(ctx
->pipe
, 2, 2);
657 ctx
->vertex_buffer_size
= width
/ MACROBLOCK_WIDTH
* height
/ MACROBLOCK_HEIGHT
;
658 ctx
->vertex_elems_state
= vl_vb_get_elems_state(ctx
->pipe
, true);
660 if (ctx
->vertex_elems_state
== NULL
) {
661 ctx
->pipe
->destroy(ctx
->pipe
);
666 ctx
->buffer_width
= pot_buffers
? util_next_power_of_two(width
) : align(width
, MACROBLOCK_WIDTH
);
667 ctx
->buffer_height
= pot_buffers
? util_next_power_of_two(height
) : align(height
, MACROBLOCK_HEIGHT
);
669 if (!init_idct(ctx
, ctx
->buffer_width
, ctx
->buffer_height
)) {
670 ctx
->pipe
->destroy(ctx
->pipe
);
675 if (!vl_mpeg12_mc_renderer_init(&ctx
->mc_renderer
, ctx
->pipe
,
676 ctx
->buffer_width
, ctx
->buffer_height
,
678 vl_idct_cleanup(&ctx
->idct_y
);
679 vl_idct_cleanup(&ctx
->idct_cr
);
680 vl_idct_cleanup(&ctx
->idct_cb
);
681 ctx
->pipe
->destroy(ctx
->pipe
);
686 if (!vl_compositor_init(&ctx
->compositor
, ctx
->pipe
)) {
687 vl_idct_cleanup(&ctx
->idct_y
);
688 vl_idct_cleanup(&ctx
->idct_cr
);
689 vl_idct_cleanup(&ctx
->idct_cb
);
690 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
691 ctx
->pipe
->destroy(ctx
->pipe
);
696 if (!init_pipe_state(ctx
)) {
697 vl_idct_cleanup(&ctx
->idct_y
);
698 vl_idct_cleanup(&ctx
->idct_cr
);
699 vl_idct_cleanup(&ctx
->idct_cb
);
700 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
701 vl_compositor_cleanup(&ctx
->compositor
);
702 ctx
->pipe
->destroy(ctx
->pipe
);