glsl2: Add and use new variable mode ir_var_temporary
[mesa/nouveau-pmpeg.git] / src / gallium / state_trackers / wgl / stw_device.c
bloba107c71bdab0c2be1646502bbe6c480e845f8385
1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
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:
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.
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.
26 **************************************************************************/
28 #include <windows.h>
30 #include "glapi/glthread.h"
31 #include "util/u_debug.h"
32 #include "util/u_math.h"
33 #include "util/u_memory.h"
34 #include "pipe/p_screen.h"
36 #include "stw_device.h"
37 #include "stw_winsys.h"
38 #include "stw_pixelformat.h"
39 #include "stw_icd.h"
40 #include "stw_tls.h"
41 #include "stw_framebuffer.h"
42 #include "stw_st.h"
44 #ifdef WIN32_THREADS
45 extern _glthread_Mutex OneTimeLock;
46 #endif
49 struct stw_device *stw_dev = NULL;
51 static int
52 stw_get_param(struct st_manager *smapi,
53 enum st_manager_param param)
55 return 0;
58 boolean
59 stw_init(const struct stw_winsys *stw_winsys)
61 static struct stw_device stw_dev_storage;
62 struct pipe_screen *screen;
64 debug_printf("%s\n", __FUNCTION__);
66 assert(!stw_dev);
68 stw_tls_init();
70 stw_dev = &stw_dev_storage;
71 memset(stw_dev, 0, sizeof(*stw_dev));
73 #ifdef DEBUG
74 stw_dev->memdbg_no = debug_memory_begin();
75 #endif
77 stw_dev->stw_winsys = stw_winsys;
79 #ifdef WIN32_THREADS
80 _glthread_INIT_MUTEX(OneTimeLock);
81 #endif
83 stw_dev->stapi = stw_st_create_api();
84 stw_dev->smapi = CALLOC_STRUCT(st_manager);
85 if (!stw_dev->stapi || !stw_dev->smapi)
86 goto error1;
88 screen = stw_winsys->create_screen();
89 if(!screen)
90 goto error1;
92 if(stw_winsys->get_adapter_luid)
93 stw_winsys->get_adapter_luid(screen, &stw_dev->AdapterLuid);
95 stw_dev->smapi->screen = screen;
96 stw_dev->smapi->get_param = stw_get_param;
97 stw_dev->screen = screen;
99 pipe_mutex_init( stw_dev->ctx_mutex );
100 pipe_mutex_init( stw_dev->fb_mutex );
102 stw_dev->ctx_table = handle_table_create();
103 if (!stw_dev->ctx_table) {
104 goto error1;
107 stw_pixelformat_init();
109 return TRUE;
111 error1:
112 if (stw_dev->smapi)
113 FREE(stw_dev->smapi);
114 if (stw_dev->stapi)
115 stw_dev->stapi->destroy(stw_dev->stapi);
117 stw_dev = NULL;
118 return FALSE;
122 boolean
123 stw_init_thread(void)
125 return stw_tls_init_thread();
129 void
130 stw_cleanup_thread(void)
132 stw_tls_cleanup_thread();
136 void
137 stw_cleanup(void)
139 DHGLRC dhglrc;
141 debug_printf("%s\n", __FUNCTION__);
143 if (!stw_dev)
144 return;
147 * Abort cleanup if there are still active contexts. In some situations
148 * this DLL may be unloaded before the DLL that is using GL contexts is.
150 pipe_mutex_lock( stw_dev->ctx_mutex );
151 dhglrc = handle_table_get_first_handle(stw_dev->ctx_table);
152 pipe_mutex_unlock( stw_dev->ctx_mutex );
153 if (dhglrc) {
154 debug_printf("%s: contexts still active -- cleanup aborted\n", __FUNCTION__);
155 stw_dev = NULL;
156 return;
159 handle_table_destroy(stw_dev->ctx_table);
161 stw_framebuffer_cleanup();
163 pipe_mutex_destroy( stw_dev->fb_mutex );
164 pipe_mutex_destroy( stw_dev->ctx_mutex );
166 FREE(stw_dev->smapi);
167 stw_dev->stapi->destroy(stw_dev->stapi);
169 stw_dev->screen->destroy(stw_dev->screen);
171 #ifdef WIN32_THREADS
172 _glthread_DESTROY_MUTEX(OneTimeLock);
174 _glapi_destroy_multithread();
175 #endif
177 #ifdef DEBUG
178 debug_memory_end(stw_dev->memdbg_no);
179 #endif
181 stw_tls_cleanup();
183 stw_dev = NULL;
187 struct stw_context *
188 stw_lookup_context_locked( DHGLRC dhglrc )
190 if (dhglrc == 0)
191 return NULL;
193 if (stw_dev == NULL)
194 return NULL;
196 return (struct stw_context *) handle_table_get(stw_dev->ctx_table, dhglrc);
200 void APIENTRY
201 DrvSetCallbackProcs(
202 INT nProcs,
203 PROC *pProcs )
205 size_t size;
207 if (stw_dev == NULL)
208 return;
210 size = MIN2(nProcs * sizeof *pProcs, sizeof stw_dev->callbacks);
211 memcpy(&stw_dev->callbacks, pProcs, size);
213 return;
217 BOOL APIENTRY
218 DrvValidateVersion(
219 ULONG ulVersion )
221 /* TODO: get the expected version from the winsys */
222 return ulVersion == 1;