CAAtom

From iPhone Development Wiki
Revision as of 20:57, 21 January 2011 by KennyTM~ (talk | contribs) (Removed the list of atoms, which is version specific. Instead, instruction was given to how to get the atoms.)
Jump to: navigation, search

CAAtom refers to a string for identification in QuartzCore. As of 3.1, there are over 300 internal atoms.

Converting atoms to and from strings

Signature NSString* CAAtomGetString(uint32_t atomicValue);
Available in 2.0 –
Signature uint32_t CAInternAtom(NSString* atommicString);
Available in 2.0 –

There is only 2 exported C function for CAAtom, CAAtomGetString() and CAInternAtom(), which converts between an integer and its corresponding string value. Most internal code in QuartzCore are identified using atoms. For example, a portion of disassembled code may read:

-[CAGradientLayer setLocations:]:
;
+00000 0008d9cc             stmdb             sp!,{r7,lr}
+00004 0008d9d0             add               r7,sp,#0x0
+00008 0008d9d4             mov               r1,#0xad
+0000c 0008d9d8             bl                CALayer_setter_kCAValueCopiedPointer
+00010 0008d9dc             ldmia             sp!,{r7,pc}                       ; return

here, the magic number 0xAD is in fact an atom, which is unsurprisingly the value "locations":

cy# CAAtomGetString(0xad)
"locations"

You may find the list of predefined atoms as an array of strings at the (private) symbol _stringpool_contents. Values larger than the pool's size are custom atoms.