drawlines: single-threaded with fswait

This commit is contained in:
K. Lange 2018-10-30 21:20:10 +09:00
parent a8b39ada97
commit ba40bb5cc6

View File

@ -17,11 +17,12 @@
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <sched.h>
#include <math.h>
#include <sys/fswait.h>
#include <toaru/yutani.h>
#include <toaru/graphics.h>
@ -33,19 +34,13 @@ static gfx_context_t * ctx;
static int should_exit = 0;
static int thick = 0;
void * draw_thread(void * garbage) {
(void)garbage;
while (!should_exit) {
static void draw(void) {
if (thick) {
draw_line_aa(ctx, rand() % width, rand() % width, rand() % height, rand() % height, rgb(rand() % 255,rand() % 255,rand() % 255), (float)thick);
} else {
draw_line(ctx, rand() % width, rand() % width, rand() % height, rand() % height, rgb(rand() % 255,rand() % 255,rand() % 255));
}
yutani_flip(yctx, wina);
usleep(16666);
}
pthread_exit(0);
return NULL;
}
static void show_usage(char * argv[]) {
@ -93,12 +88,12 @@ int main (int argc, char ** argv) {
ctx = init_graphics_yutani(wina);
draw_fill(ctx, rgb(0,0,0));
pthread_t thread;
pthread_create(&thread, NULL, draw_thread, NULL);
while (!should_exit) {
int fds[1] = {fileno(yctx->sock)};
int index = fswait2(1,fds,20);
if (index == 0) {
yutani_msg_t * m = yutani_poll(yctx);
if (m) {
while (m) {
switch (m->type) {
case YUTANI_MSG_KEY_EVENT:
{
@ -124,8 +119,11 @@ int main (int argc, char ** argv) {
default:
break;
}
}
free(m);
m = yutani_poll_async(yctx);
}
}
draw();
}
yutani_close(yctx, wina);