1 #include "sp_video_context.h"
2 #include <pipe/p_inlines.h>
3 #include <util/u_memory.h>
4 #include "softpipe/sp_winsys.h"
5 #include "softpipe/sp_texture.h"
8 sp_mpeg12_destroy(struct pipe_video_context
*vpipe
)
10 struct sp_mpeg12_context
*ctx
= (struct sp_mpeg12_context
*)vpipe
;
14 /* Asserted in softpipe_delete_fs_state() for some reason */
15 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
16 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
18 ctx
->pipe
->delete_blend_state(ctx
->pipe
, ctx
->blend
);
19 ctx
->pipe
->delete_rasterizer_state(ctx
->pipe
, ctx
->rast
);
20 ctx
->pipe
->delete_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
22 pipe_video_surface_reference(&ctx
->decode_target
, NULL
);
23 vl_compositor_cleanup(&ctx
->compositor
);
24 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
25 ctx
->pipe
->destroy(ctx
->pipe
);
31 sp_mpeg12_decode_macroblocks(struct pipe_video_context
*vpipe
,
32 struct pipe_video_surface
*past
,
33 struct pipe_video_surface
*future
,
34 unsigned num_macroblocks
,
35 struct pipe_macroblock
*macroblocks
,
36 struct pipe_fence_handle
**fence
)
38 struct sp_mpeg12_context
*ctx
= (struct sp_mpeg12_context
*)vpipe
;
39 struct pipe_mpeg12_macroblock
*mpeg12_macroblocks
= (struct pipe_mpeg12_macroblock
*)macroblocks
;
42 assert(num_macroblocks
);
44 assert(macroblocks
->codec
== PIPE_VIDEO_CODEC_MPEG12
);
45 assert(ctx
->decode_target
);
47 vl_mpeg12_mc_renderer_render_macroblocks(&ctx
->mc_renderer
,
48 softpipe_video_surface(ctx
->decode_target
)->tex
,
49 past
? softpipe_video_surface(past
)->tex
: NULL
,
50 future
? softpipe_video_surface(future
)->tex
: NULL
,
51 num_macroblocks
, mpeg12_macroblocks
, fence
);
55 sp_mpeg12_clear_surface(struct pipe_video_context
*vpipe
,
56 unsigned x
, unsigned y
,
57 unsigned width
, unsigned height
,
59 struct pipe_surface
*surface
)
61 struct sp_mpeg12_context
*ctx
= (struct sp_mpeg12_context
*)vpipe
;
66 ctx
->pipe
->surface_fill(ctx
->pipe
, surface
, x
, y
, width
, height
, value
);
70 sp_mpeg12_render_picture(struct pipe_video_context
*vpipe
,
71 /*struct pipe_surface *backround,
72 struct pipe_video_rect *backround_area,*/
73 struct pipe_video_surface
*src_surface
,
74 enum pipe_mpeg12_picture_type picture_type
,
75 /*unsigned num_past_surfaces,
76 struct pipe_video_surface *past_surfaces,
77 unsigned num_future_surfaces,
78 struct pipe_video_surface *future_surfaces,*/
79 struct pipe_video_rect
*src_area
,
80 struct pipe_surface
*dst_surface
,
81 struct pipe_video_rect
*dst_area
,
82 /*unsigned num_layers,
83 struct pipe_surface *layers,
84 struct pipe_video_rect *layer_src_areas,
85 struct pipe_video_rect *layer_dst_areas*/
86 struct pipe_fence_handle
**fence
)
88 struct sp_mpeg12_context
*ctx
= (struct sp_mpeg12_context
*)vpipe
;
96 vl_compositor_render(&ctx
->compositor
, softpipe_video_surface(src_surface
)->tex
,
97 picture_type
, src_area
, dst_surface
->texture
, dst_area
, fence
);
101 sp_mpeg12_set_decode_target(struct pipe_video_context
*vpipe
,
102 struct pipe_video_surface
*dt
)
104 struct sp_mpeg12_context
*ctx
= (struct sp_mpeg12_context
*)vpipe
;
109 pipe_video_surface_reference(&ctx
->decode_target
, dt
);
112 static void sp_mpeg12_set_csc_matrix(struct pipe_video_context
*vpipe
, const float *mat
)
114 struct sp_mpeg12_context
*ctx
= (struct sp_mpeg12_context
*)vpipe
;
118 vl_compositor_set_csc_matrix(&ctx
->compositor
, mat
);
122 init_pipe_state(struct sp_mpeg12_context
*ctx
)
124 struct pipe_rasterizer_state rast
;
125 struct pipe_blend_state blend
;
126 struct pipe_depth_stencil_alpha_state dsa
;
132 rast
.flatshade_first
= 0;
133 rast
.light_twoside
= 0;
134 rast
.front_winding
= PIPE_WINDING_CCW
;
135 rast
.cull_mode
= PIPE_WINDING_CW
;
136 rast
.fill_cw
= PIPE_POLYGON_MODE_FILL
;
137 rast
.fill_ccw
= PIPE_POLYGON_MODE_FILL
;
141 rast
.poly_smooth
= 0;
142 rast
.poly_stipple_enable
= 0;
143 rast
.point_sprite
= 0;
144 rast
.point_size_per_vertex
= 0;
145 rast
.multisample
= 0;
146 rast
.line_smooth
= 0;
147 rast
.line_stipple_enable
= 0;
148 rast
.line_stipple_factor
= 0;
149 rast
.line_stipple_pattern
= 0;
150 rast
.line_last_pixel
= 0;
151 rast
.bypass_vs_clip_and_viewport
= 0;
153 rast
.point_smooth
= 0;
155 rast
.offset_units
= 1;
156 rast
.offset_scale
= 1;
157 /*rast.sprite_coord_mode[i] = ;*/
158 ctx
->rast
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &rast
);
159 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rast
);
161 blend
.blend_enable
= 0;
162 blend
.rgb_func
= PIPE_BLEND_ADD
;
163 blend
.rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
164 blend
.rgb_dst_factor
= PIPE_BLENDFACTOR_ONE
;
165 blend
.alpha_func
= PIPE_BLEND_ADD
;
166 blend
.alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
167 blend
.alpha_dst_factor
= PIPE_BLENDFACTOR_ONE
;
168 blend
.logicop_enable
= 0;
169 blend
.logicop_func
= PIPE_LOGICOP_CLEAR
;
170 /* Needed to allow color writes to FB, even if blending disabled */
171 blend
.colormask
= PIPE_MASK_RGBA
;
173 ctx
->blend
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &blend
);
174 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend
);
176 dsa
.depth
.enabled
= 0;
177 dsa
.depth
.writemask
= 0;
178 dsa
.depth
.func
= PIPE_FUNC_ALWAYS
;
179 for (i
= 0; i
< 2; ++i
) {
180 dsa
.stencil
[i
].enabled
= 0;
181 dsa
.stencil
[i
].func
= PIPE_FUNC_ALWAYS
;
182 dsa
.stencil
[i
].fail_op
= PIPE_STENCIL_OP_KEEP
;
183 dsa
.stencil
[i
].zpass_op
= PIPE_STENCIL_OP_KEEP
;
184 dsa
.stencil
[i
].zfail_op
= PIPE_STENCIL_OP_KEEP
;
185 dsa
.stencil
[i
].ref_value
= 0;
186 dsa
.stencil
[i
].valuemask
= 0;
187 dsa
.stencil
[i
].writemask
= 0;
189 dsa
.alpha
.enabled
= 0;
190 dsa
.alpha
.func
= PIPE_FUNC_ALWAYS
;
191 dsa
.alpha
.ref_value
= 0;
192 ctx
->dsa
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
, &dsa
);
193 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
198 static struct pipe_video_context
*
199 sp_mpeg12_create(struct pipe_screen
*screen
, enum pipe_video_profile profile
,
200 enum pipe_video_chroma_format chroma_format
,
201 unsigned width
, unsigned height
)
203 struct sp_mpeg12_context
*ctx
;
205 assert(u_reduce_video_profile(profile
) == PIPE_VIDEO_CODEC_MPEG12
);
207 ctx
= CALLOC_STRUCT(sp_mpeg12_context
);
212 ctx
->base
.profile
= profile
;
213 ctx
->base
.chroma_format
= chroma_format
;
214 ctx
->base
.width
= width
;
215 ctx
->base
.height
= height
;
217 ctx
->base
.screen
= screen
;
218 ctx
->base
.destroy
= sp_mpeg12_destroy
;
219 ctx
->base
.decode_macroblocks
= sp_mpeg12_decode_macroblocks
;
220 ctx
->base
.clear_surface
= sp_mpeg12_clear_surface
;
221 ctx
->base
.render_picture
= sp_mpeg12_render_picture
;
222 ctx
->base
.set_decode_target
= sp_mpeg12_set_decode_target
;
223 ctx
->base
.set_csc_matrix
= sp_mpeg12_set_csc_matrix
;
225 ctx
->pipe
= softpipe_create(screen
);
231 /* TODO: Use slice buffering for softpipe when implemented, no advantage to buffering an entire picture */
232 if (!vl_mpeg12_mc_renderer_init(&ctx
->mc_renderer
, ctx
->pipe
,
233 width
, height
, chroma_format
,
234 VL_MPEG12_MC_RENDERER_BUFFER_PICTURE
,
235 /* TODO: Use XFER_NONE when implemented */
236 VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE
,
238 ctx
->pipe
->destroy(ctx
->pipe
);
243 if (!vl_compositor_init(&ctx
->compositor
, ctx
->pipe
)) {
244 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
245 ctx
->pipe
->destroy(ctx
->pipe
);
250 if (!init_pipe_state(ctx
)) {
251 vl_compositor_cleanup(&ctx
->compositor
);
252 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
253 ctx
->pipe
->destroy(ctx
->pipe
);
261 struct pipe_video_context
*
262 sp_video_create(struct pipe_screen
*screen
, enum pipe_video_profile profile
,
263 enum pipe_video_chroma_format chroma_format
,
264 unsigned width
, unsigned height
)
267 assert(width
&& height
);
269 switch (u_reduce_video_profile(profile
)) {
270 case PIPE_VIDEO_CODEC_MPEG12
:
271 return sp_mpeg12_create(screen
, profile
,