| Sign In/My Account | View Cart |
| Article: |
Graphical Composition in Avalon | |
| Subject: | macos x already works like this | |
| Date: | 2004-03-12 00:28:19 | |
| From: | igriffiths | |
|
Response to: macos x already works like this
|
||
|
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.
|
||
Showing messages 1 through 19 of 19.
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
1. Application that provides smooth zoom
Just modify your NSImageView a tiny little bit. Add a class BetterNSImageView with an instance variable id pdfImageRep.
To this add the following two methods:
-(void)drawRect:(NSRect)r
{
if ( pdfImageRep ) {
[pdfImageRep drawInRect:r];
} else {
[super drawRect:r];
}
}
-(void)setImage:(NSImage*)anImage
{
[anImage setDataRetained:YES];
pdfImageRep=[[[anImage representations]
lastObject] retain];
[super setImage:anImage];
}
(This code will leak the image-rep, but that's OK for us here)
The clou here is drawing the PDF directly, instead of recaching an NSImage each time around. That makes things significantly faster. I haven't put in the code that takes care of keeping the aspect ratio the same, this doesn't affect the speed and is left as an exercise for the reader.
This redraws interactively on my dual 1 GHz G4 and my 867 MHz 12" PowerBook, though it is a bit more sluggish on the PowerBook. Or, to put numbers on that, add the following trivial "benchmark" code:
-(void)doScaleBench:sender
{
int i;
NSWindow* win=[self window];
NSRect r=[win frame];
NSLog(@"start %@",[NSDate date]);
for (i=0;i<10 ;i++) {
r.size.width++;
r.size.height++;
[win setFrame:r display:YES];
}
NSLog(@"stop %@",[NSDate date]);
}
Hook that up to a menu item in Interface Builder.
On my 867MHz 12" PowerBook, that yields between 7.41 redraws/s for a complex PDF with a full page of text and 17.2 redraws a second for a simple PDF with a couple of shapes and a small amount of text. A full page of text being rescaled is very rough, because text is expensive to render and you aren't getting much use out of the text cache.
On the 1 GHz G4, we get 12.5 and 31 redraws / second, respectively. A current model G5 should be more than twice as fast, and I wonder what will be available by the time Longhorn/Avalon ships. But it's always surprised me how much faster Safari is on my 12" PowerBook than the 1.4 GHz Dell I have at work. Apart from looking incomparably better...
2. "wether mac os x has a [retained vector] mechanism like this"
*double cough* This is from the start of my first post to this thread:
"The fact is that Mac OS X already *does* work mostly like this, except for retained vectors"
To which you replied:
"But my point is that the retained vectors are crucial."
'nuff said.
3. Quartz compositor hypotheses
Just complete bollocks. Completely unrelated. Apart from being untrue, this is still bitmaps being drawn with Quartz 2D, not stuff that is turning into bitmaps as a result of the Quartz compositor, which has nothing to do with that at all.
4. OpenGL + QuickTime + Quartz
5. Diffuse worries
OK, so you had bad experiences with Windows drawing APIs that just didn't work as advertised. Yes, that is also what I heard. Especially the transition from the initial GDI to the one that supported a "Postscript-like" imaging model, with arbitrary affine transformations. I remember thinking to myself "hey, this does all I need", but then hearing that, in fact, it doesn't actually work. However, I never tried it myself, but you seem to corroborate this.
This is also where I get confused as to which Windows API is which. I remember that the original GDI did not support arbitrary (affine) transformations, or bezier-based paths. Did it support path-based clipping? The API that followed was very closely modelled after the Postscript imaging model, but that was the one that didn't really work as advertised, at least initially. Was that GDI+? I seem to be getting conflicting messages on that. You seem to say that GDI+ came with XP, but that would mean there must have been an intermediate API. Was there some renaming in the meantime?
Anyway, whatever bad experience you had with Windows APIS, the good news is: Quartz Just Works(tm), as did DPS. Your worries, as applicable as they are in the Windows world, simply do not apply here. I have lots of ideas why this is the case, but these aren't really that important. What is important is that it does just work.
[Possible reasons: well-defined drawing model, with precisely specified rendering semantics; history of implementations that have always been and continue to be device-independent stretching back more than two decades; surrounding APIs that have traditionally always worked in conjunction with a fully device-independent imaging model and count on that working correctly; developers that have worked with a device-indepndent imaging model for more than a decade etc.]
6. Concrete compositing worries
Anyway, you do give one concrete reason why there were problems with Windows, which is that windows are composed of lots of smaller windows. This isn't the case with normal Quartz windows. It is only true (to a much lesser degree) when the Quartz compositor is used to combine other media-types.
However, virtually all the concrete worries you have expressed about (sub-)pixel boundaries, arbitrary scaling and so forth already apply today in exactly the same way! So either everything is as broken as you think it will be in the future today, or it won't be broken in the future either.
[Exposé as 'proof' of compositor limitations: how many more #$%!@# lame examples are you going to come up with?! Exposé is intended to give you a rough overview over your windows, not provide precise rendering. Also, if anything it is an example of limitations of GPU-based drawing...]
7. One big Quartz 2D surface
For most windows, that is exactly what it is. The only exceptions are those that explicitly include dynamic media such as QuickTime movies and OpenGL-rendered 3D graphics
.And yes, of course it is the compositor that is placing those QuickTime streams inside Quartz windows. What else? I really understand where you're getting all this from. You seem to have a profound misunderstanding of how all this works somewhere, but I am at a bit of a loss where it is.
8. "At 300 dpi, your 128x128 pixel image is now less than half an inch across."
This makes me wonder wether you understand what device-independent graphics means at all. Probably not. The same image will be precisely the same size as it was before. It will also look (almost) exactly the same. It just won't improve as much as a vector drawing will. However, most of the time those 128 x 128 icons are drawn much smaller than 1:1, and at those sizes a higer DPI display will display those icons with much finer details than possible today.
Incidentally, that applies to all the other bitmaps in the UI, for example the traffic-light close/minimize buttons. They will render just fine even at the higher resolution, they just won't benefit much from it. That is what device-independent rendering is all about. Of course, it will be trivial for Apple to provide higher-resolution bitmaps for those higher resolution displays, or vectorized versions if that is appropriate/desirable.
9. Static vs. dynamic graphics pipelines (and retained vectors)
'"As you yourself have pointed out, both speed and quality requirements are different for dynamic and static media" Actually I don't think I did say that.'
Er, yes you did. Earlier. On bitmap-stretching used by, for example, the genie effect:
"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, at high speeds, you can get a way with imperfections. At low speeds, or a static display, you can't.
So once again, for 3D and video work, you have the fast 3D and video pipelines. For mostly static displays, you have the very high quality Quartz 2D pipeline (and you can mix in the other pipelines when necessary). Quartz 2D is plenty fast for 2D non-media, non-movie work, and offers precision/quality that other APIs can't match.
Also, you still haven't explained how 2D retained vectors would improve movie playback or OpenGL based 3D work. Are we going to vectorize movies on the fly? Is OpenGL going to render to a 2D vector representation? I don't think so.
10. "retained vectors" ... "may not the only possible solution" for "High DPI"
Good, we are making progress, then. However, it turns out that wether vectors are retained or not is completely irrelevant to the High DPI "problem".
Unless you are going to make the absolutely absurd claim that QuickTime movies are going to vectorized on the fly and OpenGL will render down to 2D vectors instead of bitmaps, you are still going to have to composite at least some bitmaps together when you join up these different pipelines, at some point, wether you have a retained vector representation or not. It only happens at a different point in the pipeline that is all, but the actual issues of compositing the bitmaps together remains exactly the same.
The other issue is bitmaps shoved into the graphics pipeline at the application end. Again, this has nothing to do with wether you have the ability to retain (vector) representations inside your graphics subsystem (or on the graphics card for that matter) at all. It is *solely* a matter of the applications providing vector or bitmap data. So once again, the API makes no difference whatsoever
.
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...