title: CALayer setNeedsDisplayInRect - what is the point of InRect? Or faster drawing in drawInContext
body: <p>I have a CALayer (imageLayer), and a subclassed CALayer that acts as a mask on the CALayer (maskLayer).</p>
  
  <p>I am painting with a finger onto the maskLayer so that I can temporarily erase out part of the imageLayer.</p>
  
  <p>I am accomplishing this by keeping one Bitmap Context (maskContext), and adding a stroke to it in touchesMoved. So my maskContext just holds all the strokes I have painted. In touchesMoved, I do <code>[maskLayer setNeedsDisplay]</code>;</p>
  
  <p>in my subclassed maskLayer, I have the <code>drawInContext</code> method:</p>
  
  <pre><code>-(void)drawInContext:(CGContextRef)ctx
  {
      CGImageRef image = CGBitmapContextCreateImage(maskContext);
      CGContextDrawImage(ctx, CGRectMake(0,0,self.frame.size.width, self.frame.size.height), image);
  }
  </code></pre>
  
  <p>This all works out really well, but is very slow as it's drawing the whole view for each touchesMoved event.</p>
  
  <p>I thought of using <code>[maskLayer setNeedsDisplayInRect:rect]</code> but I wondered what the point is, as <code>drawInContext</code> does not look at the rect. I could pass the rect to <code>drawInContext</code>, but I could do that with just <code>setNeedsDisplay</code>.</p>
  
  <p>Is there something that <code>setNeedsDisplayInRect</code> does that <code>setNeedsDisplay</code> doesn't for a CALayer?</p>
  
  <p>(I am aware that if I were using <code>drawRect</code>, that would accept the defined rect, but a CALayer's <code>drawInContext</code> doesn't)</p>
  
  <p>Also, is there any better way of accomplishing this masking by painting with a finger? The main problem is that the CGContext is not a canvas and does not remember previous strokes, so they have to be redrawn all the time.</p>