2 min read

Animations using Hardware Layers part 2

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.


Originally published: Mar 7, 2009 8:30:42 PM, updated 03/23/20

Brian Edmond
Written by Brian Edmond

Brian co-founded Crank Software in 2007, after leading the graphics development group at QNX Software Systems where he spent the majority of his career working and consulting on UI design, embedded software architecture, and web browser technology. As he watched embedded graphics teams struggle, he developed an acute understanding of the common workflow problem between the designers and engineers. Brian built Crank Storyboard out of this need to help these teams collaborate more effectively, optimize for exceptional performance, and get their award-winning touch screens to market, close to 50% faster. A triathlon and mountain biking enthusiast (explaining the name Crank Software), Brian is a regular Ironman and cyclocross participant, and can often be found biking the trails with his co-founders behind the Crank offices in Kanata, Ottawa. Brian holds an Electrical Engineering degree from the Technical University of Nova Scotia.

Post a Comment

New call-to-action