Take it with a grain of salt

Published Thursday December 17th, 2009
13 Comments on Take it with a grain of salt
Posted in Qt

A few weeks ago, Paul blogged about the Lighthouse project. The unofficial goal of that project is to allow every Qt developer to port Qt to their favorite platform. Of course we like it when new platforms come along so we can put Lighthouse through its paces and share their experience. Google’s open source Native Client project seemed like a perfect opportunity. I’ve been playing with it on my creative fridays, and here’s what I’ve got so far:

The industry standard Qt porting example, wiggly widget, in action.

Native Client (NaCl for short) is a carefully sandboxed browser plug-in framework, for running native x86 (and ARM) code in a web browser, in a native execution sandbox completely isolated from the host’s regular processes or the browser itself. That makes it quite different from ActiveX or Netscape plug-ins, which run as regular programs in the browser’s main thread. Security implications of programs running under NaCl are similar to those for JavaScript programs – which means it’s ok to deploy NaCl programs without even telling the user, just like JavaScript.

From a developer’s perspective NaCl can be viewed as a very small operating system, with a cross-compiling GCC toolchain, some POSIX support, and a basic multimedia interface for keyboard and mouse events, audio and video. In addition you can access the browser to read or modify the web page the plugin is embedded in, so everything you can do from JavaScript, you can also do from NaCl.

The security part of NaCl is implemented as a code scanner/verifier, which runs when a program is loaded into NaCl, and makes sure the code being loaded does not contain any unsafe instruction sequences, eg jumps to arbitrary memory locations or self-modifying code. The compiler itself is not a part of the security system, it’s merely a help to produce a valid instruction stream that won’t be rejected by the scanner. This NaCl research paper has all the details.

So how did it go with Lighthouse? Pretty good! We’re not finished yet, but we got some real chemistry πŸ™‚ with NaCl , really quickly. I especially enjoyed working with the new QWindowSurface and QGraphicsSystem classes, which allowed me to fill in the blanks with Native Client API calls and get results on screen right away.

The elastic nodes example running in Firefox

At this point, Qt for NaCl is at the level that QtCore and QtGui compiles with a minimum system-dependencies configuration. The event loop is up and running, with timers, mouse and half-way working keyboard input support. There is one font available (Native Client does not seem to have a font API yet, so each application has to bring their own fonts.) Several widgets work, as well as QGraphicsView (there seems to be an issue with pixmaps not showing up though). The QPainter rasterizer triggers an optimizer bug in the NaCl compiler, so I’ve left optimizations disabled for now. QThread should work, although we are still using the generic mutex-based QAtomic fallback, so multi-threaded performance might not be that great. Finally, NaCl event handling seems to be polling-based only, which means that all applications spin at 100% CPU usage – not quite our preferred style.

So, nice results for Lighthouse, but still work to do.

Want to try it out? Download Native Client, clone the Qt for NaCl git repository, and see the readme-nacl file in the root Qt directory for further instructions. Enjoy!

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in Qt


Adam Higerd says:

Table salt? *laugh*

This is interesting. I may have to look into it.

vpicaver says:

I guessing you can’t call opengl through it, or can you? Can you send data from a web server to your application?

mx says:

http://groups.google.com/group/native-client-discuss/browse_thread/thread/8cefc4bb1f2bf06b :

“We are planning to provide Open GL ES 2.0 bindings. I am interested in
feedback from the community about whether this is a good match for what app
developers would like to see.”

tr3w says:

Android (NDK)?
What do you think? Is this possible?

sonofanickel says:

Wow, quite an eye-opening post. This is some really neat stuff. Being able to harness the power and ease of use offered by Qt on the web platform would be quite extraordinary. I’ll be watching this closely.

Mark Turney says:

I have been planning to dip into Native Client as a way to make my Qt applications web portable, but yet again the Trolls keep doing the hard work for me πŸ™‚ This is a thrilling development and I’m looking forward to reports on your progress!

amolokoedov says:

Really impressive. I’ll be watching this closely.

This is pretty cool. I’d love to see what non-native (browser-interpreted) solution might be possible to get true run-anywhere output, but this is pretty fancy. Are you only plugging into Firefox today? Have you tried doing a plugin with something like Arora, giving you a Qt environment inside a Qt-based browser?

Jasper says:

From my point of view, this is better than QWebClient. So how does this affect the development of QWebClient?

Paul Tomkins says:

Porting Qt to Native Client would be brilliant because it would allow developers to host rich desktop Qt apps in a browser rather than having to rewrite it in HTML+JavaScript. Please keep up the great work (as always πŸ™‚

Morten says:

Jason: Browser support depends on what browsers Native Client target, so there is little I can do πŸ™‚ Without speaking too much for the Native Client devs, it looks like they are actually looking into deeper browser integration (beyond plugins) to enable things like OpenGL support. Unfortunately I don’t think Aurora is high on the browser priority list.

Jasper: QWebClient and this project are two different lines of research in this area, but I agree that Native Client has greater potential. The use cases are different though, sometimes you really do want a thin client.

Note that these projects are all on the Creative Friday level which means limited resources and no official commitments. I enjoy working on them though, so chances are good there will be further updates πŸ™‚

centipede says:

Good god this is excellent news! Only wonderful things can come from this. I actually tried porting Qt to NaCl myself but got lost in the QWS layer. Now I just have to wait and check each friday, muaha.
… And as an added benefit this Lighthouse project seems very interesting too.

Ouch! This is a big one. Running QT OpenGL in Firefox would literally change my world.

Commenting closed.

Get started today with Qt Download now