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
);
113 init_pipe_state(struct sp_mpeg12_context
*ctx
)
115 struct pipe_rasterizer_state rast
;
116 struct pipe_blend_state blend
;
117 struct pipe_depth_stencil_alpha_state dsa
;
123 rast
.flatshade_first
= 0;
124 rast
.light_twoside
= 0;
125 rast
.front_winding
= PIPE_WINDING_CCW
;
126 rast
.cull_mode
= PIPE_WINDING_CW
;
127 rast
.fill_cw
= PIPE_POLYGON_MODE_FILL
;
128 rast
.fill_ccw
= PIPE_POLYGON_MODE_FILL
;
132 rast
.poly_smooth
= 0;
133 rast
.poly_stipple_enable
= 0;
134 rast
.point_sprite
= 0;
135 rast
.point_size_per_vertex
= 0;
136 rast
.multisample
= 0;
137 rast
.line_smooth
= 0;
138 rast
.line_stipple_enable
= 0;
139 rast
.line_stipple_factor
= 0;
140 rast
.line_stipple_pattern
= 0;
141 rast
.line_last_pixel
= 0;
142 rast
.bypass_vs_clip_and_viewport
= 0;
144 rast
.point_smooth
= 0;
146 rast
.offset_units
= 1;
147 rast
.offset_scale
= 1;
148 /*rast.sprite_coord_mode[i] = ;*/
149 ctx
->rast
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &rast
);
150 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rast
);
152 blend
.blend_enable
= 0;
153 blend
.rgb_func
= PIPE_BLEND_ADD
;
154 blend
.rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
155 blend
.rgb_dst_factor
= PIPE_BLENDFACTOR_ONE
;
156 blend
.alpha_func
= PIPE_BLEND_ADD
;
157 blend
.alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
158 blend
.alpha_dst_factor
= PIPE_BLENDFACTOR_ONE
;
159 blend
.logicop_enable
= 0;
160 blend
.logicop_func
= PIPE_LOGICOP_CLEAR
;
161 /* Needed to allow color writes to FB, even if blending disabled */
162 blend
.colormask
= PIPE_MASK_RGBA
;
164 ctx
->blend
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &blend
);
165 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend
);
167 dsa
.depth
.enabled
= 0;
168 dsa
.depth
.writemask
= 0;
169 dsa
.depth
.func
= PIPE_FUNC_ALWAYS
;
170 dsa
.depth
.occlusion_count
= 0;
171 for (i
= 0; i
< 2; ++i
) {
172 dsa
.stencil
[i
].enabled
= 0;
173 dsa
.stencil
[i
].func
= PIPE_FUNC_ALWAYS
;
174 dsa
.stencil
[i
].fail_op
= PIPE_STENCIL_OP_KEEP
;
175 dsa
.stencil
[i
].zpass_op
= PIPE_STENCIL_OP_KEEP
;
176 dsa
.stencil
[i
].zfail_op
= PIPE_STENCIL_OP_KEEP
;
177 dsa
.stencil
[i
].ref_value
= 0;
178 dsa
.stencil
[i
].valuemask
= 0;
179 dsa
.stencil
[i
].writemask
= 0;
181 dsa
.alpha
.enabled
= 0;
182 dsa
.alpha
.func
= PIPE_FUNC_ALWAYS
;
183 dsa
.alpha
.ref_value
= 0;
184 ctx
->dsa
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
, &dsa
);
185 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
190 static struct pipe_video_context
*
191 sp_mpeg12_create(struct pipe_screen
*screen
, enum pipe_video_profile profile
,
192 enum pipe_video_chroma_format chroma_format
,
193 unsigned width
, unsigned height
)
195 struct sp_mpeg12_context
*ctx
;
197 assert(u_reduce_video_profile(profile
) == PIPE_VIDEO_CODEC_MPEG12
);
199 ctx
= CALLOC_STRUCT(sp_mpeg12_context
);
204 ctx
->base
.profile
= profile
;
205 ctx
->base
.chroma_format
= chroma_format
;
206 ctx
->base
.width
= width
;
207 ctx
->base
.height
= height
;
209 ctx
->base
.screen
= screen
;
210 ctx
->base
.destroy
= sp_mpeg12_destroy
;
211 ctx
->base
.decode_macroblocks
= sp_mpeg12_decode_macroblocks
;
212 ctx
->base
.clear_surface
= sp_mpeg12_clear_surface
;
213 ctx
->base
.render_picture
= sp_mpeg12_render_picture
;
214 ctx
->base
.set_decode_target
= sp_mpeg12_set_decode_target
;
216 ctx
->pipe
= softpipe_create(screen
);
222 /* TODO: Use slice buffering for softpipe when implemented, no advantage to buffering an entire picture */
223 if (!vl_mpeg12_mc_renderer_init(&ctx
->mc_renderer
, ctx
->pipe
,
224 width
, height
, chroma_format
,
225 VL_MPEG12_MC_RENDERER_BUFFER_PICTURE
,
226 /* TODO: Use XFER_NONE when implemented */
227 VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE
,
229 ctx
->pipe
->destroy(ctx
->pipe
);
234 if (!vl_compositor_init(&ctx
->compositor
, ctx
->pipe
)) {
235 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
236 ctx
->pipe
->destroy(ctx
->pipe
);
241 if (!init_pipe_state(ctx
)) {
242 vl_compositor_cleanup(&ctx
->compositor
);
243 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
244 ctx
->pipe
->destroy(ctx
->pipe
);
252 struct pipe_video_context
*
253 sp_video_create(struct pipe_screen
*screen
, enum pipe_video_profile profile
,
254 enum pipe_video_chroma_format chroma_format
,
255 unsigned width
, unsigned height
)
258 assert(width
&& height
);
260 switch (u_reduce_video_profile(profile
)) {
261 case PIPE_VIDEO_CODEC_MPEG12
:
262 return sp_mpeg12_create(screen
, profile
,