presentation.c revision 5aa26412432dbdb3b1677d6d2f74bba010f443ae
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 _debug_printf("[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->compositor = context->create_compositor(context); 70 pq->drawable = pqt->drawable; 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 return VDP_STATUS_NO_IMPLEMENTATION; 93} 94 95VdpStatus 96vlVdpPresentationQueueSetBackgroundColor(VdpPresentationQueue presentation_queue, 97 VdpColor *const background_color) 98{ 99 if (!background_color) 100 return VDP_STATUS_INVALID_POINTER; 101 102 return VDP_STATUS_NO_IMPLEMENTATION; 103} 104 105VdpStatus 106vlVdpPresentationQueueGetBackgroundColor(VdpPresentationQueue presentation_queue, 107 VdpColor *const background_color) 108{ 109 if (!background_color) 110 return VDP_STATUS_INVALID_POINTER; 111 112 return VDP_STATUS_NO_IMPLEMENTATION; 113} 114 115VdpStatus 116vlVdpPresentationQueueGetTime(VdpPresentationQueue presentation_queue, 117 VdpTime *current_time) 118{ 119 if (!current_time) 120 return VDP_STATUS_INVALID_POINTER; 121 122 return VDP_STATUS_NO_IMPLEMENTATION; 123} 124 125VdpStatus 126vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue, 127 VdpOutputSurface surface, 128 uint32_t clip_width, 129 uint32_t clip_height, 130 VdpTime earliest_presentation_time) 131{ 132 static int dump_window = -1; 133 134 vlVdpPresentationQueue *pq; 135 vlVdpOutputSurface *surf; 136 struct pipe_surface *drawable_surface; 137 138 pq = vlGetDataHTAB(presentation_queue); 139 if (!pq) 140 return VDP_STATUS_INVALID_HANDLE; 141 142 drawable_surface = vl_drawable_surface_get(pq->device->context, pq->drawable); 143 if (!drawable_surface) 144 return VDP_STATUS_INVALID_HANDLE; 145 146 surf = vlGetDataHTAB(surface); 147 if (!surf) 148 return VDP_STATUS_INVALID_HANDLE; 149 150 pq->compositor->clear_layers(pq->compositor); 151 pq->compositor->set_rgba_layer(pq->compositor, 0, surf->sampler_view, NULL, NULL); 152 pq->compositor->render_picture(pq->compositor, PIPE_MPEG12_PICTURE_TYPE_FRAME, 153 drawable_surface, NULL, NULL); 154 155 pq->device->context->vpipe->screen->flush_frontbuffer 156 ( 157 pq->device->context->vpipe->screen, 158 drawable_surface->texture, 159 0, 0, 160 vl_contextprivate_get(pq->device->context, drawable_surface) 161 ); 162 163 if(dump_window == -1) { 164 dump_window = debug_get_num_option("VDPAU_DUMP", 0); 165 } 166 167 if(dump_window) { 168 static unsigned int framenum = 0; 169 char cmd[256]; 170 171 sprintf(cmd, "xwd -id %d -out vdpau_frame_%08d.xwd", (int)pq->drawable, ++framenum); 172 if (system(cmd) != 0) 173 _debug_printf("[XvMC] Dumping surface %d failed.\n", surface); 174 } 175 176 return VDP_STATUS_OK; 177} 178 179VdpStatus 180vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_queue, 181 VdpOutputSurface surface, 182 VdpTime *first_presentation_time) 183{ 184 if (!first_presentation_time) 185 return VDP_STATUS_INVALID_POINTER; 186 187 //return VDP_STATUS_NO_IMPLEMENTATION; 188 return VDP_STATUS_OK; 189} 190 191VdpStatus 192vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue, 193 VdpOutputSurface surface, 194 VdpPresentationQueueStatus *status, 195 VdpTime *first_presentation_time) 196{ 197 if (!(status && first_presentation_time)) 198 return VDP_STATUS_INVALID_POINTER; 199 200 return VDP_STATUS_NO_IMPLEMENTATION; 201} 202