2 min read

Animations using Hardware Layers part 2

Topics:

In my last layer post I discussed how you can use hardware layers to achieve animation effects using limited CPU.  The only problem with this is that most graphics toolits out there do not give you access to the layers.  Some call it a video overlay and let you use one layer but what if the hardware has more layers.  The Freescale i.MX line has 2 layers that can be used but some chips have up to 8 independent layers.  To my knowledge GTK and QT do not allow you access to multiple layers.  Other user interface applications, such as Adobe Flash and Browser based HMI's render to a single framebuffer and therefore cannot take advantage of all the hardware features.

One system that has embraced the layer concept is the QNX Advanced Graphics framework, or the GF library.  This library was designed from the ground up to match the capabilities of the hardware and provide access to all features.  Being one of the original architects I feel it gives the most powerful API for layer control :).   Using the GF library you can attach to layers and set features such as source and destination viewports, alpha blending and color keying.  For example to load a large image into a surface and pan around it you could do this:

<em>// attach the image surface to the layer </em>
gf_layer_set_surfaces(layer, image_surface, 1);
<em>// set destination viewport to the size of the display</em>
<em>gf_layer_set_dst_viewport(layer, 0, 0, xres, yres);</em>
<em>// show the top left content of the image surface</em>
<em>gf_layer_set_src_viewport(layer, 0, 0, width, height);</em>
<em>gf_layer_update(layer, 0);</em>

Now you can pan the image using the display controller very easily by changing the viewport.

gf_layer_set_src_viewport(layer, x, y, x+width, y+height);
gf_layer_update(layer, 0);

To do this on other systems would require you to blit an area of the source image each time.  Doing this on a time can achieve a smooth animation such as an Ease-in-out.

Brian