X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fstate_trackers%2Fwgl%2Fstw_framebuffer.c;h=321fbb6ea7747b8943ed3cb010d1c8e5ca6ebb4c;hb=83ca6b9d31005a11380f9dbd1b5531294f5c3e92;hp=09b57766dc0b72874d20a7a6f4b58dcdbd7c38a8;hpb=52f297d144de69d494b5573920c33902063d3628;p=mesa.git diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c index 09b57766dc0..321fbb6ea77 100644 --- a/src/gallium/state_trackers/wgl/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c @@ -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" @@ -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); }