09dba61603f277156a290bb1d8ff911fa3a0c040
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
);
73 pipe_mutex_unlock( stw_dev
->mutex
);
83 struct stw_context
*ctx1
;
84 struct stw_context
*ctx2
;
87 pipe_mutex_lock( stw_dev
->mutex
);
89 ctx1
= stw_lookup_context_locked( hglrc1
);
90 ctx2
= stw_lookup_context_locked( hglrc2
);
93 ctx1
->pfi
== ctx2
->pfi
) {
94 ret
= _mesa_share_state(ctx2
->st
->ctx
, ctx1
->st
->ctx
);
97 pipe_mutex_unlock( stw_dev
->mutex
);
103 stw_create_layer_context(
108 const struct stw_pixelformat_info
*pf
= NULL
;
109 struct stw_context
*ctx
= NULL
;
110 GLvisual
*visual
= NULL
;
111 struct pipe_screen
*screen
= NULL
;
112 struct pipe_context
*pipe
= NULL
;
117 if (iLayerPlane
!= 0)
120 pfi
= stw_pixelformat_get( hdc
);
124 pf
= stw_pixelformat_get_info( pfi
- 1 );
126 ctx
= CALLOC_STRUCT( stw_context
);
132 /* Create visual based on flags
134 visual
= _mesa_create_visual(
135 (pf
->pfd
.iPixelType
== PFD_TYPE_RGBA
) ? GL_TRUE
: GL_FALSE
,
136 (pf
->pfd
.dwFlags
& PFD_DOUBLEBUFFER
) ? GL_TRUE
: GL_FALSE
,
137 (pf
->pfd
.dwFlags
& PFD_STEREO
) ? GL_TRUE
: GL_FALSE
,
142 (pf
->pfd
.iPixelType
== PFD_TYPE_COLORINDEX
) ? pf
->pfd
.cColorBits
: 0,
144 pf
->pfd
.cStencilBits
,
145 pf
->pfd
.cAccumRedBits
,
146 pf
->pfd
.cAccumGreenBits
,
147 pf
->pfd
.cAccumBlueBits
,
148 pf
->pfd
.cAccumAlphaBits
,
153 screen
= stw_dev
->screen
;
157 if(stw_dev
->trace_running
)
158 screen
= trace_screen(screen
)->screen
;
161 pipe
= stw_dev
->stw_winsys
->create_context( screen
);
167 if(stw_dev
->trace_running
)
168 pipe
= trace_context_create(stw_dev
->screen
, pipe
);
174 ctx
->st
= st_create_context( pipe
, visual
, NULL
);
178 ctx
->st
->ctx
->DriverCtx
= ctx
;
181 pipe_mutex_lock( stw_dev
->mutex
);
182 ctx
->hglrc
= handle_table_add(stw_dev
->ctx_table
, ctx
);
183 pipe_mutex_unlock( stw_dev
->mutex
);
190 st_destroy_context(ctx
->st
);
191 goto no_pipe
; /* st_context_destroy already destroys pipe */
193 pipe
->destroy( pipe
);
195 _mesa_destroy_visual( visual
);
206 struct stw_context
*ctx
;
212 pipe_mutex_lock( stw_dev
->mutex
);
213 ctx
= stw_lookup_context_locked(hglrc
);
214 handle_table_remove(stw_dev
->ctx_table
, hglrc
);
215 pipe_mutex_unlock( stw_dev
->mutex
);
218 GLcontext
*glctx
= ctx
->st
->ctx
;
219 GET_CURRENT_CONTEXT( glcurctx
);
220 struct stw_framebuffer
*fb
;
222 /* Unbind current if deleting current context.
224 if (glcurctx
== glctx
)
225 st_make_current( NULL
, NULL
, NULL
);
227 fb
= stw_framebuffer_from_hdc( ctx
->hdc
);
229 stw_framebuffer_destroy( fb
);
231 if (WindowFromDC( ctx
->hdc
) != NULL
)
232 ReleaseDC( WindowFromDC( ctx
->hdc
), ctx
->hdc
);
234 st_destroy_context(ctx
->st
);
247 struct stw_context
*ctx
;
252 pipe_mutex_lock( stw_dev
->mutex
);
253 ctx
= stw_lookup_context_locked( hglrc
);
254 pipe_mutex_unlock( stw_dev
->mutex
);
259 /* The expectation is that ctx is the same context which is
260 * current for this thread. We should check that and return False
264 GLcontext
*glctx
= ctx
->st
->ctx
;
265 GET_CURRENT_CONTEXT( glcurctx
);
267 if (glcurctx
!= glctx
)
271 if (stw_make_current( NULL
, 0 ) == FALSE
)
277 /* Find the width and height of the window named by hdc.
280 stw_get_window_size( HDC hdc
, GLuint
*pwidth
, GLuint
*pheight
)
282 GLuint width
, height
;
285 hwnd
= WindowFromDC( hdc
);
288 GetClientRect( hwnd
, &rect
);
289 width
= rect
.right
- rect
.left
;
290 height
= rect
.bottom
- rect
.top
;
293 width
= GetDeviceCaps( hdc
, HORZRES
);
294 height
= GetDeviceCaps( hdc
, VERTRES
);
307 stw_get_current_context( void )
309 GET_CURRENT_CONTEXT( glcurctx
);
310 struct stw_context
*ctx
;
315 ctx
= (struct stw_context
*)glcurctx
->DriverCtx
;
324 stw_get_current_dc( void )
326 GET_CURRENT_CONTEXT( glcurctx
);
327 struct stw_context
*ctx
;
332 ctx
= (struct stw_context
*)glcurctx
->DriverCtx
;
345 struct stw_context
*ctx
;
346 GET_CURRENT_CONTEXT( glcurctx
);
347 struct stw_framebuffer
*fb
;
350 struct stw_context
*curctx
= NULL
;
355 pipe_mutex_lock( stw_dev
->mutex
);
356 ctx
= stw_lookup_context_locked( hglrc
);
357 pipe_mutex_unlock( stw_dev
->mutex
);
359 if (glcurctx
!= NULL
) {
360 curctx
= (struct stw_context
*) glcurctx
->DriverCtx
;
363 st_flush(glcurctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
366 if (hdc
== NULL
|| hglrc
== 0) {
367 st_make_current( NULL
, NULL
, NULL
);
371 /* Return if already current.
373 if (glcurctx
!= NULL
) {
374 if (curctx
!= NULL
&& curctx
== ctx
&& ctx
->hdc
== hdc
)
378 fb
= stw_framebuffer_from_hdc( hdc
);
381 stw_get_window_size( hdc
, &width
, &height
);
383 /* Lazy creation of stw_framebuffers.
385 if (fb
== NULL
&& ctx
!= NULL
&& hdc
!= NULL
) {
386 GLvisual
*visual
= &ctx
->st
->ctx
->Visual
;
388 fb
= stw_framebuffer_create( hdc
, visual
, ctx
->pfi
, width
, height
);
394 pipe_mutex_lock( fb
->mutex
);
395 st_make_current( ctx
->st
, fb
->stfb
, fb
->stfb
);
396 st_resize_framebuffer( fb
->stfb
, width
, height
);
397 pipe_mutex_unlock( fb
->mutex
);
400 ctx
->st
->pipe
->priv
= hdc
;
404 st_make_current( NULL
, NULL
, NULL
);