Graphical Composition in Avalon
Pages: 1, 2
Avalon Graphical Composition
Avalon introduces a new model for graphical composition. It does two things in a fundamentally different way from Win32 that enable much richer composition without risking flicker, while making developers' lives much easier. First, visual elements are free to overlap. Second, composition is all done off-screen.
Because Avalon is designed to allow visual elements to overlap as much as they like, elements are no longer required to supply their own backgrounds. So while in Win32, the first thing a control typically draws is its background, in Avalon, the background is whatever happens to be underneath. A control can choose to be opaque and fill in its background if it wants to, but this is no longer a requirement. So if you choose to put some text in a UI, it will draw directly onto whatever is beneath it, rather than appearing in its own solid box as a label control would in Windows. For example, in this XAML snippet:
<Canvas DockPanel.Dock="Fill">
<Rectangle Fill="VerticalGradient Navy Cyan"
Stroke="DarkGreen" StrokeThickness="3px"
Canvas.Left="5" Canvas.Top="20"
RectangleWidth="185" RectangleHeight="50" />
<Ellipse Fill="PaleGreen" Opacity="0.5"
Stroke="Green" StrokeThickness="2px"
Canvas.Left="62" Canvas.Top="10"
RadiusX="30" RadiusY="40" />
<Text Canvas.Left="10" Canvas.Top="0" FontSize="24pt"
Foreground="Red">Hello, world!</Text>
</Canvas>
the text element is drawn over the ellipse and rectangle, but these remain visible behind the text:

