1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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
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 **************************************************************************/
30 #include "glapi/glthread.h"
31 #include "util/u_debug.h"
32 #include "pipe/p_screen.h"
33 #include "state_tracker/st_public.h"
36 #include "trace/tr_screen.h"
37 #include "trace/tr_texture.h"
40 #include "stw_device.h"
41 #include "stw_winsys.h"
42 #include "stw_pixelformat.h"
45 #include "stw_framebuffer.h"
48 extern _glthread_Mutex OneTimeLock
;
49 extern void FreeAllTSD(void);
53 struct stw_device
*stw_dev
= NULL
;
57 * XXX: Dispatch pipe_screen::flush_front_buffer to our
58 * stw_winsys::flush_front_buffer.
61 stw_flush_frontbuffer(struct pipe_screen
*screen
,
62 struct pipe_surface
*surface
,
63 void *context_private
)
65 const struct stw_winsys
*stw_winsys
= stw_dev
->stw_winsys
;
66 HDC hdc
= (HDC
)context_private
;
67 struct stw_framebuffer
*fb
;
69 fb
= stw_framebuffer_from_hdc( hdc
);
70 /* fb can be NULL if window was destroyed already */
74 struct pipe_surface
*surface2
;
76 if(!st_get_framebuffer_surface( fb
->stfb
, ST_SURFACE_FRONT_LEFT
, &surface2
))
79 assert(surface2
== surface
);
84 if(stw_dev
->trace_running
) {
85 screen
= trace_screen(screen
)->screen
;
86 surface
= trace_surface(surface
)->surface
;
91 stw_winsys
->flush_frontbuffer(screen
, surface
, hdc
);
94 stw_framebuffer_update(fb
);
95 stw_framebuffer_release(fb
);
101 stw_init(const struct stw_winsys
*stw_winsys
)
103 static struct stw_device stw_dev_storage
;
104 struct pipe_screen
*screen
;
106 debug_printf("%s\n", __FUNCTION__
);
112 stw_dev
= &stw_dev_storage
;
113 memset(stw_dev
, 0, sizeof(*stw_dev
));
116 stw_dev
->memdbg_no
= debug_memory_begin();
119 stw_dev
->stw_winsys
= stw_winsys
;
122 _glthread_INIT_MUTEX(OneTimeLock
);
125 screen
= stw_winsys
->create_screen();
130 stw_dev
->screen
= trace_screen_create(screen
);
131 stw_dev
->trace_running
= stw_dev
->screen
!= screen
? TRUE
: FALSE
;
133 stw_dev
->screen
= screen
;
136 stw_dev
->screen
->flush_frontbuffer
= &stw_flush_frontbuffer
;
138 pipe_mutex_init( stw_dev
->ctx_mutex
);
139 pipe_mutex_init( stw_dev
->fb_mutex
);
141 stw_dev
->ctx_table
= handle_table_create();
142 if (!stw_dev
->ctx_table
) {
146 stw_pixelformat_init();
157 stw_init_thread(void)
159 return stw_tls_init_thread();
164 stw_cleanup_thread(void)
166 stw_tls_cleanup_thread();
175 debug_printf("%s\n", __FUNCTION__
);
180 pipe_mutex_lock( stw_dev
->ctx_mutex
);
182 /* Ensure all contexts are destroyed */
183 i
= handle_table_get_first_handle(stw_dev
->ctx_table
);
186 i
= handle_table_get_next_handle(stw_dev
->ctx_table
, i
);
188 handle_table_destroy(stw_dev
->ctx_table
);
190 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
192 stw_framebuffer_cleanup();
194 pipe_mutex_destroy( stw_dev
->fb_mutex
);
195 pipe_mutex_destroy( stw_dev
->ctx_mutex
);
197 stw_dev
->screen
->destroy(stw_dev
->screen
);
200 _glthread_DESTROY_MUTEX(OneTimeLock
);
205 debug_memory_end(stw_dev
->memdbg_no
);
215 stw_lookup_context_locked( DHGLRC dhglrc
)
223 return (struct stw_context
*) handle_table_get(stw_dev
->ctx_table
, dhglrc
);
240 /* TODO: get the expected version from the winsys */
241 return ulVersion
== 1;