What is the difference between CGLayer, CALayer and CGContext?
-
1http://stackoverflow.com/questions/4458812/whats-the-difference-and-compatibility-of-cglayer-and-calayer – Vivek Sehrawat Sep 26 '16 at 05:09
-
http://stackoverflow.com/questions/14658750/cgcontext-vs-calayer – Vivek Sehrawat Sep 26 '16 at 05:09
2 Answers
So, as a documentation says
CALayer from QuartzCore framework
is
The CALayer class manages image-based content and allows you to perform animations on that content. Layers are often used to provide the backing store for views but can also be used without a view to display content.
For more info please look https://developer.apple.com/reference/quartzcore/calayer
CGLayer from Core Graphics framework
is
Layer objects are useful for offscreen drawing and can be used in much the same way that a bitmap context can be used. In fact, a CGLayer object is a much better representation than a bitmap context. Using CGLayer objects can improve performance, particularly when you need to capture a piece of drawing that you stamp repeatedly (using the same scale factor and orientation)
For more info please look https://developer.apple.com/reference/coregraphics/1666309-cglayer
Note CGLayer objects are unrelated to Core Animation layers (CALayer objects).
CGContext from Core Graphics framework
is
A graphics context contains drawing parameters and all device-specific information needed to render the paint on a page to the destination, whether the destination is a window in an application, a bitmap image, a PDF document, or a printer.
For more info please look https://developer.apple.com/reference/coregraphics/1666363-cgcontext

- 2,326
- 13
- 21
CG in CGLayer stands for core graphics and CA in CALayer for core animation. These are indeed confusing.
CGLayer is provided by CoreGraphics.framework
and its main use to draw vector objects of various geometric shapes like circle, rectangle, line etc. This provides for high performance graphics support with CPU rendering IIRC.
CALayer (provided by Quartz framework) is simply for content animation in your 'Views'. This is OpenGL based mostly that uses GPU.
CGContext (again provided by Quartz framework) - this content is copied from doc directly
A graphics context contains drawing parameters and all device-specific information needed to render the paint on a page to the destination, whether the destination is a window in an application, a bitmap image, a PDF document, or a printer. You can obtain a graphics context by using Quartz graphics context creation functions or by using higher-level functions provided in the Carbon, Cocoa, or Printing frameworks. Quartz provides creation functions for various flavors of Quartz graphics contexts including bitmap images and PDF. The Cocoa framework provides functions for obtaining window graphics contexts. The Printing framework provides functions that obtain a graphics context appropriate for the destination printer.

- 3,547
- 2
- 30
- 51