svga: fix constant indices for texcoord scale factors and texture buffer size
[mesa.git] / src / gallium / state_trackers / wgl / stw_framebuffer.c
index d770adb2a55b2ced6ff2a6db008e8f1493cc6924..321fbb6ea7747b8943ed3cb010d1c8e5ca6ebb4c 100644 (file)
@@ -30,6 +30,7 @@
 #include "pipe/p_screen.h"
 #include "util/u_memory.h"
 #include "hud/hud_context.h"
+#include "os/os_time.h"
 #include "state_tracker/st_api.h"
 
 #include "stw_icd.h"
@@ -47,7 +48,7 @@
  * If a stw_framebuffer is found, lock it and return the pointer.
  * Else, return NULL.
  */
-static inline struct stw_framebuffer *
+static struct stw_framebuffer *
 stw_framebuffer_from_hwnd_locked(HWND hwnd)
 {
    struct stw_framebuffer *fb;
@@ -367,7 +368,7 @@ stw_framebuffer_cleanup(void)
  * Given an hdc, return the corresponding stw_framebuffer.
  * The returned stw_framebuffer will have its mutex locked.
  */
-static inline struct stw_framebuffer *
+static struct stw_framebuffer *
 stw_framebuffer_from_hdc_locked(HDC hdc)
 {
    HWND hwnd;
@@ -580,6 +581,38 @@ stw_framebuffer_present_locked(HDC hdc,
 }
 
 
+/**
+ * This is called just before issuing the buffer swap/present.
+ * We query the current time and determine if we should sleep before
+ * issuing the swap/present.
+ * This is a bit of a hack and is certainly not very accurate but it
+ * basically works.
+ * This is for the WGL_ARB_swap_interval extension.
+ */
+static void
+wait_swap_interval(struct stw_framebuffer *fb)
+{
+   /* Note: all time variables here are in units of microseconds */
+   int64_t cur_time = os_time_get_nano() / 1000;
+
+   if (fb->prev_swap_time != 0) {
+      /* Compute time since previous swap */
+      int64_t delta = cur_time - fb->prev_swap_time;
+      int64_t min_swap_period =
+         1.0e6 / stw_dev->refresh_rate * stw_dev->swap_interval;
+
+      /* if time since last swap is less than wait period, wait */
+      if (delta < min_swap_period) {
+         float fudge = 1.75f;  /* emperical fudge factor */
+         int64_t wait = (min_swap_period - delta) * fudge;
+         os_time_sleep(wait);
+      }
+   }
+
+   fb->prev_swap_time = cur_time;
+}
+
+
 BOOL APIENTRY
 DrvSwapBuffers(HDC hdc)
 {
@@ -615,6 +648,10 @@ DrvSwapBuffers(HDC hdc)
       }
    }
 
+   if (stw_dev->swap_interval != 0) {
+      wait_swap_interval(fb);
+   }
+
    return stw_st_swap_framebuffer_locked(hdc, fb->stfb);
 }