00001 /* 00002 * @(#)jawt.h 1.8 01/12/03 00003 * 00004 * Copyright 2002 Sun Microsystems, Inc. All rights reserved. 00005 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 00006 */ 00007 00008 #ifndef _JAVASOFT_JAWT_H_ 00009 #define _JAVASOFT_JAWT_H_ 00010 00011 #include "jni.h" 00012 00013 #ifdef __cplusplus 00014 extern "C" { 00015 #endif 00016 00017 /* 00018 * AWT native interface (new in JDK 1.3) 00019 * 00020 * The AWT native interface allows a native C or C++ application a means 00021 * by which to access native structures in AWT. This is to facilitate moving 00022 * legacy C and C++ applications to Java and to target the needs of the 00023 * community who, at present, wish to do their own native rendering to canvases 00024 * for performance reasons. Standard extensions such as Java3D also require a 00025 * means to access the underlying native data structures of AWT. 00026 * 00027 * There may be future extensions to this API depending on demand. 00028 * 00029 * A VM does not have to implement this API in order to pass the JCK. 00030 * It is recommended, however, that this API is implemented on VMs that support 00031 * standard extensions, such as Java3D. 00032 * 00033 * Since this is a native API, any program which uses it cannot be considered 00034 * 100% pure java. 00035 */ 00036 00037 /* 00038 * AWT Native Drawing Surface (JAWT_DrawingSurface). 00039 * 00040 * For each platform, there is a native drawing surface structure. This 00041 * platform-specific structure can be found in jawt_md.h. It is recommended 00042 * that additional platforms follow the same model. It is also recommended 00043 * that VMs on Win32 and Solaris support the existing structures in jawt_md.h. 00044 * 00045 ******************* 00046 * EXAMPLE OF USAGE: 00047 ******************* 00048 * 00049 * In Win32, a programmer wishes to access the HWND of a canvas to perform 00050 * native rendering into it. The programmer has declared the paint() method 00051 * for their canvas subclass to be native: 00052 * 00053 * 00054 * MyCanvas.java: 00055 * 00056 * import java.awt.*; 00057 * 00058 * public class MyCanvas extends Canvas { 00059 * 00060 * static { 00061 * System.loadLibrary("mylib"); 00062 * } 00063 * 00064 * public native void paint(Graphics g); 00065 * } 00066 * 00067 * 00068 * myfile.c: 00069 * 00070 * #include "jawt_md.h" 00071 * #include <assert.h> 00072 * 00073 * JNIEXPORT void JNICALL 00074 * Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics) 00075 * { 00076 * JAWT awt; 00077 * JAWT_DrawingSurface* ds; 00078 * JAWT_DrawingSurfaceInfo* dsi; 00079 * JAWT_Win32DrawingSurfaceInfo* dsi_win; 00080 * jboolean result; 00081 * jint lock; 00082 * 00083 * // Get the AWT 00084 * awt.version = JAWT_VERSION_1_3; 00085 * result = JAWT_GetAWT(env, &awt); 00086 * assert(result != JNI_FALSE); 00087 * 00088 * // Get the drawing surface 00089 * ds = awt.GetDrawingSurface(env, canvas); 00090 * assert(ds != NULL); 00091 * 00092 * // Lock the drawing surface 00093 * lock = ds->Lock(ds); 00094 * assert((lock & JAWT_LOCK_ERROR) == 0); 00095 * 00096 * // Get the drawing surface info 00097 * dsi = ds->GetDrawingSurfaceInfo(ds); 00098 * 00099 * // Get the platform-specific drawing info 00100 * dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo; 00101 * 00102 * ////////////////////////////// 00103 * // !!! DO PAINTING HERE !!! // 00104 * ////////////////////////////// 00105 * 00106 * // Free the drawing surface info 00107 * ds->FreeDrawingSurfaceInfo(dsi); 00108 * 00109 * // Unlock the drawing surface 00110 * ds->Unlock(ds); 00111 * 00112 * // Free the drawing surface 00113 * awt.FreeDrawingSurface(ds); 00114 * } 00115 * 00116 */ 00117 00118 /* 00119 * JAWT_Rectangle 00120 * Structure for a native rectangle. 00121 */ 00122 typedef struct jawt_Rectangle { 00123 jint x; 00124 jint y; 00125 jint width; 00126 jint height; 00127 } JAWT_Rectangle; 00128 00129 struct jawt_DrawingSurface; 00130 00131 /* 00132 * JAWT_DrawingSurfaceInfo 00133 * Structure for containing the underlying drawing information of a component. 00134 */ 00135 typedef struct jawt_DrawingSurfaceInfo { 00136 /* 00137 * Pointer to the platform-specific information. This can be safely 00138 * cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a 00139 * JAWT_X11DrawingSurfaceInfo on Solaris. See jawt_md.h for details. 00140 */ 00141 void* platformInfo; 00142 /* Cached pointer to the underlying drawing surface */ 00143 struct jawt_DrawingSurface* ds; 00144 /* Bounding rectangle of the drawing surface */ 00145 JAWT_Rectangle bounds; 00146 /* Number of rectangles in the clip */ 00147 jint clipSize; 00148 /* Clip rectangle array */ 00149 JAWT_Rectangle* clip; 00150 } JAWT_DrawingSurfaceInfo; 00151 00152 #define JAWT_LOCK_ERROR 0x00000001 00153 #define JAWT_LOCK_CLIP_CHANGED 0x00000002 00154 #define JAWT_LOCK_BOUNDS_CHANGED 0x00000004 00155 #define JAWT_LOCK_SURFACE_CHANGED 0x00000008 00156 00157 /* 00158 * JAWT_DrawingSurface 00159 * Structure for containing the underlying drawing information of a component. 00160 * All operations on a JAWT_DrawingSurface MUST be performed from the same 00161 * thread as the call to GetDrawingSurface. 00162 */ 00163 typedef struct jawt_DrawingSurface { 00164 /* 00165 * Cached reference to the Java environment of the calling thread. 00166 * If Lock(), Unlock(), GetDrawingSurfaceInfo() or 00167 * FreeDrawingSurfaceInfo() are called from a different thread, 00168 * this data member should be set before calling those functions. 00169 */ 00170 JNIEnv* env; 00171 /* Cached reference to the target object */ 00172 jobject target; 00173 /* 00174 * Lock the surface of the target component for native rendering. 00175 * When finished drawing, the surface must be unlocked with 00176 * Unlock(). This function returns a bitmask with one or more of the 00177 * following values: 00178 * 00179 * JAWT_LOCK_ERROR - When an error has occurred and the surface could not 00180 * be locked. 00181 * 00182 * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed. 00183 * 00184 * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed. 00185 * 00186 * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed 00187 */ 00188 jint (JNICALL *Lock) 00189 (struct jawt_DrawingSurface* ds); 00190 /* 00191 * Get the drawing surface info. 00192 * The value returned may be cached, but the values may change if 00193 * additional calls to Lock() or Unlock() are made. 00194 * Lock() must be called before this can return a valid value. 00195 * Returns NULL if an error has occurred. 00196 * When finished with the returned value, FreeDrawingSurfaceInfo must be 00197 * called. 00198 */ 00199 JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo) 00200 (struct jawt_DrawingSurface* ds); 00201 /* 00202 * Free the drawing surface info. 00203 */ 00204 void (JNICALL *FreeDrawingSurfaceInfo) 00205 (JAWT_DrawingSurfaceInfo* dsi); 00206 /* 00207 * Unlock the drawing surface of the target component for native rendering. 00208 */ 00209 void (JNICALL *Unlock) 00210 (struct jawt_DrawingSurface* ds); 00211 } JAWT_DrawingSurface; 00212 00213 /* 00214 * JAWT 00215 * Structure for containing native AWT functions. 00216 */ 00217 typedef struct jawt { 00218 /* 00219 * Version of this structure. This must always be set before 00220 * calling JAWT_GetAWT() 00221 */ 00222 jint version; 00223 /* 00224 * Return a drawing surface from a target jobject. This value 00225 * may be cached. 00226 * Returns NULL if an error has occurred. 00227 * Target must be a java.awt.Component (should be a Canvas 00228 * or Window for native rendering). 00229 * FreeDrawingSurface() must be called when finished with the 00230 * returned JAWT_DrawingSurface. 00231 */ 00232 JAWT_DrawingSurface* (JNICALL *GetDrawingSurface) 00233 (JNIEnv* env, jobject target); 00234 /* 00235 * Free the drawing surface allocated in GetDrawingSurface. 00236 */ 00237 void (JNICALL *FreeDrawingSurface) 00238 (JAWT_DrawingSurface* ds); 00239 /* 00240 * Since 1.4 00241 * Locks the entire AWT for synchronization purposes 00242 */ 00243 void (JNICALL *Lock)(JNIEnv* env); 00244 /* 00245 * Since 1.4 00246 * Unlocks the entire AWT for synchronization purposes 00247 */ 00248 void (JNICALL *Unlock)(JNIEnv* env); 00249 /* 00250 * Since 1.4 00251 * Returns a reference to a java.awt.Component from a native 00252 * platform handle. On Windows, this corresponds to an HWND; 00253 * on Solaris and Linux, this is a Drawable. For other platforms, 00254 * see the appropriate machine-dependent header file for a description. 00255 * The reference returned by this function is a local 00256 * reference that is only valid in this environment. 00257 * This function returns a NULL reference if no component could be 00258 * found with matching platform information. 00259 */ 00260 jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo); 00261 00262 } JAWT; 00263 00264 /* 00265 * Get the AWT native structure. This function returns JNI_FALSE if 00266 * an error occurs. 00267 */ 00268 _JNI_IMPORT_OR_EXPORT_ 00269 jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt); 00270 00271 #define JAWT_VERSION_1_3 0x00010003 00272 #define JAWT_VERSION_1_4 0x00010004 00273 00274 #ifdef __cplusplus 00275 } /* extern "C" */ 00276 #endif 00277 00278 #endif /* !_JAVASOFT_JAWT_H_ */