device.c revision 3299997bcc5a672617095adb560b3834dced39a6
1/************************************************************************** 2 * 3 * Copyright 2010 Younes Manton. 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 <vdpau/vdpau_x11.h> 29#include <pipe/p_compiler.h> 30#include <vl_winsys.h> 31#include <util/u_memory.h> 32#include "vdpau_private.h" 33 34VdpDeviceCreateX11 vdp_imp_device_create_x11; 35 36PUBLIC VdpStatus 37vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device, VdpGetProcAddress **get_proc_address) 38{ 39 VdpStatus ret; 40 vlVdpDevice *dev = NULL; 41 struct vl_screen *vlscreen = NULL; 42 43 if (!(display && device && get_proc_address)) 44 return VDP_STATUS_INVALID_POINTER; 45 46 if (!vlCreateHTAB()) { 47 ret = VDP_STATUS_RESOURCES; 48 goto no_htab; 49 } 50 51 dev = CALLOC(0, sizeof(vlVdpDevice)); 52 if (!dev) { 53 ret = VDP_STATUS_RESOURCES; 54 goto no_dev; 55 } 56 dev->display = display; 57 dev->screen = screen; 58 59 60 *device = vlAddDataHTAB(dev); 61 if (*device == 0) { 62 ret = VDP_STATUS_ERROR; 63 goto no_handle; 64 } 65 66 *get_proc_address = &vlVdpGetProcAddress; 67 68 return VDP_STATUS_OK; 69 70no_handle: 71 FREE(dev); 72no_dev: 73 vlDestroyHTAB(); 74no_htab: 75 return ret; 76} 77 78VdpStatus vlVdpDeviceDestroy(VdpDevice device) 79{ 80 vlVdpDevice *dev = vlGetDataHTAB(device); 81 if (!dev) 82 return VDP_STATUS_INVALID_HANDLE; 83 FREE(dev); 84 vlDestroyHTAB(); 85 86 return VDP_STATUS_OK; 87} 88 89VdpStatus vlVdpGetProcAddress(VdpDevice device, VdpFuncId function_id, void **function_pointer) 90{ 91 vlVdpDevice *dev = vlGetDataHTAB(device); 92 if (!dev) 93 return VDP_STATUS_INVALID_HANDLE; 94 95 if (!function_pointer) 96 return VDP_STATUS_INVALID_POINTER; 97 98 if (!vlGetFuncFTAB(function_id, function_pointer)) 99 return VDP_STATUS_INVALID_FUNC_ID; 100 101 return VDP_STATUS_OK; 102} 103