presentation.c revision 08f3a7cf7e9133f50adf33f800aa3696c909347f
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 struct pipe_video_context *context; 44 VdpStatus ret; 45 46 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating PresentationQueue\n"); 47 48 if (!presentation_queue) 49 return VDP_STATUS_INVALID_POINTER; 50 51 vlVdpDevice *dev = vlGetDataHTAB(device); 52 if (!dev) 53 return VDP_STATUS_INVALID_HANDLE; 54 55 vlVdpPresentationQueueTarget *pqt = vlGetDataHTAB(presentation_queue_target); 56 if (!pqt) 57 return VDP_STATUS_INVALID_HANDLE; 58 59 if (dev != pqt->device) 60 return VDP_STATUS_HANDLE_DEVICE_MISMATCH; 61 62 context = dev->context->vpipe; 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 pq->compositor = context->create_compositor(context); 71 if (!pq->compositor) { 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; 83no_handle: 84no_compositor: 85 FREE(pq); 86 return ret; 87} 88 89VdpStatus 90vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue) 91{ 92 vlVdpPresentationQueue *pq; 93 94 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying PresentationQueue\n"); 95 96 pq = vlGetDataHTAB(presentation_queue); 97 if (!pq) 98 return VDP_STATUS_INVALID_HANDLE; 99 100 pq->compositor->destroy(pq->compositor); 101 102 vlRemoveDataHTAB(presentation_queue); 103 FREE(pq); 104 105 return VDP_STATUS_OK; 106} 107 108VdpStatus 109vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue, 110 VdpColor *const background_color) 111{ 112 if (!background_color) 113 return VDP_STATUS_INVALID_POINTER; 114 115 return VDP_STATUS_NO_IMPLEMENTATION; 116} 117 118VdpStatus 119vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue, 120 VdpColor *const background_color) 121{ 122 if (!background_color) 123 return VDP_STATUS_INVALID_POINTER; 124 125 return VDP_STATUS_NO_IMPLEMENTATION; 126} 127 128VdpStatus 129vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue, 130 VdpTime *current_time) 131{ 132 if (!current_time) 133 return VDP_STATUS_INVALID_POINTER; 134 135 return VDP_STATUS_NO_IMPLEMENTATION; 136} 137 138VdpStatus 139vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue, 140 VdpOutputSurface surface, 141 uint32_t clip_width, 142 uint32_t clip_height, 143 VdpTime earliest_presentation_time) 144{ 145 static int dump_window = -1; 146 147 vlVdpPresentationQueue *pq; 148 vlVdpOutputSurface *surf; 149 struct pipe_surface *drawable_surface; 150 151 pq = vlGetDataHTAB(presentation_queue); 152 if (!pq) 153 return VDP_STATUS_INVALID_HANDLE; 154 155 drawable_surface = vl_drawable_surface_get(pq->device->context, pq->drawable); 156 if (!drawable_surface) 157 return VDP_STATUS_INVALID_HANDLE; 158 159 surf = vlGetDataHTAB(surface); 160 if (!surf) 161 return VDP_STATUS_INVALID_HANDLE; 162 163 pq->compositor->clear_layers(pq->compositor); 164 pq->compositor->set_rgba_layer(pq->compositor, 0, surf->sampler_view, NULL, NULL); 165 pq->compositor->render_picture(pq->compositor, PIPE_MPEG12_PICTURE_TYPE_FRAME, 166 drawable_surface, NULL, NULL); 167 168 pq->device->context->vpipe->screen->flush_frontbuffer 169 ( 170 pq->device->context->vpipe->screen, 171 drawable_surface->texture, 172 0, 0, 173 vl_contextprivate_get(pq->device->context, drawable_surface) 174 ); 175 176 if(dump_window == -1) { 177 dump_window = debug_get_num_option("VDPAU_DUMP", 0); 178 } 179 180 if(dump_window) { 181 static unsigned int framenum = 0; 182 char cmd[256]; 183 184 sprintf(cmd, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq->drawable, ++framenum); 185 if (system(cmd) != 0) 186 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Dumping surface %d failed.\n", surface); 187 } 188 189 return VDP_STATUS_OK; 190} 191 192VdpStatus 193vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue, 194 VdpOutputSurface surface, 195 VdpTime *first_presentation_time) 196{ 197 if (!first_presentation_time) 198 return VDP_STATUS_INVALID_POINTER; 199 200 //return VDP_STATUS_NO_IMPLEMENTATION; 201 return VDP_STATUS_OK; 202} 203 204VdpStatus 205vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue, 206 VdpOutputSurface surface, 207 VdpPresentationQueueStatus *status, 208 VdpTime *first_presentation_time) 209{ 210 if (!(status && first_presentation_time)) 211 return VDP_STATUS_INVALID_POINTER; 212 213 return VDP_STATUS_NO_IMPLEMENTATION; 214} 215