/* This function will be called from a thread and/or the main loop.
* Textures are threadsafe after all. */ staticvoid
ensure_texture_access (GdkTexture *texture)
{ /* Make sure to initialize the pixel to anything but red */
guint32 pixel = 0;
g_test_message ("Checking texture access in thread %p...", g_thread_self()); /* Just to be sure */
g_assert_cmpint (gdk_texture_get_width (texture), ==, 1);
g_assert_cmpint (gdk_texture_get_height (texture), ==, 1);
staticvoid
texture_download_thread (GTask *task,
gpointer texture,
gpointer unused,
GCancellable *cancellable)
{
g_test_message ("Starting thread %p.", g_thread_self()); /* not sure this can happen, but if it does, we
* should clear_current() here. */
g_assert_null (gdk_gl_context_get_current ());
ensure_texture_access (GDK_TEXTURE (texture));
/* Makes sure the GL context is still NULL, because all the
* GL stuff should have happened in the main thread. */
g_assert_null (gdk_gl_context_get_current ());
g_test_message ("Returning from thread %p.", g_thread_self());
/* 3. This is a bit fishy, but we want to make sure that *thetexture'sGLcontextiscurrentinthemainthread. * *Ifwehadaccesstothecontext,we'dmake_current()here.
*/
ensure_texture_access (texture);
g_assert_nonnull (gdk_gl_context_get_current ());
/* 4. Acquire the main loop, so the run_in_thread() doesn't *trytoacquireitifitmanagestooutracethisthread.
*/
g_assert_true (g_main_context_acquire (NULL));
/* 5. Run a thread trying to download the texture */
loop = g_main_loop_new (NULL, TRUE);
task = g_task_new (texture, NULL, texture_download_done, loop);
g_task_set_source_tag (task, texture_threads);
g_task_run_in_thread (task, texture_download_thread);
g_clear_object (&task);
/* 6. Run the main loop waiting for the thread to return */
g_main_loop_run (loop);
/* 7. All good */
gsk_renderer_unrealize (gl_renderer);
g_clear_pointer (&loop, g_main_loop_unref);
g_clear_object (&gl_renderer);
g_main_context_release (NULL);
gdk_gl_context_clear_current ();
}
int
main (int argc, char *argv[])
{
gtk_test_init (&argc, &argv, NULL);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.