jawt.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
  3. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. *
  5. *
  6. *
  7. *
  8. *
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *
  15. *
  16. *
  17. *
  18. *
  19. *
  20. *
  21. *
  22. *
  23. *
  24. */
  25. #ifndef _JAVASOFT_JAWT_H_
  26. #define _JAVASOFT_JAWT_H_
  27. #include "jni.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /*
  32. * AWT native interface (new in JDK 1.3)
  33. *
  34. * The AWT native interface allows a native C or C++ application a means
  35. * by which to access native structures in AWT. This is to facilitate moving
  36. * legacy C and C++ applications to Java and to target the needs of the
  37. * community who, at present, wish to do their own native rendering to canvases
  38. * for performance reasons. Standard extensions such as Java3D also require a
  39. * means to access the underlying native data structures of AWT.
  40. *
  41. * There may be future extensions to this API depending on demand.
  42. *
  43. * A VM does not have to implement this API in order to pass the JCK.
  44. * It is recommended, however, that this API is implemented on VMs that support
  45. * standard extensions, such as Java3D.
  46. *
  47. * Since this is a native API, any program which uses it cannot be considered
  48. * 100% pure java.
  49. */
  50. /*
  51. * AWT Native Drawing Surface (JAWT_DrawingSurface).
  52. *
  53. * For each platform, there is a native drawing surface structure. This
  54. * platform-specific structure can be found in jawt_md.h. It is recommended
  55. * that additional platforms follow the same model. It is also recommended
  56. * that VMs on Win32 and Solaris support the existing structures in jawt_md.h.
  57. *
  58. *******************
  59. * EXAMPLE OF USAGE:
  60. *******************
  61. *
  62. * In Win32, a programmer wishes to access the HWND of a canvas to perform
  63. * native rendering into it. The programmer has declared the paint() method
  64. * for their canvas subclass to be native:
  65. *
  66. *
  67. * MyCanvas.java:
  68. *
  69. * import java.awt.*;
  70. *
  71. * public class MyCanvas extends Canvas {
  72. *
  73. * static {
  74. * System.loadLibrary("mylib");
  75. * }
  76. *
  77. * public native void paint(Graphics g);
  78. * }
  79. *
  80. *
  81. * myfile.c:
  82. *
  83. * #include "jawt_md.h"
  84. * #include <assert.h>
  85. *
  86. * JNIEXPORT void JNICALL
  87. * Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics)
  88. * {
  89. * JAWT awt;
  90. * JAWT_DrawingSurface* ds;
  91. * JAWT_DrawingSurfaceInfo* dsi;
  92. * JAWT_Win32DrawingSurfaceInfo* dsi_win;
  93. * jboolean result;
  94. * jint lock;
  95. *
  96. * // Get the AWT
  97. * awt.version = JAWT_VERSION_1_3;
  98. * result = JAWT_GetAWT(env, &awt);
  99. * assert(result != JNI_FALSE);
  100. *
  101. * // Get the drawing surface
  102. * ds = awt.GetDrawingSurface(env, canvas);
  103. * assert(ds != NULL);
  104. *
  105. * // Lock the drawing surface
  106. * lock = ds->Lock(ds);
  107. * assert((lock & JAWT_LOCK_ERROR) == 0);
  108. *
  109. * // Get the drawing surface info
  110. * dsi = ds->GetDrawingSurfaceInfo(ds);
  111. *
  112. * // Get the platform-specific drawing info
  113. * dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
  114. *
  115. * //////////////////////////////
  116. * // !!! DO PAINTING HERE !!! //
  117. * //////////////////////////////
  118. *
  119. * // Free the drawing surface info
  120. * ds->FreeDrawingSurfaceInfo(dsi);
  121. *
  122. * // Unlock the drawing surface
  123. * ds->Unlock(ds);
  124. *
  125. * // Free the drawing surface
  126. * awt.FreeDrawingSurface(ds);
  127. * }
  128. *
  129. */
  130. /*
  131. * JAWT_Rectangle
  132. * Structure for a native rectangle.
  133. */
  134. typedef struct jawt_Rectangle {
  135. jint x;
  136. jint y;
  137. jint width;
  138. jint height;
  139. } JAWT_Rectangle;
  140. struct jawt_DrawingSurface;
  141. /*
  142. * JAWT_DrawingSurfaceInfo
  143. * Structure for containing the underlying drawing information of a component.
  144. */
  145. typedef struct jawt_DrawingSurfaceInfo {
  146. /*
  147. * Pointer to the platform-specific information. This can be safely
  148. * cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a
  149. * JAWT_X11DrawingSurfaceInfo on Solaris. On Mac OS X this is a
  150. * pointer to a NSObject that conforms to the JAWT_SurfaceLayers
  151. * protocol. See jawt_md.h for details.
  152. */
  153. void* platformInfo;
  154. /* Cached pointer to the underlying drawing surface */
  155. struct jawt_DrawingSurface* ds;
  156. /* Bounding rectangle of the drawing surface */
  157. JAWT_Rectangle bounds;
  158. /* Number of rectangles in the clip */
  159. jint clipSize;
  160. /* Clip rectangle array */
  161. JAWT_Rectangle* clip;
  162. } JAWT_DrawingSurfaceInfo;
  163. #define JAWT_LOCK_ERROR 0x00000001
  164. #define JAWT_LOCK_CLIP_CHANGED 0x00000002
  165. #define JAWT_LOCK_BOUNDS_CHANGED 0x00000004
  166. #define JAWT_LOCK_SURFACE_CHANGED 0x00000008
  167. /*
  168. * JAWT_DrawingSurface
  169. * Structure for containing the underlying drawing information of a component.
  170. * All operations on a JAWT_DrawingSurface MUST be performed from the same
  171. * thread as the call to GetDrawingSurface.
  172. */
  173. typedef struct jawt_DrawingSurface {
  174. /*
  175. * Cached reference to the Java environment of the calling thread.
  176. * If Lock(), Unlock(), GetDrawingSurfaceInfo() or
  177. * FreeDrawingSurfaceInfo() are called from a different thread,
  178. * this data member should be set before calling those functions.
  179. */
  180. JNIEnv* env;
  181. /* Cached reference to the target object */
  182. jobject target;
  183. /*
  184. * Lock the surface of the target component for native rendering.
  185. * When finished drawing, the surface must be unlocked with
  186. * Unlock(). This function returns a bitmask with one or more of the
  187. * following values:
  188. *
  189. * JAWT_LOCK_ERROR - When an error has occurred and the surface could not
  190. * be locked.
  191. *
  192. * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
  193. *
  194. * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
  195. *
  196. * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
  197. */
  198. jint (JNICALL *Lock)
  199. (struct jawt_DrawingSurface* ds);
  200. /*
  201. * Get the drawing surface info.
  202. * The value returned may be cached, but the values may change if
  203. * additional calls to Lock() or Unlock() are made.
  204. * Lock() must be called before this can return a valid value.
  205. * Returns NULL if an error has occurred.
  206. * When finished with the returned value, FreeDrawingSurfaceInfo must be
  207. * called.
  208. */
  209. JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo)
  210. (struct jawt_DrawingSurface* ds);
  211. /*
  212. * Free the drawing surface info.
  213. */
  214. void (JNICALL *FreeDrawingSurfaceInfo)
  215. (JAWT_DrawingSurfaceInfo* dsi);
  216. /*
  217. * Unlock the drawing surface of the target component for native rendering.
  218. */
  219. void (JNICALL *Unlock)
  220. (struct jawt_DrawingSurface* ds);
  221. } JAWT_DrawingSurface;
  222. /*
  223. * JAWT
  224. * Structure for containing native AWT functions.
  225. */
  226. typedef struct jawt {
  227. /*
  228. * Version of this structure. This must always be set before
  229. * calling JAWT_GetAWT()
  230. */
  231. jint version;
  232. /*
  233. * Return a drawing surface from a target jobject. This value
  234. * may be cached.
  235. * Returns NULL if an error has occurred.
  236. * Target must be a java.awt.Component (should be a Canvas
  237. * or Window for native rendering).
  238. * FreeDrawingSurface() must be called when finished with the
  239. * returned JAWT_DrawingSurface.
  240. */
  241. JAWT_DrawingSurface* (JNICALL *GetDrawingSurface)
  242. (JNIEnv* env, jobject target);
  243. /*
  244. * Free the drawing surface allocated in GetDrawingSurface.
  245. */
  246. void (JNICALL *FreeDrawingSurface)
  247. (JAWT_DrawingSurface* ds);
  248. /*
  249. * Since 1.4
  250. * Locks the entire AWT for synchronization purposes
  251. */
  252. void (JNICALL *Lock)(JNIEnv* env);
  253. /*
  254. * Since 1.4
  255. * Unlocks the entire AWT for synchronization purposes
  256. */
  257. void (JNICALL *Unlock)(JNIEnv* env);
  258. /*
  259. * Since 1.4
  260. * Returns a reference to a java.awt.Component from a native
  261. * platform handle. On Windows, this corresponds to an HWND;
  262. * on Solaris and Linux, this is a Drawable. For other platforms,
  263. * see the appropriate machine-dependent header file for a description.
  264. * The reference returned by this function is a local
  265. * reference that is only valid in this environment.
  266. * This function returns a NULL reference if no component could be
  267. * found with matching platform information.
  268. */
  269. jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);
  270. } JAWT;
  271. /*
  272. * Get the AWT native structure. This function returns JNI_FALSE if
  273. * an error occurs.
  274. */
  275. _JNI_IMPORT_OR_EXPORT_
  276. jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt);
  277. #define JAWT_VERSION_1_3 0x00010003
  278. #define JAWT_VERSION_1_4 0x00010004
  279. #define JAWT_VERSION_1_7 0x00010007
  280. #ifdef __cplusplus
  281. } /* extern "C" */
  282. #endif
  283. #endif /* !_JAVASOFT_JAWT_H_ */