20

I am trying to find out what actually happens in background when we do this (please see the image)

enter image description here

As you can see in image I have added few buttons and have checked Content View from Interface builder for window.

Now as we know it will make use of core animation or say will create layers. (Please correct me if I am wrong. Still studying...)

I want to know how does these buttons are drawn?

My assumption is when we tick Content View, these buttons are drawn from CGBitmapContextRef and bitmap created from it are handed over to Core Animation (OpenGL). But I am not being able to prove it so far. How do I prove it? Any example or some approach idea would be great?

Thing I am sure of is buttons created from CGBitmapContextRef. But what happens to those button images is unknown.

Can anyone explain how is that integration possible? How those image would have got on screen?

Edit:

To add some more information on same topic, please check the image below for layers of OpenGL. I think I am targeting common OpenGL Framework layer. enter image description here

RLT
  • 4,219
  • 4
  • 37
  • 91
  • 6
    We don't know, and we don't *want* to know. The integration between Core Animation and the view hierarchy is an implementation detail and could change at any time if Apple thinks of a better way to do it. :) – Jonathan Grynspan Sep 28 '11 at 12:20
  • It's really not clear what you are asking here. "How does these buttons are drawn?" is really vague. If you just want to know how it all works internally, you won't find out here, because that's secret Apple sauce. – benzado Nov 01 '11 at 19:28
  • Yes I was looking for some internal details. May not be all.. but some nice discussion around the area, some ideas, some clues can reveal the mystery. – RLT Nov 03 '11 at 09:40
  • The title of your question indicates that you are interested in mixing Quartz/Cocoa drawing code with 'native' OpenGL drawing code. Is that what you are actually interested in? If so, this question is probably already answered [here](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/QuartzOpenGL/QuartzOpenGL.html) (without having to know about secret Apple code.) – starbugs Nov 20 '11 at 14:26
  • This question is for "other way around": [http://stackoverflow.com/q/8214884/963550](http://stackoverflow.com/q/8214884/963550) – debleek63 Nov 28 '11 at 14:41
  • Use Instruments and sample the running application. It will show you exactly what system calls are being executed behind the scenes. – StilesCrisis Dec 06 '11 at 05:01

2 Answers2

1

I would start by making a tight loop that re-draws your buttons forever. Then, while it's running, use Activity Monitor to do a sample trace of your process. You'll see all the code paths it's taking to draw the buttons. You should be able to see what's happening from there from the names of the routines in the drawing stack. If you can't make sense of it, post the relevant bits and here and we could take a look.

Ken Aspeslagh
  • 11,484
  • 2
  • 36
  • 42
0

Buttons are draw on CGBitmapContextRef.

Lets say, we have CGBitmapContextRef objected created using

CGContextRef CGBitmapContextCreate (
   void *data,
   size_t width,
   size_t height,
   size_t bitsPerComponent,
   size_t bytesPerRow,
   CGColorSpaceRef colorspace,
   CGBitmapInfo bitmapInfo
);

Here void *data, is a pointer to the destination in memory where the drawing is to be rendered.

CGContext API can be then used to perform various operation on data. Thus buttons and background can be draw on it.

Once done we can release the CGContextRef but data is still in memory which can be passed to OpenGLContext(CGLContextObj).

I still do not know how it uploads data to CGLContextObj. Must be using some private api.

RLT
  • 4,219
  • 4
  • 37
  • 91