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 "pipe/p_compiler.h"
31 #include "pipe/p_context.h"
32 #include "state_tracker/st_api.h"
34 /* for _mesa_share_state */
35 #include "state_tracker/st_context.h"
36 #include "main/core.h"
39 #include "stw_device.h"
40 #include "stw_winsys.h"
41 #include "stw_framebuffer.h"
42 #include "stw_pixelformat.h"
43 #include "stw_context.h"
47 static INLINE
struct stw_context
*
48 stw_current_context(void)
50 struct st_context_iface
*st
;
52 st
= (stw_dev
) ? stw_dev
->stapi
->get_current(stw_dev
->stapi
) : NULL
;
54 return (struct stw_context
*) ((st
) ? st
->st_manager_private
: NULL
);
63 struct stw_context
*src
;
64 struct stw_context
*dst
;
70 pipe_mutex_lock( stw_dev
->ctx_mutex
);
72 src
= stw_lookup_context_locked( dhrcSource
);
73 dst
= stw_lookup_context_locked( dhrcDest
);
83 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
93 struct stw_context
*ctx1
;
94 struct stw_context
*ctx2
;
100 pipe_mutex_lock( stw_dev
->ctx_mutex
);
102 ctx1
= stw_lookup_context_locked( dhglrc1
);
103 ctx2
= stw_lookup_context_locked( dhglrc2
);
106 struct st_context
*st1
, *st2
;
108 st1
= (struct st_context
*) ctx1
->st
;
109 st2
= (struct st_context
*) ctx2
->st
;
110 ret
= _mesa_share_state(st2
->ctx
, st1
->ctx
);
113 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
122 return DrvCreateLayerContext( hdc
, 0 );
126 DrvCreateLayerContext(
131 const struct stw_pixelformat_info
*pfi
;
132 struct st_context_attribs attribs
;
133 struct stw_context
*ctx
= NULL
;
138 if (iLayerPlane
!= 0)
141 iPixelFormat
= GetPixelFormat(hdc
);
145 pfi
= stw_pixelformat_get_info( iPixelFormat
- 1 );
147 ctx
= CALLOC_STRUCT( stw_context
);
152 ctx
->iPixelFormat
= iPixelFormat
;
154 memset(&attribs
, 0, sizeof(attribs
));
155 attribs
.profile
= ST_PROFILE_DEFAULT
;
156 attribs
.visual
= pfi
->stvis
;
158 ctx
->st
= stw_dev
->stapi
->create_context(stw_dev
->stapi
,
159 stw_dev
->smapi
, &attribs
, NULL
);
163 ctx
->st
->st_manager_private
= (void *) ctx
;
165 pipe_mutex_lock( stw_dev
->ctx_mutex
);
166 ctx
->dhglrc
= handle_table_add(stw_dev
->ctx_table
, ctx
);
167 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
174 ctx
->st
->destroy(ctx
->st
);
185 struct stw_context
*ctx
;
191 pipe_mutex_lock( stw_dev
->ctx_mutex
);
192 ctx
= stw_lookup_context_locked(dhglrc
);
193 handle_table_remove(stw_dev
->ctx_table
, dhglrc
);
194 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
197 struct stw_context
*curctx
= stw_current_context();
199 /* Unbind current if deleting current context. */
201 stw_dev
->stapi
->make_current(stw_dev
->stapi
, NULL
, NULL
, NULL
);
203 ctx
->st
->destroy(ctx
->st
);
216 struct stw_context
*ctx
;
221 pipe_mutex_lock( stw_dev
->ctx_mutex
);
222 ctx
= stw_lookup_context_locked( dhglrc
);
223 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
228 /* The expectation is that ctx is the same context which is
229 * current for this thread. We should check that and return False
232 if (ctx
!= stw_current_context())
235 if (stw_make_current( NULL
, 0 ) == FALSE
)
243 stw_get_current_context( void )
245 struct stw_context
*ctx
;
247 ctx
= stw_current_context();
255 stw_get_current_dc( void )
257 struct stw_context
*ctx
;
259 ctx
= stw_current_context();
271 struct stw_context
*curctx
= NULL
;
272 struct stw_context
*ctx
= NULL
;
273 struct stw_framebuffer
*fb
= NULL
;
278 curctx
= stw_current_context();
279 if (curctx
!= NULL
) {
280 if (curctx
->dhglrc
!= dhglrc
)
281 curctx
->st
->flush(curctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
283 /* Return if already current. */
284 if (curctx
->dhglrc
== dhglrc
&& curctx
->hdc
== hdc
) {
286 fb
= stw_framebuffer_from_hdc( hdc
);
290 stw_framebuffer_reference(&curctx
->current_framebuffer
, NULL
);
293 if (hdc
== NULL
|| dhglrc
== 0) {
294 return stw_dev
->stapi
->make_current(stw_dev
->stapi
, NULL
, NULL
, NULL
);
297 pipe_mutex_lock( stw_dev
->ctx_mutex
);
298 ctx
= stw_lookup_context_locked( dhglrc
);
299 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
303 fb
= stw_framebuffer_from_hdc( hdc
);
305 stw_framebuffer_update(fb
);
308 /* Applications should call SetPixelFormat before creating a context,
309 * but not all do, and the opengl32 runtime seems to use a default pixel
310 * format in some cases, so we must create a framebuffer for those here
312 int iPixelFormat
= GetPixelFormat(hdc
);
314 fb
= stw_framebuffer_create( hdc
, iPixelFormat
);
319 if(fb
->iPixelFormat
!= ctx
->iPixelFormat
)
322 /* Bind the new framebuffer */
325 if (!stw_dev
->stapi
->make_current(stw_dev
->stapi
, ctx
->st
, fb
->stfb
, fb
->stfb
))
328 stw_framebuffer_reference(&ctx
->current_framebuffer
, fb
);
333 stw_framebuffer_release(fb
);
340 stw_framebuffer_release(fb
);
341 stw_dev
->stapi
->make_current(stw_dev
->stapi
, NULL
, NULL
, NULL
);
346 * Flush the current context if it is bound to the framebuffer.
349 stw_flush_current_locked( struct stw_framebuffer
*fb
)
351 struct stw_context
*ctx
= stw_current_context();
353 if (ctx
&& ctx
->current_framebuffer
== fb
) {
354 ctx
->st
->flush(ctx
->st
,
355 PIPE_FLUSH_RENDER_CACHE
|
356 PIPE_FLUSH_SWAPBUFFERS
|
363 * Notify the current context that the framebuffer has become invalid.
366 stw_notify_current_locked( struct stw_framebuffer
*fb
)
368 struct stw_context
*ctx
= stw_current_context();
370 if (ctx
&& ctx
->current_framebuffer
== fb
)
371 ctx
->st
->notify_invalid_framebuffer(ctx
->st
, fb
->stfb
);
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
))