*** From the Archives ***

This article is from August 22, 2002, and is no longer current.

Under the Desktop: Prospecting for Quartz in Mac OS X

Watching the countdown timer in anticipation of this weekend’s release of Apple Mac OS X v10.2 update, a.k.a. Jaguar, the mind wanders to related subjects, such as Quartz, the imaging model used in OS X. We see its graphics bells and whistles reflected in the Aqua interface, but how much do you really know about the fundamental underlying technology in Quartz? For example, did you know that PDF is at the core of Apple’s next-generation operating system? Or that its desktop interface uses layers, just like a photo-editing application?

Here’s a (very) brief discussion of the technology as well as its implications for users and developers of professional graphics creation applications.

Digging for Quartz
Quartz distinguishes itself from Windows computers and even graphics workstations through its handling of layered color information and the internal use of an independent imaging model, in this case, PDF. These features echo steps taken by Apple and NeXT in earlier operating systems.

Long ago, the Mac introduced a then-revolutionary approach to computer graphics: QuickDraw, a set of standard routines that developers could use for their applications to handle text, vector graphics and bitmapped images, and then send them to the screen and output devices. Until then, applications developers were responsible for providing all of that fundamental code and many of them did things differently.

Later, NeXT licensed Adobe’s Display PostScript interpreter for its OS. This vector-based architecture provided users with a more accurate relationship between the image on the screen and its eventual transition to the printed page.

Enter Quartz.

Quartz has two main parts: a Core Graphics Services component that keeps track of each window and its contents, and a Core Graphics Rendering component that decides what goes inside each window. Much more technical information can be found in the Graphics and Windowing Environment section of Apple’s developer website.

Quartz handles windows on the screen (please note the lower case “W” here) differently from other computers. A software controller, called a “service” in Unix lingo, tracks the contents of each window on the screen, pixel by pixel, retaining any information about translucency (the good old alpha channel) and anti-aliasing data for text. Some programmers call this the Quartz Compositor, since it takes the information from the rendering component and writes it to the screen. As the windows are layered on the screen, the manager recalculates, or recomposites, each pixel on the screen, still taking into consideration what’s underneath.

Leonard Rosenthol, chief technology officer of a PDF consultancy called PDF Sages, compared the action of the OS X window server to a painter, who “mixes color on top of color until the one on top wins.” Apple calls this a “video mixer model.”

This approach is much different than the windowing systems of previous Mac OSes, Windows, or Unix, Rosenthol added. These OSes simply track the top-most window and display it to the user. Apple calls this a “switch model” because the pixels displayed belong to one window or the desktop and switch immediately when moving from one window to another.

The result of Quartz’s window server is obvious after just a few moments looking at OS X’s Aqua interface. With even a couple of open windows on the screen, it’s easy to see the outlines and shadings of buttons and other window elements through the translucent title bars of inactive windows. These graphical layers are also very evident when a window is minimized in slow motion into the Dock.

Figure 1: Here’s a screenshot of the overlap of several windows on my desktop. As you can see, there’s a drop shadow on the front-most window, adding to its weight on the screen. Behind the inactive window labeled “Creativepro,” you can see the top of a custom and an ordinary folder icon on the desktop and to the right the outlines of several round buttons. Some folks think this looks like a muddy mess (I personally like seeing the items) and that’s a matter of taste. However, there’s no disputing that Aqua is using some powerful imaging features to present graphical information to the viewer.

This architecture and its reflection in Aqua have drawn some criticism from some quarters. First, there’s a performance overhead to compositing all these pixels, especially when displaying 3D and video content on bigger screens. And this painting approach is deemed a waste of cycles when using the Mac as a server.

Apple aims to address much of this criticism with Jaguar, which offers Quartz Extreme in Jaguar. This update improves performance via better use of OpenGL acceleration on certain graphics cards on AGP-equipped Macs as well as optimization of some functions for the Velocity Engine (AlitVec) floating-point calculator in the PowerPC G4 processor.

No surprise that these are the very same high-performance machines that content creators might have, and Apple said that Quartz Extreme lets some operations run twice as fast. It won’t provide such a performance boost on older machines based on the PowerPC G3 chip.

In addition, I’ve always found the argument against using a graphical interface for servers completely bogus. There’s a macho pride evident in those insisting that a “real” server should be run from a command line (or a bare bones interface devoid of graphics).

