File size: 948 Bytes
987b273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
#include <stdio.h>
/* 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;
}