Figure 4. Text over an ellipse and a rectangle
This example also illustrates Avalon's support for partial transparency. The ellipse's Opacity
property has been set to 0.5, indicating that the composition engine should blend the ellipse with whatever is
behind it. The value of Opacity indicates the ratio in which to blend. The default value of 1 indicates that
the element should not be see-through at all, while a value of 0 would make the item invisible. The composition
engine can also apply other effects; for example, you can clip elements against any path, or you can specify transformations such as scaling, shearing, rotation,
and translation. You will also be able to apply image effects such as blurring or a "glow." (The Longhorn preview
distributed at the PDC only allows image effects to be applied to bitmaps, but the plan is to be able to apply these
effects to any part of the UI.)
Given this support for overlapping and partially-transparent objects, you might think that Avalon would suffer from
the same flickering issues mentioned earlier for the WS_CLIPCHILDREN and
WS_CLIPSIBLINGS styles in Win32. After all, if our program does something to change any of the
elements in this example, the chances are that all three elements will need to be redrawn in order to generate the
correct final picture. For example, if we change the font size of the text, the text will clearly need to be redrawn,
but the change will uncover parts of the ellipse and rectangle that were previously covered, so those will need
to be at least partially redrawn, as well. However, Avalon manages to do this without causing any flicker. The key to
this is the second fundamental change between Win32 and Avalon -- the off-screen composition.
Off-Screen Composition
One of well-known but often misunderstood facts about Avalon is that it makes use of modern graphics cards. This is often described somewhat misleadingly as a "3D API," because the GPUs (Graphics Processing Units) on modern graphics cards are designed mainly to render 3D graphics very quickly. Moreover, the API Avalon uses to control the graphics hardware is DirectX, the API used by most 3D games. This tends to bring to mind futuristic movie-like, virtual-reality user interfaces. However, while 3D user interfaces are certainly a possibility, Avalon actually makes much more pragmatic use of the GPU -- it can put features designed for 3D use to work in generating 2D images.
For example, high-end graphics cards have much more memory than is necessary to manage the screen's contents. A dual-monitor setup with 1600-by-1200 pixel, full-color displays is high-end by today's standards, but only requires about 7.4MB of video memory. And yet high-end laptops are shipping today with 128MB of video memory, some 17 times as much memory as would seem to be required. The reason for all of this extra memory is that it allows games to run faster -- it is typically used to hold the "texture" images used to make 3D surfaces look interesting or realistic (or both). Increasing the memory available for textures allows games to provide either more detail or greater variety, with no loss of performance.
In normal non-gaming activity, while some of this video memory is used for caching fonts, most of it typically goes unused today. However, Avalon will make extensive use of this memory. When a GUI needs to be rendered on screen, Avalon does not use the Win32 approach of getting each visible item to draw directly into its on-screen region. Instead, drawing is done into off-screen buffers, using all of that extra video memory normally used for 3D textures. This means that applications are no longer obliged to perform their own double buffering to avoid flicker -- Avalon will do it for them. Moreover, because Avalon is managing the buffering, it can choose the optimum moment to transfer the buffer onto the screen. (In forthcoming builds of Longhorn, the DCE will be responsible for this final transfer to the screen, enabling it to apply any further desktop-level transformations such as scaling, or fancy transition effects.) It can wait until all of the visual elements have made their contributions before updating the screen. So unlike in Win32, where double buffering can only normally be applied at the level of a single window, Avalon can double buffer entire trees of UI elements.
There are more clever tricks that Avalon can do with this off-screen buffering. For example, it doesn't necessarily have to use a single buffer for a particular window. It could render subsections of the visual tree into their own buffers, and then compose these buffers into the main window's buffer. The big advantage of this is that it allows sections of the UI to change without having to redraw everything.
For example, consider a complex and graphically rich document -- even exploiting the full power of a modern GPU, it might take a significant amount of time to draw. Bear in mind that when elements are being dragged by the mouse or animated, for the movement to look totally smooth, updates should be performed at the refresh rate of the monitor. With the 60Hz refresh used by most LCD panels, this gives you just under 17ms between updates. A complex document might have many thousands of details (particularly if it contains a lot of small text), at which point 17ms starts to look like an aggressive target. So if you wanted to be able to drag anything like a selection rectangle over the document, it might not be able to redraw the entire document at the frame rate, so the drag operation will end up feeling rather sluggish. However, if the composition engine renders the layer containing the drag rectangle in a separate off-screen buffer from the document, all it has to do in order to update the UI is redraw the drag rectangle in its off-screen buffer, and then compose that with the pre-drawn document off-screen buffer, and copy the result to the screen. This is likely to be very much faster than redrawing everything from scratch.
The use of off-screen buffers also allows Avalon to exploit the graphics card's ability to transform images. All modern GPUs are able to perform scaling, rotation, and shearing of images as part of their basic 3D functionality. This means that if you have an animation that is rotating or zooming part of the UI, those parts don't necessarily need to be redrawn each time the transformation changes -- the animation can simply use the graphics card to transform the pre-drawn image during the composition process. There are limits to this technique -- if you scale an off-screen buffer too much, the image quality will suffer. However, this technique can be used to reduce the frequency with which a full redraw is required, reducing the load on the CPU.
Retaining the UI
If there is sufficient memory available on the graphics card, Avalon does not need to free up the off-screen buffers it allocates once it has finished updating the display. It can keep them, so that if an application's window needs to be redrawn due to other display activity, it can just copy the image straight out of the buffer back onto the screen without needing to get the application code involved at all.
Even if there is insufficient video memory to buffer all open windows, Avalon doesn't need to pester the application, because it has another way of retaining the information needed to rebuild the display. Avalon maintains a scene graph, which is a data structure representing all of the elements of an application's UI. This is a private structure that your code cannot access directly, and is not the same thing as the logical tree or visual tree that you program against, although its structure will be closely related to theirs. It contains all of the information required to represent the visible aspects of the UI, including animation. If you make changes to the logical tree that cause visible changes, this will result in the scene graph being updated appropriately. But because the scene graph is a distinct data structure that the system controls, Avalon can keep the display up to date autonomously -- animations and video playback can run without continuous attention from the application.
This retained scene graph lets the operating system make fewer demands on the program. In classic Win32
applications, the system sends lots of WM_PAINT messages to the application in order to keep the
screen up to date, but with Avalon, this is not necessary. This offers several benefits. The display remains intact even
if the application is busy. The load on the CPU is reduced because far fewer messages need to be sent to the
application. And this technique scales better in terminal server scenarios, both because of lower CPU load and the
fact that the scene graph can be sent to the client machine in a reasonably compact form. This enables most of the
repainting to be offloaded to the client, allowing high-quality visuals and even animation to be used without using too
much network bandwidth.
Conclusion
The new composition model in Avalon removes many of the visual design constraints that applied to most Win32 applications. It also improves performance by making more effective use of modern graphics cards, reducing the frequency with which the OS has to call the application back to keep the display up to date, and enabling a much higher quality of user interface.
Ian Griffiths is an independent consultant specializing in medical imaging applications and digital video. He also works as an instructor, teaching courses on .NET for DevelopMentor. Ian holds a degree in computer science from Cambridge University.
Return to ONDotnet.com
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 27 of 27.
-
XAML
2004-03-17 07:17:54 zicco [Reply | View]
-
XAML
2004-04-06 10:03:25 musnat [Reply | View]
I truly admired the patience of the author to such stupid claims. SVG has nothing to do with XAML. What an idiot you are zicco. Just because you think you can get away with, you throw out something you are not even knowledgable about. XAML competes with XUL in a way, you may accuse Microsoft for not using XUL, but still that will not change the fact that you are a pure idiot. I don't understand why Microsoft attracks so many idiots. XUL is a half-ass solution with lots of stuff up in the air. That's why not many people use it. It is not a bad stuff, but so much more has to be done, and mozilla developers clearly declared that they are against Microsoft and thus it is stupid to say Microsoft should use XUL. Many mozilla developers are eager to take down Microsoft, they are not open minded people. In the slides one of the lead developers say that mozilla should colloborate with Safari and Opera, there is no mention of Microsoft. That's pure evil.
SVG is also going through a stupid slow process. Even on mozilla they don't have built-in support for that. Adobe has a nice plugin which works great on Internet Explorer, but because irresponsible mozilla developers changed some of the APIs, adobe's plugin doesn't work on mozilla. That's where SVG is. Its progress is painfully slow, yet many idiots do not acknowledge that fact. So we end up having nothing, but they don't want Microsoft to develop something either, they just want everybody to sit and wait W3C. -
XAML
2004-03-17 08:15:30 Ian Griffiths |
[Reply | View]
XAML doesn't reinvent SVG. It also doesn't reinvent XUL. People regularly accuse it of doing both, but if you're familiar with both SVG and XUL, you'll know that at least one of those accusations has to be false. (Most people wouldn't accuse XUL of competing with SVG.) :-)
As it happens, it doesn't really reinvent either.
This has been hashed through many times already elsewhere, so instead of rehearsing the arguments yet again here, I'll just point you at a few existing discussions:
I already addressed this very point in an earlier article in this series here: http://www.ondotnet.com/pub/a/dotnet/2004/01/19/longhorn.html
One of the architects who designed XAML writes a little about the history here. Although he doesn't mention SVG, once you've read the design goals, it becomes clear why SVG would never have worked:
http://www.simplegeek.com/permalink.aspx/100aec62-3352-4c35-b471-f3f2fa5fac5a
Some more from the same guy on why not they're not using CSS either:
http://www.simplegeek.com/permalink.aspx/b7e02709-0112-4977-9b73-1aa9d471a570
Another guy from Microsoft on why they didn't use SVG: http://www.eightypercent.net/Archive/2003/11/04.html#a153
Don Box blogged several times about XAML in November 2003, all of it showing how to use XAML without using Avalon, demonstrating again one of the fundamental features of XAML that means they couldn't have used SVG (it really has nothing to do with graphics - XAML is just a way of hooking up .NET object models; it's only the XAML+Avalon combination that does graphics): http://www.gotdotnet.com/team/dbox/default.aspx?month=2003-11
(I'd recommend starting from the bottom of that page and working up.)
More can be found easily via Google...
-
Quartz Exteme Explained
2004-03-09 18:30:08 indigenous [Reply | View]
For those interested, here is a link to John Siracusa's discussion of Quartz and Quartz Extreme from his review of OS X Janguar over on ars Technica.
Click Here
-
macos x already works like this
2004-03-09 06:37:16 jannino [Reply | View]
Its an other case where Microsoft is learning something from Apple, but thats a good thing for everyone. MacOS X always had a compositional rendering engine like what is described in Avalon, but they call it Quartz, and since 10.2 has been able to use 3D graphics cards to help with the off screen rendering. If Windows people want to get an idea of what's coming and how it might work and what you might be able to do with it, taking a look at Apple's documentation is a good start until Microsoft fleshes out their implementation. -
macos x already works like this
2004-03-09 07:15:49 Ian Griffiths |
[Reply | View]
Sort of... (I'm the author of this article. I've also done some Mac OS X programming.) Quartz is considerably more advanced than Win32, but Avalon actually leapfrogs Quartz.
Quartz uses composition, but despite the fact that it also has extensive support for vector drawing, there is a big limitation: there is no vector-level retention - as I understand it the composition is done *after* the rasterization of the vector imagery. The vector support in Mac OS X actually works in pretty much exactly the same way as GDI+ does in current versions of Windows, and is not integrated into the composition engine.
Compare this with Avalon, which uses vector-level retention as part of its composition model, and can interleave multiple transform and rasterization steps as a result. (It can also retain bitmaps as an optimization, but it always retains vector information too.) This enables transforms to be integrated with the composition engine. Transforms in Quartz are done much more like current versions of Windows handle them - they are dealt with at the level of a drawing context when the application generates its imagery. (At least that's how I've always seen it done. If you can point me at an example that shows transformations at the composition level rather than the drawing level in Quartz, I'd be very interested to see that.)
What does this mean in practice? Well for one thing, it makes life easier for the developer: in Avalon, you can adjust a transform object and the display will reflect that change automatically - the composition engine can handle such changes implicitly. In Quartz, you'd have to handle all your own redrawing, just like you do today in GDI+ on Windows, because both Quartz and GDI+ use bitmaps as the only kind of retainable drawing.
But there are also implications for the quality of user experience: as far as I know, Quartz doesn't have a good way of dealing with high-dpi displays. With Avalon, the desktop composition engine will be able to apply a scale transform to an entire window. While Quartz can scale and stretch windows too (e.g. when you minimize a window to the dock), because the composition model is downstream of the rasterizer, the results will be of suboptimal quality - it'll look a bit fuzzy, like a scaled bitmap. (Whereas a scaled UI in Avalon will look like a scaled vector drawing looks: every bit as crisp and clean as it did before scaling.) Quartz gets away with this for high-speed animations like minimization because they're over before you have a chance to see the imperfections. But it would not stand up to close sustained scrutiny. And a crummy image would completely defeat the purpose of a high-dpi display!
So Quartz doesn't appear to deliver the full advantages a composition model can offer both developers and users. (But I should admit that I'm not a Quartz expert. But I spent a long time trying to get it to do all this stuff, because when I first started learning to develop on OS X, I was really hoping that Quartz would be the graphics system I really wanted. I was looking forward to seeing what the composition engine could do. I was somewhat disappointed with what I found, both with the available examples, and with what my own experiments revealed. And also with what applications seem to do with it in practice. But if you think I just didn't look in the right places, I'd love to learn how better to exploit Quartz.) -
macos x already works like this
2004-03-09 13:14:57 zootbobbalu [Reply | View]
I'm not a Quartz expert, but you have to admit that your article is void of any mention of Quartz. For someone that claims to have developed with Quartz, I find it odd that you were so displeased with Quartz you came to the conclusion that a six-year wait for a technology to do your work is not that big of a deal.
Hopefully all of you claims about Quartz are correct, because I would hate to see this become a public display of uninformed comparisons.
"Avalon actually leapfrogs Quartz."
I too feel that Avalon better leapfrog what will become a six year old technology reference.
Go Microsoft!!
-
macos x already works like this
2004-03-10 03:20:33 Ian Griffiths |
[Reply | View]
Yes, my article is devoid of any mention of Quartz. I didn't think it would be useful to mention it for two reasons:
(1) I thought that most developers likely to be reading a Microsoft-centric site such as ONdotnet would not be Mac developers. I don't believe that drawing comparisons of the form "This is a bit like something you've never used" are very helpful, so any comparison would only have benefited a minority of readers. If I underestimated how many readers would come to see what the other guys are doing, then I apologise for that, but I still think it would not have been useful to mention Quartz because:
(2) It's not actually that similar, so even if you are familiar with Quartz or Quartz extreme, there aren't many useful comparisons you can draw. So this reduces it to "This is quite different from this other thing." In fact for most readers, the result is "This is quite different from this other thing that you've never used," which I don't believe is very useful.
And in general, I find competitive comparisons pretty unedifying - they have an unpleasant tendency to end up in 'My OS is better than your OS' slanging matches with little to no useful content.
But since you seem to be saying that the article could have been improved through the addition of my opinion on the comparative merits, here goes: I was disappointed with Quartz mainly because it didn't seem like a great leap forward; all the hype had led me to believe it would be significantly better than where Windows is today. Layered Windows, which were introduced in Windows 2000, provide hardware composition for top level windows, and that has been around since long before Quartz Extreme. I mentioned layered windows briefly in the article, but I didn't go into much depth, because layered windows aren't that interesting - they suffer from the same set of limitations that Quartz Extreme suffers from today: they offer only bitmap based composition, and at a level that is removed from the rest of the drawing APIs. If this had been an article on layered windows, then a comparison with Quartz and Quartz Extreme would have been appropriate, because there are some very important similarities. But that's not what the article was about.
Also, GDI+, which was introduced with Windows XP in October 2001 (and which has also been available since then for installation on older versions of Windows back to NT 4.0) has offered vector-based drawing features that Mac OS X didn't catch up with until Mac OS X 10.2. Again, if this had been an article about GDI+, then a comparison with the 2D parts of Quartz [Extreme] would have been a good idea, because there are many similarities here. But again, that's not what it was about.
In short, it's pretty disingenuous to claim that Quartz Extreme is ahead of where Windows is today. (It's ahead of Windows ME, but not Windows XP.) Max OS X looks far prettier, but that has nothing to do with technology - technologically there's a fairly small difference, despite the claims made in the hype.
I can't offer a comparison between Avalon and the Mac equivalent (i.e., whatever the Mac graphics technology will be in 2006) because as far as I know, Apple haven't announced what it will be.
I don't think any of the above tells you anything more about Avalon, which is why I didn't feel it would have been a productive use of space in the main article. I thought most readers would find such comparisons completely irrelevant, and the remaining readers would have found them only barely relevant. And I didn't have any particular desire to engage in any Mac bashing, which is how I suspect this comment will come across to the Mac faithful. (It isn't intended as such - I like my Mac, despite being disappointed by Quartz, so I don't have any desire to criticize it. The above is just a dispassionate attempt to make an accuaret comparison.)
If Apple were telling us what their plans for the next generation of their graphics architecture was, then it would obviously be a different story - then there would be something useful to make comparisons with. If this information had been available to me, I would have included it in the article. But as far as I am aware, Apple haven't released any such information.
As for the "Avalon actually leapfrogs Quartz", that was in response to the wholly inaccurate "macos x already works like this" claim. I wasn't making a big deal of the fact that Avalon will leapfrog today's Mac OS X technology - obviously it will, and obviously we'd all be hugely disappointed if it didn't. But the original post in this thread suggested that Mac OS X is already ahead of where Avalon will be. I was simply pointing out that this is not true. Mac OS X does not already work like Avalon will work, despite what the subject line of this thread claims. -
macos x already works like this
2004-03-10 06:34:39 zootbobbalu [Reply | View]
You sound like a very intelligent person, but where is the logic in waiting six years for a graphics technology.
Here’s how I see it. Sixty percent of you article is devoted to explaining the basics of composition and the mechanics of drawing a background to a control. You meticulously steer the reader into a state of enlightenment that is able to comprehend the following fact. In Win32, the first thing a control typically draws is its own background and in Avalon (Windows 2007) the background is whatever happens to be underneath. Didn’t Quartz allow you to do this?
You briefly discuss how Avalon is able to composite text over an ellipse and a rectangle. Didn’t Quartz allow you to do this?
1/5 of your article talks about how you no longer have to draw directly to the screen. This section talks about how the GPU will play a major role in the windowing environment. Isn’t this what Quartz Extreme is all about?
The remaining 1/5 of your article is up for debate. If Avalon is able to retain a vector representation for each window, I don’t know which system is better. Quartz is essentially a form of Display PostScript, but I don’t know how efficiently the composition is done. I have created OpenGL views that render in a transparent window and the frame rates are very respectable. You seem to be stuck on the notion that a retained vector representation will solve all of your problems. I have to admit that I don’t see the functional difference between having the vector drawing commands reside in user space and having the vector drawing commands retained within the graphics engine. Vector based transformations have always been part of Quartz, so I don’t see how Avalon is superior in this regard. You point out that, in OS X, the window animation that occurs when a window is minimized into the dock is using a bitmap representation. Is this crux of the matter? Are you saying that Avalon is essentially drawing directly onto surfaces instead of into bitmaps that can later be used as textures? If this is true then I can say without any sarcasm that Avalon is really cool. But, if the end result of Avalon’s “magic” is a bitmap representation, then I still don’t get it.
On a side note, you still have not explained the benefits of pushing a deployment back for more than half a decade.
-
macos x already works like this
2004-04-06 05:38:43 musnat [Reply | View]
Very once in a while, some of the mac idiots, like zootbobbalu will come and try to say something. What they say is general stupid, nonesense stuff as we witness from zootbobbalu's posts. When you read what he is saying, at the end you conclude that the guy is nothing but an idiot who didn't like what he heard. This is a site for programmers, serious people, not some idiot who is devoted to Apple. So I suggest zootbobbalu to increase his iq first, than his skills, be more mature etc.., and then come back and discuss whatever he wants with us. Right now, he is more like an annoying Mac troll. -
macos x already works like this
2004-03-10 09:58:42 Ian Griffiths |
[Reply | View]
"where is the logic in waiting six years for a graphics technology. "
The same place as the logic in waiting about 15 years between the release of the first Mac, and the availability of Quartz, surely!
In 2000, graphics hardware wasn't up to running Avalon. The performance problems that Quartz suffered from in its early days pretty much answer your question for you - the early versions were slow because the typical hardware of the time wasn't quite ready for the architecture. This is why you have to wait - arguably Apple didn't wait quite long enough with Quartz. Hardware acceleration didn't come along until Quartz Extreme, and that placed some minimum requirements on the hardware - older machines can't run Quartz Extreme, and are stuck with crummy performance because the graphics architecture is just too heavy to fly on those systems. (Indeed, I gather that Apple now offer refunds to people who bought Mac OS X for some older systems, because they've had to admit that the machines simply cannot cope.)
These days (four years down the line), typical modern graphics hardware is good enough to cope with Quartz Extreme. Two years hence, things will have moved on again. Avalon is designed explicitly to exploit what will be available on high end systems in two years time (and on mainstream systems in three to four years time). If Avalon had been available in 2000, it wouldn't have worked because it makes assumptions about graphics hardware that simply weren't true back then. That's why we wait.
You could ask the exact same question with something like Java. Why wait 25 years for virtual execution environments to come along when you could write assembly language programs just fine in 1980? Java would never have worked in 1980. But very few people write assembly language today - we've all moved on. The platforms and development tools evolve to take best advantage of current hardware. In 1980 you had to wait 25 years for something like Java because that's how long it took for hardware to evolve to the point where Java made sense as a solution. In 2000, Windows made good use of typical graphics hardware from that era. In 2003, Quartz Extreme made good use of typical contemporary graphics hardware. In 2006, Avalon will make good use of graphics hardware that'll be available in 2006. And on it will go - once Quartz reaches the end of its useful life, Apple will no doubt come up with something more appropriate for whatever graphics hardware can do by then, thus leapfrogging Microsoft.
Is 6 years too long? I'm not sure. You can't change architecture every 2 years - it takes years to move developers over from one system to the next. (At least it does on Windows - a lot of Microsoft developers are comparatively conservative. I'm not sure what Mac developers tend to be like - maybe they're happier to undertake the necessary reengineering more often. But Microsoft know that every time they make a change, some customers will just stick with the old stuff for years. Look how many places still use Windows NT 4.0 - it's a conservative world out there.)
As for your other questions, the answer to the control composition and the rectangle/ellipse composition is the same: a heavily qualified yes. You can do this in Quartz *unless* you want to use transformations, in which case you can't use the compositor. If you want to do this with transforms, you have to abandon the compositor. You can still draw what you want by using Quartz 2D to draw everything into a single surface, but then you get no hardware acceleration, and no integration with anything else in the composition tree. (The lack of acceleration there is just a shortcoming of the current Quartz Extreme implementation by the way - in theory they could probably fix that specific problem in a future version.) Quartz supports transformations, but only in the same limited way as GDI+ (the Windows 2D technology which has been around for about as long as Quartz): it doesn't support transformations at the composition level. So this makes the compositor entirely useless for anything involving transformations. (Unless you're prepared to put up with the low image quality you get when performing affine transformations on bitmaps.) One reason that's important is that you absolutely need this for high-dpi displays to be supported automatically for all applications. (High-dpi support is seen by Microsoft as a key feature.) It's also important if you want to support refresh-rate animation. (E.g., although Quartz seems to be able to do video and 3D at the refresh rate, 2D drawing seems to be very much slower. I think it's no coincidence that 3D and video are accelerated and don't require the application to regenerate the entire display on a regular basis, unlike the Quartz 2D stuff, and these are the only bits of Quartz that really cut the mustard for performance today.)
As for the GPU playing a major role, Quartz Extreme doesn't use it at all for 2D drawing as far as I know. (All the articles I've read say that it accelerates composition and 3D, but not 2D drawing. I've not actually done any independent analysis to confirm this myself, but I'm assuming they can't all be wrong.) In Avalon it accelerates everything. So it's not really the same thing at all. And given that most drawing done by most applications is in fact 2D, it's curious that Apple leave this path unaccelerated. (I suspect it's because their most egregious performance problems were caused by the pre-Extreme compositor so they decided to fix that first.) So no, that's not what Quartz Extreme is all about. Quartz Extreme was all about accelerating one specific thing (composition), and leaving 2D in software. (Meanwhile, composition has been accelerated in Windows since Windows 2000. But I concede that Quartz Extreme's composition is more capable than Windows 2000's.)
You mention that Quartz does vector transformations, which is partially correct: transformations are a part of Quartz 2D. They are *not* a part of Quartz Composition, and that is the fundamental difference. This is what I was talking about in my earlier comment when I said that the Quartz Composition engine happens entirely downstream of the rasterizer.
So yes, as you say, I am "stuck on the notion that a retained vector representation" is important. This is the crucial difference. The big difference with having this handled by the platform, rather than requiring the application to issue the drawing commands on demand (which is how GDI+ and Quartz both work) is that the latter is very much slower due the the extremely chatty nature of the API, and impossible to integrate with the composition engine without resorting to bitmap-based composition. (Which is why both GDI+ and Quartz use bitmap-based composition.)
It's a popular meme that quartz is a form of display postscript, but everything I've seen and read indicates that what this really means is that as a developer, you get to issue commands to execute all of the postscript primitives, but that retention is entirely bitmap-based. So it's true that the 2D API has postscript-like features, but none of that permeates any of the rest of the Quartz architecture.
OpenGL is an entirely different matter by the way. The whole rendering pipeline is hardware accelerated there in Mac OS X, which is why you get good performance on that. (And if we're comparing things with Windows, today's OpenGL support in Mac OS X is not significantly different in architecture from today's DirectX 3D support in Windows today.)
As to your final point, yes, the end result of all the magic is a bitmap - ultimately it has to end up on a raster display of some kind, so that's inevitable. But I wouldn't agree that this makes the end-to-end vector support that differentiates Avalon from Quartz pointless. Dropping down to bitmaps too early in the pipeline has a performance impact, because it substantially increases the amount of communication required between the application and the display subsystem, and furthermore, it is likely to hamper the ability to support high-DPI displays. So both systems eventually have to produce bitmap as their final output, I'm just saying that in my opinion, Quartz drops down to bitmaps prematurely for 2D rendering.
But even if none of the above applied, there's also the fact that this is an article about Avalon, not Mac OS X. When I wrote the article, I had in mind a mainly Microsoft audience, for whom many of the concepts of composition will be new. If I had chosen to target a Mac developer audience, I would have written the article differently. I'm sorry if you felt the article wasn't very interesting. -
macos x already works like this
2004-03-10 13:20:16 zootbobbalu [Reply | View]
“The same place as the logic in waiting about 15 years between the release of the first Mac, and the availability of Quartz, surely!”
Nobody waited 15 years for Quartz. So this argument is fatedly flawed. You, on the other hand, stated that Quartz wasn’t up to snuff for your work. Your decision to forgo working with an excellent compositing engine for six years is still baffling in my honest opinion. You can’t argue with the fact that most of the functionality presented in your article is already facilitated by Quartz. You yourself say that OS X is pleasing to the eyes, so it should be fare to assume that the quality of the output generated by Quartz is not an issue. This is why people feel you could have mentioned Quartz as an example of how composition can be done well. You don’t have to attack this recommendation. You stance is way too negative toward Quartz. Many of the features you herald in your article are many of the same features “hyped” when OS X was first released to the public three years ago. The key difference here is that much of the hype has become a reality on the Mac side and much of the “hype” is still being hammered out on the Windows side.
I’ll regress…
I have to say that your deep understanding of 2D drawing on both platforms is valuable at these forums. All of the experience you have shared is greatly appreciated. Can you clarify a couple of things? You say that Quartz is unable to perform transformations interleaved with compositing operations. Do you mean the following sequence is not possible?
Fill a rectangle with a color that has an alpha component
Perform an affine transform that scales, rotates and translates
Fill an ellipse with a color that has an alpha component
Perform an affine transform that scales, rotates and translates
Draw some text with a color that has an alpha component
Quartz does composite this drawing sequence properly. What am I not getting here?
The other thing that is confusing is related to Vector-level retention. Would the simple vector drawing example above be turned into a stream of low level drawing primitives and stored in memory to be replayed whenever a dirty region needs redrawn? That would be definitely be much more efficient than having each client application redraw global transformations. I wonder if this means that image resources used to create controls and other graphic elements will be now have to include multiple resolutions for this on the fly global transformation model, or are bitmap images going to be a thing of the past. Wait that would require an image with infinite resolution!! OK back to planet earth. Now I’m curious how bitmap image representations will coexist in a vector-level retention graphics engine. Hmmm very interesting.
-
macos x already works like this
2004-04-06 05:50:12 musnat [Reply | View]
"You stance is way too negative toward Quartz."
This is a site for windows programmer, and a mac idiot who has no idea on what's going on in the graphical APIs come and say that he didn't like what he heard about his beloved technology. Because he is too stupid to believe in everything Apple told him and that after spending thousands of dollars to a mac he doesn't want anybodyelse to say anything "negative" about his mac, even though everything is true. He doesn't even understand what's going on here.
I am completely suprised by the author's mature raction. Frankly, it is quite obvious that he is dealing with a mac idiot who will never ever get what he is saying.
By the way, this is obviously not about mac vs windows, except for this little idiot. The problem is to me, an idiot who views everything as mac vs windows is coming here and trying to discredit someone without putting anything to the table, by pure personal attacks. The above statement is a good indacation on where this idiot stands. -
macos x already works like this
2004-03-11 04:58:13 Ian Griffiths |
[Reply | View]
"Nobody waited 15 years for Quartz. So this argument is fatedly flawed. "
In which case, in what sense are people waiting 6 years for Avalon? It wasn't even announced until late in 2003, and is supposed to be shipping in 2006 or 2007. So that's not really a 6 year wait. (OK, I was being deliberately extreme in the example above to emphasize the point. But when was the last time the Mac drawing APIs had a substantial workover prior to Mac OS X?)
When you said that people will have waited for 6 years, I was assuming that you meant the gap between two technologies. So I no longer have any idea what you really mean by with this 6 year wait thing.
"You, on the other hand, stated that Quartz wasn’t up to snuff for your work. Your decision to forgo working with an excellent compositing engine for six years is still baffling in my honest opinion."
I think what I actually said was that it was disappointing. That's not quite the same thing. It's up to snuff in the same way as Windows is - I can usually make either of them do what I want given sufficient effort. In certain cases you have to abandon the 2D API and drop down to fully-accelerated pipelines like OpenGL or DirectX (on Quartz and Windows respectively) to get sufficient performance, but if you are determined enough, and have the time, you can usually bend them to your needs, even though you sometimes have to completely abandon the normal way of doing things.
But it shouldn't be that much effort. What I like about Avalon is that it will make it easy to use some UI features which currently require heroic programming to make it work fast enough. (Just to be clear, I'm hoping that future versions of Quartz will also make it easy to do things that are hard today. I just have no idea right now what Apple's plans are there.)
"You can’t argue with the fact that most of the functionality presented in your article is already facilitated by Quartz."
Yes, I'm not arguing with that. (I have been arguing that quite a lot of what's in Quartz is in Windows today, but I don't disagree with the above.) But then about half of what the article covers is the basics of composition, because most windows developers aren't familiar with that. Even though Windows has supported top-level composition since Windows 2000, most developers don't actually use it.
So is the fact that Windows 2000 style composition and more is available today in Quartz relevant to an article that explains some differences between current versions of Windows and the next version of Windows?
"You yourself say that OS X is pleasing to the eyes, so it should be fare to assume that the quality of the output generated by Quartz is not an issue."
If OS X really was a good showcase for the Quartz compositor, I would agree, but I don't think it is. It makes very unambitious use of the compositor.
The Mac looks nice principally because the graphic design is good, not because of the way the compositor works. An awful lot of the eye candy is done with bitmaps, and the composition techniques it uses don't show off Quartz's technical abilities. I had originally assumed (before I got my Mac) that the Aqua look was all done by exploiting the compositor, but it doesn't take long with the development tools to discover that this is not the case. Try and arrange a UI so that some of the widgets overlap, and it tends to end up looking quite a lot like the example in my article where I show how pseudo-transparency in Windows falls down. UIs have to avoid certain styles of layout to avoid this. (All of the recommendations in the user interface guidelines steer you against designs that cause a problem.)
The only things that exploit the compositor are the drop shadows and the semi-see-through bits. Since both of these effects have also been doable in Windows since Windows 2000, I don't think it does all that good a job of showing off the Quartz compositor. Most of what gives Aqua its distinctive look is all the bitmaps used for the various UI widgets and the window backgrounds.
Given all that, I have to disagree with the sentiment you expressed next:
"This is why people feel you could have mentioned Quartz as an example of how composition can be done well. "
The Aqua look is absolutely not a good demonstration of the Quartz compositor. It's a testament to the design skills of the artists at Apple, but it is in no way a technical tour de force. It barely uses the compositor. And what it *does* do with the compositor is basic stuff - they don't do anything you couldn't do with the Windows 2000 compositor.
I think this is a shame because, as I've already said, the Quartz compositor is more capable than the Windows 2000/XP one, so it's a pity that Mac OS X doesn't showcase this. (But I suspect the reason they don't is that this would raise the minimum spec required to run OS X - see the comments towards the end of this post on for a little detail on why it's comparatively expensive to exploit the the Quartz compositor.)
"You stance is way too negative toward Quartz. "
OK, you've got me there - I'll admit that. But I'm just defending what I wrote, and to do that I'm countering all of the arguments presented in this thread that I have disagreed with to a greater or lesser extent. This inevitably comes across as negative, because I'm always taking the contrary stance. So I apologise for that. I'm not as down on Quartz as it probably seems.
Just so it's clear, I think Quartz is a Good Thing. It's better in every respect than where GDI+ on Windows is today. I hope it continues to evolve - if, after Avalon ships, Quartz improves enough to regain its lead (or even steals a march by beating Avalon to it) then that can only be good for the quality of graphics systems in the industry as a whole. I want to see Apple and Microsoft continually strive to outdo each other, so that the state of the art moves ever forwards.
"Many of the features you herald in your article are many of the same features “hyped” when OS X was first released to the public three years ago."
Agreed. But I still don't understand why that would be relevant on a site targeted at Windows developers. As you already acknowledged, the first half of the article is about bringing people up to speed on composition, rather than talking about anything new. As I've already said, I don't believe that telling people that it shares some aspects in common with a system they are unfamiliar with is a useful observation.
And I think anyone already familiar with Quartz will recognize the stuff they are familiar with without me needing to point it out. So I honestly don't see how you think that references to Quartz would have made the article better for any readers. It would have been meaningless for those unfamiliar with Quartz, and redundant for those familiar with Quartz. Who benefits?
As for your example of layering the rectangle, the ellipse, and the text, thanks - that's a great example! So everything is fine up to the point your example goes to, but here's a followup step to be performed some time after the UI has already become visible. (So we're adjusting a UI that's already on screen.) This step shows the problem:
Perform the following operation: go back and change the transform on the Ellipse.
In Avalon, the compositor will handle the UI update - once you have changed the transform (i.e. just set a property on the relevant transform object), the ellipse's appearance will be changed appropriately. (So if you applied a rotation to the transform, the ellipse will rotate, but everything else will stay still.) You don't need to regenerate the imagery - it's enough to simply adjust the transform and the compositor does the rest.
In Quartz, the instruction "go back and change the transform on the Ellipse" don't even make sense. That's not something you can do because Quartz doesn't retain the transform - the transform was an object you created whilst doing the drawing, and even if you did hold onto it in your program, adjusting it later on won't have any impact on the display. As far as the Quartz 2D API is concerned, it's a transient entity.
With Quartz, what you've got after performing those drawing operations is a single surface containing the combined otuput of those three drawing primitives. If you want to rotate the ellipse, you have no choice but to clear the surface, and redraw the whole thing, using a suitably modified transform for the ellipse. In fact that applies to *any* change - if you wanted to change the text you would also have to repaint the entire surface for each change.
Now what you *could* do in Quartz is create three seperate drawing surfaces, one for the rectangle, one for the ellipse, and one for the text, and get the compositor to combine them. Then if you want to adjust the ellipse's transform, it's no longer necessary to redraw everything. But you still have to reset and redraw the surface containing the ellipse.
That wouldn't be so bad, but this goes directly against what the developer guides recommend for Mac OS X. They say that surfaces are relatively heavyweight, particularly if you enable full composition for them. (It's actually recommended that if at all possible, you disable the compositor support for your drawing surfaces unless you really need it.) So this is a technique which can easily end up consuming a lot of resources in the display subsystem.
If you tried to use element-level composition for every single element in your UI, you'd grind the display system into the ground for anything but the most powerful systems. (Or the simplest UIs.)
Avalon is designed to allow you do just this however. And it's able to do so without killing perf because it uses vector-level retention rather than bitmap-level retention. This enables it to retain a much, much larger number of independently composable entities because it's a lot cheaper to hold the vectors than the bitmaps. (Retaining a 200x100 pixel rectangle in bitmap form requires about 80KB. It takes a lot less space to retain the description of the rectangle.)
Ultimately a certain amount of redrawing still goes on in Avalon. But there are two key advantages. (1) it's all done for you, simplifying the programming model. And (2), it's much faster: crucially, Avalon can decide when bitmap retention will be worth the extra memory, or when its more efficient for it to just redraw all your imagery for you. But even when it redraws, it doesn't need to go and hit your application - the display server can do all the recomposition itself. And it can even retain vectors as instruction sequences in the graphics card's memory. When it has chosen not to retain a bitmap, all it has to do to redraw the retained vectors is tell the GPU to go and execute those instructions, which will be a lot faster than having the application run its repaint code.
"Would the simple vector drawing example above be turned into a stream of low level drawing primitives and stored in memory to be replayed whenever a dirty region needs redrawn?"
It depends. As far as I've been able to tell from my experiments, sometimes it does this, and sometimes it does actually retain bitmaps as well. (It appears to retain bitmaps for complex bits of the display, for example. So if you have a page full of text, it appears to decide that it would take so long to redraw that every time, its worth allocating a bitmap to hold the image. So I'm assuming there are some heuristics it uses to decide whether to retain vectors and bitmaps, or just vectors.) -
macos x already works like this
2004-03-11 13:40:55 rosyna [Reply | View]
Isn't there a problem with using vectors all over the place if no current graphics card accelerates these operations? Wouldn't it make Avalon slightly slower than it could be if it used bitmaps (pre-rendered) only?
As for the compositing (both back windows and top windows), Quartz (or rather the drawing methods an application uses) supports compositing drawing of controls inside a window. It will only redraw the part of the view that is necessary and no other. The older method, QuickDraw, did not support this and an entire, large (usually the entire window) region had to be repainted to get the view hierarchy to redraw correctly.
You say that OS X didn't get vector support until Jaguar (10.2). What vector support is this that it got?
And a person much more intelligent than me tells me that Avalon doesn't support context shearing. Is this correct? The genie effect uses shearing.
It'd be super if OS X supported vector everything but right now vector everything is just too slow to base the entire GUI model off of. No matter the platform. -
macos x already works like this
2004-03-12 00:28:19 Ian Griffiths |
[Reply | View]
It's not that graphics cards are incapable of accelerating vector drawing operations. They are wholly capable of doing so, it's simply that neither Windows XP nor Mac OS X currently exploit that in their 2D drawing architectures. In the Windows world this is mostly because the focus of the graphics card companies has been on 3D performance, because gaming is the main application that drives their sales. I don't know why Mac OS X doesn't do it, but I would guess it was simply a case of Apple prioritising their development - it was more important for them to fix the compositor performance first.
Re: vector support, that wasn't quite what I said. I simply said that Quartz didn't *catch up* with GDI+ until 10.2. Specifically, I was thinking of all the gradient fill functionality wasn't there prior to 10.2. (Which is surprising when you first see Aqua as it looks like it's using that all over the place. Then you realise it's all done with bitmaps.) Prior to 10.2, Quartz's vector functionality was a subset of GDI+.
Yes, Quartz does now support compositing with a window, but last time I checked, the documentation tells you to avoid using this if possible, because the way Quartz does its composition means that it's pretty heavy on the memory consumption. (For the reasons I described in my previous entry.)
By 'context shearing' I assume your acquaintance is referring to non-linear transforms. (Avalon does support shearing, but that's a linear transform. You couldn't use it to do the genie effect, because that uses a non-linear transform.) In today's builds of Avalon (which Microsoft describe as a pre-alpha developer preview, remember) it's true that only linear transforms are available. These include scaling, rotation, translation, and shearing. However, future builds of Longhorn are very likely to support other effects. For example, perspective transforms (which are non-linear) have been explicitly mentioned as something they want to add. And given the way that Avalon's architecture works, there's no reason for them not to support these transforms, it's just that the current bits don't happen to do so. So the person is correct for the current very early preview build of Avalon, but that is going to change.
Vector drawing is demonstrably fast enough: all modern 3D games use vector-based drawing and composition to build their displays, using increasingly large numbers of elements. (There are texture bitmaps of course, but a typical frame from a 3D game contains very large numbers of vectors.) These routinely achieve high redraw rates - games would be unplayable if they didn't. So if the GPU is exploited properly, it is clear that vectors definitely can be fast enough. It's just that neither Windows nor Quartz currently have the right architecture - GDI+ and Quartz 2D are both relatively slow at drawing vectors. But DirectX and OpenGL performance indicates that given the right approach to acceleration, vectors can be plenty fast enough. Faster than bitmap-based approaches in many cases. -
macos x already works like this
2004-03-14 10:23:25 mweiher [Reply | View]
I think it would be easier if you separated defending your article (which rightfully addresses the needs of Windows developers) from trying to refute the statement "macos x already works like this".
The fact is that Mac OS X already *does* work mostly like this, except for retained vectors within the graphics API, and wether this is a good thing or not is at the very least debatable (I don't agree it is). I don't think you needed to dwell on Quartz, but a short reference to existing state of the art is almost always appopriate, if just to provide context.
With that out of the way, I do believe you made a number of statements in your replies that need to be addressed.
1. High DPI displays
Quartz will be quite capable of adapting to high DPI displays, just not using the mechanism you envisage. In fact, Quartz uses the PDF/Postscript imaging model, which as you may recall, is device independent and theoretically arbitrarily scalable, and practically scales at least to imagesetter and film-printers, with around 2500 dpi, and has done so for a couple of decades.
The mechanism is quite simple and has been in uses for several decades: apply a device-transform with a higher scale factor before any other rendering is done. Voilá, you get a bitmap rendered at a higher resolution.
Your proposed mechanism of applying a compositing transform to the completed Window is unlikely to work well even in the Windows world, because it assumes that *all* drawing by *all* applications will use the retained vector API. This assumption seems unlikely unless non-retained APIs are removed, and completely hopeless once you consider legacy applications.
2. "You have to do your own redrawing"
This is false. Or more precisely, this really depends on who you mean with "you". If you mean "some entity outside the low graphics library", then it is technically true. However, if you mean "you, the developer", this is simply false (and since you put this under "it makes life easier for the developer:", that seems the only reasonable definition).
Most modern app development on Mac OS X is done using the Cocoa frameworks, and these will handle the refresh logic, calling your redraw methods when necessary (and appropriately clipped) without you being aware of it.
You might reasonably counter that this goes outside the scope of graphics APIs, and the answer is that yes it does. However, just because something isn't handled by a particular API doesn't mean it isn't handled, and just possibly a retained-mode graphics API isn't the best way of handling this situation.
[I would argue that it is not]
3. "big limitation: there is no vector-level retention"
You assert that this is a big limitation. Unlike the other two points, which were factual errors, this is more of a value judgement that I can't factually refute quite as easily. However, I do disagree, and point out that your primary arguments supporting your assertion [1+2 above] have been shown to be factually incorrect.
3a. newness
The retained vector model is not new in any sense of the word, it is actually one of the oldest in town, with GKS and similar systems going back to the 70ies and before (anyone remember Tektronix storage tube displays? :-) )
Now that doesn't mean it is bad, just like claiming it is new doesn't make it good.
However, it should be noted that retained-mode graphics systems were the norm a while ago, and then were rejected in favor of immediate drawing, at least for 2D graphics. Attempts to reintroduce retained mode drawing such as QuickDraw GX did not meet with success.
3b. drawing using the GPU vs. unified imaging model
You seem to assume that drawing via the GPU is inherently "better" or "more advanced", without apparently even considering the possibility that *not* drawing via the GPU may be a conscious design decision.
However, this was precisely the decision taken for DisplayPostscript and I am almost certain also for Quartz. The reason was/is that the Postscript/PDF imaging model is precisely defined (in a device independent manner, see above), and most GPUs simply don't draw precisely way, and even if some do, there is no guarantee of this.
You don't need to be convinced that this is a good idea, but at the very least it is an alternative view and means that GPU-based drawing is not necessarily "better" or "more advanced", or "leap-frogging".
3c. (vector level) retention automatically fast(er)
Once you are not drawing retained vectors with the GPU, there is no particular reason why it should be faster than immediate mode drawing, and experience with DPS, for example, showed that it almost never was.
The reason for this is that you are doing extra work: building up the retained graphics representation from the application-level representation, and then drawing that. Drawing directly from the application-level representation eliminates one step.
3d. (vector level) retention makes for easier APIs
As I already showed above, it is not true that vector-level retention automatically makes for less work by the programmer.
In fact, retained mode APIs tend to make things more complicated, not easier. The reason is that almost all applications will already *have* a retained-mode representation of whatever it is they want to draw, in application-level terms.
This will be true in every case where the application-level model is not exactly the same as the retained-mode graphics model that the API offers. I can't imagine an application where this will *not* be the case, except maybe for a trivial "Avalon" viewer.
So you end up simultaneously maintaining *two* models, instead of just one, and trying to propagate changes between them. Doing this via "diffs", which is the advantage you are proposing, is very complex and error prone. So complex that I am not going to go into too much detail here.
All this extra complexity for what? Supposedly faster 2D drawing. Hmm....I just profiled TextEdit during live resize, and actual drawing was a negligible percentage of total CPU usage. So what are we gaining here? Optimizing a small fraction of an operation that is already fast enough, with no guarantee that the "optimization" will actually be an improvement.
That isn't just premature optimziation, that is completely superluous optimization. Classical "Mount Everest Syndrome".
4. Quartz Extreme and Window Level compositing
Another factual error: window-level compositing is not a feature of Quartz Extreme. It was always in Quartz, Extreme just made things faster by putting the compositor on the graphics board.
I find it interesting that you think that hardware support and feature support are intrinsically linked, because that is exactly the way Avalon seems to be going...
-
macos x already works like this
2004-03-15 05:51:48 Ian Griffiths |
[Reply | View]
"The fact is that Mac OS X already *does* work mostly like this, except for retained vectors"
But my point is that the retained vectors are crucial.
But other than this fundamentally important feature, yes, very roughly speaking, Mac OS X more or less works this way. I say "roughly speaking" because there is still the issue that the compositor and the 2D drawing APIs are two seperate entities. (At least that's what Apple's documentation shows in all the pictures of Quartz's architecture.) In Avalon, composition and drawing are tightly linked.
To answer your points:
(1) This PDF/Postscript thing keeps coming up. I think I already said this, but just to be clear, that's entirely internal to the Quartz 2D API, and has absolutely no bearing on the Quartz Compositor which is, as far as I can tell, resolutely bitmap based.
Try taking a screen grab using the Shift-Command-3 shortcut. This produces a PDF. When I first saw that, I thought, "Aha, this must be because Quartz uses the PDF/Postscript imaging model." But look at the PDF - it contains a big bitmap. If you zoom in on it, everything pixellates. Why? Presumably it's because displaying a window involves composition, and the Quartz Compositor is *not* in fact PDF/Postscript based, it's bitmap based. So by the time you get to composition, the PDF/Poscript nature of the Quartz 2D API has been lost, and it's just so many pixels.
So while PDF files are theoretically able to scale to typesetting resolutions, the ones the come out of the Quartz compositor don't. Try to print one of these things out on a high resolution device, and voilá, you get a low quality pixellated image.
Perhaps there is some different way of getting PDFs of the display that I don't know about. If there is, please let me know. But Apple's documentation suggests that I shouldn't be surprised that these things are all pixel-based, because that's how they claim their compositor works. And unsurprisingly, the evidence backs them up.
The fact that these things pixellate doesn't bode well for the likely quality of support for high-DPI displays. And it's hardly surprising, given that the compositor offers a range of effects that are not, as far as I know, supported in PDF. (E.g., someone else mentioned non-linear transforms such as the Genie effect. Can you do that in a PDF without dropping down to bitmaps?)
By the way, I think Apple could mostly fix this in a future version if they want to. (It would require a significant change to Quartz's design, but I can't think of any fundamental reasons they couldn't do it if they really wanted. The only truly problematic thing that springs to mind is the way gradient fills require a callback function - makes it kind of hard to push that onto the pixel shaders...) I hope they do fix these issues in the future. I'm just saying how it appears to work at the moment - after all, that is the subject of the thread. But Apple need to start making moves in this direction now if they want to be ready for high DPI displays, which brings me onto the next point:
There seems to be a lack of leadership here from Apple - all of their graphical widgets appear to be bitmaps, not vector images. This means that even if the PDF-ness of Quartz 2D did manage to permeate all the way through to the composition level, what you'd see instead of one big bitmap is a PDF containing lots of individual bitmaps. This won't scale any better than one big bitmap.
Once again, I'd better point out that I'm not a Quartz expert, I'm just reporting my findings. If someone can tell me what I'm doing wrong, and show me evidence of resolution independence I'll happily admit to error. But so far, all the experiments I've tried point strongly towards the direction of purely bitmap-oriented composition. (As do all of Apple's architecture diagrams showing how the compositor relates to the other parts of Quartz.)
I have a couple of Macs, so just tell me what I should be doing to see evidence of this supposed resolution independence, and you'll make me happy. But for the meantime, I can only go on the basis of what Apple's documentation claims, and what I've seen with my own eyes.
"Your proposed mechanism of applying a compositing transform to the completed Window is unlikely to work well even in the Windows world, because it assumes that *all* drawing by *all* applications will use the retained vector API. This assumption seems unlikely unless non-retained APIs are removed, and completely hopeless once you consider legacy applications."
You are right that legacy applications are indeed a problem. The quality of display for those will be inferior to those of native Avalon applications. But for new applications, Microsoft are providing a strong and clear lead in telling everyone that vector-based UIs are the way to go. They're also providing tool support to make this easy in practice. I see no such leadership in this direction from Apple, which leads me to conclude that Apple don't regard this as important.
So I would agree that for today's Windows applications, high DPI will be less than completely satisfactory, and the same will be true for today's OS X applications. Both OSs will have to resort to the same tricks, resulting in less than ideal image quality. But for the future, Microsoft have made their strategy clear, and have made it equally clear what high DPI support will require from developers. I don't believe Apple have made their strategy for high DPI clear yet. I hope they do soon. (And I really hope they realise that the PDF/Postscript level drawing isn't the whole story - what worries me is the possibility that they don't even know they have a problem yet. Windows' GDI+ API uses a model which is almost identical, and it isn't a complete solution to the high DPI issue either, for the same reasons.)
(Of course, both Mac OS X and Windows could introduce partial solutions to these problems - they could apply bitmap scaling to those parts of the display relying on bitmaps, and high resolution versions of everything else. But this is a difficult area to get right - even when drawing with a resolution-independent API such as GDI+ or Quartz 2D, it's surprisingly easy to write code that only works properly at one resolution, and has some visual anomalies at any other resolution. That said, I think Quartz 2D will probably have fewer problems here than Win32.)
(2)
"Most modern app development on Mac OS X is done using the Cocoa frameworks, and these will handle the refresh logic, calling your redraw methods when necessary"
That would be an example of doing your own redrawing. The fact that OS X is calling your redraw methods is a clear indication that it has not retained your UI - if it were retaining the UI, why would it need to send you a message saying "Please redraw your UI?"
3. Yes, I continue to assert that the lack of vector-level retention is a key issue. I believe it is the cause of the problem mentioned above in point (1) - the pixel-based nature of the compositor's output. It's also the reason behind (2).
I'm well aware that vector retention is an old model. I considered writing a retrospective intro to the article on our industry's tendancy to revisit old solutions, but I was already over the requested length by a large factor...
The integration with the GPU is an important feature simply because it's the only way you're going to get adequate performance for anything other than static images or very simple animations. The frame rates achievable with OpenGL are far better than with Quartz 2D. And likewise on Windows, DirectX fares better than GDI+. So in both cases, the accelerated pipeline works far faster than the unaccelerated postscript-style API.
(The reason acceleration is faster, by the way, has nothing to do with how fast the drawing can be performed, by the way. It's all to do with minimizing the amount of data that needs to be sent across the bus to the GPU. The fact that the CPU may be able to render something as fast as the GPU would have is of no consolation if you now have to transfer 200K of data into the graphics subsystem, rather than a few hundred bytes.)
I understand your point that Apple may have painted themselves into a corner here by requiring precise rendering semantics that think cannot be achieved with acceleration, although I'm not sure that's still true with the latest generation of graphics cards. GPUs have moved away from the inflexible fixed pipeline architectures popular a few years ago, and now have a much more reconfigurable set of acceleration building blocks.
Microsoft made exactly the same decision with GDI+ as Apple did with Quartz 2D - these two APIs are more or less contemporaries, and both use software rendering because of the limitations of the hardware of the late 90s and early 2000s. These hardware restrictions no longer apply, so that decision looks a little outmoded now, which is why I think it's reasonable to say that accelerating the 2D pipeline is more advanced. An unaccelerated pipeline will become increasingly anachronistic.
More importantly though, software rendering becomes a performance liability. Now that these drawing operations can be accelerated, it makes little sense not to accelerate them, because it's very easy to max out the CPU and/or PCI bus (mostly the latter) with Quartz 2D, limiting use of animation. You can happily use animations for the other parts of Quartz - QuickTime, OpenGL and the compositor itself all enable animation just fine, because not much data needs to be sent to the graphics card for each change. But you just use animation in Quartz 2D except in very limited ways. (So it's OK for the highlighted button to pulse gently because that's a tiny screen area and doesn't require a very high update rate to get that effect. But anything more ambitious is likely to peg the PCI bus or CPU.)
You might argue that this is a good thing - too much animation is distracting and pointless. And poor use of animation is just that. But I regularly watch subtle but extremely effective use of animation to present information on television. But unless/until Quartz 2D gets acceleration, it's not going to have the performance to offer the quality of visualization that is commonplace on television.
(Also, remember that 'animation' effectively includes interactive stuff like the user picking something up and moving it around. The speed at which such drawing can be updated has a significant impact on the feel of the operation.)
3c. - your point is predicated on the assumption that 2D drawing with the quality offered by Quartz 2D and GDI+ can never be accelerated. As I said above, I believe this is no longer true, so I reject your conclusion on this point for that reason.
Perhaps Apple is betting the farm on the prediction that the advantage offered by current GPUs will be transient, and that they will win in the long run, because doing everything in the CPU is more flexible. And then you can just invoke Moore's law as the solution to any performance problems. Except I think that's a flawed strategy because it ignores one very important fact: the speed at which computers can move data from one piece of memory to another has not been keeping up with Moore's law. The trend for a long time now has been for memory speed to drop further and further behind the speed at which CPUs can execute instructions.
This is an aspect that worries me about Quartz 2d's current approach: it requires large bodies of data (the bitmaps generated by the Quartz 2D code on the CPU) to be shifted to an external memory system (the graphics card) any time anything changes. This is likely to be a bottleneck already, and will become a worse one as time goes one - Moore's law is the enemy of this graphics architecture, not its friend. (A different physical architecture for the display and memory systems might mitigate this, but can Apple really afford to stop using off-the-shelf GPUs and commission the design of custom graphics chips?)
3d "As I already showed above, it is not true that vector-level retention automatically makes for less work by the programmer."
I don't think you did show it, you just claimed it. You made two points. With the first, under your label '2', you missed something crucial - having the OS send your code a message saying "you must redraw now" is not the same as not having to redraw. It's pretty much the opposite in fact. And the second thing you mentioned was QuickDraw GX, which I have to admit I have no familiarity with.
Have you tried writing any code that targets Avalon? I'm guessing not from what you've written, in which case, what are you basing your claims on? It sounds like neither of us has enough common ground to agree on here - I suspect you've not used Avalon, and I've not used QuickDraw GX. All I can say is that so far, my experience with Avalon has been positive.
"you end up simultaneously maintaining *two* models"
I agree that this issue is a potential cause of trouble, but on the other hand, there are plenty of precedents for this kind of thing working just fine: there are controls today that retain information (but not the actual drawing), so this is hardly new. (Text controls and list controls being the two obvious examples. Even though the table views go through the data source object, you still need to perform work to keep the view and the source synchronized.)
The notion of maintaining seperate objects for your view and your model isn't a new one. I've written code for both this approach, and the imperative style used by Quartz 2D and GDI+, and so far, I prefer the retained model.
But programming styles are a very personal thing - you might well simply prefer the imperative style. Fortunately, Avalon lets you use that and still get most of the performance benefit of retention: the OS will retain any drawing you give it either declaratively or imperatively and not ask you to repaint until you send it a messages saying "this piece of the UI tree is out of date, I'd like to replace it with something else." In this style of programming, you still have a repaint method just like you do in Quartz, meaning that you're no longer obliged to sync up your model with the OS's (in both cases you just say "Junk what I gave you before - I want to redraw from scratch"). It's just that you only get the repaint requests when you tell the OS that something has changed. (So it actually feels more like the relationship between the NSTableView and its data source in Cocoa.) So you can have the same programming model that OS X and GDI+ use today if you really want it without paying too much of a performance hit. (There is some perf cost - rebuilding part of the UI tree is likely to be more expensive than adjusting it. But it's still better than having to recreate it every time the OS decides it needs to refresh the display!)
"Hmm....I just profiled TextEdit during live resize, and actual drawing was a negligible percentage of total CPU usage. So what are we gaining here? [...] That isn't just premature optimziation, that is completely superluous optimization."
What kind of Mac do you have? On my 1GHz G4 PowerBook, and also on my 866Mhz iMac, resizing of windows is pretty sluggish. It seems to do resizing at a much slower rate than, say, scrolling - it behaves as though the resize rate has actually been throttled back. It's certainly not resizing at an update rate that would be fast enough on either of my Macs to do smooth transitions. (It's noticably much less smooth than scrolling, dock animations and the like.) So is that actually a realistic way of measuring performance? You're measuring something which (on both my Macs at least) is visibly obviously not going fast enough.
(Of course it could be that resizing is a difficult operation for the Quartz Extreme engine - because Quartz uses a bitmap-based composition model, it will have to rejuggle all of its composition buffers when things change sizes. So it's possible that in this particular scenario, the CPU load is low because everything is stalled waiting for the compositor; you may simply have pegged the GPU rather than the CPU. Remember that a maxed out composition engine won't max out the CPU on Quartz Extreme because with QE, composition is done by the graphics card. That's obviously speculation of course - I've no idea why resizing is so much slower than everything else in Quartz, but I'm definitely not the only person to have noticed the problem if the web is anything to go by.) -
macos x already works like this
2004-04-06 06:17:25 musnat [Reply | View]
I don't understand why you suddenly get personal, most probably because you are a mac idiot. Instead of trying to be to the point, you seem to be more agressive, despite the fact that the author is really trying to discuss the real issues.
By doing this, you void your whole posts, because it seems to me that they are either made-up or that you simply don't know enough about APIs and Quartz.
You already stopped discussing the real issues, you are trying to discussing your own stuff. You never attempted to understand what the author says, instead you seem to try to save Apple's ass here, thinking that if you somehow make the point that quartz is great and actually far more better, than you would be done.
Here is how things went.
A mac idiot claimed that Quartz is actually working the same way as Avalon, because he reads too much slashdot or mac magazines.
The author, as someone who knows what he is talking about refuted the idea.
Another mac idiot came in and said bunch of stuff which didn't say much with respect to the fact that quartz is not a revolutionary api after all. He sort of continued to attack the author, but suprisingly (to me) the author was very patient and still to the point.
Finally another mac idiot come in, who in this case seem to know more than other mac idiots, and again said bunch of stuff.
If you ask whether quartz is something like avalon or not, it is clear that it is not and that quartz is not something revolutionary and that what you have in quartz is also in windows xp.
With all the mac idiots coming in, trying to attack the author personally, all we got is a long thread without much substance from the mac idiots. I don't get this, why are you guys so stupid? -
macos x already works like this
2004-03-17 04:33:50 Ian Griffiths |
[Reply | View]
Oh one more thing...
(For those interested in this discussion, please note that O'Reilly's forums seem to be chopping the conversation off once the replies get more than 13 levels deep. If you click on the "View" link under mweiher's post of 2004-03-15 13:58:01 you'll see that I replied, even though that reply does not show up on the main page. And then I replied again when the first reply seemed not to have appeared...oops!)
We seem to have moved onto arguing over the relative merits of vector vs bitmap retention, and the right place of the compositor in relation to the drawing mechanisms.
Does this mean that we can all at least agree that macos x does not in fact work like this today? (Despite what the subject line says.) -
macos x already works like this
2004-03-15 13:58:01 mweiher [Reply | View]
1. "But my point is that the retained vectors are crucial."
Yes, it is obvious that you think so. But this is just your claim. Alas, you seem to not even have attempted to understand the points I have raised, so I am not sure wether continuing this discussion is going to be useful. I am going to give it one more shot
2. "This PDF/Postscript thing keeps coming up."
Yes, it will continue to come up until you begin to understand it. Quartz has a device independent imaging model, implemented by the Quartz 2D renderer and based on the Postscript/PDF imaging model. It is not tied to screen resolution.
First of all, let's be clear about one thing: Quartz is not DPS, it is not "DisplayPDF", it is rendering engine closely tied to the PS/PDF *imaging model*, in such a way that calls to CoreGraphics API correspond closely to PDF 'operators'. That way, PDF can be used as the 'storage' for a stream of CoreGraphics commands.
Second, despite your fixation on "Quartz compositor", the part that actually does the rendering is "Quartz 2D". The compositor just handles "windowing services", meaning mostly the interaction between different application's windows, such as the various bits of transparency between windows (translucent titles, menu-bars, drop-shadows).
I am not sure why you are so fixated with the compositor, or what led you to believe that this is the part to look at. Maybe it is because Avalon pushed its rendering back to the last step, or because Windows uses multitudes of composed Windows for a lot of its drawing. Whatever the reason, the Quartz compositor is (essentially) just for handling what you would refer to as "top level" windows and how they interact.
This has *nothing* to do with an applications drawing objects into its window(s), wether with transparency or not. That is all handled by the Quartz 2D rasterizer, the drawing engine if you will. Once again, increasing the resolution of the output of Quartz 2D simply means concatenating a device-(scale)-matrix before you do the rest of your drawing. I do this all the time, and you get beautiful high-resolution bitmaps. In fact, this is how Quartz rasterizes for bitmap printers.
I have to admit I am somewhat flabbergasted by your screen-grab example and your mention of PDFs coming out of the compositor. I can only assume you were hurried and didn't think your response through.
PDFs go *into* Quarz 2D (the rasterizer part), they don't come *out* of it. Also, they go into Quartz 2D (again, the rasterizer) not the compositor. Once they have been rasterized, they are, of course, rasters. What did you think a rasterizer does?
Anyway, I have to agree that Apple does make things confusing by saving the (bitmap) screenshots in PDF format, because they are really just bitmaps. However, and repeating redundantly just to make sure, that is *after* rasterization.
The way to handle other resolutions is, of course, not *after* rasterization, because then you will obviously be scaling rasters, but *during* rasterization. And, repeating myself, the process is simple: just supply a different initial transformation matrix (or device matrix in PS/PDF terms). And yes, this works today, though of course not when going to screen, where you'd just get a bigger bitmap, not a higher-resolution one...
So once again, you are looking at the wrong thing. The compositor is not the part that handles what you want to do, Quartz 2D is. And it handles it just fine. And yes, Quartz 2D also handles transparency (and any compositing it may have to do internally to achieve transparency effects).
I am getting the feeling that you have been misled to believe that all transparency handling (all 'compositing') is handled by the Quartz compositor. This is not the case (or at least not visible). Once again, Quartz 2D handles this just fine.
I have written a Postscript interpreter that can be hooked up to Quartz to do its rendering, resulting in a little live PS viewer with live output.
The Postscript code shown below results in black text shining through the translucent red rectangle painted on top of it:
0 setgray
/Times-Italic 50 selectfont
50 150 moveto (This is an example of Quartz transparency!) show
1 0 0 setrgbcolor
.5 setalpha
100 100 200 200 rectfill
The result can be seen here:
quartz2d_transparency.tiff
[Note: this is actually different from the way DisplayPostscript handled transparency, where painting the rectangle would have obscured the text below using the standard painter algorithm. The transparency would only have mattered if the resulting bitmap were later composited with another bitmap. I am guessing that this is actually close to the way you are thinking about it, but that is NOT the way Qartz works. Quartz applies the transperency immediately]
This will render at any resolution I want it to, not buts about it and nor jaggies from bitmap scaling. Of course, drawing this results in some sort of compositing operation occuring internally, but how this is handled is up to Quartz 2D.
In fact, the compositor is for the most part not even a publically accessible API. I am guessing that you got confused because Avalon seems to mix these functions up into one.
So to sum up: Quartz 2D can handle higher resolutions just fine, including rendering transparency, which may or may not include a hidden "compositing" step, without scaling bitmaps. This compositing step has nothing to do with the Quartz compositor (unless possible internally) and preserves full resolution.
3. "doing your own redrawing"
My comments already contained a reply to your reply, but maybe it was a bit terse, so I will try to expand.
Once again, you put this point under "it makes life easier for the developer:". So the question is *not* "does OS X retain graphics", it does not. The question is wether your assumption that not having graphics that are retained by the OS means extra developer burden is correct.
Your assumption that this means extra burden is not correct. With Cocoa, the *developer* does not have to do anything extra.
Let's examine this step by step.
At some point, the developer's code has to somehow draw/paint/define the display. Agreed?
With Cocoa, this is done once, in the View's -drawRect: method. That is all there is.
With a retained drawing model, your application also has to do this (at least) once. So at this point were are even. Agreed?
The difference you want to see is when a redraw happens. Agreed?
So let's see what happens in the retained drawing case. Part of the system software (the graphics subsystem) notices it needs to regenerate part of the display. It consults the model it has been passed (a display list) to regenerate that part of the display. Easy, no new code for the programmer to write.
So now let's see what happens in Cocoa's case. Part of the system software (the Cocoa framework) notices it needs to regenerate part of the display. It consults the display model the programmer (already) defined (the NSView hierarchy) to regenerate the part of the display. Also no new code for the programmer to write because the framework just uses the code from above.
From the *developer's* point of view the two are absolutely equivalent: no extra code to handle the update event.
And it was *developer* ease of use that you claimed was the advantage.
Of course, there *is* a difference in that it is actually the application's code that is being exercised in the redraw in the Cocoa case, but that is a question of how system-software is partitioned, not a question of developer ease of use.
To sum up:
4. Lack of retained graphics is a core issue
I hope I have managed to communicate more effectively why the problems that you think exist ( "high dpi" , "more programmer work") actually do not.
5. GDI+ vs. Quartz
You keep claiming that GDI+ is somehow up to the level of Quartz. This is simply not the case. GDI+ is, from an imaging model point of view, much more like DisplayPostscript (around 1989).
6. Speed
There are actually a number of smaller factual errors that I am not going to go into now, this post is already too long. However, I seem to have not managed to get the point of my TextEdit rescaling example across at all. I will have to do better.
You say: "Of course it could be that resizing is a difficult operation for the Quartz Extreme engine"
This isn't even close.
What the profile showed that most of the time was *not* spent rendering graphics. It was spent on the *application* side, not in the graphics subsystem. It was spend recalculating the line-layout, doing typography, not rendering it.
So the graphics subsystem (Quartz 2D, not Quartz Extreme, which is just a marketing name for the hardware accelerated compositor that isn't really much involved here at all, see above) is not the limiting part of this. If we could drop in Avalon and Avalon were infinitely fast, it would hardly speed this operation up at all.
Is it at all clear what I am saying here? If you have an operation (a live resize), with 90% of the time being taken up by recalculating your line-layouts, and 10% by redraws, then accelerating the 10% part is not going to have a significant effect on performance.
And of course, if you actually do junk the entire retained model each time you update the application model, then you are not going to gain any performance, because you are actually doing *more* work by building up this model that you then promptly destroy. Trust me, this has been hashed out before...
To sum up: graphics subsystem performance is not the limiting factor of the TextEdit live-redraw, making redraw faster would have negligible effect on performance.
7. Other issues
There are actually a whole number of other issues that need to be addressed, but these are a bit more subtle and complex than the very simple issues here. So I don't think there is much of a point of starting on those before the much more simple (mostly basic factual errors) here have been dealt with.
Summary:
- The immediate-drawing model of Quartz 2D does not have the "problems" you think you identified (inherently incapable of handling higher res displays, more work for the developer)
- Quartz 2D renders vector graphics with correct transparency effects today, at any resolution desired (subject to implementation limits). You do not have to invoke the Quartz compositor to do this, the Quartz compositor is used for different tasks. (The implementation probably uses compositing operators to achieve these effects, this is hidden).
- Lack of retained graphics is not a "core issue", it is an implementation choice.
- Drawing performance is not the limiting factor for "normal" applications, even with during highly interactive and graphics-intensive operations.
-
macos x already works like this
2004-04-06 06:16:16 musnat [Reply | View]
I don't understand why you suddenly get personal, most probably because you are a mac idiot. Instead of trying to be to the point, you seem to be more agressive, despite the fact that the author is really trying to discuss the real issues.
By doing this, you void your whole posts, because it seems to me that they are either made-up or that you simply don't know enough about APIs and Quartz.
You already stopped discussing the real issues, you are trying to discussing your own stuff. You never attempted to understand what the author says, instead you seem to try to save Apple's ass here, thinking that if you somehow make the point that quartz is great and actually far more better, than you would be done.
Here is how things went.
A mac idiot claimed that Quartz is actually working the same way as Avalon, because he reads too much slashdot or mac magazines.
The author, as someone who knows what he is talking about refuted the idea.
Another mac idiot came in and said bunch of stuff which didn't say much with respect to the fact that quartz is not a revolutionary api after all. He sort of continued to attack the author, but suprisingly (to me) the author was very patient and still to the point.
Finally another mac idiot come in, who in this case seem to know more than other mac idiots, and again said bunch of stuff.
If you ask whether quartz is something like avalon or not, it is clear that it is not and that quartz is not something revolutionary and that what you have in quartz is also in windows xp.
With all the mac idiots coming in, trying to attack the author personally, all we got is a long thread without much substance from the mac idiots. I don't get this, why are you guys so stupid? -
macos x already works like this
2004-03-17 04:29:36 Ian Griffiths |
[Reply | View]
For some reason my previous post didn't get through, possibly because it had embedded URLs, so here it is again, but without the URLs...
"Alas, you seem to not even have attempted to understand the points I have raised"
Since I replied to every point that you raised, and explained which parts I was finding hard to understand or impossible to resolve with experimental evidence, that seems like a harsh comment. Particularly as I have been trying out code samples on both Mac OS X and the Longhorn preview to try and make sure that all my statements were based on real observations, rather than conjecture.
"Quartz has a device independent imaging model, implemented by the Quartz 2D renderer and based on the Postscript/PDF imaging model."
I've read this whole section of yours again, and nothing you say contradicts my current understanding. You've gone into a detailed explanation of a bunch of stuff I already knew... I don't disagree with anything you said about the relationship between Quartz 2D, PDF/poscript drawing primitives and the like. Neither does it have any bearing on what I'm trying to explain.
So I'm evidently not making my point clearly enough! But it occurs to me that I could express my view of what I think the problem is in a different way, because then it might be more clear what I'm on about. Here, in a nutshell, is the problem:
Just because your drawing API is resolution independent doesn't mean your GUIs are.
Why on earth would I say that? Mainly because of the extensive experience I've had over the last 15 years with three different drawing APIs that were all resolution independent, two of which were modelled closely on the drawing facilities of Postscript, and none of which yielded resolution-independent APIs.
The APIs in question are:
GDI32, the original Win32 drawing API
GDI+, the new Win32 drawing API
DrawingModule, the vector drawing section of the long-since-defunct RISC OS
GDI32 is and always has been resolution independent - not only does it support a variety of drawing units, it also supports arbitrary transformations - all drawing can be put through a world transform matrix that allows all the normal affine transforms. The only APIs that deal in actual pixels are the bitmap APIs.
GDI+ is the same. The main differences are that is supports a wider range of drawing primitives, and it also supports anti-aliasing and alpha blending.
The (rather obscure) RISC OS vector drawing facilities are pretty similar again - a set of vector drawing facilities providing the same basic set of primitives as Postscript, but because it's much older (introduced in 1987) it doesn't have any of the new stuff that GDI+ has like alpha blending.
All of these can perform the trick you showed with your postscript sample - you can stream out a series of drawing commands into a file, and then play them back at any resolution with no loss of precision. (In Win32 you do this with EMF files, GDI+ uses EMF+ files, and RISC OS had, if memory serves, what were called !Draw files.)
And yet none of these could scale the entire UI. They could all scale individual fragments of drawing, just like you showed, but that's the easy bit. The hard part is scaling the entire UI.
Why is that hard? Well, the key to this was revealed when you said this:
"Whatever the reason, the Quartz compositor is (essentially) just for handling what you would refer to as "top level" windows and how they interact.
"This has *nothing* to do with an applications drawing objects into its window(s), wether with transparency or not. That is all handled by the Quartz 2D rasterizer, the drawing engine if you will."
But you can put an OpenGL surface in a window. You can put a QuickTime surface in a window. These can both coexist in the same window as Quartz 2D stuff, and yet neither of these things are drawn by the Quartz 2D rasterizer are they?
So what you're saying doesn't appear to be consistent with reality - how can the window be built entirely by Quartz 2D when it contains non-Quartz-2D elements?
It is clear that a window in Mac OS X can be composed from multiple elements, not all of which are Quartz 2D elements. So what you say here cannot possibly be true, can it? Something must be composing the 2D stuff with the OpenGL stuff and the QuickTime stuff. If it's not the Quartz Compositor, then what is it? (And according to all of Apple's diagrams, it is the Quartz compositor. But you're saying this is not so. What do you think does this composition?)
If the inside of every window was a purely Quartz 2D world (which appears to be what you're saying, even though firing up the QuickTime player will disprove it pretty quickly) then yes, we would have instant scalability. And in the same way, if the inside of a window in a Windows application is a pure GDI32 world or a GDI+ world, then again you have full scalability.
But certainly in Windows, the problem is that you don't have just one GDI+ surface or one GDI32 context for a whole window. What you have is a bunch of little drawing areas composed together. And where Windows and RISC OS all fell short is that the technology that composed these windows together wasn't resolution independent.
You're telling me that Quartz doesn't suffer from this because you believe the compositor is irrelevant. So here's the thing I don't understand: if the compositor is irrelevant, how do QuickTime and OpenGL fit into all this? Are you saying that if I put down an NSMovieView in a window, it's not actually QuickTime that renders it, but the Quartz 2D engine? I'm guessing you won't claim that, in which case, how can these things end up side by side in one window without getting the compositor involved?
"I have to admit I am somewhat flabbergasted by your screen-grab example and your mention of PDFs coming out of the compositor. I can only assume you were hurried and didn't think your response through."
I was trying to see if I could find some concrete evidence to prove your claim that the UI is scalable to be correct. (Actually I first tried this experiment ages ago, back when I believed that the UI was scalable.)
Here's the thinking behind the experiment. There doesn't appear to be any way of scaling windows up on screen built in to OS X. (And the Expose stuff that scales things down *definitely* does bitmap scaling, not vector scaling.) So I was looking for some way of obtaining the contents of a window in scalable form.
PDFs are, as you say, normally scalable to very high resolutions, so given that the built-in screen grab shortcut generates a PDF, then surely if the whole UI is scalable, there's no good reason for that PDF not to be a scalable one. It should be possible for OS X to generate a PDF that contains a scalable version of what's in the window, if the whole UI really is scalable - it should be trivial in fact.
But as it happens, that's not what you get - it's just a bitmap. (I don't really see why they put it in a PDF if all they're going to produce is a bitmap...)
While that's disappointing, I'm aware that it's also inconclusive. If the PDF had been a proper vector PDF, then that would have proved your argument conclusively - it would have demonstrated the scalability of the UI by showing a scalable representation of the UI. However, the fact that it just produced a bitmap is odd, but inconclusive. (Particularly when it does this even for individual windows. I could see how a full screen grab would be problematic, as it has to show the drop shadows, but why would it need to use a bitmap for a single window? Unless perhaps it uses bitmap composition within windows too...)
The reason I described what I had done despite the inconclusive results was to illustrate the kind of thing I was hoping to see - a complete scalable representation of a window. I was hoping you'd show me something similar, but which actually works.
I understand that Quartz 2D isn't using PDF from end to end, and is instead using a repertoire of drawing primitives very similar to what PDF offers. (I've been using drawing APIs that work that way for 15 years now, so I've had a while to get used to the idea!) But that's not a reason for it *not* to generate resolution independent output from a screen grab, if, as you're claiming, the UI really is scalable. I know that the vector handling is not as simple as the screen being one big PDF, but nonetheless, it could just convert from its internal representation back to PDF at the last minute, as long as its internal representation really is completely vector-based. (After all, it's perfectly capable of letting you print to PDF. So the fact that it can't do the same with a window is suspicious.)
So the screen grab experiement is a failure. I mentioned it because I was hoping you were going to show me some technique for getting a scalable representation of a window.
Instead you showed me a little bit of postscript.
In other words you showed me the easy bit - scaling a bit of drawing, rather than scaling the whole UI. The three other drawing technologies I mentioned can all do that too. Even Win16 could do that with the WMF file format. (10 years ago I wrote a Windows program that used WMFs for all of its internal icons precisely because I wanted to be able to scale the drawings. And it works just fine. But I couldn't scale the rest of the UI.) The support for individual snippets of fully scalable drawing either held in internal data structures or serialized out to some stream has been in Windows for a decade and a half, and yet Windows does not have a scalable UI.
This is why I was trying to see if there was some way of getting a scalable representation of a whole window - that's the tricky part, and is the acid test of genuine UI resolution independence; rendering snippets proves nothing. The whole UI is tricky because it might not just contain a single Quartz 2D surface. It could easily contain other surfaces. This is precisely where Windows falls over. It was precisely where RISC OS fell over. So it seems likely that Mac OS X will fall over here too, since it really isn't significantly different from GDI+. (Despite what you appear to think GDI+ is. But I'll come back to that later.)
As I said before, just because your drawing API is scalable doesn't mean your UI will be, unless your UI uses nothing but your scalable drawing API. And Quartz supports multiple drawing APIs within a single window - that's the problem. (And because it has to support this, the support impinges on the design even when you're not using the functionality.)
I challenge you to show me an example demonstrating a whole *window* in a scalable form, toolbars title bars and all. I suspect it cannot be done. If you can show me an example of this, then great! I'm happy to believe evidence, and it will reverse the disappointment I expressed earlier int his thread. All the evidence I've seen from the experiments I've tried seem to indicate that it cannot. (And I've tried lots of things to see if it can be done - I initially just assumed that it could be done when I first got my Mac, because my understanding of how Quartz worked was, well, pretty much what you've described. I've since discovered that my understanding seems to have been a little oversimplified, and that it apparently can't do all the things I thought and you still do think it could do.)
"doing your own redrawing"
"Once again, you put this point under "it makes life easier for the developer:". "
That's one of the points, although not the only advantage. The other big advantage is perf - if the application is required to respond to redraw requests, it forces everything the app redraws to go across a bus to the graphics card in some form, and that bus is a major bottleneck.
But I did also make claims on easy of programming. As an example of how retained UI makes things easier, do you think that HTML pages would be as easy to author if you had to handle repaint messages, rather than simply declaring what you want on screen? I know loads of non-technical people who are quite capable of creating web pages. I believe there is a gulf between this level of ease of use and the ease of use of handling repaint requests from the OS. Do you really disagree with that?
"At some point, the developer's code has to somehow draw/paint/define the display. Agreed?"
Actually no - read my earlier article in this series on XAML for details. Or indeed learn about HTML.
(This is a complete new subject area by the way, and I know that it's kind of irritating when someone starts talking about something else in the middle of an argument, but you made that statement, and ask me if I agreed. I disagree strongly, and now feel compelled to explain why, so I apologise in advance for talking about a new topic. You did ask.)
A declarative UI model mandates a retained model, although a retained model does not require a declarative UI. So just to be clear, you can use either declarative+retained or imperative+retained in Avalon.
If you employ a declarative UI model, there is absolutely no need for developers to get involved with redrawing. They can just create the display with so much markup.
You shouldn't really be surprised at that, because that's not so very different from how you build UIs in OS X. The Interface Builder uses drag and drop while today, Microsoft don't have an interactive Avalon GUI builder ready, but that will come. And while Avalon uses markup, Interface Builder generates serialized objects, if I understand correctly. But it's still a case of telling the system "One of these here, one of those there" and letting it handle the detail without having to write any code to manage the UI. Where Mac OS X falls short is that you can only assemble existing components this way - it doesn't let you handle drawing primitives in this way, forcing you instead to write code to generate those primitives.
In my opinion, that's bad for ease of use.
It's also ridiculously easy for code to make use of stuff defined in the markup, so don't fall into the trap of thinking that this is only any use for static UIs. It's not so different from the HTML DOM (except you're not obliged to use a scripting language - any .NET-capable language will do) - everything you define in markup is an object, so you can write code to go and twiddle with it at runtime.
I wrote an example showing how to draw 'rubber band' outline selections without having to write a line of drawing code that illustrates both how you can use markup instead of code to create a UI, and also illustrates how that UI can still be dynamic. It's in the second half of this blog entry [URL removed; Google for: ian griffiths rubber band). I suggest you take a look - given the blanket statement you made, it sounds like you've not even considered this style of programming before. It might help you understand where I'm coming from. (Again I'd skip over the first part - that's mostly for the benefit of Windows developers, and will be old hat for anyone familiar with Quartz 2D.)
So no, I strongly disagree with your thesis that drawing is necessarily the programmer's job. (And since your thesis was the underpinning of everything that followed that section of your post, there's not a whole lot else I can say in reply. Your axioms are wrong, so the rest of the argument isn't useful.)
"I hope I have managed to communicate more effectively why the problems that you think exist ( "high dpi" , "more programmer work") actually do not."
Well... you've successfully explained how I used to think Quartz 2D works. But try as I might I can't find any way of proving that a window can necessarily be scaled, and I hope I've presented some issues that show that some kind of compositor that is not part of Quartz 2D is necessarily involved. So I now hope you can refute this with a simple example. I'm afraid that I'm the kind of person who prefers proof, so if you can't show me an example that demonstrates the scalability of an entire window (rather than just an isolated piece of graphics) you're going to have a hard time convincing me.
GDI+ vs. Quartz
"You keep claiming that GDI+ is somehow up to the level of Quartz. This is simply not the case. GDI+ is, from an imaging model point of view, much more like DisplayPostscript (around 1989)."
Could you be specific there? As far as I know there's nothing Quartz 2D can do that GDI+ can't. And GDI+ is way ahead of circa 1989 DPS - there's plenty GDI+ can do that display postscript can't. (You gave the example of transparency handling and how display postscript uses the painters algorithm. That's what GDI32 uses too. But it's not what GDI+ uses - you can specify alpha for any drawing operation in GDI+, just like you can in Quartz 2D.)
Moreover, until Jaguar came along, GDI+ was able to do things Quartz 2D couldn't. Quartz 2D didn't original support gradient fills, for example, but these have been in GDI+ from the start.
Are you sure you're not confusing GDI+ with GDI32? Your description characterises GDI32 perfectly, but it's an inaccurate description of GDI+.
On profiling
"What the profile showed that most of the time was *not* spent rendering graphics. It was spent on the *application* side, not in the graphics subsystem. It was spend recalculating the line-layout, doing typography, not rendering it"
You don't consider line layout and typography to be graphics operations?
To be honest, you've not given enough detail for me to be able to draw any conclusions from your profiling. Any chance you could post what you actually found somewhere? This forum doesn't really make it easy to provide enough detail. For example, it now seems like you're saying the complete opposite of what you said last time about the profiling results. (I'm sure that's not what you thought you said, but that's honestly how it came across to me.)
"If we could drop in Avalon and Avalon were infinitely fast, it would hardly speed this operation up at all."
Layout and typography support is all part of what Avalon supplies, so that's not in fact correct. If Avalon were infinitely fast, it would make this operation infinitely fast.
Of course that has nothing to do with acceleration, since it's pretty unlikely that Avalon will hardware accelerate layout. I'm pretty amazed that it really is spending this much time in layout code, which is why I'm intrigued to see your actual profiling results. From what you've told me so far, the most likely explanation would seem to be that the layout code is a bit crappy - maybe you've just found a weak spot of Quartz 2D. However, I don't think that's the whole story - resize performance is pretty ropey on *all* windows on all Macs I've ever used (all the ones using OS X at least). Even on a little program that draws nothing but a single ellipse in a resizable view, and I'm pretty sure that program isn't spending all its time laying out text because there was no text...
So if you can share it I'd love to see your profiling setup and the data you generated.
"And of course, if you actually do junk the entire retained model each time you update the application model, then you are not going to gain any performance, because you are actually doing *more* work by building up this model that you then promptly destroy. Trust me, this has been hashed out before..."
But that's exactly the model you've been saying is so fine in Quartz 2D! There you absolutely have to reconstruct the entire model every time you get sent a redraw request.
Also, you're ignoring what I said about the problems of a software 2D engine (regardless of whether drawings are retained) - the gap between bus transfer speeds and CPU speeds gets ever higher, so any model that rasterizes on the CPU and then transfers the results across a bus to the graphics card is going to find that transfer becoming a more and more glaring bottleneck.
It has indeed been hashed out before - the games industry has been hashing this out for years now, the introduction of GPU-side vertex handling indicates that they've all settled on a retained model, and they long since settled on moving rasterization into the GPU. This is the prevailing approaches because it's the only one that scales to the complexity and speed they need. So it's been hashed out before, the end-to-end-vectors model won long ago, and the consensus amongst graphics card manufacturers seems to be that vector retention model is also the way to go!
"Summary:"
"- The immediate-drawing model of Quartz 2D does not have the "problems" you think you identified (inherently incapable of handling higher res displays, more work for the developer)"
Until you produce convincing evidence, I have to believe what the Apple docs and my experiments tell me. Rendering snippets is not convincing, because even 16-bit Windows can do that in a resolution independent way. Show me a bitmap containing a whole window at double the resolution (or a PDF, or a postscript file - whatever is easiest), and I'll believe you. My challenge to you is that I don't believe this can be done without bitmap scaling.
"- Quartz 2D renders vector graphics with correct transparency effects today, at any resolution desired (subject to implementation limits)."
Also true of GDI+. None of which alters the fact that GDI+ hasn't solved Windows' lack of resolution independence.
"You do not have to invoke the Quartz compositor to do this, the Quartz compositor is used for different tasks. (The implementation probably uses compositing operators to achieve these effects, this is hidden)."
Of course it uses compositing operators to achieve this - otherwise you'd only ever see the last drawing primitive you drew! But of course it's a different code path from the Quartz Compositor, because Quartz 2D is all software.
"- Drawing performance is not the limiting factor for "normal" applications, even with during highly interactive and graphics-intensive operations."
The two most highly graphics-intensive kinds of applications around today are video editing and 3D work. Neither of these use the Quartz 2D pipeline.
It's true that for static form-like displays, Quartz 2D performance is adequate. But it doesn't take long to hit its limits if you try to do anything ambitious. If you have access to a box running Longhorn (and make sure it's one with a supported graphics card), try running this extremely simple drawing demo (URL removed; google for:ian griffiths zoom xaml). Compare the smoothness of response with Adobe Illustrator on a Mac. (Illustrator's pretty slow even with very simple drawings.) Particularly notice how you can zoom in and out smoothly in realtime with a drag operation. Compare this to how Illustrator only works in chunks and takes about half a second to change zoom factor.
(Just to reiterate, you will need a PC with a suitable graphics card. Because the Longhorn Developer Preview is a very early release, it supports only a small set of graphics cards. If it doesn't know your graphics card and therefore drops down to software rendering, the results will be rather disappointing. Although it's a pretty good example of why you don't want software rasterization...)
I believe this demonstrates that a faster drawing engine enables styles of user interaction that simply weren't possible before. You say that drawing performance is not a limiting factor. I think that its an ubiquitous constraint we all learnt to live with so long ago that we work within its limits without even thinking about it. Liberation from these restrictions gives us the opportunity to enhance usability no end. It's not about making existing things faster, it's about enabling things that were previously impossible.
-
macos x already works like this
2004-03-16 04:43:14 Ian Griffiths |
[Reply | View]
"Alas, you seem to not even have attempted to understand the points I have raised"
Since I replied to every point that you raised, and explained which parts I was finding hard to understand or impossible to resolve with experimental evidence, that seems like a harsh comment. Particularly as I have been trying out code samples on both Mac OS X and the Longhorn preview to try and make sure that all my statements were based on real observations, rather than conjecture.
"Quartz has a device independent imaging model, implemented by the Quartz 2D renderer and based on the Postscript/PDF imaging model."
I've read this whole section of yours again, and nothing you say contradicts my current understanding. You've gone into a detailed explanation of a bunch of stuff I already knew... I don't disagree with anything you said about the relationship between Quartz 2D, PDF/poscript drawing primitives and the like. Neither does it have any bearing on what I'm trying to explain.
So I'm evidently not making my point clearly enough! But it occurs to me that I could express my view of what I think the problem is in a different way, because then it might be more clear what I'm on about. Here, in a nutshell, is the problem:
Just because your drawing API is resolution independent doesn't mean your GUIs are.
Why on earth would I say that? Mainly because of the extensive experience I've had over the last 15 years with three different drawing APIs that were all resolution independent, two of which were modelled closely on the drawing facilities of Postscript, and none of which yielded resolution-independent APIs.
The APIs in question are:
GDI32, the original Win32 drawing API
GDI+, the new Win32 drawing API
DrawingModule, the vector drawing section of the long-since-defunct RISC OS
GDI32 is and always has been resolution independent - not only does it support a variety of drawing units, it also supports arbitrary transformations - all drawing can be put through a world transform matrix that allows all the normal affine transforms. The only APIs that deal in actual pixels are the bitmap APIs.
GDI+ is the same. The main differences are that is supports a wider range of drawing primitives, and it also supports anti-aliasing and alpha blending.
The (rather obscure) RISC OS vector drawing facilities are pretty similar again - a set of vector drawing facilities providing the same basic set of primitives as Postscript, but because it's much older (introduced in 1987) it doesn't have any of the new stuff that GDI+ has like alpha blending.
All of these can perform the trick you showed with your postscript sample - you can stream out a series of drawing commands into a file, and then play them back at any resolution with no loss of precision. (In Win32 you do this with EMF files, GDI+ uses EMF+ files, and RISC OS had, if memory serves, what were called !Draw files.)
And yet none of these could scale the entire UI. They could all scale individual fragments of drawing, just like you showed, but that's the easy bit. The hard part is scaling the entire UI.
Why is that hard? Well, the key to this was revealed when you said this:
"Whatever the reason, the Quartz compositor is (essentially) just for handling what you would refer to as "top level" windows and how they interact.
"This has *nothing* to do with an applications drawing objects into its window(s), wether with transparency or not. That is all handled by the Quartz 2D rasterizer, the drawing engine if you will."
But you can put an OpenGL surface in a window. You can put a QuickTime surface in a window. These can both coexist in the same window as Quartz 2D stuff, and yet neither of these things are drawn by the Quartz 2D rasterizer are they?
So what you're saying doesn't appear to be consistent with reality - how can the window be built entirely by Quartz 2D when it contains non-Quartz-2D elements?
It is clear that a window in Mac OS X can be composed from multiple elements, not all of which are Quartz 2D elements. So what you say here cannot possibly be true, can it? Something must be composing the 2D stuff with the OpenGL stuff and the QuickTime stuff. If it's not the Quartz Compositor, then what is it? (And according to all of Apple's diagrams, it is the Quartz compositor. But you're saying this is not so. What do you think does this composition?)
If the inside of every window was a purely Quartz 2D world (which appears to be what you're saying, even though firing up the QuickTime player will disprove it pretty quickly) then yes, we would have instant scalability. And in the same way, if the inside of a window in a Windows application is a pure GDI32 world or a GDI+ world, then again you have full scalability.
But certainly in Windows, the problem is that you don't have just one GDI+ surface or one GDI32 context for a whole window. What you have is a bunch of little drawing areas composed together. And where Windows and RISC OS all fell short is that the technology that composed these windows together wasn't resolution independent.
You're telling me that Quartz doesn't suffer from this because you believe the compositor is irrelevant. So here's the thing I don't understand: if the compositor is irrelevant, how do QuickTime and OpenGL fit into all this? Are you saying that if I put down an NSMovieView in a window, it's not actually QuickTime that renders it, but the Quartz 2D engine? I'm guessing you won't claim that, in which case, how can these things end up side by side in one window without getting the compositor involved?
"I have to admit I am somewhat flabbergasted by your screen-grab example and your mention of PDFs coming out of the compositor. I can only assume you were hurried and didn't think your response through."
I was trying to see if I could find some concrete evidence to prove your claim that the UI is scalable to be correct. (Actually I first tried this experiment ages ago, back when I believed that the UI was scalable.)
Here's the thinking behind the experiment. There doesn't appear to be any way of scaling windows up on screen built in to OS X. (And the Expose stuff that scales things down *definitely* does bitmap scaling, not vector scaling.) So I was looking for some way of obtaining the contents of a window in scalable form.
PDFs are, as you say, normally scalable to very high resolutions, so given that the built-in screen grab shortcut generates a PDF, then surely if the whole UI is scalable, there's no good reason for that PDF not to be a scalable one. It should be possible for OS X to generate a PDF that contains a scalable version of what's in the window, if the whole UI really is scalable - it should be trivial in fact.
But as it happens, that's not what you get - it's just a bitmap. (I don't really see why they put it in a PDF if all they're going to produce is a bitmap...)
While that's disappointing, I'm aware that it's also inconclusive. If the PDF had been a proper vector PDF, then that would have proved your argument conclusively - it would have demonstrated the scalability of the UI by showing a scalable representation of the UI. However, the fact that it just produced a bitmap is odd, but inconclusive. (Particularly when it does this even for individual windows. I could see how a full screen grab would be problematic, as it has to show the drop shadows, but why would it need to use a bitmap for a single window? Unless perhaps it uses bitmap composition within windows too...)
The reason I described what I had done despite the inconclusive results was to illustrate the kind of thing I was hoping to see - a complete scalable representation of a window. I was hoping you'd show me something similar, but which actually works.
I understand that Quartz 2D isn't using PDF from end to end, and is instead using a repertoire of drawing primitives very similar to what PDF offers. (I've been using drawing APIs that work that way for 15 years now, so I've had a while to get used to the idea!) But that's not a reason for it *not* to generate resolution independent output from a screen grab, if, as you're claiming, the UI really is scalable. I know that the vector handling is not as simple as the screen being one big PDF, but nonetheless, it could just convert from its internal representation back to PDF at the last minute, as long as its internal representation really is completely vector-based. (After all, it's perfectly capable of letting you print to PDF. So the fact that it can't do the same with a window is suspicious.)
So the screen grab experiement is a failure. I mentioned it because I was hoping you were going to show me some technique for getting a scalable representation of a window.
Instead you showed me a little bit of postscript.
In other words you showed me the easy bit - scaling a bit of drawing, rather than scaling the whole UI. The three other drawing technologies I mentioned can all do that too. Even Win16 could do that with the WMF file format. (10 years ago I wrote a Windows program that used WMFs for all of its internal icons precisely because I wanted to be able to scale the drawings. And it works just fine. But I couldn't scale the rest of the UI.) The support for individual snippets of fully scalable drawing either held in internal data structures or serialized out to some stream has been in Windows for a decade and a half, and yet Windows does not have a scalable UI.
This is why I was trying to see if there was some way of getting a scalable representation of a whole window - that's the tricky part, and is the acid test of genuine UI resolution independence; rendering snippets proves nothing. The whole UI is tricky because it might not just contain a single Quartz 2D surface. It could easily contain other surfaces. This is precisely where Windows falls over. It was precisely where RISC OS fell over. So it seems likely that Mac OS X will fall over here too, since it really isn't significantly different from GDI+. (Despite what you appear to think GDI+ is. But I'll come back to that later.)
As I said before, just because your drawing API is scalable doesn't mean your UI will be, unless your UI uses nothing but your scalable drawing API. And Quartz supports multiple drawing APIs within a single window - that's the problem. (And because it has to support this, the support impinges on the design even when you're not using the functionality.)
I challenge you to show me an example demonstrating a whole *window* in a scalable form, toolbars title bars and all. I suspect it cannot be done. If you can show me an example of this, then great! I'm happy to believe evidence, and it will reverse the disappointment I expressed earlier int his thread. All the evidence I've seen from the experiments I've tried seem to indicate that it cannot. (And I've tried lots of things to see if it can be done - I initially just assumed that it could be done when I first got my Mac, because my understanding of how Quartz worked was, well, pretty much what you've described. I've since discovered that my understanding seems to have been a little oversimplified, and that it apparently can't do all the things I thought and you still do think it could do.)
"doing your own redrawing"
"Once again, you put this point under "it makes life easier for the developer:". "
That's one of the points, although not the only advantage. The other big advantage is perf - if the application is required to respond to redraw requests, it forces everything the app redraws to go across a bus to the graphics card in some form, and that bus is a major bottleneck.
But I did also make claims on easy of programming. As an example of how retained UI makes things easier, do you think that HTML pages would be as easy to author if you had to handle repaint messages, rather than simply declaring what you want on screen? I know loads of non-technical people who are quite capable of creating web pages. I believe there is a gulf between this level of ease of use and the ease of use of handling repaint requests from the OS. Do you really disagree with that?
"At some point, the developer's code has to somehow draw/paint/define the display. Agreed?"
Actually no - read my earlier article in this series on XAML for details. Or indeed learn about HTML.
(This is a complete new subject area by the way, and I know that it's kind of irritating when someone starts talking about something else in the middle of an argument, but you made that statement, and ask me if I agreed. I disagree strongly, and now feel compelled to explain why, so I apologise in advance for talking about a new topic. You did ask.)
A declarative UI model mandates a retained model, although a retained model does not require a declarative UI. So just to be clear, you can use either declarative+retained or imperative+retained in Avalon.
If you employ a declarative UI model, there is absolutely no need for developers to get involved with redrawing. They can just create the display with so much markup.
You shouldn't really be surprised at that, because that's not so very different from how you build UIs in OS X. The Interface Builder uses drag and drop while today, Microsoft don't have an interactive Avalon GUI builder ready, but that will come. And while Avalon uses markup, Interface Builder generates serialized objects, if I understand correctly. But it's still a case of telling the system "One of these here, one of those there" and letting it handle the detail without having to write any code to manage the UI. Where Mac OS X falls short is that you can only assemble existing components this way - it doesn't let you handle drawing primitives in this way, forcing you instead to write code to generate those primitives.
In my opinion, that's bad for ease of use.
It's also ridiculously easy for code to make use of stuff defined in the markup, so don't fall into the trap of thinking that this is only any use for static UIs. It's not so different from the HTML DOM (except you're not obliged to use a scripting language - any .NET-capable language will do) - everything you define in markup is an object, so you can write code to go and twiddle with it at runtime.
I wrote an example showing how to draw 'rubber band' outline selections without having to write a line of drawing code that illustrates both how you can use markup instead of code to create a UI, and also illustrates how that UI can still be dynamic. It's in the second half of this blog entry. I suggest you take a look - given the blanket statement you made, it sounds like you've not even considered this style of programming before. It might help you understand where I'm coming from. (Again I'd skip over the first part - that's mostly for the benefit of Windows developers, and will be old hat for anyone familiar with Quartz 2D.)
So no, I strongly disagree with your thesis that drawing is necessarily the programmer's job. (And since your thesis was the underpinning of everything that followed that section of your post, there's not a whole lot else I can say in reply. Your axioms are wrong, so the rest of the argument isn't useful.)
"I hope I have managed to communicate more effectively why the problems that you think exist ( "high dpi" , "more programmer work") actually do not."
Well... you've successfully explained how I used to think Quartz 2D works. But try as I might I can't find any way of proving that a window can necessarily be scaled, and I hope I've presented some issues that show that some kind of compositor that is not part of Quartz 2D is necessarily involved. So I now hope you can refute this with a simple example. I'm afraid that I'm the kind of person who prefers proof, so if you can't show me an example that demonstrates the scalability of an entire window (rather than just an isolated piece of graphics) you're going to have a hard time convincing me.
GDI+ vs. Quartz
"You keep claiming that GDI+ is somehow up to the level of Quartz. This is simply not the case. GDI+ is, from an imaging model point of view, much more like DisplayPostscript (around 1989)."
Could you be specific there? As far as I know there's nothing Quartz 2D can do that GDI+ can't. And GDI+ is way ahead of circa 1989 DPS - there's plenty GDI+ can do that display postscript can't. (You gave the example of transparency handling and how display postscript uses the painters algorithm. That's what GDI32 uses too. But it's not what GDI+ uses - you can specify alpha for any drawing operation in GDI+, just like you can in Quartz 2D.)
Moreover, until Jaguar came along, GDI+ was able to do things Quartz 2D couldn't. Quartz 2D didn't original support gradient fills, for example, but these have been in GDI+ from the start.
Are you sure you're not confusing GDI+ with GDI32? Your description characterises GDI32 perfectly, but it's an inaccurate description of GDI+.
On profiling
"What the profile showed that most of the time was *not* spent rendering graphics. It was spent on the *application* side, not in the graphics subsystem. It was spend recalculating the line-layout, doing typography, not rendering it"
You don't consider line layout and typography to be graphics operations?
To be honest, you've not given enough detail for me to be able to draw any conclusions from your profiling. Any chance you could post what you actually found somewhere? This forum doesn't really make it easy to provide enough detail. For example, it now seems like you're saying the complete opposite of what you said last time about the profiling results. (I'm sure that's not what you thought you said, but that's honestly how it came across to me.)
"If we could drop in Avalon and Avalon were infinitely fast, it would hardly speed this operation up at all."
Layout and typography support is all part of what Avalon supplies, so that's not in fact correct. If Avalon were infinitely fast, it would make this operation infinitely fast.
Of course that has nothing to do with acceleration, since it's pretty unlikely that Avalon will hardware accelerate layout. I'm pretty amazed that it really is spending this much time in layout code, which is why I'm intrigued to see your actual profiling results. From what you've told me so far, the most likely explanation would seem to be that the layout code is a bit crappy - maybe you've just found a weak spot of Quartz 2D. However, I don't think that's the whole story - resize performance is pretty ropey on *all* windows on all Macs I've ever used (all the ones using OS X at least). Even on a little program that draws nothing but a single ellipse in a resizable view, and I'm pretty sure that program isn't spending all its time laying out text because there was no text...
So if you can share it I'd love to see your profiling setup and the data you generated.
"And of course, if you actually do junk the entire retained model each time you update the application model, then you are not going to gain any performance, because you are actually doing *more* work by building up this model that you then promptly destroy. Trust me, this has been hashed out before..."
But that's exactly the model you've been saying is so fine in Quartz 2D! There you absolutely have to reconstruct the entire model every time you get sent a redraw request.
Also, you're ignoring what I said about the problems of a software 2D engine (regardless of whether drawings are retained) - the gap between bus transfer speeds and CPU speeds gets ever higher, so any model that rasterizes on the CPU and then transfers the results across a bus to the graphics card is going to find that transfer becoming a more and more glaring bottleneck.
It has indeed been hashed out before - the games industry has been hashing this out for years now, the introduction of GPU-side vertex handling indicates that they've all settled on a retained model, and they long since settled on moving rasterization into the GPU. This is the prevailing approaches because it's the only one that scales to the complexity and speed they need. So it's been hashed out before, the end-to-end-vectors model won long ago, and the consensus amongst graphics card manufacturers seems to be that vector retention model is also the way to go!
"Summary:"
"- The immediate-drawing model of Quartz 2D does not have the "problems" you think you identified (inherently incapable of handling higher res displays, more work for the developer)"
Until you produce convincing evidence, I have to believe what the Apple docs and my experiments tell me. Rendering snippets is not convincing, because even 16-bit Windows can do that in a resolution independent way. Show me a bitmap containing a whole window at double the resolution (or a PDF, or a postscript file - whatever is easiest), and I'll believe you. My challenge to you is that I don't believe this can be done without bitmap scaling.
"- Quartz 2D renders vector graphics with correct transparency effects today, at any resolution desired (subject to implementation limits)."
Also true of GDI+. None of which alters the fact that GDI+ hasn't solved Windows' lack of resolution independence.
"You do not have to invoke the Quartz compositor to do this, the Quartz compositor is used for different tasks. (The implementation probably uses compositing operators to achieve these effects, this is hidden)."
Of course it uses compositing operators to achieve this - otherwise you'd only ever see the last drawing primitive you drew! But of course it's a different code path from the Quartz Compositor, because Quartz 2D is all software.
"- Drawing performance is not the limiting factor for "normal" applications, even with during highly interactive and graphics-intensive operations."
The two most highly graphics-intensive kinds of applications around today are video editing and 3D work. Neither of these use the Quartz 2D pipeline.
It's true that for static form-like displays, Quartz 2D performance is adequate. But it doesn't take long to hit its limits if you try to do anything ambitious. If you have access to a box running Longhorn (and make sure it's one with a supported graphics card), try running this extremely simple drawing demo. Compare the smoothness of response with Adobe Illustrator on a Mac. (Illustrator's pretty slow even with very simple drawings.) Particularly notice how you can zoom in and out smoothly in realtime with a drag operation. Compare this to how Illustrator only works in chunks and takes about half a second to change zoom factor.
(Just to reiterate, you will need a PC with a suitable graphics card. Because the Longhorn Developer Preview is a very early release, it supports only a small set of graphics cards. If it doesn't know your graphics card and therefore drops down to software rendering, the results will be rather disappointing. Although it's a pretty good example of why you don't want software rasterization...)
I believe this demonstrates that a faster drawing engine enables styles of user interaction that simply weren't possible before. You say that drawing performance is not a limiting factor. I think that its an ubiquitous constraint we all learnt to live with so long ago that we work within its limits without even thinking about it. Liberation from these restrictions gives us the opportunity to enhance usability no end. It's not about making existing things faster, it's about enabling things that were previously impossible. -
macos x already works like this
2004-03-19 17:33:59 mweiher [Reply | View]
"I challenge you to show me an example demonstrating a whole *window* in a scalable form, toolbars title bars and all"
Easy:
Open Xcode.
Project -> New -> New Cocoa Project
Build + Run
Print -> Save as PDF
Voilá
You will notice that the text on the title bar as well as the gradients used in the title bar are all smoothly scalable.
As well as anything scalable you place inside the window, if you decide to do so.
You will also notice that the traffic-light buttons do not scale as well. Of course, they still scale, Quartz 2D is device independent after all, but because they are drawn as bitmaps they scale as bitmaps and do not look as nice as the other elements.
As I have explained before, this has nothing to do with the drawing or windowing API used, but is simply a matter of application choice. Having a retained representation wouldn't change this by one bit.
EmptyProjectPrint.pdf
-
macos x already works like this
2004-03-09 10:07:15 James Duncan Davidson |
[Reply | View]
Well, it's natural that Avalon would be more advanced in scope than Quartz. After all, it's slated for the future and is only part of a developer release where Quartz is here and now and has been since 2001. Longhorn releases when? If Avalon only had feature parity, that would be disapointing.
The question is, what will Quartz's capabilities be by the time Longhorn ships? That's something only time will tell. -
macos x already works like this
2004-03-09 08:36:39 jannino [Reply | View]
Thanks for the great explanation of the differeneces. I'm no Quartz expert either as the work I've needed to do on the Mac has either been UNIX based and didn't use the UI at all, or used Cocoa which handles those particulars for you.
There is some relationship between Quartz and display PDF, although I never really quite understood what it was, but it may help in providing the vector based capabilities of Avalon in MacOS X in some later version. Microsoft is being pretty far sighted by putting this into their own implemetation, but I also wonder how long it will be before this makes it into a release.
Anyhow, the vector based transforms will probably be very important soon. From what I understand, light emitting plastic technologies that are just coming to market now will be capable of producing cheap displays with high DPIs. The WYSIWYG nature of both the mac and windows will require it to support screen DPIs close to what we are used to in printers, instead of just assuming everything is 72dpi regardless of the actual pixel density, as most software does now. Its pretty exciting to consider the possibilities available with this combition of hardware and software.






"XAML"? Couldn't they just use SVG so graphic designers can use existing tools and enjoy an open, tried and reliable format?