presentation.c revision 835ea8480f656ba4076e30813eb8c85965017266
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, drawable_surface, NULL, NULL); 173 174 pq->device->context->pipe->screen->flush_frontbuffer 175 ( 176 pq->device->context->pipe->screen, 177 drawable_surface->texture, 178 0, 0, 179 vl_contextprivate_get(pq->device->context, drawable_surface) 180 ); 181 182 if(dump_window == -1) { 183 dump_window = debug_get_num_option("VDPAU_DUMP", 0); 184 } 185 186 if(dump_window) { 187 static unsigned int framenum = 0; 188 char cmd[256]; 189 190 sprintf(cmd, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq->drawable, ++framenum); 191 if (system(cmd) != 0) 192 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Dumping surface %d failed.\n", surface); 193 } 194 195 pipe_surface_reference(&drawable_surface, NULL); 196 197 return VDP_STATUS_OK; 198} 199 200VdpStatus 201vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue, 202 VdpOutputSurface surface, 203 VdpTime *first_presentation_time) 204{ 205 if (!first_presentation_time) 206 return VDP_STATUS_INVALID_POINTER; 207 208 //return VDP_STATUS_NO_IMPLEMENTATION; 209 return VDP_STATUS_OK; 210} 211 212VdpStatus 213vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue, 214 VdpOutputSurface surface, 215 VdpPresentationQueueStatus *status, 216 VdpTime *first_presentation_time) 217{ 218 if (!(status && first_presentation_time)) 219 return VDP_STATUS_INVALID_POINTER; 220 221 return VDP_STATUS_NO_IMPLEMENTATION; 222} 223