1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#ifndef STW_DEVICE_H_ 29bf215546Sopenharmony_ci#define STW_DEVICE_H_ 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 33bf215546Sopenharmony_ci#include "frontend/api.h" 34bf215546Sopenharmony_ci#include "util/u_handle_table.h" 35bf215546Sopenharmony_ci#include "util/u_dynarray.h" 36bf215546Sopenharmony_ci#include "util/xmlconfig.h" 37bf215546Sopenharmony_ci#include <GL/gl.h> 38bf215546Sopenharmony_ci#include "gldrv.h" 39bf215546Sopenharmony_ci#include "stw_pixelformat.h" 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci#ifdef __cplusplus 42bf215546Sopenharmony_ciextern "C" { 43bf215546Sopenharmony_ci#endif 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_cistruct pipe_screen; 46bf215546Sopenharmony_cistruct st_api; 47bf215546Sopenharmony_cistruct st_manager; 48bf215546Sopenharmony_cistruct stw_framebuffer; 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_cistruct stw_device 51bf215546Sopenharmony_ci{ 52bf215546Sopenharmony_ci const struct stw_winsys *stw_winsys; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci CRITICAL_SECTION screen_mutex; 55bf215546Sopenharmony_ci bool screen_initialized; 56bf215546Sopenharmony_ci struct pipe_screen *screen; 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci /* Cache some PIPE_CAP_* */ 59bf215546Sopenharmony_ci unsigned max_2d_length; 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci struct st_api *stapi; 62bf215546Sopenharmony_ci struct st_manager *smapi; 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci LUID AdapterLuid; 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci struct util_dynarray pixelformats; 67bf215546Sopenharmony_ci unsigned pixelformat_count; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci struct WGLCALLBACKS callbacks; 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci CRITICAL_SECTION ctx_mutex; 72bf215546Sopenharmony_ci struct handle_table *ctx_table; 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci /* TODO: use an atomic counter to track the number of locked 75bf215546Sopenharmony_ci * stw_framebuffer objects. Assert that the counter is zero when 76bf215546Sopenharmony_ci * trying to lock this mutex. 77bf215546Sopenharmony_ci */ 78bf215546Sopenharmony_ci CRITICAL_SECTION fb_mutex; 79bf215546Sopenharmony_ci struct stw_framebuffer *fb_head; 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci#ifdef DEBUG 82bf215546Sopenharmony_ci unsigned long memdbg_no; 83bf215546Sopenharmony_ci#endif 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci /** WGL_EXT_swap_control */ 86bf215546Sopenharmony_ci int refresh_rate; 87bf215546Sopenharmony_ci int swap_interval; 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci driOptionCache option_cache; 90bf215546Sopenharmony_ci driOptionCache option_info; 91bf215546Sopenharmony_ci struct st_config_options st_options; 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci bool initialized; 94bf215546Sopenharmony_ci bool zink; 95bf215546Sopenharmony_ci}; 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ciextern struct stw_device *stw_dev; 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ciboolean 101bf215546Sopenharmony_cistw_init_screen(HDC hdc); 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_cistruct stw_device * 104bf215546Sopenharmony_cistw_get_device(void); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_cistatic inline struct stw_context * 107bf215546Sopenharmony_cistw_lookup_context_locked( DHGLRC dhglrc ) 108bf215546Sopenharmony_ci{ 109bf215546Sopenharmony_ci if (dhglrc == 0 || stw_dev == NULL) 110bf215546Sopenharmony_ci return NULL; 111bf215546Sopenharmony_ci return (struct stw_context *) handle_table_get(stw_dev->ctx_table, dhglrc); 112bf215546Sopenharmony_ci} 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_cistatic inline void 116bf215546Sopenharmony_cistw_lock_contexts(struct stw_device *stw_dev) 117bf215546Sopenharmony_ci{ 118bf215546Sopenharmony_ci EnterCriticalSection(&stw_dev->ctx_mutex); 119bf215546Sopenharmony_ci} 120bf215546Sopenharmony_ci 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_cistatic inline void 123bf215546Sopenharmony_cistw_unlock_contexts(struct stw_device *stw_dev) 124bf215546Sopenharmony_ci{ 125bf215546Sopenharmony_ci LeaveCriticalSection(&stw_dev->ctx_mutex); 126bf215546Sopenharmony_ci} 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_cistatic inline struct stw_context * 129bf215546Sopenharmony_cistw_lookup_context( DHGLRC dhglrc ) 130bf215546Sopenharmony_ci{ 131bf215546Sopenharmony_ci struct stw_context *ret; 132bf215546Sopenharmony_ci stw_lock_contexts(stw_dev); 133bf215546Sopenharmony_ci ret = stw_lookup_context_locked(dhglrc); 134bf215546Sopenharmony_ci stw_unlock_contexts(stw_dev); 135bf215546Sopenharmony_ci return ret; 136bf215546Sopenharmony_ci} 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_cistatic inline void 140bf215546Sopenharmony_cistw_lock_framebuffers(struct stw_device *stw_dev) 141bf215546Sopenharmony_ci{ 142bf215546Sopenharmony_ci EnterCriticalSection(&stw_dev->fb_mutex); 143bf215546Sopenharmony_ci} 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_cistatic inline void 147bf215546Sopenharmony_cistw_unlock_framebuffers(struct stw_device *stw_dev) 148bf215546Sopenharmony_ci{ 149bf215546Sopenharmony_ci LeaveCriticalSection(&stw_dev->fb_mutex); 150bf215546Sopenharmony_ci} 151bf215546Sopenharmony_ci 152bf215546Sopenharmony_ci#ifdef __cplusplus 153bf215546Sopenharmony_ci} 154bf215546Sopenharmony_ci#endif 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci#endif /* STW_DEVICE_H_ */ 157