When you dynamically create HTML content for a GtkHTML widget which is then reloaded, in some cases (when you use the streaming API to load HTML content and write it in several pieces) you could experience unpleasant flickering. This is because GtkHTML was designed for progressive loads and tries to redraw its content progressively and thus repeatedly.
There are two ways to reduce or completely avoid GtkHTML's flickering.
The first way is to set GtkHTML to blocking mode, where first (re)draw will happen after all streams are fully loaded. This means that GtkHTML will wait until all of the content and inlined images are loaded. Also note that blocking mode helps in cases where the IMG HTML tag does not have WIDTH and HEIGHT attributes specified.
To switch GtkHTML to blocking mode use
void gtk_html_set_blocking (GtkHTML *html, gboolean block); |
The Second method is to preload images ahead. This is extremely useful in cases where you are reloading HTML content many times and repeatedly use the same images. To preload images, use
void gtk_html_image_preload (GtkHTML *html,
const gchar *url);
|
Once you don't need a preloaded image and want resources to be freed, use
void gtk_html_image_unref (GtkHTML *html,
const gchar *url);
|
Image preloading avoids image reloading and redrawing which saves your CPU cycles and also reduces redrawing to a minimum.
If we return to the previous example, reducing flicker and unneeded image reloading and redrawing is achieved by inserting the following code before the load_content call
gtk_html_image_preload (GTK_HTML (html), "file:smiley.png"); gtk_html_set_blocking (GTK_HTML (html), TRUE); |
| <<< Previous | Home | Next >>> |
| Dynamic content | Current state and future |