CGDisplayFade.pas 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. {
  2. * CGDisplayFade.h
  3. * CoreGraphics
  4. *
  5. * API to fade displays to and from a solid color, without resorting
  6. * to playing with the gamma table APIs and losing ColorSync calibration.
  7. *
  8. * These APIs should be used in perference to manipulating the gamma tables
  9. * for purposes of performing fade effects.
  10. *
  11. * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
  12. *
  13. }
  14. { Pascal Translation: Peter N Lewis, <[email protected]>, August 2005 }
  15. {
  16. Modified for use with Free Pascal
  17. Version 200
  18. Please report any bugs to <[email protected]>
  19. }
  20. {$mode macpas}
  21. {$packenum 1}
  22. {$macro on}
  23. {$inline on}
  24. {$CALLING MWPASCAL}
  25. unit CGDisplayFade;
  26. interface
  27. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  28. {$setc GAP_INTERFACES_VERSION := $0200}
  29. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  30. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  31. {$endc}
  32. {$ifc defined CPUPOWERPC and defined CPUI386}
  33. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  34. {$endc}
  35. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  36. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  37. {$endc}
  38. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  39. {$setc __ppc__ := 1}
  40. {$elsec}
  41. {$setc __ppc__ := 0}
  42. {$endc}
  43. {$ifc not defined __i386__ and defined CPUI386}
  44. {$setc __i386__ := 1}
  45. {$elsec}
  46. {$setc __i386__ := 0}
  47. {$endc}
  48. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  49. {$error Conflicting definitions for __ppc__ and __i386__}
  50. {$endc}
  51. {$ifc defined __ppc__ and __ppc__}
  52. {$setc TARGET_CPU_PPC := TRUE}
  53. {$setc TARGET_CPU_X86 := FALSE}
  54. {$elifc defined __i386__ and __i386__}
  55. {$setc TARGET_CPU_PPC := FALSE}
  56. {$setc TARGET_CPU_X86 := TRUE}
  57. {$elsec}
  58. {$error Neither __ppc__ nor __i386__ is defined.}
  59. {$endc}
  60. {$setc TARGET_CPU_PPC_64 := FALSE}
  61. {$ifc defined FPC_BIG_ENDIAN}
  62. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  63. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  64. {$elifc defined FPC_LITTLE_ENDIAN}
  65. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  66. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  67. {$elsec}
  68. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  69. {$endc}
  70. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  71. {$setc CALL_NOT_IN_CARBON := FALSE}
  72. {$setc OLDROUTINENAMES := FALSE}
  73. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  74. {$setc OPAQUE_UPP_TYPES := TRUE}
  75. {$setc OTCARBONAPPLICATION := TRUE}
  76. {$setc OTKERNEL := FALSE}
  77. {$setc PM_USE_SESSION_APIS := TRUE}
  78. {$setc TARGET_API_MAC_CARBON := TRUE}
  79. {$setc TARGET_API_MAC_OS8 := FALSE}
  80. {$setc TARGET_API_MAC_OSX := TRUE}
  81. {$setc TARGET_CARBON := TRUE}
  82. {$setc TARGET_CPU_68K := FALSE}
  83. {$setc TARGET_CPU_MIPS := FALSE}
  84. {$setc TARGET_CPU_SPARC := FALSE}
  85. {$setc TARGET_OS_MAC := TRUE}
  86. {$setc TARGET_OS_UNIX := FALSE}
  87. {$setc TARGET_OS_WIN32 := FALSE}
  88. {$setc TARGET_RT_MAC_68881 := FALSE}
  89. {$setc TARGET_RT_MAC_CFM := FALSE}
  90. {$setc TARGET_RT_MAC_MACHO := TRUE}
  91. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  92. {$setc TYPE_BOOL := FALSE}
  93. {$setc TYPE_EXTENDED := FALSE}
  94. {$setc TYPE_LONGLONG := TRUE}
  95. uses MacTypes,CGBase,CGErrors,CGDirectDisplay,CGDisplayConfiguration;
  96. {$ALIGN POWER}
  97. type
  98. CGDisplayFadeReservationToken = UInt32;
  99. const
  100. kCGDisplayFadeReservationInvalidToken = 0;
  101. type
  102. CGDisplayBlendFraction = Float32;
  103. {
  104. * Values for the limits of the fade.
  105. * kCGDisplayBlendNormal represents a normal display state
  106. * kCGDisplayBlendSolidColor represents a display blended to a solid color
  107. }
  108. const
  109. kCGDisplayBlendNormal = 0.0;
  110. const
  111. kCGDisplayBlendSolidColor = 1.0;
  112. {
  113. * Time in seconds to perform a fade operation.
  114. }
  115. type
  116. CGDisplayFadeInterval = Float32;
  117. {
  118. *
  119. * Most fade operations done by apps and games are done around display
  120. * configuration changes. This API adds control over a built-in fade
  121. * effect when performing display configuration changes.
  122. *
  123. * The default fade effect on a display mode change uses a fade-out of
  124. * 0.3 seconds and a fade-in of 0.5 seconds. Color fades to French Blue
  125. * for a normal desktop, and black when displays are captured.
  126. *
  127. * CGConfigureDisplayFadeEffect sets the display fade time and color
  128. * for a display reconfigure operation.
  129. * Call after CGBeginDisplayConfiguration() and before
  130. * calling CGCompleteDisplayConfiguration().
  131. *
  132. * When CGCompleteDisplayConfiguration() is called, a fade-out effect will be
  133. * done prior to the display reconfiguration. When the display reconfiguration
  134. * is complete, control returns to the calling program, while a fade-in effect
  135. * runs asynchronously.
  136. }
  137. function CGConfigureDisplayFadeEffect( configRef: CGDisplayConfigRef; fadeOutSeconds: CGDisplayFadeInterval; fadeInSeconds: CGDisplayFadeInterval; fadeRed: Float32; fadeGreen: Float32; fadeBlue: Float32 ): CGError; external name '_CGConfigureDisplayFadeEffect';
  138. {
  139. * It may also be desirable to perform fade operations at other times, as when
  140. * transitioning between game play and cinematic sequences. The following API
  141. * provides a mechanism for controlling display fade operations outside of display
  142. * mode reconfigurations.
  143. }
  144. type
  145. CGDisplayReservationInterval = Float32;
  146. const
  147. kCGMaxDisplayReservationInterval = 15.0;
  148. {
  149. * Before performing fade operation, the caller must reserve the hardware
  150. * for the expected period of time that the program will be doing fades
  151. *
  152. * A reservation token is returned that must be passed in on subsequent calls.
  153. *
  154. * Failing to release the hardware by the end of the reservation interval will
  155. * result in the reservation token becomingn invalid, and the hardware being
  156. * unfaded back to a normal state. The reservation interval is limited (clipped)
  157. * to 15 seconds maximum, and should be greater than zero.
  158. *
  159. * Returns kCGErrorNoneAvailable if another reservation is in effect,
  160. * and kCGErrorSuccess on success.
  161. }
  162. function CGAcquireDisplayFadeReservation( seconds: CGDisplayReservationInterval; var pNewToken: CGDisplayFadeReservationToken ): CGError; external name '_CGAcquireDisplayFadeReservation';
  163. {
  164. * Releases a display fade reservation, and unfades the display if needed
  165. * The reservation token myToken is no longer valid after this operation.
  166. *
  167. * CGReleaseDisplayFadeReservation may be safely called while an async fade
  168. * operation is running, and if the ending blend value is kCGDisplayBlendNormal,
  169. * will not disturb the running operation. The reservation is dropped when the
  170. * fade opertion completes.
  171. *
  172. * Returns kCGErrorIllegalArgument if myToken is not the valid reservation token,
  173. * and kCGErrorSuccess on success.
  174. }
  175. function CGReleaseDisplayFadeReservation( myToken: CGDisplayFadeReservationToken ): CGError; external name '_CGReleaseDisplayFadeReservation';
  176. {
  177. * The actual fade mechanism:
  178. *
  179. * The function takes the current reservation token,
  180. * a time interval to perform the fade operation in seconds,
  181. * a starting and ending blend coefficient, an RGB color in device space,
  182. * and a boolean to indicate that the operation should be done synchronously.
  183. *
  184. * Over the fade operation time interval, the system will interpolate a
  185. * blending coefficient between the starting and ending values given,
  186. * applying a nonlinear (sine-based) bias term, and will blend the video output
  187. * with the specified color based on the resulting value.
  188. *
  189. * If the time interval is specifed as 0.0, then the ending state blend value is
  190. * applied at once and the function returns.
  191. *
  192. * The maximum allowable time interval is 15 seconds.
  193. *
  194. * If the parameter 'synchronous' is true, the function does not return
  195. * til the fade operation is complete. If false, the function returns at once,
  196. * and the fade operation runs asynchronously.
  197. *
  198. * CGReleaseDisplayFadeReservation may be safely called while an async fade
  199. * operation is running, and if the ending blend value is kCGDisplayBlendNormal,
  200. * will not disturb the running operation. The reservation is dropped when the
  201. * fade opertion completes.
  202. *
  203. * Invalid parameters result in a return value of kCGErrorIllegalArgument.
  204. * Trying to start a fade operation while an asynchronous fade operation is running
  205. * results in a return value of kCGErrorNoneAvailable.
  206. *
  207. * To perform a 2 second fade to black, waiting til complete:
  208. *
  209. * CGDisplayFade(myToken,
  210. * 2.0, // 2 seconds
  211. * kCGDisplayBlendNormal, // Starting state
  212. * kCGDisplayBlendSolidColor, // Ending state
  213. * 0.0, 0.0, 0.0, // black
  214. * true); // Wait for completion
  215. *
  216. * To perform a 2 second fade from black to normal, without waiting for completion:
  217. *
  218. * CGDisplayFade(myToken,
  219. * 2.0, // 2 seconds
  220. * kCGDisplayBlendSolidColor, // Starting state
  221. * kCGDisplayBlendNormal, // Ending state
  222. * 0.0, 0.0, 0.0, // black
  223. * false); // Don't wait for completion
  224. }
  225. function CGDisplayFade( myToken: CGDisplayFadeReservationToken; seconds: CGDisplayFadeInterval; startBlend: CGDisplayBlendFraction; endBlend: CGDisplayBlendFraction; redBlend: Float32; greenBlend: Float32; blueBlend: Float32; synchronous: boolean_t ): CGError; external name '_CGDisplayFade';
  226. {
  227. * Returns true if a fade operation is currently in progress.
  228. }
  229. function CGDisplayFadeOperationInProgress: boolean_t; external name '_CGDisplayFadeOperationInProgress';
  230. end.