gdkglcontext-win32-wgl.c: Fix using wglChoosePixelFormatARB()
authorChun-wei Fan <fanchunwei@src.gnome.org>
Wed, 3 May 2023 09:58:54 +0000 (17:58 +0800)
committerChun-wei Fan <fanchunwei@src.gnome.org>
Tue, 9 May 2023 10:15:23 +0000 (18:15 +0800)
commit50ef36d38794aab6361c94cdb3fa780e7fc4d1bc
tree8554e1e1b4b5dd4533564b7cc9cc8e0125b8c9d8
parent347561fa68457796454d2e195f83c5ae42e87235
gdkglcontext-win32-wgl.c: Fix using wglChoosePixelFormatARB()

If we are querying the best supported pixel format for our HDC via
wglChoosePixelFormatARB() (i.e. we have the WGL_ARB_pixel_format extension),
it may return a pixel format that is different from the pixel format that we
used for the dummy context that we have setup, in order to, well, run
wglChoosePixelFormatARB(), which sadly requires a WGL context (HGLRC) to be
current in order to use it, which means the dummy HDC already has a pixel
format that has been set (notice that each HDC is only allowed to have its
pixel format to be set *once*). This is notably the case on Intel display
drivers.

Since we are emulating surfaceless GL contexts, we are using the dummy GL
context (and thus dummy HDC that is derived from the notification HWND used in
GdkWin32Display) for doing that, we would get into trouble if th actual HDC
from the GdkWin32Surface has a different pixel format set.

So, as a result, in order to fix this situation, we do the following:

* Create yet another dummy HWND in order to grab the HDC to query for the
  capabilities the GL drivers support, and to call wglChoosePixelFormatARB() as
  appropriate (or ChoosePixelFormat()) for the final pixel format that we use.
* Ditch the dummy GL context, HDC and HWND after obtaining the pixel format.
* Then set the final pixel format that we obtained onto the HDC that is derived
  from the HWND used in GdkWin32Display for notifications, which will become our
  new dummy HDC.
* Create a new dummy HGLRC for use with the new dummy HDC to emulate surfaceless
  GL support.
gdk/win32/gdkdisplay-win32.c
gdk/win32/gdkdisplay-win32.h
gdk/win32/gdkglcontext-win32-wgl.c