f3c7af93f503aa99e97c33da1e99f04277b5828a
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 "main/mtypes.h"
31 #include "main/context.h"
32 #include "pipe/p_compiler.h"
33 #include "pipe/p_context.h"
34 #include "state_tracker/st_context.h"
35 #include "state_tracker/st_public.h"
38 #include "trace/tr_screen.h"
39 #include "trace/tr_context.h"
42 #include "shared/stw_device.h"
43 #include "shared/stw_winsys.h"
44 #include "shared/stw_framebuffer.h"
45 #include "shared/stw_pixelformat.h"
46 #include "stw_public.h"
47 #include "stw_context.h"
56 struct stw_context
*src
;
57 struct stw_context
*dst
;
60 pipe_mutex_lock( stw_dev
->mutex
);
62 src
= stw_lookup_context_locked( hglrcSrc
);
63 dst
= stw_lookup_context_locked( hglrcDst
);
72 pipe_mutex_unlock( stw_dev
->mutex
);
78 stw_create_layer_context(
83 const struct stw_pixelformat_info
*pf
= NULL
;
84 struct stw_context
*ctx
= NULL
;
85 GLvisual
*visual
= NULL
;
86 struct pipe_screen
*screen
= NULL
;
87 struct pipe_context
*pipe
= NULL
;
96 pfi
= stw_pixelformat_get( hdc
);
100 pf
= stw_pixelformat_get_info( pfi
- 1 );
102 ctx
= CALLOC_STRUCT( stw_context
);
107 ctx
->color_bits
= GetDeviceCaps( ctx
->hdc
, BITSPIXEL
);
109 /* Create visual based on flags
111 visual
= _mesa_create_visual(
112 (pf
->pfd
.iPixelType
== PFD_TYPE_RGBA
) ? GL_TRUE
: GL_FALSE
,
113 (pf
->pfd
.dwFlags
& PFD_DOUBLEBUFFER
) ? GL_TRUE
: GL_FALSE
,
114 (pf
->pfd
.dwFlags
& PFD_STEREO
) ? GL_TRUE
: GL_FALSE
,
119 (pf
->pfd
.iPixelType
== PFD_TYPE_COLORINDEX
) ? pf
->pfd
.cColorBits
: 0,
121 pf
->pfd
.cStencilBits
,
122 pf
->pfd
.cAccumRedBits
,
123 pf
->pfd
.cAccumGreenBits
,
124 pf
->pfd
.cAccumBlueBits
,
125 pf
->pfd
.cAccumAlphaBits
,
130 screen
= stw_dev
->screen
;
134 if(stw_dev
->trace_running
)
135 screen
= trace_screen(screen
)->screen
;
138 pipe
= stw_dev
->stw_winsys
->create_context( screen
);
144 if(stw_dev
->trace_running
)
145 pipe
= trace_context_create(stw_dev
->screen
, pipe
);
151 ctx
->st
= st_create_context( pipe
, visual
, NULL
);
155 ctx
->st
->ctx
->DriverCtx
= ctx
;
158 pipe_mutex_lock( stw_dev
->mutex
);
159 hglrc
= handle_table_add(stw_dev
->ctx_table
, ctx
);
160 pipe_mutex_unlock( stw_dev
->mutex
);
169 _mesa_destroy_visual( visual
);
172 pipe
->destroy( pipe
);
182 struct stw_context
*ctx
;
188 pipe_mutex_lock( stw_dev
->mutex
);
189 ctx
= stw_lookup_context_locked(hglrc
);
190 handle_table_remove(stw_dev
->ctx_table
, hglrc
);
191 pipe_mutex_unlock( stw_dev
->mutex
);
194 GLcontext
*glctx
= ctx
->st
->ctx
;
195 GET_CURRENT_CONTEXT( glcurctx
);
196 struct stw_framebuffer
*fb
;
198 /* Unbind current if deleting current context.
200 if (glcurctx
== glctx
)
201 st_make_current( NULL
, NULL
, NULL
);
203 fb
= stw_framebuffer_from_hdc( ctx
->hdc
);
205 stw_framebuffer_destroy( fb
);
207 if (WindowFromDC( ctx
->hdc
) != NULL
)
208 ReleaseDC( WindowFromDC( ctx
->hdc
), ctx
->hdc
);
210 st_destroy_context(ctx
->st
);
223 struct stw_context
*ctx
;
228 pipe_mutex_lock( stw_dev
->mutex
);
229 ctx
= stw_lookup_context_locked( hglrc
);
230 pipe_mutex_unlock( stw_dev
->mutex
);
235 /* The expectation is that ctx is the same context which is
236 * current for this thread. We should check that and return False
240 GLcontext
*glctx
= ctx
->st
->ctx
;
241 GET_CURRENT_CONTEXT( glcurctx
);
243 if (glcurctx
!= glctx
)
247 if (stw_make_current( NULL
, 0 ) == FALSE
)
253 /* Find the width and height of the window named by hdc.
256 stw_get_window_size( HDC hdc
, GLuint
*width
, GLuint
*height
)
258 if (WindowFromDC( hdc
)) {
261 GetClientRect( WindowFromDC( hdc
), &rect
);
262 *width
= rect
.right
- rect
.left
;
263 *height
= rect
.bottom
- rect
.top
;
266 *width
= GetDeviceCaps( hdc
, HORZRES
);
267 *height
= GetDeviceCaps( hdc
, VERTRES
);
272 stw_get_current_context( void )
274 return stw_tls_get_data()->currentGLRC
;
278 stw_get_current_dc( void )
280 return stw_tls_get_data()->currentDC
;
288 struct stw_context
*ctx
;
289 GET_CURRENT_CONTEXT( glcurctx
);
290 struct stw_framebuffer
*fb
;
293 struct stw_context
*curctx
;
298 pipe_mutex_lock( stw_dev
->mutex
);
299 ctx
= stw_lookup_context_locked( hglrc
);
300 pipe_mutex_unlock( stw_dev
->mutex
);
302 stw_tls_get_data()->currentDC
= hdc
;
303 stw_tls_get_data()->currentGLRC
= hglrc
;
305 if (glcurctx
!= NULL
) {
306 curctx
= (struct stw_context
*) glcurctx
->DriverCtx
;
309 st_flush(glcurctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
312 if (hdc
== NULL
|| hglrc
== 0) {
313 st_make_current( NULL
, NULL
, NULL
);
317 /* Return if already current.
319 if (glcurctx
!= NULL
) {
320 if (curctx
!= NULL
&& curctx
== ctx
&& ctx
->hdc
== hdc
)
324 fb
= stw_framebuffer_from_hdc( hdc
);
327 stw_get_window_size( hdc
, &width
, &height
);
329 /* Lazy creation of stw_framebuffers.
331 if (fb
== NULL
&& ctx
!= NULL
&& hdc
!= NULL
) {
332 GLvisual
*visual
= &ctx
->st
->ctx
->Visual
;
334 fb
= stw_framebuffer_create( hdc
, visual
, ctx
->pfi
, width
, height
);
340 pipe_mutex_lock( fb
->mutex
);
341 st_make_current( ctx
->st
, fb
->stfb
, fb
->stfb
);
342 st_resize_framebuffer( fb
->stfb
, width
, height
);
343 pipe_mutex_unlock( fb
->mutex
);
346 ctx
->st
->pipe
->priv
= hdc
;
350 st_make_current( NULL
, NULL
, NULL
);