Archive for 2008

Building CoverFlow for Safari on iPhone

Thursday, November 6th, 2008

Did you know that 3D graphics and animation is possible with Safari on iPhone?

If you have an iPhone, try out the CoverFlow (zflow) demo live with a live Flickr feed.

This CoverFlow demo is part of a new open source project I’ve started, CSS-VFX. The idea with CSS-VFX is to demonstrate all the cool things that are possible with Apple’s CSS Visual Effects extensions.

How does it work?

The zflow demo in CSS-VFX uses the Apple CSS Visual Effects extensions for hardware accelerated (on iPhone!) 3D perspective correct transforms and easily animated transitions. HTML 5 Canvas is used for simulating reflections.

  • zflow starts by loading each image from the images array. When each image is loaded, we scale the image to fit in a square region, and apply 3D CSS transforms to scale it in place.
  • Reflections – zflow then takes the scaled image and creates a Canvas element that contains a gradient alpha mask of the image’s reflection (using a “reflect” function to do this) and positions the canvas element in place.
  • Touch Controller – zflow creates a TouchController object, who’s job is to field touch events from Mobile Safari and calculate an appropriate offset.
  • Clicking – zflow detects when no move events have been made, and zooms + rotates the focused image forward by setting a “CSS Transition”ed 3D transform on the focused image. Clicking again transitions the image back.
  • Inertia – zflow achieves inertia by setting the “transition timing function” of the “tray” to an “ease-out” function, which slows things down. On the touch end event, we calculate the projected velocity and set the tray’s target position to that location. CSS Transitions handles the decay in velocity as the transition timing function executes — slowing the tray down gradually.

What’s next?

I hope that CSS-VFX can become a series of graphics gems that clearly illustrate how to use CSS Visual Effects, as well as talk about some of the corner cases and best practices to get the best performance. If you come up with something you’d like to include, please let me know. I’ll be tinkering with a few more gems myself, just watch the project for more as time goes on.

And tell a friend, I can’t wait to see what everyone else does with these great new features in Safari on iPhone.

Where to learn more

The CSS-VFX open source project is a good place to start. You can just use the zflow code in your own iPhone web pages (there’s docs on how to do that); and deep dive into the innerworkings of zflow to understand what exactly is going on.

Also, check out Apple’s proposed extensions: CSS 3D Transforms, CSS Transitions, and CSS Animation. They provide full specifications on what’s possible. Of course, there are a few gotchas when using these in practice, and I hope to document these as things progress.

Technorati Tags: , , , ,

SquirrelFish Extreme: Fastest JavaScript Engine Yet

Friday, September 19th, 2008

After reading the WebKit SquirrelFish Extreme announcement, I figured it’s time to revisit the JavaScript engine / web browser race once again.

In short: SquirrelFish Extreme is fastest by a whopping 35% over its nearest competitor, making WebKit the fastest browser once again. Let’s see how the numbers come out.

SunSpider Benchmark Comparison of JavaScript Engines

SunSpider running from the command line (to ensure the test is as pure as possible) was used for this test. My test system is a 2.4GHz iMac.*

These graphs are shown in runs per minute for clarity. Longer bars are better.

The raw timings are:

Detailed timings are linked above.

Of course, browsers are not purely executing JavaScript – DOM and rendering speeds are performance considerations as well. For this, we turn to Mozilla’s Dromaeo benchmark.

Dromaeo on Windows

As you can see, Firefox and WebKit smoke Google Chrome on this benchmark. WebKit comes out slightly ahead, so we need another benchmark to clear things up. Once again, Dromaeo, but on OS X now.

The full timings for these benchmarks are here:

Dromaeo on Mac OS X

Full timings for these benchmarks are here:

  • Firefox Nightly on OS X – 6648.20ms (Total)
  • WebKit Nightly on OS X – 4387.20ms (Total)
  • Winner: WebKit + SquirrelFish Extreme

    SquirrelFish Extreme wins this evolutionary cycle. Stay tuned for more coverage as Google, WebKit and Mozilla prepare their next moves.

    Running your own SunSpider tests

    Download and build WebKit trunk, Firefox trunk, and V8 trunk:

    Building SquirrelFish Extreme: from JavaScriptCore, make release

    Building V8: scons sample=shell

    Building Tracemonkey: from js/src, run make -f Makefile.ref BUILD_OPT=1

    Run the SunSpider harness from WebKitTools/SunSpider: SquirrelFish Extreme: ./sunspider --shell=../../WebKit/WebKitBuild/Release/jsc

    V8: ./sunspider --shell=../../v8-edge/shell --args=-expose-gc

    TraceMonkey: ./sunspider --shell=../../tracemonkey/js/src/Darwin_OPT.OBJ/js --args="-j"

    Notes

    • The Windows benchmarks ran on different test hardware from the Mac OS X and engine benchmarks.

    Technorati Tags: , , , , , , , ,

iPhone – Just Like Developing For Nintendo

Sunday, September 14th, 2008

DOOM and GLOOM! The blogosphere is whining about Apple’s recent App Store rejections. (Surprisingly, even John Gruber.) Only Mikey has a contrarian view, but sadly always has Facebook on the brain.

Look, developing for iPhone is just like developing for a Nintendo console.

Nintendo owns the hardware. Nintendo owns the distribution mechanism. Nintendo doesn’t publish rules on what you can and cannot build.

And they do just fine. Many developers still develop great stuff for Nintendo DS and Wii. Why? It’s successful and profitable. And Nintendo is far more of a pain in the ass than Apple.

Common sense says: You’re not going to develop an Italian plumber 2D platform scroller for a Nintendo DS. Even if you were thinking about it, you’d talk to Apple about it first.

Should Apple get a free pass then? No.

Does this mean App Store is doomed? It hasn’t doomed Nintendo (not yet anyway).

Will Apple innovate over Nintendo and reverse their decision? Yes, and I’m sure it’s coming soon.

Technorati Tags: , , , ,