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 **************************************************************************/
30 #include <vdpau/vdpau.h>
32 #include <util/u_debug.h>
33 #include <util/u_memory.h>
35 #include "vdpau_private.h"
38 vlVdpPresentationQueueCreate(VdpDevice device
,
39 VdpPresentationQueueTarget presentation_queue_target
,
40 VdpPresentationQueue
*presentation_queue
)
42 vlVdpPresentationQueue
*pq
= NULL
;
43 struct pipe_video_context
*context
;
46 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Creating PresentationQueue\n");
48 if (!presentation_queue
)
49 return VDP_STATUS_INVALID_POINTER
;
51 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
53 return VDP_STATUS_INVALID_HANDLE
;
55 vlVdpPresentationQueueTarget
*pqt
= vlGetDataHTAB(presentation_queue_target
);
57 return VDP_STATUS_INVALID_HANDLE
;
59 if (dev
!= pqt
->device
)
60 return VDP_STATUS_HANDLE_DEVICE_MISMATCH
;
62 context
= dev
->context
->vpipe
;
64 pq
= CALLOC(1, sizeof(vlVdpPresentationQueue
));
66 return VDP_STATUS_RESOURCES
;
69 pq
->drawable
= pqt
->drawable
;
70 pq
->compositor
= context
->create_compositor(context
);
71 if (!pq
->compositor
) {
72 ret
= VDP_STATUS_ERROR
;
76 *presentation_queue
= vlAddDataHTAB(pq
);
77 if (*presentation_queue
== 0) {
78 ret
= VDP_STATUS_ERROR
;
90 vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue
)
92 vlVdpPresentationQueue
*pq
;
94 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Destroying PresentationQueue\n");
96 pq
= vlGetDataHTAB(presentation_queue
);
98 return VDP_STATUS_INVALID_HANDLE
;
100 pq
->compositor
->destroy(pq
->compositor
);
102 vlRemoveDataHTAB(presentation_queue
);
105 return VDP_STATUS_OK
;
109 vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue
,
110 VdpColor
*const background_color
)
112 vlVdpPresentationQueue
*pq
;
114 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Setting Background Color\n");
116 if (!background_color
)
117 return VDP_STATUS_INVALID_POINTER
;
119 pq
= vlGetDataHTAB(presentation_queue
);
121 return VDP_STATUS_INVALID_HANDLE
;
123 pq
->compositor
->set_clear_color(pq
->compositor
, (float*)background_color
);
125 return VDP_STATUS_OK
;
129 vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue
,
130 VdpColor
*const background_color
)
132 if (!background_color
)
133 return VDP_STATUS_INVALID_POINTER
;
135 return VDP_STATUS_NO_IMPLEMENTATION
;
139 vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue
,
140 VdpTime
*current_time
)
143 return VDP_STATUS_INVALID_POINTER
;
145 return VDP_STATUS_NO_IMPLEMENTATION
;
149 vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue
,
150 VdpOutputSurface surface
,
152 uint32_t clip_height
,
153 VdpTime earliest_presentation_time
)
155 static int dump_window
= -1;
157 vlVdpPresentationQueue
*pq
;
158 vlVdpOutputSurface
*surf
;
159 struct pipe_surface
*drawable_surface
;
161 pq
= vlGetDataHTAB(presentation_queue
);
163 return VDP_STATUS_INVALID_HANDLE
;
165 drawable_surface
= vl_drawable_surface_get(pq
->device
->context
, pq
->drawable
);
166 if (!drawable_surface
)
167 return VDP_STATUS_INVALID_HANDLE
;
169 surf
= vlGetDataHTAB(surface
);
171 return VDP_STATUS_INVALID_HANDLE
;
173 pq
->compositor
->clear_layers(pq
->compositor
);
174 pq
->compositor
->set_rgba_layer(pq
->compositor
, 0, surf
->sampler_view
, NULL
, NULL
);
175 pq
->compositor
->render_picture(pq
->compositor
, PIPE_MPEG12_PICTURE_TYPE_FRAME
,
176 drawable_surface
, NULL
, NULL
);
178 pq
->device
->context
->vpipe
->screen
->flush_frontbuffer
180 pq
->device
->context
->vpipe
->screen
,
181 drawable_surface
->texture
,
183 vl_contextprivate_get(pq
->device
->context
, drawable_surface
)
186 if(dump_window
== -1) {
187 dump_window
= debug_get_num_option("VDPAU_DUMP", 0);
191 static unsigned int framenum
= 0;
194 sprintf(cmd
, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq
->drawable
, ++framenum
);
195 if (system(cmd
) != 0)
196 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Dumping surface %d failed.\n", surface
);
199 return VDP_STATUS_OK
;
203 vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue
,
204 VdpOutputSurface surface
,
205 VdpTime
*first_presentation_time
)
207 if (!first_presentation_time
)
208 return VDP_STATUS_INVALID_POINTER
;
210 //return VDP_STATUS_NO_IMPLEMENTATION;
211 return VDP_STATUS_OK
;
215 vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue
,
216 VdpOutputSurface surface
,
217 VdpPresentationQueueStatus
*status
,
218 VdpTime
*first_presentation_time
)
220 if (!(status
&& first_presentation_time
))
221 return VDP_STATUS_INVALID_POINTER
;
223 return VDP_STATUS_NO_IMPLEMENTATION
;