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/context.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 stw_context
*ctx
= NULL
;
137 if (iLayerPlane
!= 0)
140 iPixelFormat
= GetPixelFormat(hdc
);
144 pfi
= stw_pixelformat_get_info( iPixelFormat
- 1 );
146 ctx
= CALLOC_STRUCT( stw_context
);
151 ctx
->iPixelFormat
= iPixelFormat
;
153 ctx
->st
= stw_dev
->stapi
->create_context(stw_dev
->stapi
,
154 stw_dev
->smapi
, &pfi
->stvis
, NULL
);
158 ctx
->st
->st_manager_private
= (void *) ctx
;
160 pipe_mutex_lock( stw_dev
->ctx_mutex
);
161 ctx
->dhglrc
= handle_table_add(stw_dev
->ctx_table
, ctx
);
162 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
169 ctx
->st
->destroy(ctx
->st
);
180 struct stw_context
*ctx
;
186 pipe_mutex_lock( stw_dev
->ctx_mutex
);
187 ctx
= stw_lookup_context_locked(dhglrc
);
188 handle_table_remove(stw_dev
->ctx_table
, dhglrc
);
189 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
192 struct stw_context
*curctx
= stw_current_context();
194 /* Unbind current if deleting current context. */
196 stw_dev
->stapi
->make_current(stw_dev
->stapi
, NULL
, NULL
, NULL
);
198 ctx
->st
->destroy(ctx
->st
);
211 struct stw_context
*ctx
;
216 pipe_mutex_lock( stw_dev
->ctx_mutex
);
217 ctx
= stw_lookup_context_locked( dhglrc
);
218 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
223 /* The expectation is that ctx is the same context which is
224 * current for this thread. We should check that and return False
227 if (ctx
!= stw_current_context())
230 if (stw_make_current( NULL
, 0 ) == FALSE
)
238 stw_get_current_context( void )
240 struct stw_context
*ctx
;
242 ctx
= stw_current_context();
250 stw_get_current_dc( void )
252 struct stw_context
*ctx
;
254 ctx
= stw_current_context();
266 struct stw_context
*curctx
= NULL
;
267 struct stw_context
*ctx
= NULL
;
268 struct stw_framebuffer
*fb
= NULL
;
273 curctx
= stw_current_context();
274 if (curctx
!= NULL
) {
275 if (curctx
->dhglrc
!= dhglrc
)
276 curctx
->st
->flush(curctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
278 /* Return if already current. */
279 if (curctx
->dhglrc
== dhglrc
&& curctx
->hdc
== hdc
) {
281 fb
= stw_framebuffer_from_hdc( hdc
);
285 stw_framebuffer_reference(&curctx
->current_framebuffer
, NULL
);
288 if (hdc
== NULL
|| dhglrc
== 0) {
289 return stw_dev
->stapi
->make_current(stw_dev
->stapi
, NULL
, NULL
, NULL
);
292 pipe_mutex_lock( stw_dev
->ctx_mutex
);
293 ctx
= stw_lookup_context_locked( dhglrc
);
294 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
298 fb
= stw_framebuffer_from_hdc( hdc
);
300 stw_framebuffer_update(fb
);
303 /* Applications should call SetPixelFormat before creating a context,
304 * but not all do, and the opengl32 runtime seems to use a default pixel
305 * format in some cases, so we must create a framebuffer for those here
307 int iPixelFormat
= GetPixelFormat(hdc
);
309 fb
= stw_framebuffer_create( hdc
, iPixelFormat
);
314 if(fb
->iPixelFormat
!= ctx
->iPixelFormat
)
317 /* Bind the new framebuffer */
320 if (!stw_dev
->stapi
->make_current(stw_dev
->stapi
, ctx
->st
, fb
->stfb
, fb
->stfb
))
323 stw_framebuffer_reference(&ctx
->current_framebuffer
, fb
);
328 stw_framebuffer_release(fb
);
335 stw_framebuffer_release(fb
);
336 stw_dev
->stapi
->make_current(stw_dev
->stapi
, NULL
, NULL
, NULL
);
341 * Flush the current context if it is bound to the framebuffer.
344 stw_flush_current_locked( struct stw_framebuffer
*fb
)
346 struct stw_context
*ctx
= stw_current_context();
348 if (ctx
&& ctx
->current_framebuffer
== fb
) {
349 ctx
->st
->flush(ctx
->st
,
350 PIPE_FLUSH_RENDER_CACHE
|
351 PIPE_FLUSH_SWAPBUFFERS
|
358 * Notify the current context that the framebuffer has become invalid.
361 stw_notify_current_locked( struct stw_framebuffer
*fb
)
363 struct stw_context
*ctx
= stw_current_context();
365 if (ctx
&& ctx
->current_framebuffer
== fb
)
366 ctx
->st
->notify_invalid_framebuffer(ctx
->st
, fb
->stfb
);
370 * Although WGL allows different dispatch entrypoints per context
372 static const GLCLTPROCTABLE cpt
=
374 OPENGL_VERSION_110_ENTRIES
,
650 &glGetPolygonStipple
,
658 &glGetTexParameterfv
,
659 &glGetTexParameteriv
,
660 &glGetTexLevelParameterfv
,
661 &glGetTexLevelParameteriv
,
685 &glDisableClientState
,
689 &glEnableClientState
,
693 &glInterleavedArrays
,
698 &glAreTexturesResident
,
701 &glCopyTexSubImage1D
,
702 &glCopyTexSubImage2D
,
707 &glPrioritizeTextures
,
715 PGLCLTPROCTABLE APIENTRY
719 PFN_SETPROCTABLE pfnSetProcTable
)
721 PGLCLTPROCTABLE r
= (PGLCLTPROCTABLE
)&cpt
;
723 if (!stw_make_current( hdc
, dhglrc
))