Merge remote-tracking branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / state_trackers / vdpau / presentation.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 <stdio.h>
29
30 #include <vdpau/vdpau.h>
31
32 #include <util/u_debug.h>
33 #include <util/u_memory.h>
34
35 #include "vdpau_private.h"
36
37 VdpStatus
38 vlVdpPresentationQueueCreate(VdpDevice device,
39 VdpPresentationQueueTarget presentation_queue_target,
40 VdpPresentationQueue *presentation_queue)
41 {
42 vlVdpPresentationQueue *pq = NULL;
43 struct pipe_video_context *context;
44 VdpStatus ret;
45
46 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating PresentationQueue\n");
47
48 if (!presentation_queue)
49 return VDP_STATUS_INVALID_POINTER;
50
51 vlVdpDevice *dev = vlGetDataHTAB(device);
52 if (!dev)
53 return VDP_STATUS_INVALID_HANDLE;
54
55 vlVdpPresentationQueueTarget *pqt = vlGetDataHTAB(presentation_queue_target);
56 if (!pqt)
57 return VDP_STATUS_INVALID_HANDLE;
58
59 if (dev != pqt->device)
60 return VDP_STATUS_HANDLE_DEVICE_MISMATCH;
61
62 context = dev->context->vpipe;
63
64 pq = CALLOC(1, sizeof(vlVdpPresentationQueue));
65 if (!pq)
66 return VDP_STATUS_RESOURCES;
67
68 pq->device = dev;
69 pq->drawable = pqt->drawable;
70 pq->compositor = context->create_compositor(context);
71 if (!pq->compositor) {
72 ret = VDP_STATUS_ERROR;
73 goto no_compositor;
74 }
75
76 *presentation_queue = vlAddDataHTAB(pq);
77 if (*presentation_queue == 0) {
78 ret = VDP_STATUS_ERROR;
79 goto no_handle;
80 }
81
82 return VDP_STATUS_OK;
83 no_handle:
84 no_compositor:
85 FREE(pq);
86 return ret;
87 }
88
89 VdpStatus
90 vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue)
91 {
92 vlVdpPresentationQueue *pq;
93
94 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying PresentationQueue\n");
95
96 pq = vlGetDataHTAB(presentation_queue);
97 if (!pq)
98 return VDP_STATUS_INVALID_HANDLE;
99
100 pq->compositor->destroy(pq->compositor);
101
102 vlRemoveDataHTAB(presentation_queue);
103 FREE(pq);
104
105 return VDP_STATUS_OK;
106 }
107
108 VdpStatus
109 vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue,
110 VdpColor *const background_color)
111 {
112 vlVdpPresentationQueue *pq;
113
114 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Setting Background Color\n");
115
116 if (!background_color)
117 return VDP_STATUS_INVALID_POINTER;
118
119 pq = vlGetDataHTAB(presentation_queue);
120 if (!pq)
121 return VDP_STATUS_INVALID_HANDLE;
122
123 pq->compositor->set_clear_color(pq->compositor, (float*)background_color);
124
125 return VDP_STATUS_OK;
126 }
127
128 VdpStatus
129 vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue,
130 VdpColor *const background_color)
131 {
132 if (!background_color)
133 return VDP_STATUS_INVALID_POINTER;
134
135 return VDP_STATUS_NO_IMPLEMENTATION;
136 }
137
138 VdpStatus
139 vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue,
140 VdpTime *current_time)
141 {
142 if (!current_time)
143 return VDP_STATUS_INVALID_POINTER;
144
145 return VDP_STATUS_NO_IMPLEMENTATION;
146 }
147
148 VdpStatus
149 vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue,
150 VdpOutputSurface surface,
151 uint32_t clip_width,
152 uint32_t clip_height,
153 VdpTime earliest_presentation_time)
154 {
155 static int dump_window = -1;
156
157 vlVdpPresentationQueue *pq;
158 vlVdpOutputSurface *surf;
159 struct pipe_surface *drawable_surface;
160
161 pq = vlGetDataHTAB(presentation_queue);
162 if (!pq)
163 return VDP_STATUS_INVALID_HANDLE;
164
165 drawable_surface = vl_drawable_surface_get(pq->device->context, pq->drawable);
166 if (!drawable_surface)
167 return VDP_STATUS_INVALID_HANDLE;
168
169 surf = vlGetDataHTAB(surface);
170 if (!surf)
171 return VDP_STATUS_INVALID_HANDLE;
172
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);
177
178 pq->device->context->vpipe->screen->flush_frontbuffer
179 (
180 pq->device->context->vpipe->screen,
181 drawable_surface->texture,
182 0, 0,
183 vl_contextprivate_get(pq->device->context, drawable_surface)
184 );
185
186 if(dump_window == -1) {
187 dump_window = debug_get_num_option("VDPAU_DUMP", 0);
188 }
189
190 if(dump_window) {
191 static unsigned int framenum = 0;
192 char cmd[256];
193
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);
197 }
198
199 return VDP_STATUS_OK;
200 }
201
202 VdpStatus
203 vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue,
204 VdpOutputSurface surface,
205 VdpTime *first_presentation_time)
206 {
207 if (!first_presentation_time)
208 return VDP_STATUS_INVALID_POINTER;
209
210 //return VDP_STATUS_NO_IMPLEMENTATION;
211 return VDP_STATUS_OK;
212 }
213
214 VdpStatus
215 vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue,
216 VdpOutputSurface surface,
217 VdpPresentationQueueStatus *status,
218 VdpTime *first_presentation_time)
219 {
220 if (!(status && first_presentation_time))
221 return VDP_STATUS_INVALID_POINTER;
222
223 return VDP_STATUS_NO_IMPLEMENTATION;
224 }