2 * Copyright (C) 2009-2010 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * CooperYuan <cooper.yuan@amd.com>, <cooperyuan@gmail.com>
28 #include <X11/Xutil.h>
29 #include <pipe/p_defines.h>
30 #include <pipe/p_context.h>
31 #include <pipe/p_screen.h>
32 #include <pipe/p_inlines.h>
33 #include <util/u_memory.h>
38 #include "radeon_buffer.h"
39 #include "radeon_r300.h"
40 #include "r300_screen.h"
41 #include "r300_texture.h"
42 #include "p_video_context.h"
43 #include "radeon_vl.h"
44 #include "softpipe/sp_winsys.h"
45 #include "softpipe/sp_texture.h"
47 #include "r300_video_context.h"
48 #include <softpipe/sp_video_context.h>
50 static void r300_mpeg12_destroy(struct pipe_video_context
*vpipe
)
52 struct radeon_mpeg12_context
*ctx
= (struct radeon_mpeg12_context
*)vpipe
;
56 ctx
->pipe
->bind_vs_state(ctx
->pipe
, NULL
);
57 ctx
->pipe
->bind_fs_state(ctx
->pipe
, NULL
);
59 ctx
->pipe
->delete_blend_state(ctx
->pipe
, ctx
->blend
);
60 ctx
->pipe
->delete_rasterizer_state(ctx
->pipe
, ctx
->rast
);
61 ctx
->pipe
->delete_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
63 pipe_video_surface_reference(&ctx
->decode_target
, NULL
);
64 vl_compositor_cleanup(&ctx
->compositor
);
65 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
66 ctx
->pipe
->destroy(ctx
->pipe
);
72 r300_mpeg12_decode_macroblocks(struct pipe_video_context
*vpipe
,
73 struct pipe_video_surface
*past
,
74 struct pipe_video_surface
*future
,
75 unsigned num_macroblocks
,
76 struct pipe_macroblock
*macroblocks
,
77 struct pipe_fence_handle
**fence
)
79 struct radeon_mpeg12_context
*ctx
= (struct radeon_mpeg12_context
*)vpipe
;
80 struct pipe_mpeg12_macroblock
*mpeg12_macroblocks
=
81 (struct pipe_mpeg12_macroblock
*)macroblocks
;
84 assert(num_macroblocks
);
86 assert(macroblocks
->codec
== PIPE_VIDEO_CODEC_MPEG12
);
87 assert(ctx
->decode_target
);
89 vl_mpeg12_mc_renderer_render_macroblocks(
91 r300_video_surface(ctx
->decode_target
)->tex
,
92 past
? r300_video_surface(past
)->tex
: NULL
,
93 future
? r300_video_surface(future
)->tex
: NULL
,
94 num_macroblocks
, mpeg12_macroblocks
, fence
);
97 static void r300_mpeg12_clear_surface(struct pipe_video_context
*vpipe
,
98 unsigned x
, unsigned y
,
99 unsigned width
, unsigned height
,
101 struct pipe_surface
*surface
)
103 struct radeon_mpeg12_context
*ctx
= (struct radeon_mpeg12_context
*)vpipe
;
108 if (ctx
->pipe
->surface_fill
)
109 ctx
->pipe
->surface_fill(ctx
->pipe
, surface
, x
, y
, width
, height
, value
);
111 util_surface_fill(ctx
->pipe
, surface
, x
, y
, width
, height
, value
);
115 r300_mpeg12_render_picture(struct pipe_video_context
*vpipe
,
116 struct pipe_video_surface
*src_surface
,
117 enum pipe_mpeg12_picture_type picture_type
,
118 struct pipe_video_rect
*src_area
,
119 struct pipe_surface
*dst_surface
,
120 struct pipe_video_rect
*dst_area
,
121 struct pipe_fence_handle
**fence
)
123 struct radeon_mpeg12_context
*ctx
= (struct radeon_mpeg12_context
*)vpipe
;
131 vl_compositor_render(&ctx
->compositor
,
132 r300_video_surface(src_surface
)->tex
,
133 picture_type
, src_area
, dst_surface
->texture
,
137 static void r300_mpeg12_set_decode_target(struct pipe_video_context
*vpipe
,
138 struct pipe_video_surface
*dt
)
140 struct radeon_mpeg12_context
*ctx
= (struct radeon_mpeg12_context
*)vpipe
;
145 pipe_video_surface_reference(&ctx
->decode_target
, dt
);
148 static void r300_mpeg12_set_csc_matrix(struct pipe_video_context
*vpipe
,
151 struct radeon_mpeg12_context
*ctx
= (struct radeon_mpeg12_context
*)vpipe
;
155 vl_compositor_set_csc_matrix(&ctx
->compositor
, mat
);
158 static bool r300_mpeg12_init_pipe_state(struct radeon_mpeg12_context
*ctx
)
160 struct pipe_rasterizer_state rast
;
161 struct pipe_blend_state blend
;
162 struct pipe_depth_stencil_alpha_state dsa
;
168 rast
.flatshade_first
= 0;
169 rast
.light_twoside
= 0;
170 rast
.front_winding
= PIPE_WINDING_CCW
;
171 rast
.cull_mode
= PIPE_WINDING_CW
;
172 rast
.fill_cw
= PIPE_POLYGON_MODE_FILL
;
173 rast
.fill_ccw
= PIPE_POLYGON_MODE_FILL
;
177 rast
.poly_smooth
= 0;
178 rast
.poly_stipple_enable
= 0;
179 rast
.point_sprite
= 0;
180 rast
.point_size_per_vertex
= 0;
181 rast
.multisample
= 0;
182 rast
.line_smooth
= 0;
183 rast
.line_stipple_enable
= 0;
184 rast
.line_stipple_factor
= 0;
185 rast
.line_stipple_pattern
= 0;
186 rast
.line_last_pixel
= 0;
187 rast
.bypass_vs_clip_and_viewport
= 0;
189 rast
.point_smooth
= 0;
191 rast
.offset_units
= 1;
192 rast
.offset_scale
= 1;
193 /*rast.sprite_coord_mode[i] = ;*/
194 ctx
->rast
= ctx
->pipe
->create_rasterizer_state(ctx
->pipe
, &rast
);
195 ctx
->pipe
->bind_rasterizer_state(ctx
->pipe
, ctx
->rast
);
197 blend
.blend_enable
= 0;
198 blend
.rgb_func
= PIPE_BLEND_ADD
;
199 blend
.rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
200 blend
.rgb_dst_factor
= PIPE_BLENDFACTOR_ONE
;
201 blend
.alpha_func
= PIPE_BLEND_ADD
;
202 blend
.alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
203 blend
.alpha_dst_factor
= PIPE_BLENDFACTOR_ONE
;
204 blend
.logicop_enable
= 0;
205 blend
.logicop_func
= PIPE_LOGICOP_CLEAR
;
206 /* Needed to allow color writes to FB, even if blending disabled */
207 blend
.colormask
= PIPE_MASK_RGBA
;
209 ctx
->blend
= ctx
->pipe
->create_blend_state(ctx
->pipe
, &blend
);
210 ctx
->pipe
->bind_blend_state(ctx
->pipe
, ctx
->blend
);
212 dsa
.depth
.enabled
= 0;
213 dsa
.depth
.writemask
= 0;
214 dsa
.depth
.func
= PIPE_FUNC_ALWAYS
;
215 for (i
= 0; i
< 2; ++i
)
217 dsa
.stencil
[i
].enabled
= 0;
218 dsa
.stencil
[i
].func
= PIPE_FUNC_ALWAYS
;
219 dsa
.stencil
[i
].fail_op
= PIPE_STENCIL_OP_KEEP
;
220 dsa
.stencil
[i
].zpass_op
= PIPE_STENCIL_OP_KEEP
;
221 dsa
.stencil
[i
].zfail_op
= PIPE_STENCIL_OP_KEEP
;
222 dsa
.stencil
[i
].ref_value
= 0;
223 dsa
.stencil
[i
].valuemask
= 0;
224 dsa
.stencil
[i
].writemask
= 0;
226 dsa
.alpha
.enabled
= 0;
227 dsa
.alpha
.func
= PIPE_FUNC_ALWAYS
;
228 dsa
.alpha
.ref_value
= 0;
229 ctx
->dsa
= ctx
->pipe
->create_depth_stencil_alpha_state(ctx
->pipe
, &dsa
);
230 ctx
->pipe
->bind_depth_stencil_alpha_state(ctx
->pipe
, ctx
->dsa
);
235 static struct pipe_video_context
*
236 r300_mpeg12_context_create(struct pipe_screen
*screen
,
237 enum pipe_video_profile profile
,
238 enum pipe_video_chroma_format chroma_format
,
242 struct radeon_mpeg12_context
*ctx
;
243 ctx
= CALLOC_STRUCT(radeon_mpeg12_context
);
247 ctx
->base
.profile
= profile
;
248 ctx
->base
.chroma_format
= chroma_format
;
249 ctx
->base
.width
= width
;
250 ctx
->base
.height
= height
;
251 ctx
->base
.screen
= screen
;
253 ctx
->base
.destroy
= radeon_mpeg12_destroy
;
254 ctx
->base
.decode_macroblocks
= radeon_mpeg12_decode_macroblocks
;
255 ctx
->base
.clear_surface
= radeon_mpeg12_clear_surface
;
256 ctx
->base
.render_picture
= radeon_mpeg12_render_picture
;
257 ctx
->base
.set_decode_target
= radeon_mpeg12_set_decode_target
;
258 ctx
->base
.set_csc_matrix
= radeon_mpeg12_set_csc_matrix
;
260 ctx
->pipe
= r300_create_context(screen
,(struct r300_winsys
*)screen
->winsys
);
267 if (!vl_mpeg12_mc_renderer_init(&ctx
->mc_renderer
, ctx
->pipe
,
268 width
, height
, chroma_format
,
269 VL_MPEG12_MC_RENDERER_BUFFER_PICTURE
,
270 VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE
,
273 ctx
->pipe
->destroy(ctx
->pipe
);
278 if (!vl_compositor_init(&ctx
->compositor
, ctx
->pipe
))
280 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
281 ctx
->pipe
->destroy(ctx
->pipe
);
286 if (!radeon_mpeg12_init_pipe_state(ctx
))
288 vl_compositor_cleanup(&ctx
->compositor
);
289 vl_mpeg12_mc_renderer_cleanup(&ctx
->mc_renderer
);
290 ctx
->pipe
->destroy(ctx
->pipe
);
298 struct pipe_video_context
*
299 r300_video_create(struct pipe_context
*pipe
, enum pipe_video_profile profile
,
300 enum pipe_video_chroma_format chroma_format
,
301 unsigned width
, unsigned height
,
304 struct pipe_video_context
*vpipe
;
305 struct radeon_vl_context
*rvl_ctx
;
308 assert(width
&& height
);
310 /* create radeon pipe_context */
311 switch(u_reduce_video_profile(profile
))
313 case PIPE_VIDEO_CODEC_MPEG12
:
314 vpipe
= radeon_mpeg12_context_create(p_screen
, profile
, chr_f
,
321 /* create radeon_vl_context */
322 rvl_ctx
= calloc(1, sizeof(struct radeon_vl_context
));
323 rvl_ctx
->display
= display
;
324 rvl_ctx
->screen
= screen
;
326 vpipe
->priv
= rvl_ctx
;