[cairo-commit] [cairo-www] src/threaded_animation_with_cairo.mdwn
Carl Worth
cworth at freedesktop.org
Thu Jan 17 20:20:16 PST 2008
src/threaded_animation_with_cairo.mdwn | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
New commits:
commit 60b8959533bea6e80b336c486ceb9a96d5e44477
Author: Carl Worth <cworth at freedesktop.org>
Date: Thu Jan 17 20:20:15 2008 -0800
web commit by Albert
diff --git a/src/threaded_animation_with_cairo.mdwn b/src/threaded_animation_with_cairo.mdwn
index 61cd1be..53188b1 100644
--- a/src/threaded_animation_with_cairo.mdwn
+++ b/src/threaded_animation_with_cairo.mdwn
@@ -23,7 +23,7 @@ A minimal thread-aware gtk program might look like:
//we need to initialize all these functions so that gtk knows
//to be thread-aware
- g_thread_init(NULL);
+ if (!g_thread_supported ()){ g_thread_init(NULL); }
gdk_threads_init();
gdk_threads_enter();
@@ -55,7 +55,7 @@ We will use a `g_timeout_add` to call our `do_draw()` routine at 30 fps. Eventu
//we need to initialize all these functions so that gtk knows
//to be thread-aware
- g_thread_init(NULL);
+ if (!g_thread_supported ()){ g_thread_init(NULL); }
gdk_threads_init();
gdk_threads_enter();
@@ -86,6 +86,7 @@ We will use a `g_timeout_add` to call our `do_draw()` routine at 30 fps. Eventu
return 0;
}
+ * `g_thread_init(NULL)` starts a bunch of threading preparation. This functions should only be called once in any given program. Consequentially, it is called as `if (!g_thread_supported ()){ g_thread_init(NULL); }` This is not strictly necessary (because we are fully aware that `g_threads_init()` is called nowhere else in our code; however, when integrating with other projects, it is a good safety precaution.
* `g_signal_connect(G_OBJECT(window), "configure_event", G_CALLBACK(on_window_configure_event), NULL)` adds a callback to the configure event so that we can detect and handle resizes.
* `gtk_widget_set_app_paintable(window, TRUE)` and `gtk_widget_set_double_buffered(window, FALSE)` tells gtk that we will be doing our own buffering of the window
* `(void)g_timeout_add(33, (GSourceFunc)timer_exe, window)` adds a timer that will be executed by `gtk_main()` 30 times a second (unless `gtk_main()` is too busy with other things). We pass it the name of the function we'd like to call `timer_exe` cast as a `GSourceFunc` and we also pass it a pointer to the object we'd like to draw on, this time
@@ -349,7 +350,7 @@ For your compiling pleasure, the full source in proper order.
//we need to initialize all these functions so that gtk knows
//to be thread-aware
- g_thread_init(NULL);
+ if (!g_thread_supported ()){ g_thread_init(NULL); }
gdk_threads_init();
gdk_threads_enter();
More information about the cairo-commit
mailing list