00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #include <fcntl.h>
00025 #include <unistd.h>
00026 #include <sys/ioctl.h>
00027
00028 #include "driver.h"
00029 #include "scblog.h"
00030
00031 #define FBIO_IOCTL_BASE 'v'
00032 #define FBIO_DRAWPIXELS _IOW(FBIO_IOCTL_BASE, 3, DrvPointsBuf)
00033
00034 int fbdev = 0;
00035
00036 void scb_driver_init()
00037 {
00038 if (fbdev)
00039 {
00040 SCB_ERROR("/dev/fb0 already open!");
00041 return;
00042 }
00043
00044 fbdev = open("/dev/fb0", O_RDWR);
00045 if (-1 == fbdev)
00046 {
00047 SCB_ERROR("Could not open /dev/fb0!");
00048 return;
00049 }
00050 }
00051
00052 void scb_driver_close()
00053 {
00054
00055 close(fbdev);
00056 }
00057
00058 void scb_driver_draw(DrvPointsBufPtr ptr)
00059 {
00060 if (ptr)
00061 {
00062 if (0 != ioctl (fbdev, FBIO_DRAWPIXELS, ptr))
00063 {
00064 SCB_ERROR("ioctl request error!");
00065 }
00066 }
00067 }
00068
00069
00070
00071 FastDrawContext s_fast_draw_ctx;
00072 void scb_fast_draw_reset_context()
00073 {
00074 s_fast_draw_ctx.points.count = 0;
00075 gettimeofday(&s_fast_draw_ctx.t1, NULL);
00076 s_fast_draw_ctx.t2.tv_sec = s_fast_draw_ctx.t1.tv_sec;
00077 s_fast_draw_ctx.t2.tv_usec = s_fast_draw_ctx.t1.tv_usec;
00078 }
00079
00080
00081 gboolean scb_fast_draw_now()
00082 {
00083
00084 if (s_fast_draw_ctx.points.count > SCB_DEF_FAST_DRAW_COUNT)
00085 {
00086
00087 return TRUE;
00088 }
00089
00090
00091 static const long usec = 1000 * 1000;
00092 long elapsed = ( s_fast_draw_ctx.t2.tv_sec - s_fast_draw_ctx.t1.tv_sec ) * usec;
00093 elapsed += s_fast_draw_ctx.t2.tv_usec - s_fast_draw_ctx.t1.tv_usec;
00094
00095 if (elapsed >= SCB_DEF_FAST_DRAW_TIME)
00096 {
00098 return TRUE;
00099 }
00100
00101 return FALSE;
00102 }
00103
00104
00105
00106 void scb_fast_draw_record(const ScbDevPointPtr ptr,
00107 const unsigned char size,
00108 const unsigned char color,
00109 const unsigned char pen_down)
00110 {
00111
00112 if (s_fast_draw_ctx.points.count < SCB_DEF_FAST_DRAW_BUF_LEN && ptr)
00113 {
00114 s_fast_draw_ctx.points.points[s_fast_draw_ctx.points.count].x = ptr->x;
00115 s_fast_draw_ctx.points.points[s_fast_draw_ctx.points.count].y = ptr->y;
00116 s_fast_draw_ctx.points.points[s_fast_draw_ctx.points.count].size = size;
00117 s_fast_draw_ctx.points.points[s_fast_draw_ctx.points.count].color = color;
00118 s_fast_draw_ctx.points.points[s_fast_draw_ctx.points.count].pen_down = pen_down;
00119 ++s_fast_draw_ctx.points.count;
00120 gettimeofday(&s_fast_draw_ctx.t2, NULL);
00121 }
00122 }
00123
00124
00125 void scb_fast_draw()
00126 {
00127 scb_driver_draw(&s_fast_draw_ctx.points);
00128 }
00129
00130
00131 void scb_fast_draw_points(DrvPointsBufPtr ptr)
00132 {
00133 scb_driver_draw(ptr);
00134 }