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 "stw_device.h"
39 #include "stw_winsys.h"
40 #include "stw_framebuffer.h"
41 #include "stw_pixelformat.h"
42 #include "stw_context.h"
46 static INLINE
struct stw_context
*
47 stw_context(GLcontext
*glctx
)
51 assert(glctx
->DriverCtx
);
52 return (struct stw_context
*)glctx
->DriverCtx
;
55 static INLINE
struct stw_context
*
56 stw_current_context(void)
58 /* We must check if multiple threads are being used or GET_CURRENT_CONTEXT
59 * might return the current context of the thread first seen. */
60 _glapi_check_multithread();
63 GET_CURRENT_CONTEXT( glctx
);
64 return stw_context(glctx
);
74 struct stw_context
*src
;
75 struct stw_context
*dst
;
81 pipe_mutex_lock( stw_dev
->ctx_mutex
);
83 src
= stw_lookup_context_locked( dhrcSource
);
84 dst
= stw_lookup_context_locked( dhrcDest
);
94 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
104 struct stw_context
*ctx1
;
105 struct stw_context
*ctx2
;
111 pipe_mutex_lock( stw_dev
->ctx_mutex
);
113 ctx1
= stw_lookup_context_locked( dhglrc1
);
114 ctx2
= stw_lookup_context_locked( dhglrc2
);
117 ret
= _mesa_share_state(ctx2
->st
->ctx
, ctx1
->st
->ctx
);
120 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
126 stw_viewport(GLcontext
* glctx
, GLint x
, GLint y
,
127 GLsizei width
, GLsizei height
)
129 struct stw_context
*ctx
= (struct stw_context
*)glctx
->DriverCtx
;
130 struct stw_framebuffer
*fb
;
132 fb
= stw_framebuffer_from_hdc( ctx
->hdc
);
134 stw_framebuffer_update(fb
);
135 stw_framebuffer_release(fb
);
143 return DrvCreateLayerContext( hdc
, 0 );
147 DrvCreateLayerContext(
152 const struct stw_pixelformat_info
*pfi
;
154 struct stw_context
*ctx
= NULL
;
155 struct pipe_context
*pipe
= NULL
;
160 if (iLayerPlane
!= 0)
163 iPixelFormat
= GetPixelFormat(hdc
);
167 pfi
= stw_pixelformat_get_info( iPixelFormat
- 1 );
168 stw_pixelformat_visual(&visual
, pfi
);
170 ctx
= CALLOC_STRUCT( stw_context
);
175 ctx
->iPixelFormat
= iPixelFormat
;
177 /* priv == hdc, pass to stw_flush_frontbuffer as context_private
179 pipe
= stw_dev
->screen
->context_create( stw_dev
->screen
, hdc
);
183 ctx
->st
= st_create_context( pipe
, &visual
, NULL
);
187 ctx
->st
->ctx
->DriverCtx
= ctx
;
188 ctx
->st
->ctx
->Driver
.Viewport
= stw_viewport
;
190 pipe_mutex_lock( stw_dev
->ctx_mutex
);
191 ctx
->dhglrc
= handle_table_add(stw_dev
->ctx_table
, ctx
);
192 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
199 st_destroy_context(ctx
->st
);
200 goto no_pipe
; /* st_context_destroy already destroys pipe */
202 pipe
->destroy( pipe
);
213 struct stw_context
*ctx
;
219 pipe_mutex_lock( stw_dev
->ctx_mutex
);
220 ctx
= stw_lookup_context_locked(dhglrc
);
221 handle_table_remove(stw_dev
->ctx_table
, dhglrc
);
222 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
225 struct stw_context
*curctx
= stw_current_context();
227 /* Unbind current if deleting current context. */
229 st_make_current( NULL
, NULL
, NULL
, NULL
);
231 st_destroy_context(ctx
->st
);
244 struct stw_context
*ctx
;
249 pipe_mutex_lock( stw_dev
->ctx_mutex
);
250 ctx
= stw_lookup_context_locked( dhglrc
);
251 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
256 /* The expectation is that ctx is the same context which is
257 * current for this thread. We should check that and return False
260 if (ctx
!= stw_current_context())
263 if (stw_make_current( NULL
, 0 ) == FALSE
)
271 stw_get_current_context( void )
273 struct stw_context
*ctx
;
275 ctx
= stw_current_context();
283 stw_get_current_dc( void )
285 struct stw_context
*ctx
;
287 ctx
= stw_current_context();
299 struct stw_context
*curctx
= NULL
;
300 struct stw_context
*ctx
= NULL
;
301 struct stw_framebuffer
*fb
= NULL
;
306 curctx
= stw_current_context();
307 if (curctx
!= NULL
) {
308 if (curctx
->dhglrc
!= dhglrc
)
309 st_flush(curctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
311 /* Return if already current. */
312 if (curctx
->dhglrc
== dhglrc
&& curctx
->hdc
== hdc
) {
314 fb
= stw_framebuffer_from_hdc( hdc
);
319 if (hdc
== NULL
|| dhglrc
== 0) {
320 return st_make_current( NULL
, NULL
, NULL
, NULL
);
323 pipe_mutex_lock( stw_dev
->ctx_mutex
);
324 ctx
= stw_lookup_context_locked( dhglrc
);
325 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
329 fb
= stw_framebuffer_from_hdc( hdc
);
331 /* Applications should call SetPixelFormat before creating a context,
332 * but not all do, and the opengl32 runtime seems to use a default pixel
333 * format in some cases, so we must create a framebuffer for those here
335 int iPixelFormat
= GetPixelFormat(hdc
);
337 fb
= stw_framebuffer_create( hdc
, iPixelFormat
);
342 if(fb
->iPixelFormat
!= ctx
->iPixelFormat
)
345 /* Lazy allocation of the frame buffer */
346 if(!stw_framebuffer_allocate(fb
))
349 /* Bind the new framebuffer */
352 /* pass to stw_flush_frontbuffer as context_private */
353 ctx
->st
->pipe
->priv
= hdc
;
355 if(!st_make_current( ctx
->st
, fb
->stfb
, fb
->stfb
, hdc
))
361 stw_framebuffer_update(fb
);
362 stw_framebuffer_release(fb
);
369 stw_framebuffer_release(fb
);
370 st_make_current( NULL
, NULL
, NULL
, NULL
);
375 * Although WGL allows different dispatch entrypoints per context
377 static const GLCLTPROCTABLE cpt
=
379 OPENGL_VERSION_110_ENTRIES
,
655 &glGetPolygonStipple
,
663 &glGetTexParameterfv
,
664 &glGetTexParameteriv
,
665 &glGetTexLevelParameterfv
,
666 &glGetTexLevelParameteriv
,
690 &glDisableClientState
,
694 &glEnableClientState
,
698 &glInterleavedArrays
,
703 &glAreTexturesResident
,
706 &glCopyTexSubImage1D
,
707 &glCopyTexSubImage2D
,
712 &glPrioritizeTextures
,
720 PGLCLTPROCTABLE APIENTRY
724 PFN_SETPROCTABLE pfnSetProcTable
)
726 PGLCLTPROCTABLE r
= (PGLCLTPROCTABLE
)&cpt
;
728 if (!stw_make_current( hdc
, dhglrc
))