1 /**************************************************************************
3 * Copyright 2010 Thomas Balling Sørensen.
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 <vdpau/vdpau.h>
30 #include "util/u_memory.h"
31 #include "util/u_debug.h"
33 #include "vl/vl_csc.h"
35 #include "vdpau_private.h"
38 * Create a VdpVideoMixer.
41 vlVdpVideoMixerCreate(VdpDevice device
,
42 uint32_t feature_count
,
43 VdpVideoMixerFeature
const *features
,
44 uint32_t parameter_count
,
45 VdpVideoMixerParameter
const *parameters
,
46 void const *const *parameter_values
,
49 vlVdpVideoMixer
*vmixer
= NULL
;
53 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Creating VideoMixer\n");
55 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
57 return VDP_STATUS_INVALID_HANDLE
;
59 vmixer
= CALLOC(1, sizeof(vlVdpVideoMixer
));
61 return VDP_STATUS_RESOURCES
;
64 vl_compositor_init(&vmixer
->compositor
, dev
->context
->pipe
);
68 debug_get_bool_option("G3DVL_NO_CSC", FALSE
) ?
69 VL_CSC_COLOR_STANDARD_IDENTITY
: VL_CSC_COLOR_STANDARD_BT_601
,
72 vl_compositor_set_csc_matrix(&vmixer
->compositor
, csc
);
75 * TODO: Handle features and parameters
78 *mixer
= vlAddDataHTAB(vmixer
);
80 ret
= VDP_STATUS_ERROR
;
91 * Destroy a VdpVideoMixer.
94 vlVdpVideoMixerDestroy(VdpVideoMixer mixer
)
96 vlVdpVideoMixer
*vmixer
;
98 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Destroying VideoMixer\n");
100 vmixer
= vlGetDataHTAB(mixer
);
102 return VDP_STATUS_INVALID_HANDLE
;
104 vl_compositor_cleanup(&vmixer
->compositor
);
108 return VDP_STATUS_OK
;
112 * Enable or disable features.
115 vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer
,
116 uint32_t feature_count
,
117 VdpVideoMixerFeature
const *features
,
118 VdpBool
const *feature_enables
)
120 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Setting VideoMixer features\n");
122 if (!(features
&& feature_enables
))
123 return VDP_STATUS_INVALID_POINTER
;
125 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
127 return VDP_STATUS_INVALID_HANDLE
;
133 return VDP_STATUS_OK
;
137 * Perform a video post-processing and compositing operation.
139 VdpStatus
vlVdpVideoMixerRender(VdpVideoMixer mixer
,
140 VdpOutputSurface background_surface
,
141 VdpRect
const *background_source_rect
,
142 VdpVideoMixerPictureStructure current_picture_structure
,
143 uint32_t video_surface_past_count
,
144 VdpVideoSurface
const *video_surface_past
,
145 VdpVideoSurface video_surface_current
,
146 uint32_t video_surface_future_count
,
147 VdpVideoSurface
const *video_surface_future
,
148 VdpRect
const *video_source_rect
,
149 VdpOutputSurface destination_surface
,
150 VdpRect
const *destination_rect
,
151 VdpRect
const *destination_video_rect
,
152 uint32_t layer_count
,
153 VdpLayer
const *layers
)
155 struct pipe_video_rect src_rect
, dst_rect
;
157 vlVdpVideoMixer
*vmixer
;
159 vlVdpOutputSurface
*dst
, *bg
;
162 vmixer
= vlGetDataHTAB(mixer
);
164 return VDP_STATUS_INVALID_HANDLE
;
166 surf
= vlGetDataHTAB(video_surface_current
);
168 return VDP_STATUS_INVALID_HANDLE
;
170 dst
= vlGetDataHTAB(destination_surface
);
172 return VDP_STATUS_INVALID_HANDLE
;
174 vl_compositor_clear_layers(&vmixer
->compositor
);
175 vl_compositor_reset_dirty_area(&vmixer
->compositor
);
176 if (background_surface
!= VDP_INVALID_HANDLE
) {
177 bg
= vlGetDataHTAB(background_surface
);
179 return VDP_STATUS_INVALID_HANDLE
;
180 vl_compositor_set_rgba_layer(&vmixer
->compositor
, layer
++, bg
->sampler_view
,
181 RectToPipe(background_source_rect
, &src_rect
), NULL
);
183 vl_compositor_set_buffer_layer(&vmixer
->compositor
, layer
, surf
->video_buffer
,
184 RectToPipe(video_source_rect
, &src_rect
),
185 RectToPipe(destination_video_rect
, &dst_rect
));
186 vl_compositor_render(&vmixer
->compositor
, dst
->surface
, NULL
,
187 RectToPipe(destination_rect
, &dst_rect
), !layer
);
189 assert(!layer_count
);
190 return VDP_STATUS_OK
;
194 * Set attribute values.
197 vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer
,
198 uint32_t attribute_count
,
199 VdpVideoMixerAttribute
const *attributes
,
200 void const *const *attribute_values
)
202 if (!(attributes
&& attribute_values
))
203 return VDP_STATUS_INVALID_POINTER
;
205 vlVdpVideoMixer
*vmixer
= vlGetDataHTAB(mixer
);
207 return VDP_STATUS_INVALID_HANDLE
;
210 * TODO: Implement the function
213 return VDP_STATUS_OK
;
217 * Retrieve whether features were requested at creation time.
220 vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer
,
221 uint32_t feature_count
,
222 VdpVideoMixerFeature
const *features
,
223 VdpBool
*feature_supports
)
225 return VDP_STATUS_NO_IMPLEMENTATION
;
229 * Retrieve whether features are enabled.
232 vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer
,
233 uint32_t feature_count
,
234 VdpVideoMixerFeature
const *features
,
235 VdpBool
*feature_enables
)
237 return VDP_STATUS_NO_IMPLEMENTATION
;
241 * Retrieve parameter values given at creation time.
244 vlVdpVideoMixerGetParameterValues(VdpVideoMixer mixer
,
245 uint32_t parameter_count
,
246 VdpVideoMixerParameter
const *parameters
,
247 void *const *parameter_values
)
249 return VDP_STATUS_NO_IMPLEMENTATION
;
253 * Retrieve current attribute values.
256 vlVdpVideoMixerGetAttributeValues(VdpVideoMixer mixer
,
257 uint32_t attribute_count
,
258 VdpVideoMixerAttribute
const *attributes
,
259 void *const *attribute_values
)
261 return VDP_STATUS_NO_IMPLEMENTATION
;
265 * Generate a color space conversion matrix.
268 vlVdpGenerateCSCMatrix(VdpProcamp
*procamp
,
269 VdpColorStandard standard
,
270 VdpCSCMatrix
*csc_matrix
)
273 enum VL_CSC_COLOR_STANDARD vl_std
;
274 struct vl_procamp camp
;
276 if (!(csc_matrix
&& procamp
))
277 return VDP_STATUS_INVALID_POINTER
;
279 if (procamp
->struct_version
> VDP_PROCAMP_VERSION
)
280 return VDP_STATUS_INVALID_STRUCT_VERSION
;
283 case VDP_COLOR_STANDARD_ITUR_BT_601
: vl_std
= VL_CSC_COLOR_STANDARD_BT_601
; break;
284 case VDP_COLOR_STANDARD_ITUR_BT_709
: vl_std
= VL_CSC_COLOR_STANDARD_BT_709
; break;
285 case VDP_COLOR_STANDARD_SMPTE_240M
: vl_std
= VL_CSC_COLOR_STANDARD_SMPTE_240M
; break;
286 default: return VDP_STATUS_INVALID_COLOR_STANDARD
;
288 camp
.brightness
= procamp
->brightness
;
289 camp
.contrast
= procamp
->contrast
;
290 camp
.saturation
= procamp
->saturation
;
291 camp
.hue
= procamp
->hue
;
292 vl_csc_get_matrix(vl_std
, &camp
, 1, matrix
);
293 memcpy(csc_matrix
, matrix
, sizeof(float)*12);
294 return VDP_STATUS_OK
;