title: iPhone: optimized drawing in quartz
body: <p>I have created a CG context that is 800 pixels wide and 1200 pixels height. I have created CGLayer over this context that has been transformed (scaled, translated and rotated). So, at some point, as the CGLayer is bigger than the context and has been translated, rotated, etc., not all parts of this CGLayer falls inside the context. See next picture:</p>
  
  <p><a href="https://imgur.com/kSXLG" rel="nofollow noreferrer">layer and context</a></p>
  
  <p>As you can see by the picture, some parts of the layer falls outside the context area. When I render the final composition using </p>
  
  <pre><code>CGContextDrawLayerInRect(context, superRect, objectLayer);
  </code></pre>
  
  <p>it will render the full layer, including those unnecessary parts outside the context.</p>
  
  <p>My problem is: if I can make it draw just the relevant parts inside the context I can make it render fast and save memory.</p>
  
  <p>Is there any way to do that?</p>
  
  <p><strong>NOTE: LAYER contains transparency.</strong></p>
  
  <p>Please refrain from giving solutions that don't involve CGLayers.</p>
  
  <p>thanks in advance.</p>