stw: remove duplicate function declarations
[mesa.git] / src / gallium / state_trackers / wgl / icd / stw_icd.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include <windows.h>
29 #include <stdio.h>
30
31 #include "GL/gl.h"
32
33 #include "pipe/p_debug.h"
34
35 #include "shared/stw_public.h"
36 #include "icd/stw_icd.h"
37 #include "stw.h"
38
39
40 #define DRV_CONTEXT_MAX 32
41
42 struct stw_icd
43 {
44 struct {
45 HGLRC hglrc;
46 } ctx_array[DRV_CONTEXT_MAX];
47
48 DHGLRC ctx_current;
49 };
50
51
52 static struct stw_icd *stw_icd = NULL;
53
54
55 boolean
56 stw_icd_init( void )
57 {
58 static struct stw_icd stw_icd_storage;
59
60 assert(!stw_icd);
61
62 stw_icd = &stw_icd_storage;
63 memset(stw_icd, 0, sizeof(*stw_icd));
64
65 return TRUE;
66 }
67
68 void
69 stw_icd_cleanup(void)
70 {
71 DHGLRC dhglrc;
72
73 if(!stw_icd)
74 return;
75
76 /* Ensure all contexts are destroyed */
77 for (dhglrc = 1; dhglrc <= DRV_CONTEXT_MAX; dhglrc++)
78 if (stw_icd->ctx_array[dhglrc - 1].hglrc)
79 DrvDeleteContext( dhglrc );
80
81 stw_icd = NULL;
82 }
83
84
85 static HGLRC
86 lookup_hglrc( DHGLRC dhglrc )
87 {
88 if (dhglrc == 0 ||
89 dhglrc >= DRV_CONTEXT_MAX)
90 return NULL;
91
92 return stw_icd->ctx_array[dhglrc - 1].hglrc;
93 }
94
95 BOOL APIENTRY
96 DrvCopyContext(
97 DHGLRC dhrcSource,
98 DHGLRC dhrcDest,
99 UINT fuMask )
100 {
101 HGLRC src = lookup_hglrc( dhrcSource );
102 HGLRC dst = lookup_hglrc( dhrcDest );
103
104 if (src == NULL ||
105 dst == NULL)
106 return FALSE;
107
108 return stw_copy_context( src, dst, fuMask );
109 }
110
111 DHGLRC APIENTRY
112 DrvCreateLayerContext(
113 HDC hdc,
114 INT iLayerPlane )
115 {
116 DWORD i;
117
118 for (i = 0; i < DRV_CONTEXT_MAX; i++) {
119 if (stw_icd->ctx_array[i].hglrc == NULL)
120 goto found_slot;
121 }
122
123 /* No slot available, fail:
124 */
125 return 0;
126
127 found_slot:
128 stw_icd->ctx_array[i].hglrc = stw_create_context( hdc, iLayerPlane );
129 if (stw_icd->ctx_array[i].hglrc == NULL)
130 return 0;
131
132 return (DHGLRC) i + 1;
133 }
134
135 DHGLRC APIENTRY
136 DrvCreateContext(
137 HDC hdc )
138 {
139 return DrvCreateLayerContext( hdc, 0 );
140 }
141
142 BOOL APIENTRY
143 DrvDeleteContext(
144 DHGLRC dhglrc )
145 {
146 HGLRC hglrc = lookup_hglrc( dhglrc );
147 BOOL success = FALSE;
148
149 if (hglrc != NULL) {
150 success = stw_delete_context( hglrc );
151 if (success)
152 stw_icd->ctx_array[dhglrc - 1].hglrc = NULL;
153 }
154
155 debug_printf( "%s( %u ) = %s\n", __FUNCTION__, dhglrc, success ? "TRUE" : "FALSE" );
156
157 return success;
158 }
159
160 BOOL APIENTRY
161 DrvDescribeLayerPlane(
162 HDC hdc,
163 INT iPixelFormat,
164 INT iLayerPlane,
165 UINT nBytes,
166 LPLAYERPLANEDESCRIPTOR plpd )
167 {
168 debug_printf( "%s\n", __FUNCTION__ );
169
170 return FALSE;
171 }
172
173 LONG APIENTRY
174 DrvDescribePixelFormat(
175 HDC hdc,
176 INT iPixelFormat,
177 ULONG cjpfd,
178 PIXELFORMATDESCRIPTOR *ppfd )
179 {
180 LONG r;
181
182 r = stw_pixelformat_describe( hdc, iPixelFormat, cjpfd, ppfd );
183
184 debug_printf( "%s( 0x%p, %d, %u, 0x%p ) = %d\n",
185 __FUNCTION__, hdc, iPixelFormat, cjpfd, ppfd, r );
186
187 return r;
188 }
189
190 int APIENTRY
191 DrvGetLayerPaletteEntries(
192 HDC hdc,
193 INT iLayerPlane,
194 INT iStart,
195 INT cEntries,
196 COLORREF *pcr )
197 {
198 debug_printf( "%s\n", __FUNCTION__ );
199
200 return 0;
201 }
202
203 PROC APIENTRY
204 DrvGetProcAddress(
205 LPCSTR lpszProc )
206 {
207 PROC r;
208
209 r = stw_get_proc_address( lpszProc );
210
211 debug_printf( "%s( \", __FUNCTION__%s\" ) = 0x%p\n", lpszProc, r );
212
213 return r;
214 }
215
216 BOOL APIENTRY
217 DrvRealizeLayerPalette(
218 HDC hdc,
219 INT iLayerPlane,
220 BOOL bRealize )
221 {
222 debug_printf( "%s\n", __FUNCTION__ );
223
224 return FALSE;
225 }
226
227 BOOL APIENTRY
228 DrvReleaseContext(
229 DHGLRC dhglrc )
230 {
231 BOOL success = FALSE;
232
233 if (dhglrc == stw_icd->ctx_current) {
234 HGLRC hglrc = lookup_hglrc( dhglrc );
235
236 if (hglrc != NULL) {
237 success = stw_make_current( NULL, NULL );
238 if (success)
239 stw_icd->ctx_current = 0;
240 }
241 }
242
243 debug_printf( "%s( %u ) = %s\n", __FUNCTION__, dhglrc, success ? "TRUE" : "FALSE" );
244
245 return success;
246 }
247
248 void APIENTRY
249 DrvSetCallbackProcs(
250 INT nProcs,
251 PROC *pProcs )
252 {
253 debug_printf( "%s( %d, 0x%p )\n", __FUNCTION__, nProcs, pProcs );
254
255 return;
256 }
257
258 #define GPA_GL( NAME ) disp->NAME = gl##NAME
259
260 static GLCLTPROCTABLE cpt;
261
262 PGLCLTPROCTABLE APIENTRY
263 DrvSetContext(
264 HDC hdc,
265 DHGLRC dhglrc,
266 PFN_SETPROCTABLE pfnSetProcTable )
267 {
268 HGLRC hglrc = lookup_hglrc( dhglrc );
269 GLDISPATCHTABLE *disp = &cpt.glDispatchTable;
270
271 debug_printf( "%s( 0x%p, %u, 0x%p )\n", __FUNCTION__, hdc, dhglrc, pfnSetProcTable );
272
273 if (hglrc == NULL)
274 return NULL;
275
276 if (!stw_make_current( hdc, hglrc ))
277 return NULL;
278
279 memset( &cpt, 0, sizeof( cpt ) );
280 cpt.cEntries = OPENGL_VERSION_110_ENTRIES;
281
282 GPA_GL( NewList );
283 GPA_GL( EndList );
284 GPA_GL( CallList );
285 GPA_GL( CallLists );
286 GPA_GL( DeleteLists );
287 GPA_GL( GenLists );
288 GPA_GL( ListBase );
289 GPA_GL( Begin );
290 GPA_GL( Bitmap );
291 GPA_GL( Color3b );
292 GPA_GL( Color3bv );
293 GPA_GL( Color3d );
294 GPA_GL( Color3dv );
295 GPA_GL( Color3f );
296 GPA_GL( Color3fv );
297 GPA_GL( Color3i );
298 GPA_GL( Color3iv );
299 GPA_GL( Color3s );
300 GPA_GL( Color3sv );
301 GPA_GL( Color3ub );
302 GPA_GL( Color3ubv );
303 GPA_GL( Color3ui );
304 GPA_GL( Color3uiv );
305 GPA_GL( Color3us );
306 GPA_GL( Color3usv );
307 GPA_GL( Color4b );
308 GPA_GL( Color4bv );
309 GPA_GL( Color4d );
310 GPA_GL( Color4dv );
311 GPA_GL( Color4f );
312 GPA_GL( Color4fv );
313 GPA_GL( Color4i );
314 GPA_GL( Color4iv );
315 GPA_GL( Color4s );
316 GPA_GL( Color4sv );
317 GPA_GL( Color4ub );
318 GPA_GL( Color4ubv );
319 GPA_GL( Color4ui );
320 GPA_GL( Color4uiv );
321 GPA_GL( Color4us );
322 GPA_GL( Color4usv );
323 GPA_GL( EdgeFlag );
324 GPA_GL( EdgeFlagv );
325 GPA_GL( End );
326 GPA_GL( Indexd );
327 GPA_GL( Indexdv );
328 GPA_GL( Indexf );
329 GPA_GL( Indexfv );
330 GPA_GL( Indexi );
331 GPA_GL( Indexiv );
332 GPA_GL( Indexs );
333 GPA_GL( Indexsv );
334 GPA_GL( Normal3b );
335 GPA_GL( Normal3bv );
336 GPA_GL( Normal3d );
337 GPA_GL( Normal3dv );
338 GPA_GL( Normal3f );
339 GPA_GL( Normal3fv );
340 GPA_GL( Normal3i );
341 GPA_GL( Normal3iv );
342 GPA_GL( Normal3s );
343 GPA_GL( Normal3sv );
344 GPA_GL( RasterPos2d );
345 GPA_GL( RasterPos2dv );
346 GPA_GL( RasterPos2f );
347 GPA_GL( RasterPos2fv );
348 GPA_GL( RasterPos2i );
349 GPA_GL( RasterPos2iv );
350 GPA_GL( RasterPos2s );
351 GPA_GL( RasterPos2sv );
352 GPA_GL( RasterPos3d );
353 GPA_GL( RasterPos3dv );
354 GPA_GL( RasterPos3f );
355 GPA_GL( RasterPos3fv );
356 GPA_GL( RasterPos3i );
357 GPA_GL( RasterPos3iv );
358 GPA_GL( RasterPos3s );
359 GPA_GL( RasterPos3sv );
360 GPA_GL( RasterPos4d );
361 GPA_GL( RasterPos4dv );
362 GPA_GL( RasterPos4f );
363 GPA_GL( RasterPos4fv );
364 GPA_GL( RasterPos4i );
365 GPA_GL( RasterPos4iv );
366 GPA_GL( RasterPos4s );
367 GPA_GL( RasterPos4sv );
368 GPA_GL( Rectd );
369 GPA_GL( Rectdv );
370 GPA_GL( Rectf );
371 GPA_GL( Rectfv );
372 GPA_GL( Recti );
373 GPA_GL( Rectiv );
374 GPA_GL( Rects );
375 GPA_GL( Rectsv );
376 GPA_GL( TexCoord1d );
377 GPA_GL( TexCoord1dv );
378 GPA_GL( TexCoord1f );
379 GPA_GL( TexCoord1fv );
380 GPA_GL( TexCoord1i );
381 GPA_GL( TexCoord1iv );
382 GPA_GL( TexCoord1s );
383 GPA_GL( TexCoord1sv );
384 GPA_GL( TexCoord2d );
385 GPA_GL( TexCoord2dv );
386 GPA_GL( TexCoord2f );
387 GPA_GL( TexCoord2fv );
388 GPA_GL( TexCoord2i );
389 GPA_GL( TexCoord2iv );
390 GPA_GL( TexCoord2s );
391 GPA_GL( TexCoord2sv );
392 GPA_GL( TexCoord3d );
393 GPA_GL( TexCoord3dv );
394 GPA_GL( TexCoord3f );
395 GPA_GL( TexCoord3fv );
396 GPA_GL( TexCoord3i );
397 GPA_GL( TexCoord3iv );
398 GPA_GL( TexCoord3s );
399 GPA_GL( TexCoord3sv );
400 GPA_GL( TexCoord4d );
401 GPA_GL( TexCoord4dv );
402 GPA_GL( TexCoord4f );
403 GPA_GL( TexCoord4fv );
404 GPA_GL( TexCoord4i );
405 GPA_GL( TexCoord4iv );
406 GPA_GL( TexCoord4s );
407 GPA_GL( TexCoord4sv );
408 GPA_GL( Vertex2d );
409 GPA_GL( Vertex2dv );
410 GPA_GL( Vertex2f );
411 GPA_GL( Vertex2fv );
412 GPA_GL( Vertex2i );
413 GPA_GL( Vertex2iv );
414 GPA_GL( Vertex2s );
415 GPA_GL( Vertex2sv );
416 GPA_GL( Vertex3d );
417 GPA_GL( Vertex3dv );
418 GPA_GL( Vertex3f );
419 GPA_GL( Vertex3fv );
420 GPA_GL( Vertex3i );
421 GPA_GL( Vertex3iv );
422 GPA_GL( Vertex3s );
423 GPA_GL( Vertex3sv );
424 GPA_GL( Vertex4d );
425 GPA_GL( Vertex4dv );
426 GPA_GL( Vertex4f );
427 GPA_GL( Vertex4fv );
428 GPA_GL( Vertex4i );
429 GPA_GL( Vertex4iv );
430 GPA_GL( Vertex4s );
431 GPA_GL( Vertex4sv );
432 GPA_GL( ClipPlane );
433 GPA_GL( ColorMaterial );
434 GPA_GL( CullFace );
435 GPA_GL( Fogf );
436 GPA_GL( Fogfv );
437 GPA_GL( Fogi );
438 GPA_GL( Fogiv );
439 GPA_GL( FrontFace );
440 GPA_GL( Hint );
441 GPA_GL( Lightf );
442 GPA_GL( Lightfv );
443 GPA_GL( Lighti );
444 GPA_GL( Lightiv );
445 GPA_GL( LightModelf );
446 GPA_GL( LightModelfv );
447 GPA_GL( LightModeli );
448 GPA_GL( LightModeliv );
449 GPA_GL( LineStipple );
450 GPA_GL( LineWidth );
451 GPA_GL( Materialf );
452 GPA_GL( Materialfv );
453 GPA_GL( Materiali );
454 GPA_GL( Materialiv );
455 GPA_GL( PointSize );
456 GPA_GL( PolygonMode );
457 GPA_GL( PolygonStipple );
458 GPA_GL( Scissor );
459 GPA_GL( ShadeModel );
460 GPA_GL( TexParameterf );
461 GPA_GL( TexParameterfv );
462 GPA_GL( TexParameteri );
463 GPA_GL( TexParameteriv );
464 GPA_GL( TexImage1D );
465 GPA_GL( TexImage2D );
466 GPA_GL( TexEnvf );
467 GPA_GL( TexEnvfv );
468 GPA_GL( TexEnvi );
469 GPA_GL( TexEnviv );
470 GPA_GL( TexGend );
471 GPA_GL( TexGendv );
472 GPA_GL( TexGenf );
473 GPA_GL( TexGenfv );
474 GPA_GL( TexGeni );
475 GPA_GL( TexGeniv );
476 GPA_GL( FeedbackBuffer );
477 GPA_GL( SelectBuffer );
478 GPA_GL( RenderMode );
479 GPA_GL( InitNames );
480 GPA_GL( LoadName );
481 GPA_GL( PassThrough );
482 GPA_GL( PopName );
483 GPA_GL( PushName );
484 GPA_GL( DrawBuffer );
485 GPA_GL( Clear );
486 GPA_GL( ClearAccum );
487 GPA_GL( ClearIndex );
488 GPA_GL( ClearColor );
489 GPA_GL( ClearStencil );
490 GPA_GL( ClearDepth );
491 GPA_GL( StencilMask );
492 GPA_GL( ColorMask );
493 GPA_GL( DepthMask );
494 GPA_GL( IndexMask );
495 GPA_GL( Accum );
496 GPA_GL( Disable );
497 GPA_GL( Enable );
498 GPA_GL( Finish );
499 GPA_GL( Flush );
500 GPA_GL( PopAttrib );
501 GPA_GL( PushAttrib );
502 GPA_GL( Map1d );
503 GPA_GL( Map1f );
504 GPA_GL( Map2d );
505 GPA_GL( Map2f );
506 GPA_GL( MapGrid1d );
507 GPA_GL( MapGrid1f );
508 GPA_GL( MapGrid2d );
509 GPA_GL( MapGrid2f );
510 GPA_GL( EvalCoord1d );
511 GPA_GL( EvalCoord1dv );
512 GPA_GL( EvalCoord1f );
513 GPA_GL( EvalCoord1fv );
514 GPA_GL( EvalCoord2d );
515 GPA_GL( EvalCoord2dv );
516 GPA_GL( EvalCoord2f );
517 GPA_GL( EvalCoord2fv );
518 GPA_GL( EvalMesh1 );
519 GPA_GL( EvalPoint1 );
520 GPA_GL( EvalMesh2 );
521 GPA_GL( EvalPoint2 );
522 GPA_GL( AlphaFunc );
523 GPA_GL( BlendFunc );
524 GPA_GL( LogicOp );
525 GPA_GL( StencilFunc );
526 GPA_GL( StencilOp );
527 GPA_GL( DepthFunc );
528 GPA_GL( PixelZoom );
529 GPA_GL( PixelTransferf );
530 GPA_GL( PixelTransferi );
531 GPA_GL( PixelStoref );
532 GPA_GL( PixelStorei );
533 GPA_GL( PixelMapfv );
534 GPA_GL( PixelMapuiv );
535 GPA_GL( PixelMapusv );
536 GPA_GL( ReadBuffer );
537 GPA_GL( CopyPixels );
538 GPA_GL( ReadPixels );
539 GPA_GL( DrawPixels );
540 GPA_GL( GetBooleanv );
541 GPA_GL( GetClipPlane );
542 GPA_GL( GetDoublev );
543 GPA_GL( GetError );
544 GPA_GL( GetFloatv );
545 GPA_GL( GetIntegerv );
546 GPA_GL( GetLightfv );
547 GPA_GL( GetLightiv );
548 GPA_GL( GetMapdv );
549 GPA_GL( GetMapfv );
550 GPA_GL( GetMapiv );
551 GPA_GL( GetMaterialfv );
552 GPA_GL( GetMaterialiv );
553 GPA_GL( GetPixelMapfv );
554 GPA_GL( GetPixelMapuiv );
555 GPA_GL( GetPixelMapusv );
556 GPA_GL( GetPolygonStipple );
557 GPA_GL( GetString );
558 GPA_GL( GetTexEnvfv );
559 GPA_GL( GetTexEnviv );
560 GPA_GL( GetTexGendv );
561 GPA_GL( GetTexGenfv );
562 GPA_GL( GetTexGeniv );
563 GPA_GL( GetTexImage );
564 GPA_GL( GetTexParameterfv );
565 GPA_GL( GetTexParameteriv );
566 GPA_GL( GetTexLevelParameterfv );
567 GPA_GL( GetTexLevelParameteriv );
568 GPA_GL( IsEnabled );
569 GPA_GL( IsList );
570 GPA_GL( DepthRange );
571 GPA_GL( Frustum );
572 GPA_GL( LoadIdentity );
573 GPA_GL( LoadMatrixf );
574 GPA_GL( LoadMatrixd );
575 GPA_GL( MatrixMode );
576 GPA_GL( MultMatrixf );
577 GPA_GL( MultMatrixd );
578 GPA_GL( Ortho );
579 GPA_GL( PopMatrix );
580 GPA_GL( PushMatrix );
581 GPA_GL( Rotated );
582 GPA_GL( Rotatef );
583 GPA_GL( Scaled );
584 GPA_GL( Scalef );
585 GPA_GL( Translated );
586 GPA_GL( Translatef );
587 GPA_GL( Viewport );
588 GPA_GL( ArrayElement );
589 GPA_GL( BindTexture );
590 GPA_GL( ColorPointer );
591 GPA_GL( DisableClientState );
592 GPA_GL( DrawArrays );
593 GPA_GL( DrawElements );
594 GPA_GL( EdgeFlagPointer );
595 GPA_GL( EnableClientState );
596 GPA_GL( IndexPointer );
597 GPA_GL( Indexub );
598 GPA_GL( Indexubv );
599 GPA_GL( InterleavedArrays );
600 GPA_GL( NormalPointer );
601 GPA_GL( PolygonOffset );
602 GPA_GL( TexCoordPointer );
603 GPA_GL( VertexPointer );
604 GPA_GL( AreTexturesResident );
605 GPA_GL( CopyTexImage1D );
606 GPA_GL( CopyTexImage2D );
607 GPA_GL( CopyTexSubImage1D );
608 GPA_GL( CopyTexSubImage2D );
609 GPA_GL( DeleteTextures );
610 GPA_GL( GenTextures );
611 GPA_GL( GetPointerv );
612 GPA_GL( IsTexture );
613 GPA_GL( PrioritizeTextures );
614 GPA_GL( TexSubImage1D );
615 GPA_GL( TexSubImage2D );
616 GPA_GL( PopClientAttrib );
617 GPA_GL( PushClientAttrib );
618
619 return &cpt;
620 }
621
622 int APIENTRY
623 DrvSetLayerPaletteEntries(
624 HDC hdc,
625 INT iLayerPlane,
626 INT iStart,
627 INT cEntries,
628 CONST COLORREF *pcr )
629 {
630 debug_printf( "%s\n", __FUNCTION__ );
631
632 return 0;
633 }
634
635 BOOL APIENTRY
636 DrvSetPixelFormat(
637 HDC hdc,
638 LONG iPixelFormat )
639 {
640 BOOL r;
641
642 r = stw_pixelformat_set( hdc, iPixelFormat );
643
644 debug_printf( "%s( 0x%p, %d ) = %s\n", __FUNCTION__, hdc, iPixelFormat, r ? "TRUE" : "FALSE" );
645
646 return r;
647 }
648
649 BOOL APIENTRY
650 DrvShareLists(
651 DHGLRC dhglrc1,
652 DHGLRC dhglrc2 )
653 {
654 debug_printf( "%s\n", __FUNCTION__ );
655
656 return FALSE;
657 }
658
659 BOOL APIENTRY
660 DrvSwapBuffers(
661 HDC hdc )
662 {
663 debug_printf( "%s( 0x%p )\n", __FUNCTION__, hdc );
664
665 return stw_swap_buffers( hdc );
666 }
667
668 BOOL APIENTRY
669 DrvSwapLayerBuffers(
670 HDC hdc,
671 UINT fuPlanes )
672 {
673 debug_printf( "%s\n", __FUNCTION__ );
674
675 return FALSE;
676 }
677
678 BOOL APIENTRY
679 DrvValidateVersion(
680 ULONG ulVersion )
681 {
682 debug_printf( "%s( %u )\n", __FUNCTION__, ulVersion );
683
684 return ulVersion == 1;
685 }