[Drawkit] Fix for aliasing of drawing edges

Graham Cox graham.cox at bigpond.com
Tue May 20 17:48:22 PDT 2008


On 21 May 2008, at 3:32 am, Brad Larson wrote:

> You could re-pixel-align and recache the grid on a drawing scale  
> change.

Yes, I could.

> It would make for a slower redraw on a zoom operation, but would it  
> be slow enough to bother the user?  They may not change the scale  
> very often.


I would have to try it, but I think assuming that the user won't  
change scale very often is probably false - I know I change scale  
almost continuously when I'm working on a drawing. (Aside: using the  
option key with the mouse vertical scrollwheel, if you have one,  
scales the view - I'm very much into this habit!).

The problem isn't just the grid recalculation and redrawing, it's  
everything else as well. I already employ a number of tricks to speed  
drawing when things are changing rapidly - I guess the same could be  
applied to the grid. (Another aside: the Draw Demo preferences can be  
used to enable/disable the "speed up tricks" for drawing things during  
rapid changes like scrolling and zooming).


> The cached grid would still redraw quickly on a standard drawRect:  
> operation.  To do this, could the grid layer respond to the  
> kGCDrawingViewDidChangeScale notification sent out by the GCZoomView  
> in the zoomViewByFactor:andCentrePoint: method?  Does the  
> scaleUnitSquareToSize: NSView method used in GCZoomView to do the  
> scaling trigger other redraw or recaching actions elsewhere?

Yes - everything that's shown in the resulting view needs to be redrawn.

> If you really wanted high performance, but were willing to sacrifice  
> backwards compatibility, layer-backing the drawing objects and grid  
> through Core Animation should make refreshes very fast.  This would  
> be great for dragging around lots of selected objects, where they  
> all could be assigned to the same CALayer and that layer cached on  
> the video card.  You could also do animated zooms, glowing shadows  
> on selected objects, and other slick effects.  It would take a bit  
> of work, however, and I don't know how much of a priority it is.   
> Rendering performance is very good as it is right now.

Layer backing isn't perfect - again at high zoom factors pixellation  
is extremely obvious (since layers in this sense are bitmaps).  
CGLayers already offer similar functionality without a backwards  
compatibility issue (I assume, though may be wrong, that CALayers are  
built on top of CGLayers), and I use those for some kinds of quick-and- 
dirty rendering when things need to go fast temporarily. Dragging  
objects using a temporary layer doesn't work because the Z-ordering of  
objects can't be preserved (imagine dragging a multiple selection of  
arbitrarily ordered objects past some other objects - some will pass  
in front and some behind, but if they are all added to a layer this  
effect wouldn't be possible). I'm not sure that dragging performance  
is currently an issue (do let me know if you think it is however) so I  
haven't optimised this beyond keeping the update areas to a minimum.  
Some of the other effects you mention could be cool though, no doubt.

However, temporary drawing of the grid using a CGLayer while zooming  
*might* be worth it, so I'll try and get time to look into it.


By the way, this is great feedback - keep it up.

cheers, Graham


More information about the Drawkit mailing list