presentation.c revision 85534e6f48c1ad6ff8dee77e0407c6c3dedb4b84
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/**
38 * Create a VdpPresentationQueue.
39 */
40VdpStatus
41vlVdpPresentationQueueCreate(VdpDevice device,
42                             VdpPresentationQueueTarget presentation_queue_target,
43                             VdpPresentationQueue *presentation_queue)
44{
45   vlVdpPresentationQueue *pq = NULL;
46   VdpStatus ret;
47
48   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating PresentationQueue\n");
49
50   if (!presentation_queue)
51      return VDP_STATUS_INVALID_POINTER;
52
53   vlVdpDevice *dev = vlGetDataHTAB(device);
54   if (!dev)
55      return VDP_STATUS_INVALID_HANDLE;
56
57   vlVdpPresentationQueueTarget *pqt = vlGetDataHTAB(presentation_queue_target);
58   if (!pqt)
59      return VDP_STATUS_INVALID_HANDLE;
60
61   if (dev != pqt->device)
62      return VDP_STATUS_HANDLE_DEVICE_MISMATCH;
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
71   if (!vl_compositor_init(&pq->compositor, dev->context->pipe)) {
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
84no_handle:
85no_compositor:
86   FREE(pq);
87   return ret;
88}
89
90/**
91 * Destroy a VdpPresentationQueue.
92 */
93VdpStatus
94vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue)
95{
96   vlVdpPresentationQueue *pq;
97
98   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying PresentationQueue\n");
99
100   pq = vlGetDataHTAB(presentation_queue);
101   if (!pq)
102      return VDP_STATUS_INVALID_HANDLE;
103
104   vl_compositor_cleanup(&pq->compositor);
105
106   vlRemoveDataHTAB(presentation_queue);
107   FREE(pq);
108
109   return VDP_STATUS_OK;
110}
111
112/**
113 * Configure the background color setting.
114 */
115VdpStatus
116vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue,
117                                         VdpColor *const background_color)
118{
119   vlVdpPresentationQueue *pq;
120
121   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Setting background color\n");
122
123   if (!background_color)
124      return VDP_STATUS_INVALID_POINTER;
125
126   pq = vlGetDataHTAB(presentation_queue);
127   if (!pq)
128      return VDP_STATUS_INVALID_HANDLE;
129
130   vl_compositor_set_clear_color(&pq->compositor, (float*)background_color);
131
132   return VDP_STATUS_OK;
133}
134
135/**
136 * Retrieve the current background color setting.
137 */
138VdpStatus
139vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue,
140                                         VdpColor *const background_color)
141{
142   vlVdpPresentationQueue *pq;
143
144   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Getting background color\n");
145
146   if (!background_color)
147      return VDP_STATUS_INVALID_POINTER;
148
149   pq = vlGetDataHTAB(presentation_queue);
150   if (!pq)
151      return VDP_STATUS_INVALID_HANDLE;
152
153   vl_compositor_get_clear_color(&pq->compositor, (float*)background_color);
154
155   return VDP_STATUS_OK;
156}
157
158/**
159 * Retrieve the presentation queue's "current" time.
160 */
161VdpStatus
162vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue,
163                              VdpTime *current_time)
164{
165   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Getting queue time\n");
166
167   if (!current_time)
168      return VDP_STATUS_INVALID_POINTER;
169
170   return VDP_STATUS_NO_IMPLEMENTATION;
171}
172
173/**
174 * Enter a surface into the presentation queue.
175 */
176VdpStatus
177vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue,
178                              VdpOutputSurface surface,
179                              uint32_t clip_width,
180                              uint32_t clip_height,
181                              VdpTime  earliest_presentation_time)
182{
183   static int dump_window = -1;
184
185   vlVdpPresentationQueue *pq;
186   vlVdpOutputSurface *surf;
187   struct pipe_surface *drawable_surface;
188
189   pq = vlGetDataHTAB(presentation_queue);
190   if (!pq)
191      return VDP_STATUS_INVALID_HANDLE;
192
193   drawable_surface = vl_drawable_surface_get(pq->device->context, pq->drawable);
194   if (!drawable_surface)
195      return VDP_STATUS_INVALID_HANDLE;
196
197   surf = vlGetDataHTAB(surface);
198   if (!surf)
199      return VDP_STATUS_INVALID_HANDLE;
200
201   vl_compositor_clear_layers(&pq->compositor);
202   vl_compositor_set_rgba_layer(&pq->compositor, 0, surf->sampler_view, NULL, NULL);
203   vl_compositor_render(&pq->compositor, drawable_surface, NULL, NULL, true);
204
205   pq->device->context->pipe->screen->flush_frontbuffer
206   (
207      pq->device->context->pipe->screen,
208      drawable_surface->texture,
209      0, 0,
210      vl_contextprivate_get(pq->device->context, drawable_surface)
211   );
212
213   if (dump_window == -1) {
214      dump_window = debug_get_num_option("VDPAU_DUMP", 0);
215   }
216
217   if (dump_window) {
218      static unsigned int framenum = 0;
219      char cmd[256];
220
221      sprintf(cmd, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq->drawable, ++framenum);
222      if (system(cmd) != 0)
223         VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Dumping surface %d failed.\n", surface);
224   }
225
226   pipe_surface_reference(&drawable_surface, NULL);
227
228   return VDP_STATUS_OK;
229}
230
231/**
232 * Wait for a surface to finish being displayed.
233 */
234VdpStatus
235vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue,
236                                            VdpOutputSurface surface,
237                                            VdpTime *first_presentation_time)
238{
239   if (!first_presentation_time)
240      return VDP_STATUS_INVALID_POINTER;
241
242   //return VDP_STATUS_NO_IMPLEMENTATION;
243   return VDP_STATUS_OK;
244}
245
246/**
247 * Poll the current queue status of a surface.
248 */
249VdpStatus
250vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue,
251                                         VdpOutputSurface surface,
252                                         VdpPresentationQueueStatus *status,
253                                         VdpTime *first_presentation_time)
254{
255   if (!(status && first_presentation_time))
256      return VDP_STATUS_INVALID_POINTER;
257
258   return VDP_STATUS_NO_IMPLEMENTATION;
259}
260