OSDN Git Service

g3dvl/compositor: improve dirty area handling
[android-x86/external-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 /**
38  * Create a VdpVideoMixer.
39  */
40 VdpStatus
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,
47                       VdpVideoMixer *mixer)
48 {
49    vlVdpVideoMixer *vmixer = NULL;
50    VdpStatus ret;
51    float csc[16];
52
53    VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating VideoMixer\n");
54
55    vlVdpDevice *dev = vlGetDataHTAB(device);
56    if (!dev)
57       return VDP_STATUS_INVALID_HANDLE;
58
59    vmixer = CALLOC(1, sizeof(vlVdpVideoMixer));
60    if (!vmixer)
61       return VDP_STATUS_RESOURCES;
62
63    vmixer->device = dev;
64    vl_compositor_init(&vmixer->compositor, dev->context->pipe);
65
66    vl_csc_get_matrix
67    (
68       debug_get_bool_option("G3DVL_NO_CSC", FALSE) ?
69       VL_CSC_COLOR_STANDARD_IDENTITY : VL_CSC_COLOR_STANDARD_BT_601,
70       NULL, true, csc
71    );
72    vl_compositor_set_csc_matrix(&vmixer->compositor, csc);
73
74    /*
75     * TODO: Handle features and parameters
76     */
77
78    *mixer = vlAddDataHTAB(vmixer);
79    if (*mixer == 0) {
80       ret = VDP_STATUS_ERROR;
81       goto no_handle;
82    }
83
84    return VDP_STATUS_OK;
85
86 no_handle:
87    return ret;
88 }
89
90 /**
91  * Destroy a VdpVideoMixer.
92  */
93 VdpStatus
94 vlVdpVideoMixerDestroy(VdpVideoMixer mixer)
95 {
96    vlVdpVideoMixer *vmixer;
97
98    VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying VideoMixer\n");
99
100    vmixer = vlGetDataHTAB(mixer);
101    if (!vmixer)
102       return VDP_STATUS_INVALID_HANDLE;
103
104    vl_compositor_cleanup(&vmixer->compositor);
105
106    FREE(vmixer);
107
108    return VDP_STATUS_OK;
109 }
110
111 /**
112  * Enable or disable features.
113  */
114 VdpStatus
115 vlVdpVideoMixerSetFeatureEnables(VdpVideoMixer mixer,
116                                  uint32_t feature_count,
117                                  VdpVideoMixerFeature const *features,
118                                  VdpBool const *feature_enables)
119 {
120    VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Setting VideoMixer features\n");
121
122    if (!(features && feature_enables))
123       return VDP_STATUS_INVALID_POINTER;
124
125    vlVdpVideoMixer *vmixer = vlGetDataHTAB(mixer);
126    if (!vmixer)
127       return VDP_STATUS_INVALID_HANDLE;
128
129    /*
130     * TODO: Set features
131     */
132
133    return VDP_STATUS_OK;
134 }
135
136 /**
137  * Perform a video post-processing and compositing operation.
138  */
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)
154 {
155    struct pipe_video_rect src_rect;
156
157    vlVdpVideoMixer *vmixer;
158    vlVdpSurface *surf;
159    vlVdpOutputSurface *dst;
160
161    vmixer = vlGetDataHTAB(mixer);
162    if (!vmixer)
163       return VDP_STATUS_INVALID_HANDLE;
164
165    surf = vlGetDataHTAB(video_surface_current);
166    if (!surf)
167       return VDP_STATUS_INVALID_HANDLE;
168
169    dst = vlGetDataHTAB(destination_surface);
170    if (!dst)
171       return VDP_STATUS_INVALID_HANDLE;
172
173    vl_compositor_clear_layers(&vmixer->compositor);
174    vl_compositor_set_buffer_layer(&vmixer->compositor, 0, surf->video_buffer,
175                                   RectToPipe(video_source_rect, &src_rect), NULL);
176    vl_compositor_render(&vmixer->compositor, dst->surface, NULL, NULL, NULL);
177
178    return VDP_STATUS_OK;
179 }
180
181 /**
182  * Set attribute values.
183  */
184 VdpStatus
185 vlVdpVideoMixerSetAttributeValues(VdpVideoMixer mixer,
186                                   uint32_t attribute_count,
187                                   VdpVideoMixerAttribute const *attributes,
188                                   void const *const *attribute_values)
189 {
190    if (!(attributes && attribute_values))
191       return VDP_STATUS_INVALID_POINTER;
192
193    vlVdpVideoMixer *vmixer = vlGetDataHTAB(mixer);
194    if (!vmixer)
195       return VDP_STATUS_INVALID_HANDLE;
196
197    /*
198     * TODO: Implement the function
199     */
200
201    return VDP_STATUS_OK;
202 }
203
204 /**
205  * Retrieve whether features were requested at creation time.
206  */
207 VdpStatus
208 vlVdpVideoMixerGetFeatureSupport(VdpVideoMixer mixer,
209                                  uint32_t feature_count,
210                                  VdpVideoMixerFeature const *features,
211                                  VdpBool *feature_supports)
212 {
213    return VDP_STATUS_NO_IMPLEMENTATION;
214 }
215
216 /**
217  * Retrieve whether features are enabled.
218  */
219 VdpStatus
220 vlVdpVideoMixerGetFeatureEnables(VdpVideoMixer mixer,
221                                  uint32_t feature_count,
222                                  VdpVideoMixerFeature const *features,
223                                  VdpBool *feature_enables)
224 {
225    return VDP_STATUS_NO_IMPLEMENTATION;
226 }
227
228 /**
229  * Retrieve parameter values given at creation time.
230  */
231 VdpStatus
232 vlVdpVideoMixerGetParameterValues(VdpVideoMixer mixer,
233                                   uint32_t parameter_count,
234                                   VdpVideoMixerParameter const *parameters,
235                                   void *const *parameter_values)
236 {
237    return VDP_STATUS_NO_IMPLEMENTATION;
238 }
239
240 /**
241  * Retrieve current attribute values.
242  */
243 VdpStatus
244 vlVdpVideoMixerGetAttributeValues(VdpVideoMixer mixer,
245                                   uint32_t attribute_count,
246                                   VdpVideoMixerAttribute const *attributes,
247                                   void *const *attribute_values)
248 {
249    return VDP_STATUS_NO_IMPLEMENTATION;
250 }
251
252 /**
253  * Generate a color space conversion matrix.
254  */
255 VdpStatus
256 vlVdpGenerateCSCMatrix(VdpProcamp *procamp,
257                        VdpColorStandard standard,
258                        VdpCSCMatrix *csc_matrix)
259 {
260    float matrix[16];
261    enum VL_CSC_COLOR_STANDARD vl_std;
262    struct vl_procamp camp;
263
264    if (!(csc_matrix && procamp))
265       return VDP_STATUS_INVALID_POINTER;
266
267    if (procamp->struct_version > VDP_PROCAMP_VERSION)
268       return VDP_STATUS_INVALID_STRUCT_VERSION;
269
270    switch (standard) {
271       case VDP_COLOR_STANDARD_ITUR_BT_601: vl_std = VL_CSC_COLOR_STANDARD_BT_601; break;
272       case VDP_COLOR_STANDARD_ITUR_BT_709: vl_std = VL_CSC_COLOR_STANDARD_BT_709; break;
273       case VDP_COLOR_STANDARD_SMPTE_240M:  vl_std = VL_CSC_COLOR_STANDARD_SMPTE_240M; break;
274       default: return VDP_STATUS_INVALID_COLOR_STANDARD;
275    }
276    camp.brightness = procamp->brightness;
277    camp.contrast = procamp->contrast;
278    camp.saturation = procamp->saturation;
279    camp.hue = procamp->hue;
280    vl_csc_get_matrix(vl_std, &camp, 1, matrix);
281    memcpy(csc_matrix, matrix, sizeof(float)*12);
282    return VDP_STATUS_OK;
283 }