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
;
45 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Creating PresentationQueue\n");
47 if (!presentation_queue
)
48 return VDP_STATUS_INVALID_POINTER
;
50 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
52 return VDP_STATUS_INVALID_HANDLE
;
54 vlVdpPresentationQueueTarget
*pqt
= vlGetDataHTAB(presentation_queue_target
);
56 return VDP_STATUS_INVALID_HANDLE
;
58 if (dev
!= pqt
->device
)
59 return VDP_STATUS_HANDLE_DEVICE_MISMATCH
;
61 pq
= CALLOC(1, sizeof(vlVdpPresentationQueue
));
63 return VDP_STATUS_RESOURCES
;
66 pq
->drawable
= pqt
->drawable
;
68 if (!vl_compositor_init(&pq
->compositor
, dev
->context
->pipe
)) {
69 ret
= VDP_STATUS_ERROR
;
73 *presentation_queue
= vlAddDataHTAB(pq
);
74 if (*presentation_queue
== 0) {
75 ret
= VDP_STATUS_ERROR
;
88 vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue
)
90 vlVdpPresentationQueue
*pq
;
92 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Destroying PresentationQueue\n");
94 pq
= vlGetDataHTAB(presentation_queue
);
96 return VDP_STATUS_INVALID_HANDLE
;
98 vl_compositor_cleanup(&pq
->compositor
);
100 vlRemoveDataHTAB(presentation_queue
);
103 return VDP_STATUS_OK
;
107 vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue
,
108 VdpColor
*const background_color
)
110 vlVdpPresentationQueue
*pq
;
112 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Setting Background Color\n");
114 if (!background_color
)
115 return VDP_STATUS_INVALID_POINTER
;
117 pq
= vlGetDataHTAB(presentation_queue
);
119 return VDP_STATUS_INVALID_HANDLE
;
121 vl_compositor_set_clear_color(&pq
->compositor
, (float*)background_color
);
123 return VDP_STATUS_OK
;
127 vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue
,
128 VdpColor
*const background_color
)
130 if (!background_color
)
131 return VDP_STATUS_INVALID_POINTER
;
133 return VDP_STATUS_NO_IMPLEMENTATION
;
137 vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue
,
138 VdpTime
*current_time
)
141 return VDP_STATUS_INVALID_POINTER
;
143 return VDP_STATUS_NO_IMPLEMENTATION
;
147 vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue
,
148 VdpOutputSurface surface
,
150 uint32_t clip_height
,
151 VdpTime earliest_presentation_time
)
153 static int dump_window
= -1;
155 vlVdpPresentationQueue
*pq
;
156 vlVdpOutputSurface
*surf
;
157 struct pipe_surface
*drawable_surface
;
159 pq
= vlGetDataHTAB(presentation_queue
);
161 return VDP_STATUS_INVALID_HANDLE
;
163 drawable_surface
= vl_drawable_surface_get(pq
->device
->context
, pq
->drawable
);
164 if (!drawable_surface
)
165 return VDP_STATUS_INVALID_HANDLE
;
167 surf
= vlGetDataHTAB(surface
);
169 return VDP_STATUS_INVALID_HANDLE
;
171 vl_compositor_clear_layers(&pq
->compositor
);
172 vl_compositor_set_rgba_layer(&pq
->compositor
, 0, surf
->sampler_view
, NULL
, NULL
);
173 vl_compositor_render(&pq
->compositor
, drawable_surface
, NULL
, NULL
, true);
175 pq
->device
->context
->pipe
->screen
->flush_frontbuffer
177 pq
->device
->context
->pipe
->screen
,
178 drawable_surface
->texture
,
180 vl_contextprivate_get(pq
->device
->context
, drawable_surface
)
183 if (dump_window
== -1) {
184 dump_window
= debug_get_num_option("VDPAU_DUMP", 0);
188 static unsigned int framenum
= 0;
191 sprintf(cmd
, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq
->drawable
, ++framenum
);
192 if (system(cmd
) != 0)
193 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Dumping surface %d failed.\n", surface
);
196 pipe_surface_reference(&drawable_surface
, NULL
);
198 return VDP_STATUS_OK
;
202 vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue
,
203 VdpOutputSurface surface
,
204 VdpTime
*first_presentation_time
)
206 if (!first_presentation_time
)
207 return VDP_STATUS_INVALID_POINTER
;
209 //return VDP_STATUS_NO_IMPLEMENTATION;
210 return VDP_STATUS_OK
;
214 vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue
,
215 VdpOutputSurface surface
,
216 VdpPresentationQueueStatus
*status
,
217 VdpTime
*first_presentation_time
)
219 if (!(status
&& first_presentation_time
))
220 return VDP_STATUS_INVALID_POINTER
;
222 return VDP_STATUS_NO_IMPLEMENTATION
;