#define _GNU_SOURCE #include #include #include #include #include /* Inside both comparison paths. Timestamp the real SDL return before the candidate can wait. This boundary is a software clock, not optical scanout. */ static _Thread_local int64_t observed; static unsigned count; __attribute__((destructor)) static void finish_count(void) { const char *path=getenv("XR_FIXTURE_COUNT"); if(path) { FILE *f=fopen(path,"w"); if(f) { fprintf(f,"%u\n",count); fclose(f); } } } int64_t xr_last_underlying_us(void) { return observed; } void SDL_RenderPresent(void *renderer) { typedef void (*fn)(void *); static fn next; if (!next) *(void **)(&next)=dlsym(RTLD_NEXT,"SDL_RenderPresent"); if (!next) abort(); next(renderer); ++count; struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC,&ts)) abort(); observed=(int64_t)ts.tv_sec*1000000+ts.tv_nsec/1000; }