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
;
87 vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue
)
89 vlVdpPresentationQueue
*pq
;
91 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Destroying PresentationQueue\n");
93 pq
= vlGetDataHTAB(presentation_queue
);
95 return VDP_STATUS_INVALID_HANDLE
;
97 vl_compositor_cleanup(&pq
->compositor
);
99 vlRemoveDataHTAB(presentation_queue
);
102 return VDP_STATUS_OK
;
106 vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue
,
107 VdpColor
*const background_color
)
109 vlVdpPresentationQueue
*pq
;
111 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Setting Background Color\n");
113 if (!background_color
)
114 return VDP_STATUS_INVALID_POINTER
;
116 pq
= vlGetDataHTAB(presentation_queue
);
118 return VDP_STATUS_INVALID_HANDLE
;
120 vl_compositor_set_clear_color(&pq
->compositor
, (float*)background_color
);
122 return VDP_STATUS_OK
;
126 vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue
,
127 VdpColor
*const background_color
)
129 if (!background_color
)
130 return VDP_STATUS_INVALID_POINTER
;
132 return VDP_STATUS_NO_IMPLEMENTATION
;
136 vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue
,
137 VdpTime
*current_time
)
140 return VDP_STATUS_INVALID_POINTER
;
142 return VDP_STATUS_NO_IMPLEMENTATION
;
146 vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue
,
147 VdpOutputSurface surface
,
149 uint32_t clip_height
,
150 VdpTime earliest_presentation_time
)
152 static int dump_window
= -1;
154 vlVdpPresentationQueue
*pq
;
155 vlVdpOutputSurface
*surf
;
156 struct pipe_surface
*drawable_surface
;
158 pq
= vlGetDataHTAB(presentation_queue
);
160 return VDP_STATUS_INVALID_HANDLE
;
162 drawable_surface
= vl_drawable_surface_get(pq
->device
->context
, pq
->drawable
);
163 if (!drawable_surface
)
164 return VDP_STATUS_INVALID_HANDLE
;
166 surf
= vlGetDataHTAB(surface
);
168 return VDP_STATUS_INVALID_HANDLE
;
170 vl_compositor_clear_layers(&pq
->compositor
);
171 vl_compositor_set_rgba_layer(&pq
->compositor
, 0, surf
->sampler_view
, NULL
, NULL
);
172 vl_compositor_render(&pq
->compositor
, drawable_surface
, NULL
, NULL
, true);
174 pq
->device
->context
->pipe
->screen
->flush_frontbuffer
176 pq
->device
->context
->pipe
->screen
,
177 drawable_surface
->texture
,
179 vl_contextprivate_get(pq
->device
->context
, drawable_surface
)
182 if(dump_window
== -1) {
183 dump_window
= debug_get_num_option("VDPAU_DUMP", 0);
187 static unsigned int framenum
= 0;
190 sprintf(cmd
, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq
->drawable
, ++framenum
);
191 if (system(cmd
) != 0)
192 VDPAU_MSG(VDPAU_TRACE
, "[VDPAU] Dumping surface %d failed.\n", surface
);
195 pipe_surface_reference(&drawable_surface
, NULL
);
197 return VDP_STATUS_OK
;
201 vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue
,
202 VdpOutputSurface surface
,
203 VdpTime
*first_presentation_time
)
205 if (!first_presentation_time
)
206 return VDP_STATUS_INVALID_POINTER
;
208 //return VDP_STATUS_NO_IMPLEMENTATION;
209 return VDP_STATUS_OK
;
213 vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue
,
214 VdpOutputSurface surface
,
215 VdpPresentationQueueStatus
*status
,
216 VdpTime
*first_presentation_time
)
218 if (!(status
&& first_presentation_time
))
219 return VDP_STATUS_INVALID_POINTER
;
221 return VDP_STATUS_NO_IMPLEMENTATION
;