virgl: encode index buffer offset.
[mesa.git] / src / gallium / targets / libgl-gdi / libgl_gdi.c
index 112904ab5fe88e6a690e31564808d34d9d9216dd..12576db52c26556dd0964658a7ff50b4fbbec36f 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "util/u_debug.h"
 #include "stw_winsys.h"
+#include "stw_device.h"
 #include "gdi/gdi_sw_winsys.h"
 
 #include "softpipe/sp_texture.h"
 #include "llvmpipe/lp_public.h"
 #endif
 
+#ifdef HAVE_SWR
+#include "swr/swr_public.h"
+#endif
 
 static boolean use_llvmpipe = FALSE;
-
+static boolean use_swr = FALSE;
 
 static struct pipe_screen *
 gdi_screen_create(void)
@@ -68,6 +72,8 @@ gdi_screen_create(void)
 
 #ifdef HAVE_LLVMPIPE
    default_driver = "llvmpipe";
+#elif HAVE_SWR
+   default_driver = "swr";
 #else
    default_driver = "softpipe";
 #endif
@@ -77,13 +83,21 @@ gdi_screen_create(void)
 #ifdef HAVE_LLVMPIPE
    if (strcmp(driver, "llvmpipe") == 0) {
       screen = llvmpipe_create_screen( winsys );
+      if (screen)
+         use_llvmpipe = TRUE;
+   }
+#endif
+#ifdef HAVE_SWR
+   if (strcmp(driver, "swr") == 0) {
+      screen = swr_create_screen( winsys );
+      if (screen)
+         use_swr = TRUE;
    }
 #endif
+   (void) driver;
 
    if (screen == NULL) {
       screen = softpipe_create_screen( winsys );
-   } else {
-      use_llvmpipe = TRUE;
    }
 
    if(!screen)
@@ -125,6 +139,13 @@ gdi_present(struct pipe_screen *screen,
    }
 #endif
 
+#ifdef HAVE_SWR
+   if (use_swr) {
+      swr_gdi_swap(screen, res, hDC);
+      return;
+   }
+#endif
+
    winsys = softpipe_screen(screen)->winsys,
    dt = softpipe_resource(res)->dt,
    gdi_sw_display(winsys, dt, hDC);
@@ -141,8 +162,12 @@ static const struct stw_winsys stw_winsys = {
 };
 
 
+EXTERN_C BOOL WINAPI
+DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
+
+
 BOOL WINAPI
-DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
+DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 {
    switch (fdwReason) {
    case DLL_PROCESS_ATTACH:
@@ -159,8 +184,23 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
       break;
 
    case DLL_PROCESS_DETACH:
-      stw_cleanup_thread();
-      stw_cleanup();
+      if (lpvReserved == NULL) {
+         // We're being unloaded from the process.
+         stw_cleanup_thread();
+         stw_cleanup();
+      } else {
+         // Process itself is terminating, and all threads and modules are
+         // being detached.
+         //
+         // The order threads (including llvmpipe rasterizer threads) are
+         // destroyed can not be relied up, so it's not safe to cleanup.
+         //
+         // However global destructors (e.g., LLVM's) will still be called, and
+         // if Microsoft OPENGL32.DLL's DllMain is called after us, it will
+         // still try to invoke DrvDeleteContext to destroys all outstanding,
+         // so set stw_dev to NULL to return immediately if that happens.
+         stw_dev = NULL;
+      }
       break;
    }
    return TRUE;