On 28 Mar 2012, at 09:19, Graham Cox wrote:

> 
> On 28/03/2012, at 6:36 PM, Kenneth Baxter wrote:
>> 
>> Draw each object individually (admittedly it's just a simple oval in rect 
>> which is filled and stroked): 12fps
>> Generate an NSImage of the object once and cache it, then just 
>> drawInRect...: 8fps
>> Cache a CIImage and draw that: 8fps
>> Cache a CGLayer and draw that: 8fps
>> 
>> This sure does seem to be awfully slow. Instruments tell that the time is 
>> all being spent in drawing the object, no matter how I do the drawing.
>> 
>> Is there some better way to get decent drawing performance from drawing into 
>> an NSView?
> 
> 200 x 400 is quite a big area to fill, whether by using stroke/fill or 
> blitting an image. Multiply by 100 and you are doing a lot of work pushing 
> pixels (equivalent to blitting 8 million pixels!). Though I'm surprised that 
> the NSImage method is slower than fill/stroke, in most cases I would expect 
> that to be faster, so there might be an inefficiency there somewhere.
> 

Like graham I am surprised that the NSImage cache approach is slower than 
fill/stroke.
My dynamic drawing requirements are minimal but the outline below is way 
quicker than native redrawing (of course the graphical complexity of the view 
plays a major role here).
Is your NSImage caching approach similar to below?

- (void)drawRect:(NSRect)rect 
{               
    // if cache exists use it to update rect.
    // otherwise draw into our rect
    if (_imageCache) {
        [self drawRectFromCache:rect];
        return;
    } 

    // draw to image cache
    _cacheRect  = [self bounds];
   _imageCache = [[NSImage alloc] initWithSize:_cacheRect.size];
   [_imageCache lockFocus];
                
    // now draw into _imageCache

    // done with drawing
    [_imageCache unlockFocus]
}

- (void)drawRectFromCache:(NSRect)rect
{
        [_imageCache drawInRect:rect fromRect:rect 
operation:NSCompositeSourceOver fraction:alpha];
}

Regards

Jonathan Mitchell
Mugginsoft LLP



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to