Add queue_redraw_plane function
Create a function which queues the next draw, and add a call to it by the final worker thread to finish drawing.
This commit is contained in:
parent
f5be463c05
commit
8ad76abac9
1 changed files with 27 additions and 1 deletions
28
visor.c
28
visor.c
|
@ -69,6 +69,10 @@ void draw_mandelbrot(struct threadInfo *info);
|
|||
void color_from_iteration(int *r, int *g, int *b, double x0, double y0);
|
||||
void color_lookup(int *r, int *g, int *b, double mu);
|
||||
|
||||
// This function is from the main thread, but it needs to be referenced by
|
||||
// worker code
|
||||
gboolean queue_redraw_plane(void *arg);
|
||||
|
||||
void *writer_thread(void *arg)
|
||||
{
|
||||
struct threadInfo *info = arg;
|
||||
|
@ -131,6 +135,7 @@ void draw_mandelbrot(struct threadInfo *info)
|
|||
}
|
||||
if (allWritersComplete) {
|
||||
cairo_surface_mark_dirty(surface);
|
||||
g_main_context_invoke(NULL, queue_redraw_plane, NULL);
|
||||
}
|
||||
pthread_mutex_unlock(&pixmapMutex);
|
||||
}
|
||||
|
@ -285,6 +290,8 @@ void print_usage(FILE *stream)
|
|||
fprintf(stream, "%s", err_msg);
|
||||
}
|
||||
|
||||
GtkDrawingArea *da;
|
||||
|
||||
static void app_activate(GApplication *app)
|
||||
{
|
||||
GtkWidget *win;
|
||||
|
@ -292,7 +299,6 @@ static void app_activate(GApplication *app)
|
|||
GtkWidget *btn2;
|
||||
GtkWidget *bigBox;
|
||||
GtkWidget *vertBox;
|
||||
GtkDrawingArea *da;
|
||||
|
||||
win = gtk_application_window_new(GTK_APPLICATION(app));
|
||||
gtk_window_set_title(GTK_WINDOW(win), "Mandelbrot visualiser");
|
||||
|
@ -318,6 +324,7 @@ static void app_activate(GApplication *app)
|
|||
|
||||
bigBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
|
||||
// global to enable other functions to call for a redraw
|
||||
da = g_object_new(GTK_TYPE_DRAWING_AREA,
|
||||
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
|
||||
NULL);
|
||||
|
@ -336,6 +343,25 @@ static void app_activate(GApplication *app)
|
|||
gtk_window_present(GTK_WINDOW(win));
|
||||
}
|
||||
|
||||
gboolean queue_redraw_plane(void *arg)
|
||||
{
|
||||
(void) arg;
|
||||
bool allWritersHadCompleted = true;
|
||||
for (int32_t i = 0; i < thread_count; i++) {
|
||||
if (!threads[i].complete) {
|
||||
allWritersHadCompleted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allWritersHadCompleted) {
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
gtk_widget_queue_draw(GTK_WIDGET(da));
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
void blit_plane(GtkDrawingArea *da, cairo_t *cr, int width, int height, gpointer data)
|
||||
{
|
||||
(void) da;
|
||||
|
|
Loading…
Add table
Reference in a new issue