CGDataProvider.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. { CoreGraphics - CGDataProvider.h
  2. Copyright (c) 1999-2011 Apple Inc.
  3. All rights reserved. }
  4. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, August 2005 }
  5. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2009 }
  6. { Pascal Translation Updated: Jonas Maebe, <[email protected]>, October 2012 }
  7. {
  8. Modified for use with Free Pascal
  9. Version 308
  10. Please report any bugs to <[email protected]>
  11. }
  12. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  13. {$mode macpas}
  14. {$packenum 1}
  15. {$macro on}
  16. {$inline on}
  17. {$calling mwpascal}
  18. unit CGDataProvider;
  19. interface
  20. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  21. {$setc GAP_INTERFACES_VERSION := $0308}
  22. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  23. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  24. {$endc}
  25. {$ifc defined CPUPOWERPC and defined CPUI386}
  26. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  27. {$endc}
  28. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  29. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  30. {$endc}
  31. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  32. {$setc __ppc__ := 1}
  33. {$elsec}
  34. {$setc __ppc__ := 0}
  35. {$endc}
  36. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  37. {$setc __ppc64__ := 1}
  38. {$elsec}
  39. {$setc __ppc64__ := 0}
  40. {$endc}
  41. {$ifc not defined __i386__ and defined CPUI386}
  42. {$setc __i386__ := 1}
  43. {$elsec}
  44. {$setc __i386__ := 0}
  45. {$endc}
  46. {$ifc not defined __x86_64__ and defined CPUX86_64}
  47. {$setc __x86_64__ := 1}
  48. {$elsec}
  49. {$setc __x86_64__ := 0}
  50. {$endc}
  51. {$ifc not defined __arm__ and defined CPUARM}
  52. {$setc __arm__ := 1}
  53. {$elsec}
  54. {$setc __arm__ := 0}
  55. {$endc}
  56. {$ifc not defined __arm64__ and defined CPUAARCH64}
  57. {$setc __arm64__ := 1}
  58. {$elsec}
  59. {$setc __arm64__ := 0}
  60. {$endc}
  61. {$ifc defined cpu64}
  62. {$setc __LP64__ := 1}
  63. {$elsec}
  64. {$setc __LP64__ := 0}
  65. {$endc}
  66. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  67. {$error Conflicting definitions for __ppc__ and __i386__}
  68. {$endc}
  69. {$ifc defined __ppc__ and __ppc__}
  70. {$setc TARGET_CPU_PPC := TRUE}
  71. {$setc TARGET_CPU_PPC64 := FALSE}
  72. {$setc TARGET_CPU_X86 := FALSE}
  73. {$setc TARGET_CPU_X86_64 := FALSE}
  74. {$setc TARGET_CPU_ARM := FALSE}
  75. {$setc TARGET_CPU_ARM64 := FALSE}
  76. {$setc TARGET_OS_MAC := TRUE}
  77. {$setc TARGET_OS_IPHONE := FALSE}
  78. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  79. {$setc TARGET_OS_EMBEDDED := FALSE}
  80. {$elifc defined __ppc64__ and __ppc64__}
  81. {$setc TARGET_CPU_PPC := FALSE}
  82. {$setc TARGET_CPU_PPC64 := TRUE}
  83. {$setc TARGET_CPU_X86 := FALSE}
  84. {$setc TARGET_CPU_X86_64 := FALSE}
  85. {$setc TARGET_CPU_ARM := FALSE}
  86. {$setc TARGET_CPU_ARM64 := FALSE}
  87. {$setc TARGET_OS_MAC := TRUE}
  88. {$setc TARGET_OS_IPHONE := FALSE}
  89. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  90. {$setc TARGET_OS_EMBEDDED := FALSE}
  91. {$elifc defined __i386__ and __i386__}
  92. {$setc TARGET_CPU_PPC := FALSE}
  93. {$setc TARGET_CPU_PPC64 := FALSE}
  94. {$setc TARGET_CPU_X86 := TRUE}
  95. {$setc TARGET_CPU_X86_64 := FALSE}
  96. {$setc TARGET_CPU_ARM := FALSE}
  97. {$setc TARGET_CPU_ARM64 := FALSE}
  98. {$ifc defined(iphonesim)}
  99. {$setc TARGET_OS_MAC := FALSE}
  100. {$setc TARGET_OS_IPHONE := TRUE}
  101. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  102. {$elsec}
  103. {$setc TARGET_OS_MAC := TRUE}
  104. {$setc TARGET_OS_IPHONE := FALSE}
  105. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  106. {$endc}
  107. {$setc TARGET_OS_EMBEDDED := FALSE}
  108. {$elifc defined __x86_64__ and __x86_64__}
  109. {$setc TARGET_CPU_PPC := FALSE}
  110. {$setc TARGET_CPU_PPC64 := FALSE}
  111. {$setc TARGET_CPU_X86 := FALSE}
  112. {$setc TARGET_CPU_X86_64 := TRUE}
  113. {$setc TARGET_CPU_ARM := FALSE}
  114. {$setc TARGET_CPU_ARM64 := FALSE}
  115. {$ifc defined(iphonesim)}
  116. {$setc TARGET_OS_MAC := FALSE}
  117. {$setc TARGET_OS_IPHONE := TRUE}
  118. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  119. {$elsec}
  120. {$setc TARGET_OS_MAC := TRUE}
  121. {$setc TARGET_OS_IPHONE := FALSE}
  122. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  123. {$endc}
  124. {$setc TARGET_OS_EMBEDDED := FALSE}
  125. {$elifc defined __arm__ and __arm__}
  126. {$setc TARGET_CPU_PPC := FALSE}
  127. {$setc TARGET_CPU_PPC64 := FALSE}
  128. {$setc TARGET_CPU_X86 := FALSE}
  129. {$setc TARGET_CPU_X86_64 := FALSE}
  130. {$setc TARGET_CPU_ARM := TRUE}
  131. {$setc TARGET_CPU_ARM64 := FALSE}
  132. { will require compiler define when/if other Apple devices with ARM cpus ship }
  133. {$setc TARGET_OS_MAC := FALSE}
  134. {$setc TARGET_OS_IPHONE := TRUE}
  135. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  136. {$setc TARGET_OS_EMBEDDED := TRUE}
  137. {$elifc defined __arm64__ and __arm64__}
  138. {$setc TARGET_CPU_PPC := FALSE}
  139. {$setc TARGET_CPU_PPC64 := FALSE}
  140. {$setc TARGET_CPU_X86 := FALSE}
  141. {$setc TARGET_CPU_X86_64 := FALSE}
  142. {$setc TARGET_CPU_ARM := FALSE}
  143. {$setc TARGET_CPU_ARM64 := TRUE}
  144. { will require compiler define when/if other Apple devices with ARM cpus ship }
  145. {$setc TARGET_OS_MAC := FALSE}
  146. {$setc TARGET_OS_IPHONE := TRUE}
  147. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  148. {$setc TARGET_OS_EMBEDDED := TRUE}
  149. {$elsec}
  150. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
  151. {$endc}
  152. {$ifc defined __LP64__ and __LP64__ }
  153. {$setc TARGET_CPU_64 := TRUE}
  154. {$elsec}
  155. {$setc TARGET_CPU_64 := FALSE}
  156. {$endc}
  157. {$ifc defined FPC_BIG_ENDIAN}
  158. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  159. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  160. {$elifc defined FPC_LITTLE_ENDIAN}
  161. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  162. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  163. {$elsec}
  164. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  165. {$endc}
  166. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  167. {$setc CALL_NOT_IN_CARBON := FALSE}
  168. {$setc OLDROUTINENAMES := FALSE}
  169. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  170. {$setc OPAQUE_UPP_TYPES := TRUE}
  171. {$setc OTCARBONAPPLICATION := TRUE}
  172. {$setc OTKERNEL := FALSE}
  173. {$setc PM_USE_SESSION_APIS := TRUE}
  174. {$setc TARGET_API_MAC_CARBON := TRUE}
  175. {$setc TARGET_API_MAC_OS8 := FALSE}
  176. {$setc TARGET_API_MAC_OSX := TRUE}
  177. {$setc TARGET_CARBON := TRUE}
  178. {$setc TARGET_CPU_68K := FALSE}
  179. {$setc TARGET_CPU_MIPS := FALSE}
  180. {$setc TARGET_CPU_SPARC := FALSE}
  181. {$setc TARGET_OS_UNIX := FALSE}
  182. {$setc TARGET_OS_WIN32 := FALSE}
  183. {$setc TARGET_RT_MAC_68881 := FALSE}
  184. {$setc TARGET_RT_MAC_CFM := FALSE}
  185. {$setc TARGET_RT_MAC_MACHO := TRUE}
  186. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  187. {$setc TYPE_BOOL := FALSE}
  188. {$setc TYPE_EXTENDED := FALSE}
  189. {$setc TYPE_LONGLONG := TRUE}
  190. uses MacTypes,MacOSXPosix,CFBase,CFData,CGBase,CFURL;
  191. {$endc} {not MACOSALLINCLUDE}
  192. {$ALIGN POWER}
  193. type
  194. CGDataProviderRef = ^OpaqueCGDataProviderRef; { an opaque type }
  195. OpaqueCGDataProviderRef = record end;
  196. { This callback is called to copy `count' bytes from the sequential data
  197. stream to `buffer'. }
  198. type
  199. CGDataProviderGetBytesCallback = function( info: UnivPtr; buffer: UnivPtr; count: size_t ): size_t;
  200. { This callback is called to skip `count' bytes forward in the sequential
  201. data stream. It should return the number of bytes that were actually
  202. skipped. }
  203. type
  204. CGDataProviderSkipForwardCallback = function( info: UnivPtr; count: off_t ): off_t;
  205. { This callback is called to rewind to the beginning of sequential data
  206. stream. }
  207. type
  208. CGDataProviderRewindCallback = procedure( info: UnivPtr );
  209. { This callback is called to release the `info' pointer when the data
  210. provider is freed. }
  211. type
  212. CGDataProviderReleaseInfoCallback = procedure( info: UnivPtr );
  213. { Callbacks for sequentially accessing data.
  214. `version' is the version of this structure. It should be set to 0.
  215. `getBytes' is called to copy `count' bytes from the sequential data
  216. stream to `buffer'. It should return the number of bytes copied, or 0
  217. if there's no more data.
  218. `skipForward' is called to skip ahead in the sequential data stream by
  219. `count' bytes.
  220. `rewind' is called to rewind the sequential data stream to the beginning
  221. of the data.
  222. `releaseInfo', if non-NULL, is called to release the `info' pointer when
  223. the provider is freed. }
  224. type
  225. CGDataProviderSequentialCallbacks = record
  226. version: UInt32;
  227. {$ifc TARGET_CPU_64}
  228. __alignment_dummy: UInt32;
  229. {$endc}
  230. getBytes: CGDataProviderGetBytesCallback;
  231. skipForward: CGDataProviderSkipForwardCallback;
  232. rewind: CGDataProviderRewindCallback;
  233. releaseInfo: CGDataProviderReleaseInfoCallback;
  234. end;
  235. { This callback is called to get a pointer to the entire block of data. }
  236. type
  237. CGDataProviderGetBytePointerCallback = function( info: UnivPtr ): UnivPtr;
  238. { This callback is called to release the pointer to entire block of
  239. data. }
  240. type
  241. CGDataProviderReleaseBytePointerCallback = procedure( info: UnivPtr; pointr: {const} UnivPtr );
  242. { This callback is called to copy `count' bytes at byte offset `position'
  243. into `buffer'. }
  244. type
  245. CGDataProviderGetBytesAtPositionCallback = function( info: UnivPtr; buffer: UnivPtr; position: off_t; count: size_t ): size_t;
  246. { Callbacks for directly accessing data.
  247. `version' is the version of this structure. It should be set to 0.
  248. `getBytePointer', if non-NULL, is called to return a pointer to the
  249. provider's entire block of data.
  250. `releaseBytePointer', if non-NULL, is called to release a pointer to the
  251. provider's entire block of data.
  252. `getBytesAtPosition', if non-NULL, is called to copy `count' bytes at
  253. offset `position' from the provider's data to `buffer'. It should
  254. return the number of bytes copied, or 0 if there's no more data.
  255. `releaseInfo', if non-NULL, is called to release the `info' pointer when
  256. the provider is freed.
  257. At least one of `getBytePointer' or `getBytesAtPosition' must be
  258. non-NULL. }
  259. type
  260. CGDataProviderDirectCallbacks = record
  261. version: UInt32;
  262. {$ifc TARGET_CPU_64}
  263. __alignment_dummy: UInt32;
  264. {$endc}
  265. getBytePointer: CGDataProviderGetBytePointerCallback;
  266. releaseBytePointer: CGDataProviderReleaseBytePointerCallback;
  267. getBytesAtPosition: CGDataProviderGetBytesAtPositionCallback;
  268. releaseInfo: CGDataProviderReleaseInfoCallback;
  269. end;
  270. { Return the CFTypeID for CGDataProviderRefs. }
  271. function CGDataProviderGetTypeID: CFTypeID; external name '_CGDataProviderGetTypeID';
  272. (* CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0) *)
  273. { Create a sequential-access data provider using `callbacks' to provide the
  274. data. `info' is passed to each of the callback functions. }
  275. function CGDataProviderCreateSequential( info: UnivPtr; const (*var*) callbacks: CGDataProviderSequentialCallbacks ): CGDataProviderRef; external name '_CGDataProviderCreateSequential';
  276. (* CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0) *)
  277. { Create a direct-access data provider using `callbacks' to supply `size'
  278. bytes of data. `info' is passed to each of the callback functions. }
  279. function CGDataProviderCreateDirect( info: UnivPtr; size: off_t; const (*var*) callbacks: CGDataProviderDirectCallbacks ): CGDataProviderRef; external name '_CGDataProviderCreateDirect';
  280. (* CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0) *)
  281. { The callback used by `CGDataProviderCreateWithData'. }
  282. type
  283. CGDataProviderReleaseDataCallback = procedure( info: UnivPtr; data: {const} UnivPtr; size: size_t );
  284. { Create a direct-access data provider using `data', an array of `size'
  285. bytes. `releaseData' is called when the data provider is freed, and is
  286. passed `info' as its first argument. }
  287. function CGDataProviderCreateWithData( info: UnivPtr; data: {const} UnivPtr; size: size_t; releaseData: CGDataProviderReleaseDataCallback ): CGDataProviderRef; external name '_CGDataProviderCreateWithData';
  288. (* CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0) *)
  289. { Create a direct-access data provider which reads from `data'. }
  290. function CGDataProviderCreateWithCFData( data: CFDataRef ): CGDataProviderRef; external name '_CGDataProviderCreateWithCFData';
  291. (* CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0) *)
  292. { Create a data provider reading from `url'. }
  293. function CGDataProviderCreateWithURL( url: CFURLRef ): CGDataProviderRef; external name '_CGDataProviderCreateWithURL';
  294. (* CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0) *)
  295. { Create a data provider reading from `filename'. }
  296. function CGDataProviderCreateWithFilename( filename: ConstCStringPtr ): CGDataProviderRef; external name '_CGDataProviderCreateWithFilename';
  297. (* CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0) *)
  298. { Equivalent to `CFRetain(provider)', but doesn't crash (as CFRetain does)
  299. if `provider' is NULL. }
  300. function CGDataProviderRetain( provider: CGDataProviderRef ): CGDataProviderRef; external name '_CGDataProviderRetain';
  301. (* CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0) *)
  302. { Equivalent to `CFRelease(provider)', but doesn't crash (as CFRelease
  303. does) if `provider' is NULL. }
  304. procedure CGDataProviderRelease( provider: CGDataProviderRef ); external name '_CGDataProviderRelease';
  305. (* CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0) *)
  306. { Return a copy of the data specified by provider. Returns NULL if a
  307. complete copy of the data can't be obtained (for example, if the
  308. underlying data is too large to fit in memory). }
  309. function CGDataProviderCopyData( provider: CGDataProviderRef ): CFDataRef; external name '_CGDataProviderCopyData';
  310. (* CG_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0) *)
  311. {$ifc TARGET_OS_MAC}
  312. { Deprecated API. }
  313. { This callback is called to skip `count' bytes forward in the sequential
  314. data stream. }
  315. type
  316. CGDataProviderSkipBytesCallback = procedure( info: UnivPtr; count: size_t );
  317. { Old-style callbacks for sequentially accessing data.
  318. `getBytes' is called to copy `count' bytes from the sequential data
  319. stream to `buffer'. It should return the number of bytes copied, or 0
  320. if there's no more data.
  321. `skipBytes' is called to skip ahead in the sequential data stream by
  322. `count' bytes.
  323. `rewind' is called to rewind the sequential data stream to the beginning
  324. of the data.
  325. `releaseProvider', if non-NULL, is called to release the `info' pointer
  326. when the provider is freed. }
  327. type
  328. CGDataProviderCallbacks = record
  329. getBytes: CGDataProviderGetBytesCallback;
  330. skipBytes: CGDataProviderSkipBytesCallback;
  331. rewind: CGDataProviderRewindCallback;
  332. releaseProvider: CGDataProviderReleaseInfoCallback;
  333. end;
  334. { This callback is called to copy `count' bytes at byte offset `offset'
  335. into `buffer'. }
  336. type
  337. CGDataProviderGetBytesAtOffsetCallback = function( info: UnivPtr; buffer: UnivPtr; offset: size_t; count: size_t ): size_t;
  338. { Callbacks for directly accessing data.
  339. `getBytePointer', if non-NULL, is called to return a pointer to the
  340. provider's entire block of data.
  341. `releaseBytePointer', if non-NULL, is called to release a pointer to the
  342. provider's entire block of data.
  343. `getBytes', if non-NULL, is called to copy `count' bytes at offset
  344. `offset' from the provider's data to `buffer'. It should return the
  345. number of bytes copied, or 0 if there's no more data.
  346. `releaseProvider', if non-NULL, is called when the provider is freed.
  347. At least one of `getBytePointer' or `getBytes' must be non-NULL. }
  348. type
  349. CGDataProviderDirectAccessCallbacks = record
  350. getBytePointer: CGDataProviderGetBytePointerCallback;
  351. releaseBytePointer: CGDataProviderReleaseBytePointerCallback;
  352. getBytes: CGDataProviderGetBytesAtOffsetCallback;
  353. releaseProvider: CGDataProviderReleaseInfoCallback;
  354. end;
  355. { Create a sequential-access data provider using `callbacks' to provide the
  356. data. `info' is passed to each of the callback functions. }
  357. function CGDataProviderCreate( info: UnivPtr; const (*var*) callbacks: CGDataProviderCallbacks ): CGDataProviderRef; external name '_CGDataProviderCreate';
  358. (* CG_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  359. { Create a direct-access data provider using `callbacks' to supply `size'
  360. bytes of data. `info' is passed to each of the callback functions. }
  361. function CGDataProviderCreateDirectAccess( info: UnivPtr; size: size_t; const (*var*) callbacks: CGDataProviderDirectAccessCallbacks ): CGDataProviderRef; external name '_CGDataProviderCreateDirectAccess';
  362. (* CG_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_5, __IPHONE_NA, __IPHONE_NA) *)
  363. {$endc}
  364. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  365. end.
  366. {$endc} {not MACOSALLINCLUDE}