views:

386

answers:

1

I try to learn the drawing process in UIView in iphone. as I understand the drawing process accurs only if the method [UIView drawRect] exists. it starts with [CALayer display] and from within that method [UIView drawRect] is called (to be precise :first [UIView drawLayer:layer inContext:context] is called and from within this method [UIView drawRect] is called).

I have 2 questions:

  1. how does the [CALayer display] method obtain the context of UIView? (which is used in [UIView drawLayer:layer inContext:context] within [CALayer display] method)
  2. how does updating of the contents of CALayer happens? (the updating which is discribed in the link here: [CALayer display] )
A: 

Hi,

For your first question, I would rather say that the CALayer creates the context, in terms of CGContextRef, and then pass it to the view which is its delegate. About your second question, as much as I observed, it seems that CALayers are very close to the hardware and video memory. Actually, if you set a CGImageRef as the contents of a CALayer, you will pass the image on screen, directly in the video memory (that's a time consuming operation). So I guess the CALayer gets a kind of image from its CGContextRef (the one that has been filled up by the view) and then assign it as its contents. OR, maybe the context created is directly a space in video memory and each drawing operation in drawRect triggers an access to that memory...

I'm not an expert on these processes though, I can only guess what's happening from what I've seen. Note that I say "video memory" but I think there is no such thing on iPhone, but rather a part of the main memory dedicated to video operations. That part is mapped and you can see the consumption with VMTracker in Instruments. Again, I'm not sure about that, if someone has more informations I would be delighted to hear it!

Unfalkster