st/vdpau: Various whitespace cleanups found while reading some code
[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 VdpStatus ret;
44
45 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating PresentationQueue\n");
46
47 if (!presentation_queue)
48 return VDP_STATUS_INVALID_POINTER;
49
50 vlVdpDevice *dev = vlGetDataHTAB(device);
51 if (!dev)
52 return VDP_STATUS_INVALID_HANDLE;
53
54 vlVdpPresentationQueueTarget *pqt = vlGetDataHTAB(presentation_queue_target);
55 if (!pqt)
56 return VDP_STATUS_INVALID_HANDLE;
57
58 if (dev != pqt->device)
59 return VDP_STATUS_HANDLE_DEVICE_MISMATCH;
60
61 pq = CALLOC(1, sizeof(vlVdpPresentationQueue));
62 if (!pq)
63 return VDP_STATUS_RESOURCES;
64
65 pq->device = dev;
66 pq->drawable = pqt->drawable;
67
68 if (!vl_compositor_init(&pq->compositor, dev->context->pipe)) {
69 ret = VDP_STATUS_ERROR;
70 goto no_compositor;
71 }
72
73 *presentation_queue = vlAddDataHTAB(pq);
74 if (*presentation_queue == 0) {
75 ret = VDP_STATUS_ERROR;
76 goto no_handle;
77 }
78
79 return VDP_STATUS_OK;
80
81 no_handle:
82 no_compositor:
83 FREE(pq);
84 return ret;
85 }
86
87 VdpStatus
88 vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue)
89 {
90 vlVdpPresentationQueue *pq;
91
92 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying PresentationQueue\n");
93
94 pq = vlGetDataHTAB(presentation_queue);
95 if (!pq)
96 return VDP_STATUS_INVALID_HANDLE;
97
98 vl_compositor_cleanup(&pq->compositor);
99
100 vlRemoveDataHTAB(presentation_queue);
101 FREE(pq);
102
103 return VDP_STATUS_OK;
104 }
105
106 VdpStatus
107 vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue,
108 VdpColor *const background_color)
109 {
110 vlVdpPresentationQueue *pq;
111
112 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Setting Background Color\n");
113
114 if (!background_color)
115 return VDP_STATUS_INVALID_POINTER;
116
117 pq = vlGetDataHTAB(presentation_queue);
118 if (!pq)
119 return VDP_STATUS_INVALID_HANDLE;
120
121 vl_compositor_set_clear_color(&pq->compositor, (float*)background_color);
122
123 return VDP_STATUS_OK;
124 }
125
126 VdpStatus
127 vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue,
128 VdpColor *const background_color)
129 {
130 if (!background_color)
131 return VDP_STATUS_INVALID_POINTER;
132
133 return VDP_STATUS_NO_IMPLEMENTATION;
134 }
135
136 VdpStatus
137 vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue,
138 VdpTime *current_time)
139 {
140 if (!current_time)
141 return VDP_STATUS_INVALID_POINTER;
142
143 return VDP_STATUS_NO_IMPLEMENTATION;
144 }
145
146 VdpStatus
147 vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue,
148 VdpOutputSurface surface,
149 uint32_t clip_width,
150 uint32_t clip_height,
151 VdpTime earliest_presentation_time)
152 {
153 static int dump_window = -1;
154
155 vlVdpPresentationQueue *pq;
156 vlVdpOutputSurface *surf;
157 struct pipe_surface *drawable_surface;
158
159 pq = vlGetDataHTAB(presentation_queue);
160 if (!pq)
161 return VDP_STATUS_INVALID_HANDLE;
162
163 drawable_surface = vl_drawable_surface_get(pq->device->context, pq->drawable);
164 if (!drawable_surface)
165 return VDP_STATUS_INVALID_HANDLE;
166
167 surf = vlGetDataHTAB(surface);
168 if (!surf)
169 return VDP_STATUS_INVALID_HANDLE;
170
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);
174
175 pq->device->context->pipe->screen->flush_frontbuffer
176 (
177 pq->device->context->pipe->screen,
178 drawable_surface->texture,
179 0, 0,
180 vl_contextprivate_get(pq->device->context, drawable_surface)
181 );
182
183 if (dump_window == -1) {
184 dump_window = debug_get_num_option("VDPAU_DUMP", 0);
185 }
186
187 if (dump_window) {
188 static unsigned int framenum = 0;
189 char cmd[256];
190
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);
194 }
195
196 pipe_surface_reference(&drawable_surface, NULL);
197
198 return VDP_STATUS_OK;
199 }
200
201 VdpStatus
202 vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue,
203 VdpOutputSurface surface,
204 VdpTime *first_presentation_time)
205 {
206 if (!first_presentation_time)
207 return VDP_STATUS_INVALID_POINTER;
208
209 //return VDP_STATUS_NO_IMPLEMENTATION;
210 return VDP_STATUS_OK;
211 }
212
213 VdpStatus
214 vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue,
215 VdpOutputSurface surface,
216 VdpPresentationQueueStatus *status,
217 VdpTime *first_presentation_time)
218 {
219 if (!(status && first_presentation_time))
220 return VDP_STATUS_INVALID_POINTER;
221
222 return VDP_STATUS_NO_IMPLEMENTATION;
223 }