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