ReactOS 0.4.16-dev-2284-g3529151
wgl.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS
4 * FILE: dll/opengl/opengl32/wgl.c
5 * PURPOSE: OpenGL32 DLL, WGL functions
6 */
7
8#include "opengl32.h"
9
10#include <pseh/pseh2.h>
11
13
14static CRITICAL_SECTION dc_data_cs = {NULL, -1, 0, 0, 0, 0};
15static struct wgl_dc_data* dc_data_list = NULL;
16
18
19/* FIXME: suboptimal */
20static
21struct wgl_dc_data*
23{
24 HWND hwnd = NULL;
25 struct wgl_dc_data* data;
26 DWORD objType = GetObjectType(hdc);
27 ULONG flags = 0;
28 union
29 {
30 HWND hwnd;
31 HDC hdc;
32 HANDLE u;
33 } id;
34
35 /* Look for the right data identifier */
36 if(objType == OBJ_DC)
37 {
39 if(!hwnd)
40 return NULL;
41 id.hwnd = hwnd;
43 }
44 else if(objType == OBJ_MEMDC)
45 {
46 id.hdc = hdc;
47 }
48 else
49 {
50 return NULL;
51 }
52
55 while(data)
56 {
57 if(data->owner.u == id.u)
58 {
60 return data;
61 }
62 data = data->next;
63 }
64 data= HeapAlloc(GetProcessHeap(), 0, sizeof(*data));
65 if(!data)
66 {
68 return NULL;
69 }
70 /* initialize the structure */
71 data->owner.u = id.u;
72 data->flags = flags;
73 data->pixelformat = 0;
74 data->sw_data = NULL;
75 /* Load the driver */
76 data->icd_data = IntGetIcdData(hdc);
77 /* Get the number of available formats for this DC once and for all */
78 if(data->icd_data)
79 data->nb_icd_formats = data->icd_data->DrvDescribePixelFormat(hdc, format, size, descr);
80 else
81 data->nb_icd_formats = 0;
82 TRACE("ICD %S has %u formats for HDC %x.\n", data->icd_data ? data->icd_data->DriverName : NULL, data->nb_icd_formats, hdc);
83 data->nb_sw_formats = sw_DescribePixelFormat(hdc, 0, 0, NULL);
84 data->next = dc_data_list;
87 return data;
88}
89
90static
91struct wgl_dc_data*
93{
94 return get_dc_data_ex(hdc, 0, 0, NULL);
95}
96
97void release_dc_data(struct wgl_dc_data* dc_data)
98{
99 (void)dc_data;
100}
101
103{
104 struct wgl_context* context = (struct wgl_context*)hglrc;
105
106 if(!hglrc)
107 return NULL;
108
110 {
111 if(context->magic != 'GLRC')
112 context = NULL;
113 }
115 {
116 context = NULL;
117 }
118 _SEH2_END;
119
120 return context;
121}
122
124{
125 struct wgl_dc_data* dc_data = get_dc_data_ex(hdc, format, size, descr);
126 INT ret;
127
128 if(!dc_data)
129 {
131 return 0;
132 }
133
134 ret = dc_data->nb_icd_formats + dc_data->nb_sw_formats;
135
136 if(!descr)
137 {
138 release_dc_data(dc_data);
139 return ret;
140 }
141 if((format <= 0) || (format > ret) || (size < sizeof(*descr)))
142 {
143 release_dc_data(dc_data);
145 return 0;
146 }
147
148 /* Query ICD if needed */
149 if(format <= dc_data->nb_icd_formats)
150 {
151 struct ICD_Data* icd_data = dc_data->icd_data;
152 /* SetPixelFormat may have NULLified this */
153 if (!icd_data)
154 icd_data = IntGetIcdData(hdc);
155 if(!icd_data->DrvDescribePixelFormat(hdc, format, size, descr))
156 {
157 ret = 0;
158 }
159 }
160 else
161 {
162 /* This is a software format */
163 format -= dc_data->nb_icd_formats;
165 {
166 ret = 0;
167 }
168 }
169
170 release_dc_data(dc_data);
171 return ret;
172}
173
175{
177 int i, count, best_format;
178 int bestDBuffer = -1, bestStereo = -1;
179
180 TRACE_(wgl)( "%p %p: size %u version %u flags %u type %u color %u %u,%u,%u,%u "
181 "accum %u depth %u stencil %u aux %u\n",
182 hdc, ppfd, ppfd->nSize, ppfd->nVersion, ppfd->dwFlags, ppfd->iPixelType,
183 ppfd->cColorBits, ppfd->cRedBits, ppfd->cGreenBits, ppfd->cBlueBits, ppfd->cAlphaBits,
184 ppfd->cAccumBits, ppfd->cDepthBits, ppfd->cStencilBits, ppfd->cAuxBuffers );
185
187 if (!count) return 0;
188
189 best_format = 0;
191 best.cAlphaBits = -1;
192 best.cColorBits = -1;
193 best.cDepthBits = -1;
194 best.cStencilBits = -1;
195 best.cAuxBuffers = -1;
196
197 for (i = 1; i <= count; i++)
198 {
199 if (!wglDescribePixelFormat( hdc, i, sizeof(format), &format )) continue;
200
201 if (ppfd->iPixelType != format.iPixelType)
202 {
203 TRACE( "pixel type mismatch for iPixelFormat=%d\n", i );
204 continue;
205 }
206
207 /* only use bitmap capable formats for bitmap rendering */
208 if ((ppfd->dwFlags & PFD_DRAW_TO_BITMAP) && !(format.dwFlags & PFD_DRAW_TO_BITMAP))
209 {
210 TRACE( "PFD_DRAW_TO_BITMAP mismatch for iPixelFormat=%d\n", i );
211 continue;
212 }
213
214 /* only use window capable formats for window rendering */
215 if ((ppfd->dwFlags & PFD_DRAW_TO_WINDOW) && !(format.dwFlags & PFD_DRAW_TO_WINDOW))
216 {
217 TRACE( "PFD_DRAW_TO_WINDOW mismatch for iPixelFormat=%d\n", i );
218 continue;
219 }
220
221 /* only use opengl capable formats for opengl rendering */
222 if ((ppfd->dwFlags & PFD_SUPPORT_OPENGL) && !(format.dwFlags & PFD_SUPPORT_OPENGL))
223 {
224 TRACE( "PFD_SUPPORT_OPENGL mismatch for iPixelFormat=%d\n", i );
225 continue;
226 }
227
228 /* only use GDI capable formats for GDI rendering */
229 if ((ppfd->dwFlags & PFD_SUPPORT_GDI) && !(format.dwFlags & PFD_SUPPORT_GDI))
230 {
231 TRACE( "PFD_SUPPORT_GDI mismatch for iPixelFormat=%d\n", i );
232 continue;
233 }
234
235 /* The behavior of PDF_STEREO/PFD_STEREO_DONTCARE and PFD_DOUBLEBUFFER / PFD_DOUBLEBUFFER_DONTCARE
236 * is not very clear on MSDN. They specify that ChoosePixelFormat tries to match pixel formats
237 * with the flag (PFD_STEREO / PFD_DOUBLEBUFFERING) set. Otherwise it says that it tries to match
238 * formats without the given flag set.
239 * A test on Windows using a Radeon 9500pro on WinXP (the driver doesn't support Stereo)
240 * has indicated that a format without stereo is returned when stereo is unavailable.
241 * So in case PFD_STEREO is set, formats that support it should have priority above formats
242 * without. In case PFD_STEREO_DONTCARE is set, stereo is ignored.
243 *
244 * To summarize the following is most likely the correct behavior:
245 * stereo not set -> prefer non-stereo formats, but also accept stereo formats
246 * stereo set -> prefer stereo formats, but also accept non-stereo formats
247 * stereo don't care -> it doesn't matter whether we get stereo or not
248 *
249 * In Wine we will treat non-stereo the same way as don't care because it makes
250 * format selection even more complicated and second drivers with Stereo advertise
251 * each format twice anyway.
252 */
253
254 /* Doublebuffer, see the comments above */
255 if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE))
256 {
257 if (((ppfd->dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) &&
258 ((format.dwFlags & PFD_DOUBLEBUFFER) == (ppfd->dwFlags & PFD_DOUBLEBUFFER)))
259 goto found;
260
261 if (bestDBuffer != -1 && (format.dwFlags & PFD_DOUBLEBUFFER) != bestDBuffer) continue;
262 }
263
264 /* Stereo, see the comments above. */
265 if (!(ppfd->dwFlags & PFD_STEREO_DONTCARE))
266 {
267 if (((ppfd->dwFlags & PFD_STEREO) != bestStereo) &&
268 ((format.dwFlags & PFD_STEREO) == (ppfd->dwFlags & PFD_STEREO)))
269 goto found;
270
271 if (bestStereo != -1 && (format.dwFlags & PFD_STEREO) != bestStereo) continue;
272 }
273
274 /* Below we will do a number of checks to select the 'best' pixelformat.
275 * We assume the precedence cColorBits > cAlphaBits > cDepthBits > cStencilBits -> cAuxBuffers.
276 * The code works by trying to match the most important options as close as possible.
277 * When a reasonable format is found, we will try to match more options.
278 * It appears (see the opengl32 test) that Windows opengl drivers ignore options
279 * like cColorBits, cAlphaBits and friends if they are set to 0, so they are considered
280 * as DONTCARE. At least Serious Sam TSE relies on this behavior. */
281
282 if (ppfd->cColorBits)
283 {
284 if (((ppfd->cColorBits > best.cColorBits) && (format.cColorBits > best.cColorBits)) ||
285 ((format.cColorBits >= ppfd->cColorBits) && (format.cColorBits < best.cColorBits)))
286 goto found;
287
288 if (best.cColorBits != format.cColorBits) /* Do further checks if the format is compatible */
289 {
290 TRACE( "color mismatch for iPixelFormat=%d\n", i );
291 continue;
292 }
293 }
294 if (ppfd->cAlphaBits)
295 {
296 if (((ppfd->cAlphaBits > best.cAlphaBits) && (format.cAlphaBits > best.cAlphaBits)) ||
297 ((format.cAlphaBits >= ppfd->cAlphaBits) && (format.cAlphaBits < best.cAlphaBits)))
298 goto found;
299
300 if (best.cAlphaBits != format.cAlphaBits)
301 {
302 TRACE( "alpha mismatch for iPixelFormat=%d\n", i );
303 continue;
304 }
305 }
306 if (ppfd->cDepthBits)
307 {
308 if (((ppfd->cDepthBits > best.cDepthBits) && (format.cDepthBits > best.cDepthBits)) ||
309 ((format.cDepthBits >= ppfd->cDepthBits) && (format.cDepthBits < best.cDepthBits)))
310 goto found;
311
312 if (best.cDepthBits != format.cDepthBits)
313 {
314 TRACE( "depth mismatch for iPixelFormat=%d\n", i );
315 continue;
316 }
317 }
318 if (ppfd->cStencilBits)
319 {
320 if (((ppfd->cStencilBits > best.cStencilBits) && (format.cStencilBits > best.cStencilBits)) ||
321 ((format.cStencilBits >= ppfd->cStencilBits) && (format.cStencilBits < best.cStencilBits)))
322 goto found;
323
324 if (best.cStencilBits != format.cStencilBits)
325 {
326 TRACE( "stencil mismatch for iPixelFormat=%d\n", i );
327 continue;
328 }
329 }
330 if (ppfd->cAuxBuffers)
331 {
332 if (((ppfd->cAuxBuffers > best.cAuxBuffers) && (format.cAuxBuffers > best.cAuxBuffers)) ||
333 ((format.cAuxBuffers >= ppfd->cAuxBuffers) && (format.cAuxBuffers < best.cAuxBuffers)))
334 goto found;
335
336 if (best.cAuxBuffers != format.cAuxBuffers)
337 {
338 TRACE( "aux mismatch for iPixelFormat=%d\n", i );
339 continue;
340 }
341 }
342 continue;
343
344 found:
345 /* Prefer HW accelerated formats */
346 if ((format.dwFlags & PFD_GENERIC_FORMAT) && !(best.dwFlags & PFD_GENERIC_FORMAT))
347 continue;
348 best_format = i;
349 best = format;
350 bestDBuffer = format.dwFlags & PFD_DOUBLEBUFFER;
351 bestStereo = format.dwFlags & PFD_STEREO;
352 }
353
354 TRACE( "returning %u\n", best_format );
355 return best_format;
356}
357
359{
360 struct wgl_context* ctx_src = get_context(hglrcSrc);
361 struct wgl_context* ctx_dst = get_context(hglrcDst);
362
363 if(!ctx_src || !ctx_dst)
364 {
366 return FALSE;
367 }
368
369 /* Check this is the same pixel format */
370 if((ctx_dst->icd_data != ctx_src->icd_data) ||
371 (ctx_dst->pixelformat != ctx_src->pixelformat))
372 {
374 return FALSE;
375 }
376
377 if(ctx_src->icd_data)
378 return ctx_src->icd_data->DrvCopyContext(ctx_src->dhglrc, ctx_dst->dhglrc, mask);
379
380 return sw_CopyContext(ctx_src->dhglrc, ctx_dst->dhglrc, mask);
381}
382
384{
385 struct wgl_dc_data* dc_data = get_dc_data(hdc);
386 struct wgl_context* context;
387 DHGLRC dhglrc;
388
389 TRACE("Creating context for %p.\n", hdc);
390
391 if(!dc_data)
392 {
393 WARN("Not a DC handle!\n");
395 return NULL;
396 }
397
398 if(!dc_data->pixelformat)
399 {
400 WARN("Pixel format not set!\n");
402 return NULL;
403 }
404
405 if(!dc_data->icd_data)
406 {
407 TRACE("Calling SW implementation.\n");
408 dhglrc = sw_CreateContext(dc_data);
409 TRACE("done\n");
410 }
411 else
412 {
413 TRACE("Calling ICD.\n");
414 dhglrc = dc_data->icd_data->DrvCreateContext(hdc);
415 }
416
417 if(!dhglrc)
418 {
419 WARN("Failed!\n");
421 return NULL;
422 }
423
424 context = HeapAlloc(GetProcessHeap(), 0, sizeof(*context));
425 if(!context)
426 {
427 WARN("Failed to allocate a context!\n");
428 if(!dc_data->icd_data)
430 else
431 dc_data->icd_data->DrvDeleteContext(dhglrc);
433 return NULL;
434 }
435 /* Copy info from the DC data */
436 context->dhglrc = dhglrc;
437 context->icd_data = dc_data->icd_data;
438 context->pixelformat = dc_data->pixelformat;
439 context->thread_id = 0;
440 context->magic = 'GLRC';
441
442 /* Insert into the list */
444
445 TRACE("Success!\n");
446 return (HGLRC)context;
447}
448
450{
451 struct wgl_dc_data* dc_data = get_dc_data(hdc);
452 struct wgl_context* context;
453 DHGLRC dhglrc;
454
455 if(!dc_data)
456 {
458 return NULL;
459 }
460
461 if(!dc_data->pixelformat)
462 {
463 release_dc_data(dc_data);
465 return NULL;
466 }
467
468 if(!dc_data->icd_data)
469 {
470 if(iLayerPlane != 0)
471 {
472 /* Not supported in SW implementation */
473 release_dc_data(dc_data);
475 return NULL;
476 }
477 dhglrc = sw_CreateContext(dc_data);
478 }
479 else
480 {
481 dhglrc = dc_data->icd_data->DrvCreateLayerContext(hdc, iLayerPlane);
482 }
483
484 if(!dhglrc)
485 {
486 release_dc_data(dc_data);
488 return NULL;
489 }
490
491 context = HeapAlloc(GetProcessHeap(), 0, sizeof(*context));
492 if(!context)
493 {
494 if(!dc_data->icd_data)
496 else
497 dc_data->icd_data->DrvDeleteContext(dhglrc);
498 release_dc_data(dc_data);
500 return NULL;
501 }
502 /* Copy info from the DC data */
503 context->dhglrc = dhglrc;
504 context->icd_data = dc_data->icd_data;
505 context->pixelformat = dc_data->pixelformat;
506 context->thread_id = 0;
507 context->magic = 'GLRC';
508
509 /* Insert into the list */
511
512 release_dc_data(dc_data);
513 return (HGLRC)context;
514}
515
517{
520
521 if(!context)
522 {
524 return FALSE;
525 }
526
527 /* Own this context before touching it */
528 if(InterlockedCompareExchange(&context->thread_id, thread_id, 0) != 0)
529 {
530 /* We can't delete a context current to another thread */
531 if(context->thread_id != thread_id)
532 {
534 return FALSE;
535 }
536
537 /* This is in our thread. Release and try again */
539 return FALSE;
540 return wglDeleteContext(hglrc);
541 }
542
543 if(context->icd_data)
544 context->icd_data->DrvDeleteContext(context->dhglrc);
545 else
546 sw_DeleteContext(context->dhglrc);
547
548 context->magic = 0;
549 RemoveEntryList(&context->ListEntry);
551
552 return TRUE;
553}
554
556 int iPixelFormat,
557 int iLayerPlane,
558 UINT nBytes,
560{
561 struct wgl_dc_data* dc_data = get_dc_data(hdc);
562
563 if(!dc_data)
564 {
566 return FALSE;
567 }
568
569 if(iPixelFormat <= dc_data->nb_icd_formats)
570 return dc_data->icd_data->DrvDescribeLayerPlane(hdc, iPixelFormat, iLayerPlane, nBytes, plpd);
571
572 /* SW implementation doesn't support this */
573 return FALSE;
574}
575
577{
578 return IntGetCurrentRC();
579}
580
582{
583 return IntGetCurrentDC();
584}
585
587{
588 /* undocumented... */
589 return NULL;
590}
591
592int WINAPI wglGetLayerPaletteEntries(HDC hdc, int iLayerPlane, int iStart, int cEntries, COLORREF* pcr )
593{
594 struct wgl_dc_data* dc_data = get_dc_data(hdc);
595
596 if(!dc_data)
597 {
599 return 0;
600 }
601
602 if(!dc_data->pixelformat)
603 {
605 return 0;
606 }
607
608 if(dc_data->icd_data)
609 return dc_data->icd_data->DrvGetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
610
611 /* SW implementation doesn't support this */
612 return 0;
613}
614
616{
617 INT ret;
618 struct wgl_dc_data* dc_data = get_dc_data(hdc);
619
620 if(!dc_data)
621 {
623 return 0;
624 }
625
626 ret = dc_data->pixelformat;
627 release_dc_data(dc_data);
628 return ret;
629}
630
632{
634 if(!context)
635 return NULL;
636
637 /* This shall fail for opengl 1.1 functions */
638#define USE_GL_FUNC(func, w, x, y, z) if(!strcmp(name, "gl" #func)) return NULL;
639#include "glfuncs.h"
640
641 /* Forward */
642 if(context->icd_data)
643 return context->icd_data->DrvGetProcAddress(name);
644 return sw_GetProcAddress(name);
645}
646
648{
649 IntSetCurrentDispatchTable(&table->glDispatchTable);
650}
651
653{
654 struct wgl_context* ctx = get_context(hglrc);
655 struct wgl_context* old_ctx = get_context(IntGetCurrentRC());
656 const GLCLTPROCTABLE* apiTable;
658
659 if(ctx)
660 {
661 struct wgl_dc_data* dc_data = get_dc_data(hdc);
662 if(!dc_data)
663 {
664 ERR("wglMakeCurrent was passed an invalid DC handle.\n");
666 return FALSE;
667 }
668
669 /* Check compatibility */
670 if((ctx->icd_data != dc_data->icd_data) || (ctx->pixelformat != dc_data->pixelformat))
671 {
672 /* That's bad, man */
673 ERR("HGLRC %p and HDC %p are not compatible.\n", hglrc, hdc);
674 release_dc_data(dc_data);
676 return FALSE;
677 }
678
679 /* Set the thread ID */
680 if(InterlockedCompareExchange(&ctx->thread_id, thread_id, 0) != 0)
681 {
682 /* Already current for a thread. Maybe it's us ? */
683 release_dc_data(dc_data);
684 if(ctx->thread_id != thread_id)
686 return (ctx->thread_id == thread_id);
687 }
688
689 if(old_ctx)
690 {
691 /* Unset it */
692 if(old_ctx->icd_data)
693 old_ctx->icd_data->DrvReleaseContext(old_ctx->dhglrc);
694 else
695 sw_ReleaseContext(old_ctx->dhglrc);
696 InterlockedExchange(&old_ctx->thread_id, 0);
697 }
698
699 /* Call the ICD or SW implementation */
700 if(ctx->icd_data)
701 {
702 apiTable = ctx->icd_data->DrvSetContext(hdc, ctx->dhglrc, set_api_table);
703 if(!apiTable)
704 {
705 ERR("DrvSetContext failed!\n");
706 /* revert */
707 InterlockedExchange(&ctx->thread_id, 0);
710 return FALSE;
711 }
712 set_api_table(apiTable);
713 /* Make it current */
714 IntMakeCurrent(hglrc, hdc, dc_data);
715 }
716 else
717 {
718 /* We must set current before, SW implementation relies on it */
719 IntMakeCurrent(hglrc, hdc, dc_data);
720 if(!sw_SetContext(dc_data, ctx->dhglrc))
721 {
722 ERR("sw_SetContext failed!\n");
723 /* revert */
725 InterlockedExchange(&ctx->thread_id, 0);
727 return FALSE;
728 }
729 }
730 }
731 else if(old_ctx)
732 {
733 if(old_ctx->icd_data)
734 old_ctx->icd_data->DrvReleaseContext(old_ctx->dhglrc);
735 else
736 sw_ReleaseContext(old_ctx->dhglrc);
737 InterlockedExchange(&old_ctx->thread_id, 0);
738 /* Unset it */
741 /* Test conformance (extreme cases) */
742 return hglrc == NULL;
743 }
744 else
745 {
746 /* Winetest conformance */
747 DWORD objType = GetObjectType(hdc);
748 if (objType != OBJ_DC && objType != OBJ_MEMDC)
749 {
750 if (hdc)
751 {
752 ERR("hdc (%p) is not a DC handle (ObjectType: %d)!\n", hdc, objType);
753 }
755 return FALSE;
756 }
757 }
758
759 return TRUE;
760}
761
763 int iLayerPlane,
764 BOOL bRealize)
765{
766 struct wgl_dc_data* dc_data = get_dc_data(hdc);
767
768 if(!dc_data)
769 {
771 return FALSE;
772 }
773
774 if(!dc_data->pixelformat)
775 {
777 return FALSE;
778 }
779
780 if(dc_data->icd_data)
781 return dc_data->icd_data->DrvRealizeLayerPalette(hdc, iLayerPlane, bRealize);
782
783 /* SW implementation doesn't support this */
784 return FALSE;
785}
786
788 int iLayerPlane,
789 int iStart,
790 int cEntries,
791 const COLORREF *pcr)
792{
793 struct wgl_dc_data* dc_data = get_dc_data(hdc);
794
795 if(!dc_data)
796 {
798 return 0;
799 }
800
801 if(!dc_data->pixelformat)
802 {
804 return 0;
805 }
806
807 if(dc_data->icd_data)
808 return dc_data->icd_data->DrvSetLayerPaletteEntries(hdc, iLayerPlane, iStart, cEntries, pcr);
809
810 /* SW implementation doesn't support this */
811 return 0;
812}
813
815{
816 struct wgl_dc_data* dc_data = get_dc_data(hdc);
817 INT sw_format;
818 BOOL ret;
819
820 TRACE("HDC %p, format %i.\n", hdc, format);
821
822 if(!dc_data)
823 {
824 WARN("Not a valid DC!.\n");
826 return FALSE;
827 }
828
829 if(!format)
830 {
831 WARN("format == 0!\n");
833 return FALSE;
834 }
835
836 if(dc_data->pixelformat)
837 {
838 TRACE("DC format already set, %i.\n", dc_data->pixelformat);
839 return (format == dc_data->pixelformat);
840 }
841
842 if(format <= dc_data->nb_icd_formats)
843 {
844 TRACE("Calling ICD.\n");
845 ret = dc_data->icd_data->DrvSetPixelFormat(hdc, format);
846 if(ret)
847 {
848 TRACE("Success!\n");
849 dc_data->pixelformat = format;
850 }
851 return ret;
852 }
853
854 sw_format = format - dc_data->nb_icd_formats;
855 if(sw_format <= dc_data->nb_sw_formats)
856 {
857 TRACE("Calling SW implementation.\n");
858 ret = sw_SetPixelFormat(hdc, dc_data, sw_format);
859 if(ret)
860 {
861 TRACE("Success!\n");
862 /* This is now officially a software-only HDC */
863 dc_data->icd_data = NULL;
864 dc_data->pixelformat = format;
865 }
866 return ret;
867 }
868
869 TRACE("Invalid pixel format!\n");
871 return FALSE;
872}
873
875{
876 struct wgl_context* ctx_src = get_context(hglrcSrc);
877 struct wgl_context* ctx_dst = get_context(hglrcDst);
878
879 if(!ctx_src || !ctx_dst)
880 {
882 return FALSE;
883 }
884
885 /* Check this is the same pixel format */
886 if((ctx_dst->icd_data != ctx_src->icd_data) ||
887 (ctx_dst->pixelformat != ctx_src->pixelformat))
888 {
890 return FALSE;
891 }
892
893 if(ctx_src->icd_data)
894 return ctx_src->icd_data->DrvShareLists(ctx_src->dhglrc, ctx_dst->dhglrc);
895
896 return sw_ShareLists(ctx_src->dhglrc, ctx_dst->dhglrc);
897}
898
900{
901 struct wgl_dc_data* dc_data = get_dc_data(hdc);
902
903 if(!dc_data)
904 {
906 return FALSE;
907 }
908
909 if(!dc_data->pixelformat)
910 {
912 return FALSE;
913 }
914
915 if(dc_data->icd_data)
916 return dc_data->icd_data->DrvSwapBuffers(hdc);
917
918 return sw_SwapBuffers(hdc, dc_data);
919}
920
922{
923 return FALSE;
924}
925
927{
928 return 0;
929}
930
931/* Clean up on DLL unload */
932void
934{
935 struct wgl_context* context;
937
938 while (Entry != &ContextListHead)
939 {
942 Entry = Entry->Flink;
943 }
944}
static POBJECT_TYPE GetObjectType(IN PCWSTR TypeName)
Definition: ObTypes.c:15
#define PROC(name)
Definition: WinHttpOpen.c:37
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:240
#define InterlockedExchange
Definition: armddk.h:54
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_BUSY
Definition: dderror.h:12
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define TRACE_(x)
Definition: compat.h:76
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
return ret
Definition: mutex.c:146
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLenum GLint GLuint mask
Definition: glext.h:6028
GLbitfield flags
Definition: glext.h:7161
GLuint id
Definition: glext.h:5910
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
struct ICD_Data * IntGetIcdData(HDC hdc)
Definition: icdload.c:62
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define InterlockedCompareExchange
Definition: interlocked.h:119
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:88
static DWORD thread_id
Definition: protocol.c:159
unsigned int UINT
Definition: ndis.h:50
#define OBJ_DC
Definition: objidl.idl:1016
#define OBJ_MEMDC
Definition: objidl.idl:1023
#define WGL_DC_OBJ_DC
Definition: opengl32.h:46
FORCEINLINE void IntSetCurrentDispatchTable(const GLDISPATCHTABLE *table)
Definition: opengl32.h:86
BOOL sw_CopyContext(DHGLRC dhglrcSrc, DHGLRC dhglrcDst, UINT mask)
Definition: swimpl.c:498
BOOL sw_ShareLists(DHGLRC dhglrcSrc, DHGLRC dhglrcDst)
Definition: swimpl.c:504
BOOL sw_DeleteContext(DHGLRC dhglrc)
Definition: swimpl.c:448
DHGLRC sw_CreateContext(struct wgl_dc_data *)
Definition: swimpl.c:422
BOOL sw_SetContext(struct wgl_dc_data *dc_data, DHGLRC dhglrc)
Definition: swimpl.c:1390
FORCEINLINE HGLRC IntGetCurrentRC(void)
Definition: opengl32.h:104
BOOL sw_SetPixelFormat(HDC hdc, struct wgl_dc_data *, INT format)
Definition: swimpl.c:359
INT sw_DescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR *descr)
Definition: swimpl.c:315
FORCEINLINE void IntMakeCurrent(HGLRC hglrc, HDC hdc, struct wgl_dc_data *dc_data)
Definition: opengl32.h:93
PROC sw_GetProcAddress(LPCSTR name)
Definition: swimpl.c:478
void sw_ReleaseContext(DHGLRC hglrc)
Definition: swimpl.c:1477
BOOL sw_SwapBuffers(HDC hdc, struct wgl_dc_data *dc_data)
Definition: swimpl.c:1492
FORCEINLINE HDC IntGetCurrentDC(void)
Definition: opengl32.h:111
static HGLRC(WINAPI *pwglCreateContextAttribsARB)(HDC hDC
static HDC HGLRC hglrc
Definition: opengl.c:36
#define CONST
Definition: pedump.c:81
long LONG
Definition: pedump.c:60
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
const char * descr
Definition: boot.c:45
#define TRACE(s)
Definition: solgame.cpp:4
base of all file and directory entries
Definition: entries.h:83
Definition: icd.h:366
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: http.c:7252
Definition: format.c:58
Definition: name.c:39
DHGLRC dhglrc
Definition: opengl32.h:40
struct ICD_Data * icd_data
Definition: opengl32.h:41
INT pixelformat
Definition: opengl32.h:42
volatile LONG thread_id
Definition: opengl32.h:43
LIST_ENTRY ListEntry
Definition: opengl32.h:38
INT nb_sw_formats
Definition: opengl32.h:66
INT pixelformat
Definition: opengl32.h:59
struct ICD_Data * icd_data
Definition: opengl32.h:62
INT nb_icd_formats
Definition: opengl32.h:63
int32_t INT
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
void release_dc_data(struct wgl_dc_data *dc_data)
Definition: wgl.c:97
LIST_ENTRY ContextListHead
Definition: wgl.c:17
BOOL WINAPI wglRealizeLayerPalette(HDC hdc, int iLayerPlane, BOOL bRealize)
Definition: wgl.c:762
static struct wgl_dc_data * get_dc_data(HDC hdc)
Definition: wgl.c:92
static struct wgl_dc_data * get_dc_data_ex(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR *descr)
Definition: wgl.c:22
void APIENTRY set_api_table(const GLCLTPROCTABLE *table)
Definition: wgl.c:647
INT WINAPI wglChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR *ppfd)
Definition: wgl.c:174
BOOL WINAPI wglDeleteContext(HGLRC hglrc)
Definition: wgl.c:516
static struct wgl_dc_data * dc_data_list
Definition: wgl.c:15
BOOL WINAPI wglSetPixelFormat(HDC hdc, INT format, const PIXELFORMATDESCRIPTOR *descr)
Definition: wgl.c:814
HDC WINAPI wglGetCurrentDC(void)
Definition: wgl.c:581
PROC WINAPI wglGetProcAddress(LPCSTR name)
Definition: wgl.c:631
static CRITICAL_SECTION dc_data_cs
Definition: wgl.c:14
INT WINAPI wglGetPixelFormat(HDC hdc)
Definition: wgl.c:615
struct wgl_context * get_context(HGLRC hglrc)
Definition: wgl.c:102
HGLRC WINAPI wglGetCurrentContext(void)
Definition: wgl.c:576
INT WINAPI wglDescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR *descr)
Definition: wgl.c:123
BOOL WINAPI wglSwapLayerBuffers(HDC hdc, UINT fuPlanes)
Definition: wgl.c:921
HGLRC WINAPI wglCreateContext(HDC hdc)
Definition: wgl.c:383
PROC WINAPI wglGetDefaultProcAddress(LPCSTR lpszProc)
Definition: wgl.c:586
BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc)
Definition: wgl.c:652
BOOL WINAPI wglCopyContext(HGLRC hglrcSrc, HGLRC hglrcDst, UINT mask)
Definition: wgl.c:358
BOOL WINAPI wglDescribeLayerPlane(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nBytes, LPLAYERPLANEDESCRIPTOR plpd)
Definition: wgl.c:555
DWORD WINAPI wglSwapMultipleBuffers(UINT count, CONST WGLSWAP *toSwap)
Definition: wgl.c:926
void IntDeleteAllContexts(void)
Definition: wgl.c:933
BOOL WINAPI DECLSPEC_HOTPATCH wglSwapBuffers(HDC hdc)
Definition: wgl.c:899
BOOL WINAPI wglShareLists(HGLRC hglrcSrc, HGLRC hglrcDst)
Definition: wgl.c:874
int WINAPI wglSetLayerPaletteEntries(HDC hdc, int iLayerPlane, int iStart, int cEntries, const COLORREF *pcr)
Definition: wgl.c:787
HGLRC WINAPI wglCreateLayerContext(HDC hdc, int iLayerPlane)
Definition: wgl.c:449
int WINAPI wglGetLayerPaletteEntries(HDC hdc, int iLayerPlane, int iStart, int cEntries, COLORREF *pcr)
Definition: wgl.c:592
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_In_ LONG iPixelFormat
Definition: winddi.h:3488
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
_In_ LONG _In_ ULONG _Out_opt_ PIXELFORMATDESCRIPTOR * ppfd
Definition: winddi.h:3490
DWORD COLORREF
Definition: windef.h:100
#define WINAPI
Definition: msvc.h:6
#define ERROR_INVALID_PIXEL_FORMAT
Definition: winerror.h:1543
#define PFD_SUPPORT_OPENGL
Definition: wingdi.h:306
#define PFD_STEREO_DONTCARE
Definition: wingdi.h:317
#define PFD_SUPPORT_GDI
Definition: wingdi.h:305
#define PFD_STEREO
Definition: wingdi.h:302
#define PFD_DRAW_TO_BITMAP
Definition: wingdi.h:304
#define PFD_GENERIC_FORMAT
Definition: wingdi.h:307
_In_ UINT _In_ UINT cEntries
Definition: wingdi.h:4067
#define PFD_DOUBLEBUFFER_DONTCARE
Definition: wingdi.h:316
#define PFD_DRAW_TO_WINDOW
Definition: wingdi.h:303
_In_ UINT iStart
Definition: wingdi.h:4066
#define PFD_DOUBLEBUFFER
Definition: wingdi.h:301
HWND WINAPI WindowFromDC(_In_ HDC hDC)
const char * LPCSTR
Definition: xmlstorage.h:183