presentation.c revision fa2a8316cebeb75626ffa3e38dbc1500e82054f6
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   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Getting background color\n");
143
144   if (!background_color)
145      return VDP_STATUS_INVALID_POINTER;
146
147   return VDP_STATUS_NO_IMPLEMENTATION;
148}
149
150/**
151 * Retrieve the presentation queue's "current" time.
152 */
153VdpStatus
154vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue,
155                              VdpTime *current_time)
156{
157   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Getting queue time\n");
158
159   if (!current_time)
160      return VDP_STATUS_INVALID_POINTER;
161
162   return VDP_STATUS_NO_IMPLEMENTATION;
163}
164
165/**
166 * Enter a surface into the presentation queue.
167 */
168VdpStatus
169vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue,
170                              VdpOutputSurface surface,
171                              uint32_t clip_width,
172                              uint32_t clip_height,
173                              VdpTime  earliest_presentation_time)
174{
175   static int dump_window = -1;
176
177   vlVdpPresentationQueue *pq;
178   vlVdpOutputSurface *surf;
179   struct pipe_surface *drawable_surface;
180
181   pq = vlGetDataHTAB(presentation_queue);
182   if (!pq)
183      return VDP_STATUS_INVALID_HANDLE;
184
185   drawable_surface = vl_drawable_surface_get(pq->device->context, pq->drawable);
186   if (!drawable_surface)
187      return VDP_STATUS_INVALID_HANDLE;
188
189   surf = vlGetDataHTAB(surface);
190   if (!surf)
191      return VDP_STATUS_INVALID_HANDLE;
192
193   vl_compositor_clear_layers(&pq->compositor);
194   vl_compositor_set_rgba_layer(&pq->compositor, 0, surf->sampler_view, NULL, NULL);
195   vl_compositor_render(&pq->compositor, drawable_surface, NULL, NULL, true);
196
197   pq->device->context->pipe->screen->flush_frontbuffer
198   (
199      pq->device->context->pipe->screen,
200      drawable_surface->texture,
201      0, 0,
202      vl_contextprivate_get(pq->device->context, drawable_surface)
203   );
204
205   if (dump_window == -1) {
206      dump_window = debug_get_num_option("VDPAU_DUMP", 0);
207   }
208
209   if (dump_window) {
210      static unsigned int framenum = 0;
211      char cmd[256];
212
213      sprintf(cmd, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq->drawable, ++framenum);
214      if (system(cmd) != 0)
215         VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Dumping surface %d failed.\n", surface);
216   }
217
218   pipe_surface_reference(&drawable_surface, NULL);
219
220   return VDP_STATUS_OK;
221}
222
223/**
224 * Wait for a surface to finish being displayed.
225 */
226VdpStatus
227vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue,
228                                            VdpOutputSurface surface,
229                                            VdpTime *first_presentation_time)
230{
231   if (!first_presentation_time)
232      return VDP_STATUS_INVALID_POINTER;
233
234   //return VDP_STATUS_NO_IMPLEMENTATION;
235   return VDP_STATUS_OK;
236}
237
238/**
239 * Poll the current queue status of a surface.
240 */
241VdpStatus
242vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue,
243                                         VdpOutputSurface surface,
244                                         VdpPresentationQueueStatus *status,
245                                         VdpTime *first_presentation_time)
246{
247   if (!(status && first_presentation_time))
248      return VDP_STATUS_INVALID_POINTER;
249
250   return VDP_STATUS_NO_IMPLEMENTATION;
251}
252