presentation.c revision ffcf287aa227cfd1c0f928a3310d98554caf16cd
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_private.h" 31#include <vdpau/vdpau.h> 32#include <util/u_debug.h> 33#include <util/u_memory.h> 34 35VdpStatus 36vlVdpPresentationQueueTargetDestroy(VdpPresentationQueueTarget presentation_queue_target) 37{ 38 return VDP_STATUS_NO_IMPLEMENTATION; 39} 40 41VdpStatus 42vlVdpPresentationQueueCreate(VdpDevice device, 43 VdpPresentationQueueTarget presentation_queue_target, 44 VdpPresentationQueue *presentation_queue) 45{ 46 vlVdpPresentationQueue *pq = NULL; 47 struct pipe_video_context *context; 48 VdpStatus ret; 49 50 _debug_printf("[VDPAU] Creating PresentationQueue\n"); 51 52 if (!presentation_queue) 53 return VDP_STATUS_INVALID_POINTER; 54 55 vlVdpDevice *dev = vlGetDataHTAB(device); 56 if (!dev) 57 return VDP_STATUS_INVALID_HANDLE; 58 59 vlVdpPresentationQueueTarget *pqt = vlGetDataHTAB(presentation_queue_target); 60 if (!pqt) 61 return VDP_STATUS_INVALID_HANDLE; 62 63 if (dev != pqt->device) 64 return VDP_STATUS_HANDLE_DEVICE_MISMATCH; 65 66 context = dev->context->vpipe; 67 68 pq = CALLOC(1, sizeof(vlVdpPresentationQueue)); 69 if (!pq) 70 return VDP_STATUS_RESOURCES; 71 72 pq->device = dev; 73 pq->compositor = context->create_compositor(context); 74 pq->drawable = pqt->drawable; 75 if (!pq->compositor) { 76 ret = VDP_STATUS_ERROR; 77 goto no_compositor; 78 } 79 80 *presentation_queue = vlAddDataHTAB(pq); 81 if (*presentation_queue == 0) { 82 ret = VDP_STATUS_ERROR; 83 goto no_handle; 84 } 85 86 return VDP_STATUS_OK; 87no_handle: 88no_compositor: 89 FREE(pq); 90 return ret; 91} 92 93VdpStatus 94vlVdpPresentationQueueDestroy(VdpPresentationQueue presentation_queue) 95{ 96 return VDP_STATUS_NO_IMPLEMENTATION; 97} 98 99VdpStatus 100vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue, 101 VdpColor *const background_color) 102{ 103 if (!background_color) 104 return VDP_STATUS_INVALID_POINTER; 105 106 return VDP_STATUS_NO_IMPLEMENTATION; 107} 108 109VdpStatus 110vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue, 111 VdpColor *const background_color) 112{ 113 if (!background_color) 114 return VDP_STATUS_INVALID_POINTER; 115 116 return VDP_STATUS_NO_IMPLEMENTATION; 117} 118 119VdpStatus 120vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue, 121 VdpTime *current_time) 122{ 123 if (!current_time) 124 return VDP_STATUS_INVALID_POINTER; 125 126 return VDP_STATUS_NO_IMPLEMENTATION; 127} 128 129VdpStatus 130vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue, 131 VdpOutputSurface surface, 132 uint32_t clip_width, 133 uint32_t clip_height, 134 VdpTime earliest_presentation_time) 135{ 136 static int dump_window = -1; 137 138 vlVdpPresentationQueue *pq; 139 vlVdpOutputSurface *surf; 140 struct pipe_surface *drawable_surface; 141 142 pq = vlGetDataHTAB(presentation_queue); 143 if (!pq) 144 return VDP_STATUS_INVALID_HANDLE; 145 146 drawable_surface = vl_drawable_surface_get(pq->device->context, pq->drawable); 147 if (!drawable_surface) 148 return VDP_STATUS_INVALID_HANDLE; 149 150 surf = vlGetDataHTAB(surface); 151 if (!surf) 152 return VDP_STATUS_INVALID_HANDLE; 153 154 pq->compositor->clear_layers(pq->compositor); 155 pq->compositor->set_rgba_layer(pq->compositor, 0, surf->sampler_view, NULL, NULL); 156 pq->compositor->render_picture(pq->compositor, PIPE_MPEG12_PICTURE_TYPE_FRAME, 157 drawable_surface, NULL, NULL); 158 159 pq->device->context->vpipe->screen->flush_frontbuffer 160 ( 161 pq->device->context->vpipe->screen, 162 drawable_surface->texture, 163 0, 0, 164 vl_contextprivate_get(pq->device->context, drawable_surface) 165 ); 166 167 if(dump_window == -1) { 168 dump_window = debug_get_num_option("VDPAU_DUMP", 0); 169 } 170 171 if(dump_window) { 172 static unsigned int framenum = 0; 173 char cmd[256]; 174 175 sprintf(cmd, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq->drawable, ++framenum); 176 if (system(cmd) != 0) 177 _debug_printf("[XvMC] Dumping surface %d failed.\n", surface); 178 } 179 180 return VDP_STATUS_OK; 181} 182 183VdpStatus 184vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue, 185 VdpOutputSurface surface, 186 VdpTime *first_presentation_time) 187{ 188 if (!first_presentation_time) 189 return VDP_STATUS_INVALID_POINTER; 190 191 //return VDP_STATUS_NO_IMPLEMENTATION; 192 return VDP_STATUS_OK; 193} 194 195VdpStatus 196vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue, 197 VdpOutputSurface surface, 198 VdpPresentationQueueStatus *status, 199 VdpTime *first_presentation_time) 200{ 201 if (!(status && first_presentation_time)) 202 return VDP_STATUS_INVALID_POINTER; 203 204 return VDP_STATUS_NO_IMPLEMENTATION; 205} 206