• 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: Speed of Quartz (was: optimizing compilers)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Speed of Quartz (was: optimizing compilers)


  • Subject: Re: Speed of Quartz (was: optimizing compilers)
  • From: "Erik M. Buck" <email@hidden>
  • Date: Mon, 4 Feb 2002 15:04:39 -0600

Here is the test using Core Graphics calls instead of NSBezierPath:
Once again, the second example should be slower but is in fact ten times
faster. The problem with complex paths is Quartz and not NSBezierPath.

- (void)drawRect:(NSRect)aRect
{
CGContextRef cgContext = [[NSGraphicsContext currentContext]
graphicsPort];
int i;

NSAssert(MYNUM_POINTS >= 2, @"Compiled with MYNUM_POINTS < 2");

[[NSColor whiteColor] set];
[NSBezierPath fillRect:[self bounds]];
for(i = 0; i < MYNUM_POINTS; i++)
{
_myPoints[i] = NSMakePoint(random() % (int)[self bounds].size.width,
random() % (int)[self bounds].size.height);
}

[[NSColor greenColor] set];

// Construct path
CGContextMoveToPoint(cgContext, _myPoints[0].x, _myPoints[0].y);
for(i = 1; i < MYNUM_POINTS; i++)
{
CGContextAddLineToPoint(cgContext, _myPoints[i].x, _myPoints[i].y);
}

// Stroke
CGContextSetLineWidth(cgContext, 1.0);
CGContextSetLineCap(cgContext, kCGLineCapRound);
CGContextSetLineJoin(cgContext, kCGLineJoinRound);
CGContextSetMiterLimit(cgContext, 4.0);
CGContextDrawPath(cgContext, kCGPathStroke);
}


// This one is 10 times faster
- (void)drawRect:(NSRect)aRect
{
CGContextRef cgContext = [[NSGraphicsContext currentContext]
graphicsPort];
int i;

NSAssert(MYNUM_POINTS >= 2, @"Compiled with MYNUM_POINTS < 2");

[[NSColor whiteColor] set];
[NSBezierPath fillRect:[self bounds]];

for(i = 0; i < MYNUM_POINTS; i++)
{
_myPoints[i] = NSMakePoint(random() % (int)[self bounds].size.width,
random() % (int)[self bounds].size.height);
}
[[NSColor greenColor] set];

// Construct and stroke path path
for(i = 1; i < MYNUM_POINTS; i++)
{
CGContextBeginPath(cgContext);
CGContextMoveToPoint(cgContext, _myPoints[i-1].x, _myPoints[i-1].y);
CGContextAddLineToPoint(cgContext, _myPoints[i].x, _myPoints[i].y);
CGContextSetLineWidth(cgContext, 1.0);
CGContextSetLineCap(cgContext, kCGLineCapRound);
CGContextSetLineJoin(cgContext, kCGLineJoinRound);
CGContextSetMiterLimit(cgContext, 4.0);
CGContextDrawPath(cgContext, kCGPathStroke);
}
}



----- Original Message -----

References: 
 >Re: Speed of Quartz (was: optimizing compilers) (From: Finlay Dobbie <email@hidden>)

  • Prev by Date: Re: Saving a RTFD-file with NSAttributedString
  • Next by Date: Re: Saving a RTFD-file with NSAttributedString
  • Previous by thread: Re: Speed of Quartz (was: optimizing compilers)
  • Next by thread: Re: Speed of Quartz (was: optimizing compilers)
  • Index(es):
    • Date
    • Thread