presentation.c revision 2cbf532ae13513c3cbc7dad8ae41beeff931529e
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
37VdpStatus
38vlVdpPresentationQueueCreate(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;
80no_handle:
81no_compositor:
82   FREE(pq);
83   return ret;
84}
85
86VdpStatus
87vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue)
88{
89   vlVdpPresentationQueue *pq;
90
91   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying PresentationQueue\n");
92
93   pq = vlGetDataHTAB(presentation_queue);
94   if (!pq)
95      return VDP_STATUS_INVALID_HANDLE;
96
97   vl_compositor_cleanup(&pq->compositor);
98
99   vlRemoveDataHTAB(presentation_queue);
100   FREE(pq);
101
102   return VDP_STATUS_OK;
103}
104
105VdpStatus
106vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue,
107                                         VdpColor *const background_color)
108{
109   vlVdpPresentationQueue *pq;
110
111   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Setting Background Color\n");
112
113   if (!background_color)
114      return VDP_STATUS_INVALID_POINTER;
115
116   pq = vlGetDataHTAB(presentation_queue);
117   if (!pq)
118      return VDP_STATUS_INVALID_HANDLE;
119
120   vl_compositor_set_clear_color(&pq->compositor, (float*)background_color);
121
122   return VDP_STATUS_OK;
123}
124
125VdpStatus
126vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue,
127                                         VdpColor *const background_color)
128{
129   if (!background_color)
130      return VDP_STATUS_INVALID_POINTER;
131
132   return VDP_STATUS_NO_IMPLEMENTATION;
133}
134
135VdpStatus
136vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue,
137                              VdpTime *current_time)
138{
139   if (!current_time)
140      return VDP_STATUS_INVALID_POINTER;
141
142   return VDP_STATUS_NO_IMPLEMENTATION;
143}
144
145VdpStatus
146vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue,
147                              VdpOutputSurface surface,
148                              uint32_t clip_width,
149                              uint32_t clip_height,
150                              VdpTime  earliest_presentation_time)
151{
152   static int dump_window = -1;
153
154   vlVdpPresentationQueue *pq;
155   vlVdpOutputSurface *surf;
156   struct pipe_surface *drawable_surface;
157
158   pq = vlGetDataHTAB(presentation_queue);
159   if (!pq)
160      return VDP_STATUS_INVALID_HANDLE;
161
162   drawable_surface = vl_drawable_surface_get(pq->device->context, pq->drawable);
163   if (!drawable_surface)
164      return VDP_STATUS_INVALID_HANDLE;
165
166   surf = vlGetDataHTAB(surface);
167   if (!surf)
168      return VDP_STATUS_INVALID_HANDLE;
169
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, PIPE_MPEG12_PICTURE_TYPE_FRAME,
173                        drawable_surface, NULL, NULL, NULL);
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
201VdpStatus
202vlVdpPresentationQueueBlockUntilSurfaceIdle(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
213VdpStatus
214vlVdpPresentationQueueQuerySurfaceStatus(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}
224