device.c revision 736dda82ca5477b8976e2c6b810a71efe2337267
1/************************************************************************** 2 * 3 * Copyright 2010 Younes Manton og 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 "pipe/p_compiler.h" 29 30#include "util/u_memory.h" 31#include "util/u_debug.h" 32 33#include "vl_winsys.h" 34 35#include "vdpau_private.h" 36 37/** 38 * Create a VdpDevice object for use with X11. 39 */ 40PUBLIC VdpStatus 41vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device, 42 VdpGetProcAddress **get_proc_address) 43{ 44 VdpStatus ret; 45 vlVdpDevice *dev = NULL; 46 47 if (!(display && device && get_proc_address)) 48 return VDP_STATUS_INVALID_POINTER; 49 50 if (!vlCreateHTAB()) { 51 ret = VDP_STATUS_RESOURCES; 52 goto no_htab; 53 } 54 55 dev = CALLOC(1, sizeof(vlVdpDevice)); 56 if (!dev) { 57 ret = VDP_STATUS_RESOURCES; 58 goto no_dev; 59 } 60 61 dev->vscreen = vl_screen_create(display, screen); 62 if (!dev->vscreen) { 63 ret = VDP_STATUS_RESOURCES; 64 goto no_vscreen; 65 } 66 67 dev->context = vl_video_create(dev->vscreen); 68 if (!dev->context) { 69 ret = VDP_STATUS_RESOURCES; 70 goto no_context; 71 } 72 73 *device = vlAddDataHTAB(dev); 74 if (*device == 0) { 75 ret = VDP_STATUS_ERROR; 76 goto no_handle; 77 } 78 79 vl_compositor_init(&dev->compositor, dev->context->pipe); 80 81 *get_proc_address = &vlVdpGetProcAddress; 82 83 return VDP_STATUS_OK; 84 85no_handle: 86 /* Destroy vscreen */ 87no_context: 88 vl_screen_destroy(dev->vscreen); 89no_vscreen: 90 FREE(dev); 91no_dev: 92 vlDestroyHTAB(); 93no_htab: 94 return ret; 95} 96 97/** 98 * Create a VdpPresentationQueueTarget for use with X11. 99 */ 100PUBLIC VdpStatus 101vlVdpPresentationQueueTargetCreateX11(VdpDevice device, Drawable drawable, 102 VdpPresentationQueueTarget *target) 103{ 104 vlVdpPresentationQueueTarget *pqt; 105 VdpStatus ret; 106 107 if (!drawable) 108 return VDP_STATUS_INVALID_HANDLE; 109 110 vlVdpDevice *dev = vlGetDataHTAB(device); 111 if (!dev) 112 return VDP_STATUS_INVALID_HANDLE; 113 114 pqt = CALLOC(1, sizeof(vlVdpPresentationQueue)); 115 if (!pqt) 116 return VDP_STATUS_RESOURCES; 117 118 pqt->device = dev; 119 pqt->drawable = drawable; 120 121 *target = vlAddDataHTAB(pqt); 122 if (*target == 0) { 123 ret = VDP_STATUS_ERROR; 124 goto no_handle; 125 } 126 127 return VDP_STATUS_OK; 128 129no_handle: 130 FREE(pqt); 131 return ret; 132} 133 134/** 135 * Destroy a VdpPresentationQueueTarget. 136 */ 137VdpStatus 138vlVdpPresentationQueueTargetDestroy(VdpPresentationQueueTarget presentation_queue_target) 139{ 140 vlVdpPresentationQueueTarget *pqt; 141 142 pqt = vlGetDataHTAB(presentation_queue_target); 143 if (!pqt) 144 return VDP_STATUS_INVALID_HANDLE; 145 146 vlRemoveDataHTAB(presentation_queue_target); 147 FREE(pqt); 148 149 return VDP_STATUS_OK; 150} 151 152/** 153 * Destroy a VdpDevice. 154 */ 155VdpStatus 156vlVdpDeviceDestroy(VdpDevice device) 157{ 158 vlVdpDevice *dev = vlGetDataHTAB(device); 159 if (!dev) 160 return VDP_STATUS_INVALID_HANDLE; 161 162 vl_compositor_cleanup(&dev->compositor); 163 vl_video_destroy(dev->context); 164 vl_screen_destroy(dev->vscreen); 165 166 FREE(dev); 167 vlDestroyHTAB(); 168 169 return VDP_STATUS_OK; 170} 171 172/** 173 * Retrieve a VDPAU function pointer. 174 */ 175VdpStatus 176vlVdpGetProcAddress(VdpDevice device, VdpFuncId function_id, void **function_pointer) 177{ 178 vlVdpDevice *dev = vlGetDataHTAB(device); 179 if (!dev) 180 return VDP_STATUS_INVALID_HANDLE; 181 182 if (!function_pointer) 183 return VDP_STATUS_INVALID_POINTER; 184 185 if (!vlGetFuncFTAB(function_id, function_pointer)) 186 return VDP_STATUS_INVALID_FUNC_ID; 187 188 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Got proc adress %p for id %d\n", *function_pointer, function_id); 189 190 return VDP_STATUS_OK; 191} 192 193#define _ERROR_TYPE(TYPE,STRING) case TYPE: return STRING; 194 195/** 196 * Retrieve a string describing an error code. 197 */ 198char const * 199vlVdpGetErrorString (VdpStatus status) 200{ 201 switch (status) { 202 _ERROR_TYPE(VDP_STATUS_OK,"The operation completed successfully; no error."); 203 _ERROR_TYPE(VDP_STATUS_NO_IMPLEMENTATION,"No backend implementation could be loaded."); 204 _ERROR_TYPE(VDP_STATUS_DISPLAY_PREEMPTED,"The display was preempted, or a fatal error occurred. The application must re-initialize VDPAU."); 205 _ERROR_TYPE(VDP_STATUS_INVALID_HANDLE,"An invalid handle value was provided. Either the handle does not exist at all, or refers to an object of an incorrect type."); 206 _ERROR_TYPE(VDP_STATUS_INVALID_POINTER,"An invalid pointer was provided. Typically, this means that a NULL pointer was provided for an 'output' parameter."); 207 _ERROR_TYPE(VDP_STATUS_INVALID_CHROMA_TYPE,"An invalid/unsupported VdpChromaType value was supplied."); 208 _ERROR_TYPE(VDP_STATUS_INVALID_Y_CB_CR_FORMAT,"An invalid/unsupported VdpYCbCrFormat value was supplied."); 209 _ERROR_TYPE(VDP_STATUS_INVALID_RGBA_FORMAT,"An invalid/unsupported VdpRGBAFormat value was supplied."); 210 _ERROR_TYPE(VDP_STATUS_INVALID_INDEXED_FORMAT,"An invalid/unsupported VdpIndexedFormat value was supplied."); 211 _ERROR_TYPE(VDP_STATUS_INVALID_COLOR_STANDARD,"An invalid/unsupported VdpColorStandard value was supplied."); 212 _ERROR_TYPE(VDP_STATUS_INVALID_COLOR_TABLE_FORMAT,"An invalid/unsupported VdpColorTableFormat value was supplied."); 213 _ERROR_TYPE(VDP_STATUS_INVALID_BLEND_FACTOR,"An invalid/unsupported VdpOutputSurfaceRenderBlendFactor value was supplied."); 214 _ERROR_TYPE(VDP_STATUS_INVALID_BLEND_EQUATION,"An invalid/unsupported VdpOutputSurfaceRenderBlendEquation value was supplied."); 215 _ERROR_TYPE(VDP_STATUS_INVALID_FLAG,"An invalid/unsupported flag value/combination was supplied."); 216 _ERROR_TYPE(VDP_STATUS_INVALID_DECODER_PROFILE,"An invalid/unsupported VdpDecoderProfile value was supplied."); 217 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE,"An invalid/unsupported VdpVideoMixerFeature value was supplied."); 218 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER,"An invalid/unsupported VdpVideoMixerParameter value was supplied."); 219 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE,"An invalid/unsupported VdpVideoMixerAttribute value was supplied."); 220 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_PICTURE_STRUCTURE,"An invalid/unsupported VdpVideoMixerPictureStructure value was supplied."); 221 _ERROR_TYPE(VDP_STATUS_INVALID_FUNC_ID,"An invalid/unsupported VdpFuncId value was supplied."); 222 _ERROR_TYPE(VDP_STATUS_INVALID_SIZE,"The size of a supplied object does not match the object it is being used with.\ 223 For example, a VdpVideoMixer is configured to process VdpVideoSurface objects of a specific size.\ 224 If presented with a VdpVideoSurface of a different size, this error will be raised."); 225 _ERROR_TYPE(VDP_STATUS_INVALID_VALUE,"An invalid/unsupported value was supplied.\ 226 This is a catch-all error code for values of type other than those with a specific error code."); 227 _ERROR_TYPE(VDP_STATUS_INVALID_STRUCT_VERSION,"An invalid/unsupported structure version was specified in a versioned structure. \ 228 This implies that the implementation is older than the header file the application was built against."); 229 _ERROR_TYPE(VDP_STATUS_RESOURCES,"The system does not have enough resources to complete the requested operation at this time."); 230 _ERROR_TYPE(VDP_STATUS_HANDLE_DEVICE_MISMATCH,"The set of handles supplied are not all related to the same VdpDevice.When performing operations \ 231 that operate on multiple surfaces, such as VdpOutputSurfaceRenderOutputSurface or VdpVideoMixerRender, \ 232 all supplied surfaces must have been created within the context of the same VdpDevice object. \ 233 This error is raised if they were not."); 234 _ERROR_TYPE(VDP_STATUS_ERROR,"A catch-all error, used when no other error code applies."); 235 default: return "Unknown Error"; 236 } 237} 238