17ec681f3Smrg/**************************************************************************
27ec681f3Smrg *
37ec681f3Smrg * Copyright 2008 VMware, Inc.
47ec681f3Smrg * All Rights Reserved.
57ec681f3Smrg *
67ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
77ec681f3Smrg * copy of this software and associated documentation files (the
87ec681f3Smrg * "Software"), to deal in the Software without restriction, including
97ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish,
107ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to
117ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to
127ec681f3Smrg * the following conditions:
137ec681f3Smrg *
147ec681f3Smrg * The above copyright notice and this permission notice (including the
157ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions
167ec681f3Smrg * of the Software.
177ec681f3Smrg *
187ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
197ec681f3Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
207ec681f3Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
217ec681f3Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
227ec681f3Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
237ec681f3Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
247ec681f3Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
257ec681f3Smrg *
267ec681f3Smrg **************************************************************************/
277ec681f3Smrg
287ec681f3Smrg#ifndef STW_DEVICE_H_
297ec681f3Smrg#define STW_DEVICE_H_
307ec681f3Smrg
317ec681f3Smrg
327ec681f3Smrg#include "pipe/p_compiler.h"
337ec681f3Smrg#include "frontend/api.h"
347ec681f3Smrg#include "util/u_handle_table.h"
357ec681f3Smrg#include "util/u_dynarray.h"
367ec681f3Smrg#include "util/xmlconfig.h"
377ec681f3Smrg#include <GL/gl.h>
387ec681f3Smrg#include "gldrv.h"
397ec681f3Smrg#include "stw_pixelformat.h"
407ec681f3Smrg
417ec681f3Smrg#ifdef __cplusplus
427ec681f3Smrgextern "C" {
437ec681f3Smrg#endif
447ec681f3Smrg
457ec681f3Smrgstruct pipe_screen;
467ec681f3Smrgstruct st_api;
477ec681f3Smrgstruct st_manager;
487ec681f3Smrgstruct stw_framebuffer;
497ec681f3Smrg
507ec681f3Smrgstruct stw_device
517ec681f3Smrg{
527ec681f3Smrg   const struct stw_winsys *stw_winsys;
537ec681f3Smrg
547ec681f3Smrg   CRITICAL_SECTION screen_mutex;
557ec681f3Smrg   bool screen_initialized;
567ec681f3Smrg   struct pipe_screen *screen;
577ec681f3Smrg
587ec681f3Smrg   /* Cache some PIPE_CAP_* */
597ec681f3Smrg   unsigned max_2d_length;
607ec681f3Smrg
617ec681f3Smrg   struct st_api *stapi;
627ec681f3Smrg   struct st_manager *smapi;
637ec681f3Smrg
647ec681f3Smrg   LUID AdapterLuid;
657ec681f3Smrg
667ec681f3Smrg   struct util_dynarray pixelformats;
677ec681f3Smrg   unsigned pixelformat_count;
687ec681f3Smrg
697ec681f3Smrg   struct WGLCALLBACKS callbacks;
707ec681f3Smrg
717ec681f3Smrg   CRITICAL_SECTION ctx_mutex;
727ec681f3Smrg   struct handle_table *ctx_table;
737ec681f3Smrg
747ec681f3Smrg   /* TODO: use an atomic counter to track the number of locked
757ec681f3Smrg    * stw_framebuffer objects.  Assert that the counter is zero when
767ec681f3Smrg    * trying to lock this mutex.
777ec681f3Smrg    */
787ec681f3Smrg   CRITICAL_SECTION fb_mutex;
797ec681f3Smrg   struct stw_framebuffer *fb_head;
807ec681f3Smrg
817ec681f3Smrg#ifdef DEBUG
827ec681f3Smrg   unsigned long memdbg_no;
837ec681f3Smrg#endif
847ec681f3Smrg
857ec681f3Smrg   /** WGL_EXT_swap_control */
867ec681f3Smrg   int refresh_rate;
877ec681f3Smrg   int swap_interval;
887ec681f3Smrg
897ec681f3Smrg   driOptionCache option_cache;
907ec681f3Smrg   driOptionCache option_info;
917ec681f3Smrg   struct st_config_options st_options;
927ec681f3Smrg
937ec681f3Smrg   bool initialized;
947ec681f3Smrg};
957ec681f3Smrg
967ec681f3Smrg
977ec681f3Smrgextern struct stw_device *stw_dev;
987ec681f3Smrg
997ec681f3Smrgboolean
1007ec681f3Smrgstw_init_screen(HDC hdc);
1017ec681f3Smrg
1027ec681f3Smrgstruct stw_device *
1037ec681f3Smrgstw_get_device(void);
1047ec681f3Smrg
1057ec681f3Smrgstatic inline struct stw_context *
1067ec681f3Smrgstw_lookup_context_locked( DHGLRC dhglrc )
1077ec681f3Smrg{
1087ec681f3Smrg   if (dhglrc == 0 || stw_dev == NULL)
1097ec681f3Smrg      return NULL;
1107ec681f3Smrg   return (struct stw_context *) handle_table_get(stw_dev->ctx_table, dhglrc);
1117ec681f3Smrg}
1127ec681f3Smrg
1137ec681f3Smrg
1147ec681f3Smrgstatic inline void
1157ec681f3Smrgstw_lock_contexts(struct stw_device *stw_dev)
1167ec681f3Smrg{
1177ec681f3Smrg   EnterCriticalSection(&stw_dev->ctx_mutex);
1187ec681f3Smrg}
1197ec681f3Smrg
1207ec681f3Smrg
1217ec681f3Smrgstatic inline void
1227ec681f3Smrgstw_unlock_contexts(struct stw_device *stw_dev)
1237ec681f3Smrg{
1247ec681f3Smrg   LeaveCriticalSection(&stw_dev->ctx_mutex);
1257ec681f3Smrg}
1267ec681f3Smrg
1277ec681f3Smrgstatic inline struct stw_context *
1287ec681f3Smrgstw_lookup_context( DHGLRC dhglrc )
1297ec681f3Smrg{
1307ec681f3Smrg   struct stw_context *ret;
1317ec681f3Smrg   stw_lock_contexts(stw_dev);
1327ec681f3Smrg   ret = stw_lookup_context_locked(dhglrc);
1337ec681f3Smrg   stw_unlock_contexts(stw_dev);
1347ec681f3Smrg   return ret;
1357ec681f3Smrg}
1367ec681f3Smrg
1377ec681f3Smrg
1387ec681f3Smrgstatic inline void
1397ec681f3Smrgstw_lock_framebuffers(struct stw_device *stw_dev)
1407ec681f3Smrg{
1417ec681f3Smrg   EnterCriticalSection(&stw_dev->fb_mutex);
1427ec681f3Smrg}
1437ec681f3Smrg
1447ec681f3Smrg
1457ec681f3Smrgstatic inline void
1467ec681f3Smrgstw_unlock_framebuffers(struct stw_device *stw_dev)
1477ec681f3Smrg{
1487ec681f3Smrg   LeaveCriticalSection(&stw_dev->fb_mutex);
1497ec681f3Smrg}
1507ec681f3Smrg
1517ec681f3Smrg#ifdef __cplusplus
1527ec681f3Smrg}
1537ec681f3Smrg#endif
1547ec681f3Smrg
1557ec681f3Smrg#endif /* STW_DEVICE_H_ */
156