On Wed, 22 Feb 2006, Barry Scott wrote:

> Mark Vojkovich wrote:
> >   The only mechanism I know of is OpenGL.  Most OpenGL drivers have
> > a mechanism to allow buffer swapping at vblank.
> >
> Using DRM/DRI this works:
>
> void waitForVSync()
> {
> if( card_fd < 0 )
> card_fd = open( "/dev/dri/card0", O_RDONLY );
>
> drm_wait_vblank_t wait_vblank;
> wait_vblank.request.type = _DRM_VBLANK_RELATIVE;
> wait_vblank.request.sequence = 1;
> wait_vblank.request.signal = 0;
>
> int rc;
> do
> {
> wait_vblank.request.type = _DRM_VBLANK_RELATIVE;
> rc = ioctl( card_fd, DRM_IOCTL_WAIT_VBLANK, &wait_vblank );
> }
> while( rc != 0 && errno == EINTR );
> }
>
>
> Barry

   Come to think of it, NVIDIA does, or at least did have device
file that lets you wait for vblank as well.  These types of things
are pretty unportable though.

                Mark.


/*
gcc -o polltest -Wall polltest.c
*/

#include <stdio.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#define FILENAME "/dev/nvidia0"

#define COUNT_FOR (60*4)

int main (void)
{
    struct pollfd pfd;
    struct timeval tv;
    struct timezone tz;
    double t1, t2;
    int i, fd, timeout;

    fd = open(FILENAME, O_RDONLY);

    pfd.fd = fd;
    pfd.events = POLLIN | POLLPRI;
    pfd.revents = 0;

    timeout = 1000;  /* milliseconds */

    gettimeofday(&tv, &tz);
    t1 = tv.tv_usec + (tv.tv_sec * 1000000.0);

    for(i = 0; i < COUNT_FOR; i++) {
       if(poll(&pfd, 1, timeout) <= 0) {
           printf("poll() failed\n");
           break;
       }
usleep(0);
    }

    gettimeofday(&tv, &tz);
    t2 = tv.tv_usec + (tv.tv_sec * 1000000.0);

    close(fd);

    printf("Refresh rate is %f Hz\n",
          (double)COUNT_FOR * 1000000.0 / (t2 - t1));

    return 0;
}

_______________________________________________
Devel mailing list
Devel@XFree86.Org
http://XFree86.Org/mailman/listinfo/devel

Reply via email to