Tag Archives: Hardware Acceleration

Take two tablets and call me in the morning

Well, it’s been a while. Having spent the last 8 months working on the YouView set top box platform, I’ve been so busy that I wasn’t even sure my site was still up. And now that I’ve dived headlong into the tricky world of embedded systems development, I wanted to starting playing with other platforms out there. The first two that recently caught my eye were Apple iOS (specifically the iPad) and the new Blackberry PlayBook.

I was keen to see what the application development process is like for these two platforms, especially for Flash Developers and how the two Big Tablets, iPad and PlayBook, measurement up as potential target platforms for the crazy ideas in my head that I’d want to build. So, I made the first steps at development for both.

iPad
Now that Adobe is ‘allowed’ to pursue iOS as a target platform for AIR, via its cross-compiler again, I went through the process of signing up as an iOS developer, jumping through the various other hoops and getting my first ‘hello world’ app onto my iPad. The whole process is a lot more complicated than it probably could be, but then, the same could be said of device development at YouView – this is the nature of such platforms, they are emerging technologies and, as such, are moving targets and simply not like the desktop machines we are all used to developing for. I have to say though, I’m impressed with the recent leaps in performance and functionality Adobe has made with AIR 2.6 for iOS – it leaves Packager in the dust.

PlayBook
Perhaps because the tool chain for PlayBook development feels more like developing for YouView, I was more comfortable with developing for the Playbook and managed to crack out a very simple app, getting in App World in a matter of a couple of days.

Now that I’ve stepped well outside the desktop comfort zone, I have been playing for a while with resource constrained device development, hardware acceleration of Flash content and developing an unhealthy obsession for writing clean, memory/rendering performance optimal code. I hope to bring some of this to projects for iOS and Playbook, as well as share what I’ve learned over the last year.

ActionScript performance tips

Here are a few simple tricks that may help the performance of your code/graphics intensive Flash movies. This is not an exhaustive list, by any means, rather some of the more effective performance tweaks to try out on your projects. There are the usual sensible coding tricks, like using local variables for oft-used references within functions, or planning your code loops carefully and breaking out of loops whenever feasible – but you should be doing these already. I’ll be adding to this post as and when I feel necessary, but will generally avoid the more granular tricks, such as bytecode optimisation. Some of those methods are too complex to explain in simple terms here and generally have a low effort-to-benefit ratio anyway:

Use scrollRect in conjunction with cacheAsBitmap. The cacheAsBitmap parameter of a movieclip can improve performance dramatically, but will cause problems if the render area of the movieclip gets too large (e.g. larger than 2880 in width or height), regardless of whether it is cropped by the viewable area of the Flash Player. The solution is to use scrollRect to constrain the rendering area to desired limits, in this example, the stage width/height:

import flash.geom.Rectangle;
scrollRect = new Rectangle(0, 0, Stage.width, Stage.height);
cacheAsBitmap = true;

Create bitmap snapshots of complex movieclips. Where you may have a movieclip full of layered graphical effects that isn’t animated, you can save a lot of rendering time by creating a snapshot of the movie. Similar to the cacheAsBitmap parameter, but will improve performance further if your movieclip comprises many lines or alphas. The following function shows a quick and dirty way of duplicating a movieclip as a snapshot of the original:

import flash.geom.*;
function createSnapshot (base:MovieClip, mc:MovieClip):MovieClip {
var bounds = mc.getBounds(base);
var bmpWidth = bounds.xMax-bounds.xMin;
var bmpHeight = bounds.yMax-bounds.yMin;
var bmp1 = new BitmapData(bmpWidth, bmpHeight, true, 0x00000000);
var snapshot = base.createEmptyMovieClip("snapshot"+base.getNextHighestDepth(), base.getNextHighestDepth());
snapshot._x = mc._x;
snapshot._y = mc._y;
var rect = new Rectangle(0, 0, bmpWidth, bmpHeight);
var pos = new Point(0, 0);
bmp1.draw(mc, new Matrix(mc._xscale/100, 0, 0, mc._yscale/100, mc._x-bounds.xMin, mc._y-bounds.yMin));
snapshot.attachBitmap(bmp1, 1, "auto", true);
snapshot._x = bounds.xMin;
snapshot._y = bounds.yMin;
mc.unloadMovie();
return snapshot;
}

Use the opaque window mode trick – sparingly! Setting the wmode=opaque HTML parameter of your Flash object can improve rendering performance, but at a potential cost. Not only does it make the rendering order of movieclips and frames more ‘lazy’, but will effect keyboard interaction adversely in some browsers (especially FireFox). Use with caution.

I’ll be updating and tracking back to this post occasionally, so stay tuned…