• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting the best frame rate for NSView drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the best frame rate for NSView drawing


  • Subject: Re: Getting the best frame rate for NSView drawing
  • From: "email@hidden" <email@hidden>
  • Date: Thu, 29 Mar 2012 12:49:54 +0100

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Getting the best frame rate for NSView drawing
      • From: lbland <email@hidden>
References: 
 >Getting the best frame rate for NSView drawing (From: Kenneth Baxter <email@hidden>)
 >Re: Getting the best frame rate for NSView drawing (From: Graham Cox <email@hidden>)

  • Prev by Date: recalculateKeyViewLoop doesn't work
  • Next by Date: Re: Getting the best frame rate for NSView drawing
  • Previous by thread: Re: Getting the best frame rate for NSView drawing
  • Next by thread: Re: Getting the best frame rate for NSView drawing
  • Index(es):
    • Date
    • Thread