Mesa (main): wgl: Add an explicit iPixelFormat for context creation

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Sep 15 20:46:37 UTC 2021


Module: Mesa
Branch: main
Commit: ddedf596250b0de4742322435d45df57ee6981cd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ddedf596250b0de4742322435d45df57ee6981cd

Author: Jesse Natalie <jenatali at microsoft.com>
Date:   Sat Sep  4 08:00:07 2021 -0700

wgl: Add an explicit iPixelFormat for context creation

If it's 0, then it's looked up from the framebuffer for the specified HDC

Reviewed-by: Charmaine Lee <charmainel at vmware.com>
Reviewed By: Bill Kristiansen <billkris at microsoft.com>

Acked-by: Roland Scheidegger <sroland at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12727>

---

 src/gallium/frontends/wgl/stw_context.c     | 46 ++++++++++++++++-------------
 src/gallium/frontends/wgl/stw_context.h     |  3 +-
 src/gallium/frontends/wgl/stw_ext_context.c |  2 +-
 3 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/gallium/frontends/wgl/stw_context.c b/src/gallium/frontends/wgl/stw_context.c
index 2a690208ae7..a7e57c107b7 100644
--- a/src/gallium/frontends/wgl/stw_context.c
+++ b/src/gallium/frontends/wgl/stw_context.c
@@ -127,7 +127,8 @@ DHGLRC APIENTRY
 DrvCreateLayerContext(HDC hdc, INT iLayerPlane)
 {
    struct stw_context *ctx = stw_create_context_attribs(hdc, iLayerPlane, 0, 1, 0, 0,
-                                                        WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
+                                                        WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
+                                                        0);
    if (!ctx)
       return 0;
 
@@ -165,10 +166,9 @@ get_matching_pixel_format(HDC hdc)
 struct stw_context *
 stw_create_context_attribs(HDC hdc, INT iLayerPlane, struct stw_context *shareCtx,
                            int majorVersion, int minorVersion,
-                           int contextFlags, int profileMask)
+                           int contextFlags, int profileMask,
+                           int iPixelFormat)
 {
-   int iPixelFormat;
-   struct stw_framebuffer *fb;
    const struct stw_pixelformat_info *pfi;
    struct st_context_attribs attribs;
    struct stw_context *ctx = NULL;
@@ -180,24 +180,28 @@ stw_create_context_attribs(HDC hdc, INT iLayerPlane, struct stw_context *shareCt
    if (iLayerPlane != 0)
       return 0;
 
-   /*
-    * GDI only knows about displayable pixel formats, so determine the pixel
-    * format from the framebuffer.
-    *
-    * This also allows to use a OpenGL DLL / ICD without installing.
-    */
-   fb = stw_framebuffer_from_hdc( hdc );
-   if (fb) {
-      iPixelFormat = fb->iPixelFormat;
-      stw_framebuffer_unlock(fb);
-   } else {
-      /* Applications should call SetPixelFormat before creating a context,
-       * but not all do, and the opengl32 runtime seems to use a default
-       * pixel format in some cases, so use that.
+   if (!iPixelFormat) {
+      /*
+       * GDI only knows about displayable pixel formats, so determine the pixel
+       * format from the framebuffer.
+       *
+       * This also allows to use a OpenGL DLL / ICD without installing.
        */
-      iPixelFormat = get_matching_pixel_format(hdc);
-      if (!iPixelFormat)
-         return 0;
+      struct stw_framebuffer *fb;
+      fb = stw_framebuffer_from_hdc(hdc);
+      if (fb) {
+         iPixelFormat = fb->iPixelFormat;
+         stw_framebuffer_unlock(fb);
+      }
+      else {
+         /* Applications should call SetPixelFormat before creating a context,
+          * but not all do, and the opengl32 runtime seems to use a default
+          * pixel format in some cases, so use that.
+          */
+         iPixelFormat = get_matching_pixel_format(hdc);
+         if (!iPixelFormat)
+            return 0;
+      }
    }
 
    pfi = stw_pixelformat_get_info( iPixelFormat );
diff --git a/src/gallium/frontends/wgl/stw_context.h b/src/gallium/frontends/wgl/stw_context.h
index 9685fe0c197..d61efe881a4 100644
--- a/src/gallium/frontends/wgl/stw_context.h
+++ b/src/gallium/frontends/wgl/stw_context.h
@@ -52,7 +52,8 @@ struct stw_context
 struct stw_context *stw_create_context_attribs(HDC hdc, INT iLayerPlane,
                                                struct stw_context *shareCtx,
                                                int majorVersion, int minorVersion,
-                                               int contextFlags, int profileMask);
+                                               int contextFlags, int profileMask,
+                                               int iPixelFormat);
 
 DHGLRC stw_create_context_handle(struct stw_context *context, DHGLRC handle);
 
diff --git a/src/gallium/frontends/wgl/stw_ext_context.c b/src/gallium/frontends/wgl/stw_ext_context.c
index 709d691f2c3..a549c8cd2c4 100644
--- a/src/gallium/frontends/wgl/stw_ext_context.c
+++ b/src/gallium/frontends/wgl/stw_ext_context.c
@@ -201,7 +201,7 @@ wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const int *attribList)
 
       struct stw_context *stw_ctx = stw_create_context_attribs(hDC, layerPlane, share_stw,
                                                                majorVersion, minorVersion,
-                                                               contextFlags, profileMask);
+                                                               contextFlags, profileMask, 0);
 
       if (!stw_ctx) {
          wglDeleteContext_func(context);



More information about the mesa-commit mailing list