Besides, any performance hit from the Quartz Compositor would occur when the screen is filled with rich graphics — a rather dubious task for a server.

Jumping to Quartz Speed
In a related note: Apple last week speed bumped its Power Macintosh line, giving all models dual processors. Certainly, two processors will be better than one to give OS X some juice and can take advantage of Quartz Extreme acceleration. Apple Power Mac Product Marketing Manager Todd Benjamin ran down the advantages for me:

“The preemptive multitasking features of Mac OS X keep the OS (and thus the user) in charge of the system at all times,” Benjamin said. “Mac OS 9 would sometimes allow applications to take control of the system until their processes were complete, leaving the user without the ability to use their system. In Mac OS X, users can run multiple applications at the same time and maintain a consistently responsive user interface.”

“The symmetric multiprocessing capabilities of Mac OS X allow any Mac OS X application on either processor. This provides robust multitasking capabilities that allow the user to run multiple processor intensive applications at the same time.”

“Because Mac OS X and many applications are multithreaded, they run faster on a dual processor system than on a single processor system. In Mac OS 9, the OS and applications run on one processor; [only] multithreaded applications that are written to a specific set of APIs can take advantage of the second processor. Therefore, [OS X] users can use much more of the capacity of both processors.”

Finding Gold in Quartz
Meanwhile, Quartz’s rendering component provides it with a vector system for 2D graphics, called Quartz2D. This rendering system employs the same PDF technology we know and sometimes love, bringing the capabilities of PDF Version 1.3 and some features of Version 1.4.

Quartz2D takes your input and stores everything in a PDF file, which is then used for output or display. The data could be a bitmap for the screen, or PostScript for a laser printer, or raster data for a color inkjet printer. Or you could simply use the PDF file itself, even though it may be larger than those created by Adobe Acrobat. The Jaguar update provides a Print-to-PDF button to make this process easier.

“This one-to-one mapping between the drawing API and the PDF primitives allows all drawing to be saved in a PDF file without loss of information,” said Andrew Stone, president of Stone Design, a Mac OS X developer of graphics tools. He added that this is also the way printing works: “the spool file is really a PDF document that captured the application’s drawing.”

Stone admitted that this abstraction brings its own performance penalty that developers must address, especially for those bringing Mac OS 9 applications to Mac OS X.

“The goal is to produce best quality output, for example, sophisticated filtering for images, anti-aliased drawing, and sub-pixel text rendering. There has been very little work on getting the ‘ugly and fast’ path tuned, which makes it more important for applications to be smart about drawing, like redrawing only the portions that have changed, or to avoid overdrawing,” Stone remarked. His company recently updated its $299 Stone Studio suite of graphics, layout, web design and productivity tools with Jaguar-specific tuning and new features.

Figure 2: Stone Studio’s PStill is a drag-and-drop PDF conversion utility for OS X. It offers a full set of controls and can automatically pack a folder of PDFs, images, EPS, and other files into a single PDF file.

Perhaps less evident to viewers upon first glance, another significant feature of Quartz is its integration of color management. As I mentioned in a previous column, color management is deeply embedded into the operating system. Stone reminded me that all Quartz2D drawing operations are color-matched via ColorSync.

Two Pints to a Quartz
So, what’s the big deal?

Certainly, the base technology offered with Quartz is aimed squarely at content creation applications. Its low-level integration of anti-aliasing, sophisticated text handling, translucency, and color management are all fundamental to the creation of professional-level content.

Even better, with Quartz as a base, developers can take advantage of its features without too much added effort. Any well-written application, consumer- or professional-level, could support color management and sophisticated graphics. And it lets developers of professional graphics applications concentrate on extending capabilities, adding new features, and improving performance.

Regardless of what one thinks of the Aqua interface as a user interface, good or ill, it offers a good example of the how a program can take advantage of Quartz’s graphics capabilities. After all, to the computer, Aqua is just another program. Aqua wasn’t specially programmed to provide transparency and anti-aliasing as some cool features for a checklist. Rather, Aqua is just another OS X application that takes advantage of the built-in graphics capabilities of Quartz.

This reminds me of a rabbinic saying: “You can drain a whole brook, or drill through the hardest granite, if only you have enough patience.” There’s still patience required when running Mac OS X and its Quartz imaging model. But for content creators, it holds the possibility of real graphics power.

>