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"
43 #include "stw_device.h"
44 #include "stw_winsys.h"
45 #include "stw_framebuffer.h"
46 #include "stw_pixelformat.h"
47 #include "stw_context.h"
51 static INLINE
struct stw_context
*
52 stw_context(GLcontext
*glctx
)
56 assert(glctx
->DriverCtx
);
57 return (struct stw_context
*)glctx
->DriverCtx
;
60 static INLINE
struct stw_context
*
61 stw_current_context(void)
63 /* We must check if multiple threads are being used or GET_CURRENT_CONTEXT
64 * might return the current context of the thread first seen. */
65 _glapi_check_multithread();
68 GET_CURRENT_CONTEXT( glctx
);
69 return stw_context(glctx
);
79 struct stw_context
*src
;
80 struct stw_context
*dst
;
83 pipe_mutex_lock( stw_dev
->ctx_mutex
);
85 src
= stw_lookup_context_locked( dhrcSource
);
86 dst
= stw_lookup_context_locked( dhrcDest
);
96 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
106 struct stw_context
*ctx1
;
107 struct stw_context
*ctx2
;
110 pipe_mutex_lock( stw_dev
->ctx_mutex
);
112 ctx1
= stw_lookup_context_locked( dhglrc1
);
113 ctx2
= stw_lookup_context_locked( dhglrc2
);
116 ctx1
->iPixelFormat
== ctx2
->iPixelFormat
) {
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_screen
*screen
= NULL
;
156 struct pipe_context
*pipe
= NULL
;
161 if (iLayerPlane
!= 0)
164 iPixelFormat
= GetPixelFormat(hdc
);
168 pfi
= stw_pixelformat_get_info( iPixelFormat
- 1 );
169 stw_pixelformat_visual(&visual
, pfi
);
171 ctx
= CALLOC_STRUCT( stw_context
);
176 ctx
->iPixelFormat
= iPixelFormat
;
178 screen
= stw_dev
->screen
;
182 if(stw_dev
->trace_running
)
183 screen
= trace_screen(screen
)->screen
;
186 pipe
= stw_dev
->stw_winsys
->create_context( screen
);
192 if(stw_dev
->trace_running
)
193 pipe
= trace_context_create(stw_dev
->screen
, pipe
);
196 /* pass to stw_flush_frontbuffer as context_private */
200 ctx
->st
= st_create_context( pipe
, &visual
, NULL
);
204 ctx
->st
->ctx
->DriverCtx
= ctx
;
205 ctx
->st
->ctx
->Driver
.Viewport
= stw_viewport
;
207 pipe_mutex_lock( stw_dev
->ctx_mutex
);
208 ctx
->dhglrc
= handle_table_add(stw_dev
->ctx_table
, ctx
);
209 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
216 st_destroy_context(ctx
->st
);
217 goto no_pipe
; /* st_context_destroy already destroys pipe */
219 pipe
->destroy( pipe
);
230 struct stw_context
*ctx
;
236 pipe_mutex_lock( stw_dev
->ctx_mutex
);
237 ctx
= stw_lookup_context_locked(dhglrc
);
238 handle_table_remove(stw_dev
->ctx_table
, dhglrc
);
239 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
242 struct stw_context
*curctx
= stw_current_context();
244 /* Unbind current if deleting current context. */
246 st_make_current( NULL
, NULL
, NULL
);
248 st_destroy_context(ctx
->st
);
261 struct stw_context
*ctx
;
266 pipe_mutex_lock( stw_dev
->ctx_mutex
);
267 ctx
= stw_lookup_context_locked( dhglrc
);
268 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
273 /* The expectation is that ctx is the same context which is
274 * current for this thread. We should check that and return False
277 if (ctx
!= stw_current_context())
280 if (stw_make_current( NULL
, 0 ) == FALSE
)
288 stw_get_current_context( void )
290 struct stw_context
*ctx
;
292 ctx
= stw_current_context();
300 stw_get_current_dc( void )
302 struct stw_context
*ctx
;
304 ctx
= stw_current_context();
316 struct stw_context
*curctx
= NULL
;
317 struct stw_context
*ctx
= NULL
;
318 struct stw_framebuffer
*fb
= NULL
;
323 curctx
= stw_current_context();
324 if (curctx
!= NULL
) {
325 if (curctx
->dhglrc
!= dhglrc
)
326 st_flush(curctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
328 /* Return if already current. */
329 if (curctx
->dhglrc
== dhglrc
&& curctx
->hdc
== hdc
) {
331 fb
= stw_framebuffer_from_hdc( hdc
);
336 if (hdc
== NULL
|| dhglrc
== 0) {
337 return st_make_current( NULL
, NULL
, NULL
);
340 pipe_mutex_lock( stw_dev
->ctx_mutex
);
341 ctx
= stw_lookup_context_locked( dhglrc
);
342 pipe_mutex_unlock( stw_dev
->ctx_mutex
);
346 fb
= stw_framebuffer_from_hdc( hdc
);
348 /* Applications should call SetPixelFormat before creating a context,
349 * but not all do, and the opengl32 runtime seems to use a default pixel
350 * format in some cases, so we must create a framebuffer for those here
352 int iPixelFormat
= GetPixelFormat(hdc
);
354 fb
= stw_framebuffer_create( hdc
, iPixelFormat
);
359 if(fb
->iPixelFormat
!= ctx
->iPixelFormat
)
362 /* Lazy allocation of the frame buffer */
363 if(!stw_framebuffer_allocate(fb
))
366 /* Bind the new framebuffer */
369 /* pass to stw_flush_frontbuffer as context_private */
370 ctx
->st
->pipe
->priv
= hdc
;
372 if(!st_make_current( ctx
->st
, fb
->stfb
, fb
->stfb
))
378 stw_framebuffer_update(fb
);
379 stw_framebuffer_release(fb
);
386 stw_framebuffer_release(fb
);
387 st_make_current( NULL
, NULL
, NULL
);
392 * Although WGL allows different dispatch entrypoints per context
394 static const GLCLTPROCTABLE cpt
=
396 OPENGL_VERSION_110_ENTRIES
,
672 &glGetPolygonStipple
,
680 &glGetTexParameterfv
,
681 &glGetTexParameteriv
,
682 &glGetTexLevelParameterfv
,
683 &glGetTexLevelParameteriv
,
707 &glDisableClientState
,
711 &glEnableClientState
,
715 &glInterleavedArrays
,
720 &glAreTexturesResident
,
723 &glCopyTexSubImage1D
,
724 &glCopyTexSubImage2D
,
729 &glPrioritizeTextures
,
737 PGLCLTPROCTABLE APIENTRY
741 PFN_SETPROCTABLE pfnSetProcTable
)
743 PGLCLTPROCTABLE r
= (PGLCLTPROCTABLE
)&cpt
;
745 if (!stw_make_current( hdc
, dhglrc
))