I can't understand the difference output of only a line differ
Hi, I tried gdk_draw_image with a small program, but the behavior is very confusing, please help me find out whats happening. With the sleep(1) the program shows nothing, but without it the window will show, why? Thanks. Bin #include gtk/gtk.h main(int argc, char **argv) { int ret; gtk_init(argc, argv); GtkWidget *win; GtkWidget *drawing; GdkImage *img; GdkGC *gc; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); drawing = gtk_drawing_area_new(); gtk_widget_set_size_request(drawing, 200, 200); gtk_container_add(GTK_CONTAINER(win), drawing); img = gdk_image_new(GDK_IMAGE_FASTEST, gdk_visual_get_system(), 200, 200); memset(img-mem, 1, 200 * 200 * 2); gtk_widget_show_all(win); gc = gdk_gc_new(drawing-window); while (1) { sleep(1); gdk_draw_image(drawing-window, gc, img, 0, 0, 0, 0, 200, 200); } gtk_main(); } ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 17:40 +0800, Binary Chen wrote: while (1) { sleep(1); gdk_draw_image(drawing-window, gc, img, 0, 0, 0, 0, 200, 200); } you are blocking with your own loop before entering inside the gtk+ main loop with the following call: gtk_main(); if you want to wait one second before drawing onto the window, use g_timeout_add() and call gdk_draw_image() inside the callback passed to that function. please, read the documentation about the GLib main loop at: http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html ciao, Emmanuele. -- Emmanuele Bassi, W: http://www.emmanuelebassi.net B: http://log.emmanuelebassi.net ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 10:41 +, Emmanuele Bassi wrote: On Thu, 2007-12-06 at 17:40 +0800, Binary Chen wrote: while (1) { sleep(1); gdk_draw_image(drawing-window, gc, img, 0, 0, 0, 0, 200, 200); } you are blocking with your own loop before entering inside the gtk+ main loop with the following call: gtk_main(); But without the sleep() I will also not reach gtk_main(), but the window shows, why? What I am asking is this. Thanks. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 18:54 +0800, Binary Chen wrote: But without the sleep() I will also not reach gtk_main(), but the window shows, why? What I am asking is this. I'm guessing that it fills the drawing buffer and forces a flush. That is, with the sleep, given enough time, you will see the same result. You just need to be patient. Thanks. -- behdad http://behdad.org/ ...very few phenomena can pull someone out of Deep Hack Mode, with two noted exceptions: being struck by lightning, or worse, your *computer* being struck by lightning. -- Matt Welsh ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 06:01 -0500, Behdad Esfahbod wrote: On Thu, 2007-12-06 at 18:54 +0800, Binary Chen wrote: But without the sleep() I will also not reach gtk_main(), but the window shows, why? What I am asking is this. I'm guessing that it fills the drawing buffer and forces a flush. That is, with the sleep, given enough time, you will see the same result. You just need to be patient. How long? Are you sure? Thanks. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
there's no need to reply to me: I'm subscribe to the list, so reply there. On Thu, 2007-12-06 at 18:54 +0800, Binary Chen wrote: On Thu, 2007-12-06 at 10:41 +, Emmanuele Bassi wrote: On Thu, 2007-12-06 at 17:40 +0800, Binary Chen wrote: while (1) { sleep(1); gdk_draw_image(drawing-window, gc, img, 0, 0, 0, 0, 200, 200); } you are blocking with your own loop before entering inside the gtk+ main loop with the following call: gtk_main(); But without the sleep() I will also not reach gtk_main(), but the window shows, why? What I am asking is this. gdk_draw_image() forces a flush. but that is not the problem: you should never use a while() loop inside a GTK+ application, because you are effectively blocking the real main loop from spinning. remember: GTK+ is not threaded. use a timeout or an idle source to repaint your window with the GdkImage. ciao, Emmanuele. -- Emmanuele Bassi, W: http://www.emmanuelebassi.net B: http://log.emmanuelebassi.net ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 19:08 +0800, Binary Chen wrote: On Thu, 2007-12-06 at 06:01 -0500, Behdad Esfahbod wrote: On Thu, 2007-12-06 at 18:54 +0800, Binary Chen wrote: But without the sleep() I will also not reach gtk_main(), but the window shows, why? What I am asking is this. I'm guessing that it fills the drawing buffer and forces a flush. That is, with the sleep, given enough time, you will see the same result. You just need to be patient. How long? Enough time. Are you sure? I'm guessing. Thanks. -- behdad http://behdad.org/ ...very few phenomena can pull someone out of Deep Hack Mode, with two noted exceptions: being struck by lightning, or worse, your *computer* being struck by lightning. -- Matt Welsh ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 11:33 +, Emmanuele Bassi wrote: there's no need to reply to me: I'm subscribe to the list, so reply there. On Thu, 2007-12-06 at 18:54 +0800, Binary Chen wrote: On Thu, 2007-12-06 at 10:41 +, Emmanuele Bassi wrote: On Thu, 2007-12-06 at 17:40 +0800, Binary Chen wrote: while (1) { sleep(1); gdk_draw_image(drawing-window, gc, img, 0, 0, 0, 0, 200, 200); } you are blocking with your own loop before entering inside the gtk+ main loop with the following call: gtk_main(); But without the sleep() I will also not reach gtk_main(), but the window shows, why? What I am asking is this. gdk_draw_image() forces a flush. but that is not the problem: you should never use a while() loop inside a GTK+ application, because you are effectively blocking the real main loop from spinning. remember: GTK+ is not threaded. Yes, I know GTK+ is not threaded, there is only one thread running, so this make things more complecated, whats loop am I prohibit running? Again I'd like to say in both testing the gtk_main() is not running at all, so whats the difference? Can you point out the exact source of such headache problem? use a timeout or an idle source to repaint your window with the GdkImage. This is just a testing program, not production code, I just want to find out whats happening. Thanks. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 19:40 +0800, Binary Chen wrote: gdk_draw_image() forces a flush. but that is not the problem: you should never use a while() loop inside a GTK+ application, because you are effectively blocking the real main loop from spinning. remember: GTK+ is not threaded. Yes, I know GTK+ is not threaded, there is only one thread running, so this make things more complecated, whats loop am I prohibit running? the main loop that processes and delivers the events and handles the redraws, and that is invoked by gtk_main(). you should read the GTK+ documentation, at this point. Again I'd like to say in both testing the gtk_main() is not running at all, so whats the difference? Can you point out the exact source of such headache problem? the exact source is, in this case, a PEBKAC; the documentation available on how GTK+ works (at this level, at least) is quite abundant; the GTK+ tutorial should shed some more light. use a timeout or an idle source to repaint your window with the GdkImage. This is just a testing program, not production code, I just want to find out whats happening. what's happening is that you are blocking the main loop from ever running, so any result you see is an undefined behaviour. for the third time: use a timeout/idle source instead of the while() loop to hook into the GTK+ main loop. ciao, Emmanuele. -- Emmanuele Bassi, W: http://www.emmanuelebassi.net B: http://log.emmanuelebassi.net ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 06:40 -0500, Behdad Esfahbod wrote: On Thu, 2007-12-06 at 19:08 +0800, Binary Chen wrote: On Thu, 2007-12-06 at 06:01 -0500, Behdad Esfahbod wrote: On Thu, 2007-12-06 at 18:54 +0800, Binary Chen wrote: But without the sleep() I will also not reach gtk_main(), but the window shows, why? What I am asking is this. I'm guessing that it fills the drawing buffer and forces a flush. That is, with the sleep, given enough time, you will see the same result. You just need to be patient. How long? Enough time. Are you sure? I'm guessing. Thanks. To be more helpful, and hopefully you understand it, in the case without the sleep, your loop is running over and over, very first. So, what may seem to you like immediate rendering of the window may actually not happen before (for example) the 1000th iteration of the loop. Now if you wait for the 1000th iteration of your loop with the sleep, you should get the same result. 1000 being just a guess. -- behdad http://behdad.org/ ...very few phenomena can pull someone out of Deep Hack Mode, with two noted exceptions: being struck by lightning, or worse, your *computer* being struck by lightning. -- Matt Welsh ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 11:53 +, Emmanuele Bassi wrote: On Thu, 2007-12-06 at 19:40 +0800, Binary Chen wrote: gdk_draw_image() forces a flush. but that is not the problem: you should never use a while() loop inside a GTK+ application, because you are effectively blocking the real main loop from spinning. remember: GTK+ is not threaded. Yes, I know GTK+ is not threaded, there is only one thread running, so this make things more complecated, whats loop am I prohibit running? the main loop that processes and delivers the events and handles the redraws, and that is invoked by gtk_main(). you should read the GTK+ documentation, at this point. Again I'd like to say in both testing the gtk_main() is not running at all, so whats the difference? Can you point out the exact source of such headache problem? the exact source is, in this case, a PEBKAC; the documentation available on how GTK+ works (at this level, at least) is quite abundant; the GTK+ tutorial should shed some more light. use a timeout or an idle source to repaint your window with the GdkImage. This is just a testing program, not production code, I just want to find out whats happening. what's happening is that you are blocking the main loop from ever running, so any result you see is an undefined behaviour. for the third time: use a timeout/idle source instead of the while() loop to hook into the GTK+ main loop. You don't know my situation. I am writing a media player which need to copy the decoded bitmap into screen. I am using gdk_draw_image to draw a GdkImage to the drawing area. g_timeout_add is too slow because it need to update the screen 20 times/sec. So I need to use a FAST blit to screen, which is only possible using busy while... but only if the delay is very small using usleep(1), the result is - no things on screen. Image a situation that a thread is doing decoding and put the result in somewhere memory, another thread drawing to GTK+ widget. Bin ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
Binary Chen wrote: You don't know my situation. I am writing a media player which need to copy the decoded bitmap into screen. I am using gdk_draw_image to draw a GdkImage to the drawing area. g_timeout_add is too slow because it need to update the screen 20 times/sec. So I need to use a FAST blit to screen, which is only possible using busy while... but only if the delay is very small using usleep(1), the result is - no things on screen. Image a situation that a thread is doing decoding and put the result in somewhere memory, another thread drawing to GTK+ widget. You don't seem to understand: You can not use a while loop. At all. Ever! It simply won't work! Use something else, but _not_ the while loop! tom ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Binary Chen wrote: On Thu, 2007-12-06 at 11:53 +, Emmanuele Bassi wrote: On Thu, 2007-12-06 at 19:40 +0800, Binary Chen wrote: gdk_draw_image() forces a flush. but that is not the problem: you should never use a while() loop inside a GTK+ application, because you are effectively blocking the real main loop from spinning. remember: GTK+ is not threaded. Yes, I know GTK+ is not threaded, there is only one thread running, so this make things more complecated, whats loop am I prohibit running? the main loop that processes and delivers the events and handles the redraws, and that is invoked by gtk_main(). you should read the GTK+ documentation, at this point. Again I'd like to say in both testing the gtk_main() is not running at all, so whats the difference? Can you point out the exact source of such headache problem? the exact source is, in this case, a PEBKAC; the documentation available on how GTK+ works (at this level, at least) is quite abundant; the GTK+ tutorial should shed some more light. use a timeout or an idle source to repaint your window with the GdkImage. This is just a testing program, not production code, I just want to find out whats happening. what's happening is that you are blocking the main loop from ever running, so any result you see is an undefined behaviour. for the third time: use a timeout/idle source instead of the while() loop to hook into the GTK+ main loop. You don't know my situation. I am writing a media player which need to copy the decoded bitmap into screen. I am using gdk_draw_image to draw a GdkImage to the drawing area. g_timeout_add is too slow because it need to update the screen 20 times/sec. So I need to use a FAST blit to screen, which is only possible using busy while... but only if the delay is very small using usleep(1), the result is - no things on screen. Image a situation that a thread is doing decoding and put the result in somewhere memory, another thread drawing to GTK+ widget. A couple of notes: 1) with a threaded application, you must make sure that *ALL* gtk calls are done *ONLY* from one thread. Any multi-thread calls into gtk will lead to unexplained behaviour, possibly including unexplained crashes. 2) When you write a busy loop, as you have, you are *not* giving the gtk library any chance AT all to update the screen. Updating teh screen essentially happens in the gtk_mail loop (or the idle loop), which gets called when you return from your callback. While you have not given us all your code, between what you have given us, and the above, it sounds like when your thread sleeps()'s, it is giving the gtk_main a chance to run. 3) one ugly hack (and it is just that, an ugly hack), would be do to the following in your while loop: while( gtk_events_pending()) gtk_main_iteration(); This will drain the queued up gtk events (including the display events), and you'll be happy. 4) Having said that, the fact that you have a forever loop and need to do this highly suggests that you have a design error. You REALLY should have a callback that is processing all the queued up images, and then returns. Perhaps this should even be a g_idle_add() callback if there is no convenient way to invoke it via some other callback method. - -G Bin ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list - -- +-+ Please also check the log file at /dev/null for additional information. (from /var/log/Xorg.setup.log) | Greg Hosler [EMAIL PROTECTED]| +-+ -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org iD8DBQFHV/67404fl/0CV/QRAjZmAJ9iYJVSU+xDjPLiW/0qGLpZOlceEwCgmoS5 +JNnCApXBOSEd0H6LoSinMc= =K9nu -END PGP SIGNATURE- ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
again: no need to reply to me directly. On Thu, 2007-12-06 at 20:29 +0800, Binary Chen wrote: what's happening is that you are blocking the main loop from ever running, so any result you see is an undefined behaviour. for the third time: use a timeout/idle source instead of the while() loop to hook into the GTK+ main loop. You don't know my situation. I read your other emails in this thread and I can say I understood fairly well your situation; and yet, you don't seem to understand what I'm saying to you: what are you doing leads to undefined behaviours, so *don't do it*. I am using gdk_draw_image to draw a GdkImage to the drawing area. why are you using a GdkImage in the first place? can't you just use a client-side pixbuf and then blit it to the target widget using gdk_draw_pixbuf() instead? anyway: g_timeout_add is too slow because it need to update the screen 20 times/sec. 20 times per sec is 50 msecs, which is fairly doable for a timeout source; you might want to disable the double buffering and set the widget you're drawing on as paintable, to squeeze it every millisecond. in any case, instead of using a timeout you can use an idle source with g_idle_add_full(), and setting a fairly high priority (but probably lower than GDK_PRIORITY_REDRAW to avoid useless tearing). So I need to use a FAST blit to screen, which is only possible using busy while... there already is a busy loop: it's the GTK+ main loop. you can hook into it, but you cannot avoid calling it because (and this is the central bit) it leads to undefined behaviours like you witnessed. aside from this, I cannot stress enough that it seems to me you don't know GTK+ (let alone GDK) well enough. so my recommendation is for you to spend some time learning and getting acquainted with how GTK+ works first. ciao, Emmanuele. -- Emmanuele Bassi, W: http://www.emmanuelebassi.net B: http://log.emmanuelebassi.net ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
Binary Chen wrote: Hi, I tried gdk_draw_image with a small program, but the behavior is very confusing, please help me find out whats happening. [...] I've read through the thread detailing your GTK troubles. I also know you are trying to write a custom GTK player for a particular multimedia format. I just wanted to throw out the possibility of asking your client whether they have any interest in open sourcing the video codec itself? Take this step and there is a community of fanatical open source multimedia enthusiasts (myself included) who would try to incorporate the codec into FFmpeg (ffmpeg.org), at which point it would be accessible to a huge number of existing media players. Think about it... -- -Mike Melanson ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 13:59 +, Emmanuele Bassi wrote: again: no need to reply to me directly. On Thu, 2007-12-06 at 20:29 +0800, Binary Chen wrote: what's happening is that you are blocking the main loop from ever running, so any result you see is an undefined behaviour. for the third time: use a timeout/idle source instead of the while() loop to hook into the GTK+ main loop. You don't know my situation. I read your other emails in this thread and I can say I understood fairly well your situation; and yet, you don't seem to understand what I'm saying to you: what are you doing leads to undefined behaviours, so *don't do it*. I am using gdk_draw_image to draw a GdkImage to the drawing area. why are you using a GdkImage in the first place? can't you just use a client-side pixbuf and then blit it to the target widget using gdk_draw_pixbuf() instead? anyway: g_timeout_add is too slow because it need to update the screen 20 times/sec. 20 times per sec is 50 msecs, which is fairly doable for a timeout source; you might want to disable the double buffering and set the widget you're drawing on as paintable, to squeeze it every millisecond. in any case, instead of using a timeout you can use an idle source with g_idle_add_full(), and setting a fairly high priority (but probably lower than GDK_PRIORITY_REDRAW to avoid useless tearing). So I need to use a FAST blit to screen, which is only possible using busy while... there already is a busy loop: it's the GTK+ main loop. you can hook into it, but you cannot avoid calling it because (and this is the central bit) it leads to undefined behaviours like you witnessed. aside from this, I cannot stress enough that it seems to me you don't know GTK+ (let alone GDK) well enough. so my recommendation is for you to spend some time learning and getting acquainted with how GTK+ works first. Thanks !! I solved this by using g_timeout_add, sorry for my misunderstanding becoz I vaguely remember g_timeout_add take the parameter in second precision, wrong. And another problem is after I set the priority to -90, the window's close button seems not very responsive, I think the GTK+ is busying doing the timeout function, so what priority you suggest to use in this application? Thanks! Bin ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: I can't understand the difference output of only a line differ
On Thu, 2007-12-06 at 09:40 -0800, Mike Melanson wrote: I just wanted to throw out the possibility of asking your client whether they have any interest in open sourcing the video codec itself? Now would be a good time, if the codec might be useable on the Web -- see for example http://www.webvideosummit.com/ -- especially if it not encumbered by software patents that you [Binary Chen's client] don't control... Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org www.advogato.org ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list