#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
+#include <sys/time.h>
#include <unistd.h>
#include <linux/fb.h>
return false;
}
+ fb_vblank vblank;
+ if(ioctl(dev_fd, FBIOGET_VBLANK, &vblank) == -1) {
+ fprintf(stderr, "FBIOGET_VBLANK error: %s\n", strerror(errno));
+ }
+ else {
+ printf("flags: %x\n", vblank.flags);
+ printf("count: %d\n", vblank.count);
+ printf("beam position: %d, %d\n", vblank.hcount, vblank.vcount);
+ }
+
return true;
}
{
Rect drect = rect;
- if(drect.x < 0) {
- drect.x = 0;
+ if(drect.x < screen_rect.x) {
+ drect.width -= screen_rect.x - drect.x;
+ drect.x = screen_rect.x;
+ }
+
+ if(drect.y < screen_rect.y) {
+ drect.height -= screen_rect.y - drect.y;
+ drect.y = screen_rect.y;
+ }
+
+ if(drect.x + drect.width >= screen_rect.x + screen_rect.width) {
+ drect.width = screen_rect.width - drect.x;
}
- if(drect.y < 0) {
- drect.y = 0;
+ if(drect.y + drect.height >= screen_rect.y + screen_rect.height) {
+ drect.height = screen_rect.height - drect.y;
}
unsigned char *fb = framebuffer + (drect.x + screen_rect.width * drect.y) * 4;
{
}
+void wait_vsync()
+{
+ unsigned long arg = 0;
+
+ timeval tvstart, tvend;
+ gettimeofday(&tvstart, 0);
+
+ if(ioctl(dev_fd, FBIO_WAITFORVSYNC, &arg) == -1) {
+ printf("ioctl error %s\n", strerror(errno));
+ }
+
+ gettimeofday(&tvend, 0);
+ printf("%ld %ld\n", tvend.tv_sec - tvstart.tv_sec, tvend.tv_usec - tvstart.tv_usec);
+}
+
#endif // WINNIE_FBDEV