1f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton/************************************************************************** 2f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * 3f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * Copyright 2010 Younes Manton. 4f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * All Rights Reserved. 5f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * 6f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * Permission is hereby granted, free of charge, to any person obtaining a 7f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * copy of this software and associated documentation files (the 8f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * "Software"), to deal in the Software without restriction, including 9f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * without limitation the rights to use, copy, modify, merge, publish, 10f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * distribute, sub license, and/or sell copies of the Software, and to 11f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * permit persons to whom the Software is furnished to do so, subject to 12f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * the following conditions: 13f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * 14f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * The above copyright notice and this permission notice (including the 15f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * next paragraph) shall be included in all copies or substantial portions 16f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * of the Software. 17f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * 18f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton * 26f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton **************************************************************************/ 27f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton 2828f8ff6b622d63e8ffe322ab2cdf5197941f1a40Kai Wasserbäch#include "util/u_handle_table.h" 2928f8ff6b622d63e8ffe322ab2cdf5197941f1a40Kai Wasserbäch#include "os/os_thread.h" 30f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#include "vdpau_private.h" 31f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton 32f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#ifdef VL_HANDLES 33f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Mantonstatic struct handle_table *htab = NULL; 34f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Mantonpipe_static_mutex(htab_lock); 35f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#endif 36f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton 37f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Mantonboolean vlCreateHTAB(void) 38f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton{ 39f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#ifdef VL_HANDLES 40f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton boolean ret; 41f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton /* Make sure handle table handles match VDPAU handles. */ 42f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton assert(sizeof(unsigned) <= sizeof(vlHandle)); 43f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton pipe_mutex_lock(htab_lock); 44f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton if (!htab) 45f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton htab = handle_table_create(); 46f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton ret = htab != NULL; 47f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton pipe_mutex_unlock(htab_lock); 48f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton return ret; 49f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#else 50f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton return TRUE; 51f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#endif 52f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton} 53f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton 54f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Mantonvoid vlDestroyHTAB(void) 55f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton{ 56f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#ifdef VL_HANDLES 57f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton pipe_mutex_lock(htab_lock); 58f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton if (htab) { 59f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton handle_table_destroy(htab); 60f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton htab = NULL; 61f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton } 62f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton pipe_mutex_unlock(htab_lock); 63f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#endif 64f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton} 65f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton 66f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes MantonvlHandle vlAddDataHTAB(void *data) 67f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton{ 68f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton assert(data); 69f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#ifdef VL_HANDLES 70f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton vlHandle handle = 0; 71f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton pipe_mutex_lock(htab_lock); 72f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton if (htab) 73f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton handle = handle_table_add(htab, data); 74f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton pipe_mutex_unlock(htab_lock); 75f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton return handle; 76f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#else 77f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton return (vlHandle)data; 78f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#endif 79f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton} 80f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton 81f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Mantonvoid* vlGetDataHTAB(vlHandle handle) 82f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton{ 83f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton assert(handle); 84f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#ifdef VL_HANDLES 85f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton void *data = NULL; 86f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton pipe_mutex_lock(htab_lock); 87f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton if (htab) 88f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton data = handle_table_get(htab, handle); 89f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton pipe_mutex_unlock(htab_lock); 90f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton return data; 91f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#else 92f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton return (void*)handle; 93f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton#endif 94f3e34ba6fba76870b1c91a27adb706d1b87aeec8Younes Manton} 955aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König 965aa26412432dbdb3b1677d6d2f74bba010f443aeChristian Königvoid vlRemoveDataHTAB(vlHandle handle) 975aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König{ 985aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König#ifdef VL_HANDLES 995aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König pipe_mutex_lock(htab_lock); 1005aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König if (htab) 1015aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König handle_table_remove(htab, handle); 1025aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König pipe_mutex_unlock(htab_lock); 1035aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König#endif 1045aa26412432dbdb3b1677d6d2f74bba010f443aeChristian König} 105