[g3dvl] and finally remove pipe_video_context
[mesa.git] / src / gallium / state_trackers / vdpau / mixer.c
1 /**************************************************************************
2 *
3 * Copyright 2010 Thomas Balling Sørensen.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include <vdpau/vdpau.h>
29
30 #include <util/u_memory.h>
31 #include <util/u_debug.h>
32
33 #include <vl/vl_csc.h>
34
35 #include "vdpau_private.h"
36
37 VdpStatus
38 vlVdpVideoMixerCreate(VdpDevice device,
39 uint32_t feature_count,
40 VdpVideoMixerFeature const *features,
41 uint32_t parameter_count,
42 VdpVideoMixerParameter const *parameters,
43 void const *const *parameter_values,
44 VdpVideoMixer *mixer)
45 {
46 vlVdpVideoMixer *vmixer = NULL;
47 VdpStatus ret;
48 float csc[16];
49
50 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating VideoMixer\n");
51
52 vlVdpDevice *dev = vlGetDataHTAB(device);
53 if (!dev)
54 return VDP_STATUS_INVALID_HANDLE;
55
56 vmixer = CALLOC(1, sizeof(vlVdpVideoMixer));
57 if (!vmixer)
58 return VDP_STATUS_RESOURCES;
59
60 vmixer->device = dev;
61 vl_compositor_init(&vmixer->compositor, dev->context->pipe);
62
63 vl_csc_get_matrix
64 (
65 debug_get_bool_option("G3DVL_NO_CSC", FALSE) ?
66 VL_CSC_COLOR_STANDARD_IDENTITY : VL_CSC_COLOR_STANDARD_BT_601,
67 NULL, true, csc
68 );
69 vl_compositor_set_csc_matrix(&vmixer->compositor, csc);
70
71 /*
72 * TODO: Handle features and parameters
73 * */
74
75 *mixer = vlAddDataHTAB(vmixer);
76 if (*mixer == 0) {
77 ret = VDP_STATUS_ERROR;
78 goto no_handle;
79 }
80
81 return VDP_STATUS_OK;
82 no_handle:
83 return ret;
84 }
85
86 VdpStatus
87 vlVdpVideoMixerDestroy(VdpVideoMixer mixer)
88 {
89 vlVdpVideoMixer *vmixer;
90
91 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying VideoMixer\n");
92
93 vmixer = vlGetDataHTAB(mixer);
94 if (!vmixer)
95 return VDP_STATUS_INVALID_HANDLE;
96
97 vl_compositor_cleanup(&vmixer->compositor);
98
99 FREE(vmixer);
100
101 return VDP_STATUS_OK;
102 }
103
104 VdpStatus
105 vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer,
106 uint32_t feature_count,
107 VdpVideoMixerFeature const *features,
108 VdpBool const *feature_enables)
109 {
110 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Setting VideoMixer features\n");
111
112 if (!(features && feature_enables))
113 return VDP_STATUS_INVALID_POINTER;
114
115 vlVdpVideoMixer *vmixer = vlGetDataHTAB(mixer);
116 if (!vmixer)
117 return VDP_STATUS_INVALID_HANDLE;
118
119 /*
120 * TODO: Set features
121 * */
122
123 return VDP_STATUS_OK;
124 }
125
126 VdpStatus vlVdpVideoMixerRender(VdpVideoMixer mixer,
127 VdpOutputSurface background_surface,
128 VdpRect const *background_source_rect,
129 VdpVideoMixerPictureStructure current_picture_structure,
130 uint32_t video_surface_past_count,
131 VdpVideoSurface const *video_surface_past,
132 VdpVideoSurface video_surface_current,
133 uint32_t video_surface_future_count,
134 VdpVideoSurface const *video_surface_future,
135 VdpRect const *video_source_rect,
136 VdpOutputSurface destination_surface,
137 VdpRect const *destination_rect,
138 VdpRect const *destination_video_rect,
139 uint32_t layer_count,
140 VdpLayer const *layers)
141 {
142 vlVdpVideoMixer *vmixer;
143 vlVdpSurface *surf;
144 vlVdpOutputSurface *dst;
145
146 vmixer = vlGetDataHTAB(mixer);
147 if (!vmixer)
148 return VDP_STATUS_INVALID_HANDLE;
149
150 surf = vlGetDataHTAB(video_surface_current);
151 if (!surf)
152 return VDP_STATUS_INVALID_HANDLE;
153
154 dst = vlGetDataHTAB(destination_surface);
155 if (!dst)
156 return VDP_STATUS_INVALID_HANDLE;
157
158 vl_compositor_clear_layers(&vmixer->compositor);
159 vl_compositor_set_buffer_layer(&vmixer->compositor, 0, surf->video_buffer, NULL, NULL);
160 vl_compositor_render(&vmixer->compositor, PIPE_MPEG12_PICTURE_TYPE_FRAME,
161 dst->surface, NULL, NULL);
162
163 return VDP_STATUS_OK;
164 }
165
166 VdpStatus
167 vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer,
168 uint32_t attribute_count,
169 VdpVideoMixerAttribute const *attributes,
170 void const *const *attribute_values)
171 {
172 if (!(attributes && attribute_values))
173 return VDP_STATUS_INVALID_POINTER;
174
175 vlVdpVideoMixer *vmixer = vlGetDataHTAB(mixer);
176 if (!vmixer)
177 return VDP_STATUS_INVALID_HANDLE;
178
179 /*
180 * TODO: Implement the function
181 *
182 * */
183
184 return VDP_STATUS_OK;
185 }
186
187 VdpStatus
188 vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer,
189 uint32_t feature_count,
190 VdpVideoMixerFeature const *features,
191 VdpBool *feature_supports)
192 {
193 return VDP_STATUS_NO_IMPLEMENTATION;
194 }
195
196 VdpStatus
197 vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer,
198 uint32_t feature_count,
199 VdpVideoMixerFeature const *features,
200 VdpBool *feature_enables)
201 {
202 return VDP_STATUS_NO_IMPLEMENTATION;
203 }
204
205 VdpStatus
206 vlVdpVideoMixerGetParameterValues(VdpVideoMixer mixer,
207 uint32_t parameter_count,
208 VdpVideoMixerParameter const *parameters,
209 void *const *parameter_values)
210 {
211 return VDP_STATUS_NO_IMPLEMENTATION;
212 }
213
214 VdpStatus
215 vlVdpVideoMixerGetAttributeValues(VdpVideoMixer mixer,
216 uint32_t attribute_count,
217 VdpVideoMixerAttribute const *attributes,
218 void *const *attribute_values)
219 {
220 return VDP_STATUS_NO_IMPLEMENTATION;
221 }
222
223 VdpStatus
224 vlVdpGenerateCSCMatrix(VdpProcamp *procamp,
225 VdpColorStandard standard,
226 VdpCSCMatrix *csc_matrix)
227 {
228 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Generating CSCMatrix\n");
229 if (!(csc_matrix && procamp))
230 return VDP_STATUS_INVALID_POINTER;
231
232 return VDP_STATUS_OK;
233 }