Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/javavm/export/jawt.h
38813 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifndef _JAVASOFT_JAWT_H_26#define _JAVASOFT_JAWT_H_2728#include "jni.h"2930#ifdef __cplusplus31extern "C" {32#endif3334/*35* AWT native interface (new in JDK 1.3)36*37* The AWT native interface allows a native C or C++ application a means38* by which to access native structures in AWT. This is to facilitate moving39* legacy C and C++ applications to Java and to target the needs of the40* community who, at present, wish to do their own native rendering to canvases41* for performance reasons. Standard extensions such as Java3D also require a42* means to access the underlying native data structures of AWT.43*44* There may be future extensions to this API depending on demand.45*46* A VM does not have to implement this API in order to pass the JCK.47* It is recommended, however, that this API is implemented on VMs that support48* standard extensions, such as Java3D.49*50* Since this is a native API, any program which uses it cannot be considered51* 100% pure java.52*/5354/*55* AWT Native Drawing Surface (JAWT_DrawingSurface).56*57* For each platform, there is a native drawing surface structure. This58* platform-specific structure can be found in jawt_md.h. It is recommended59* that additional platforms follow the same model. It is also recommended60* that VMs on Win32 and Solaris support the existing structures in jawt_md.h.61*62*******************63* EXAMPLE OF USAGE:64*******************65*66* In Win32, a programmer wishes to access the HWND of a canvas to perform67* native rendering into it. The programmer has declared the paint() method68* for their canvas subclass to be native:69*70*71* MyCanvas.java:72*73* import java.awt.*;74*75* public class MyCanvas extends Canvas {76*77* static {78* System.loadLibrary("mylib");79* }80*81* public native void paint(Graphics g);82* }83*84*85* myfile.c:86*87* #include "jawt_md.h"88* #include <assert.h>89*90* JNIEXPORT void JNICALL91* Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics)92* {93* JAWT awt;94* JAWT_DrawingSurface* ds;95* JAWT_DrawingSurfaceInfo* dsi;96* JAWT_Win32DrawingSurfaceInfo* dsi_win;97* jboolean result;98* jint lock;99*100* // Get the AWT101* awt.version = JAWT_VERSION_1_3;102* result = JAWT_GetAWT(env, &awt);103* assert(result != JNI_FALSE);104*105* // Get the drawing surface106* ds = awt.GetDrawingSurface(env, canvas);107* assert(ds != NULL);108*109* // Lock the drawing surface110* lock = ds->Lock(ds);111* assert((lock & JAWT_LOCK_ERROR) == 0);112*113* // Get the drawing surface info114* dsi = ds->GetDrawingSurfaceInfo(ds);115*116* // Get the platform-specific drawing info117* dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;118*119* //////////////////////////////120* // !!! DO PAINTING HERE !!! //121* //////////////////////////////122*123* // Free the drawing surface info124* ds->FreeDrawingSurfaceInfo(dsi);125*126* // Unlock the drawing surface127* ds->Unlock(ds);128*129* // Free the drawing surface130* awt.FreeDrawingSurface(ds);131* }132*133*/134135/*136* JAWT_Rectangle137* Structure for a native rectangle.138*/139typedef struct jawt_Rectangle {140jint x;141jint y;142jint width;143jint height;144} JAWT_Rectangle;145146struct jawt_DrawingSurface;147148/*149* JAWT_DrawingSurfaceInfo150* Structure for containing the underlying drawing information of a component.151*/152typedef struct jawt_DrawingSurfaceInfo {153/*154* Pointer to the platform-specific information. This can be safely155* cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a156* JAWT_X11DrawingSurfaceInfo on Solaris. On Mac OS X this is a157* pointer to a NSObject that conforms to the JAWT_SurfaceLayers158* protocol. See jawt_md.h for details.159*/160void* platformInfo;161/* Cached pointer to the underlying drawing surface */162struct jawt_DrawingSurface* ds;163/* Bounding rectangle of the drawing surface */164JAWT_Rectangle bounds;165/* Number of rectangles in the clip */166jint clipSize;167/* Clip rectangle array */168JAWT_Rectangle* clip;169} JAWT_DrawingSurfaceInfo;170171#define JAWT_LOCK_ERROR 0x00000001172#define JAWT_LOCK_CLIP_CHANGED 0x00000002173#define JAWT_LOCK_BOUNDS_CHANGED 0x00000004174#define JAWT_LOCK_SURFACE_CHANGED 0x00000008175176/*177* JAWT_DrawingSurface178* Structure for containing the underlying drawing information of a component.179* All operations on a JAWT_DrawingSurface MUST be performed from the same180* thread as the call to GetDrawingSurface.181*/182typedef struct jawt_DrawingSurface {183/*184* Cached reference to the Java environment of the calling thread.185* If Lock(), Unlock(), GetDrawingSurfaceInfo() or186* FreeDrawingSurfaceInfo() are called from a different thread,187* this data member should be set before calling those functions.188*/189JNIEnv* env;190/* Cached reference to the target object */191jobject target;192/*193* Lock the surface of the target component for native rendering.194* When finished drawing, the surface must be unlocked with195* Unlock(). This function returns a bitmask with one or more of the196* following values:197*198* JAWT_LOCK_ERROR - When an error has occurred and the surface could not199* be locked.200*201* JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.202*203* JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.204*205* JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed206*/207jint (JNICALL *Lock)208(struct jawt_DrawingSurface* ds);209/*210* Get the drawing surface info.211* The value returned may be cached, but the values may change if212* additional calls to Lock() or Unlock() are made.213* Lock() must be called before this can return a valid value.214* Returns NULL if an error has occurred.215* When finished with the returned value, FreeDrawingSurfaceInfo must be216* called.217*/218JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo)219(struct jawt_DrawingSurface* ds);220/*221* Free the drawing surface info.222*/223void (JNICALL *FreeDrawingSurfaceInfo)224(JAWT_DrawingSurfaceInfo* dsi);225/*226* Unlock the drawing surface of the target component for native rendering.227*/228void (JNICALL *Unlock)229(struct jawt_DrawingSurface* ds);230} JAWT_DrawingSurface;231232/*233* JAWT234* Structure for containing native AWT functions.235*/236typedef struct jawt {237/*238* Version of this structure. This must always be set before239* calling JAWT_GetAWT()240*/241jint version;242/*243* Return a drawing surface from a target jobject. This value244* may be cached.245* Returns NULL if an error has occurred.246* Target must be a java.awt.Component (should be a Canvas247* or Window for native rendering).248* FreeDrawingSurface() must be called when finished with the249* returned JAWT_DrawingSurface.250*/251JAWT_DrawingSurface* (JNICALL *GetDrawingSurface)252(JNIEnv* env, jobject target);253/*254* Free the drawing surface allocated in GetDrawingSurface.255*/256void (JNICALL *FreeDrawingSurface)257(JAWT_DrawingSurface* ds);258/*259* Since 1.4260* Locks the entire AWT for synchronization purposes261*/262void (JNICALL *Lock)(JNIEnv* env);263/*264* Since 1.4265* Unlocks the entire AWT for synchronization purposes266*/267void (JNICALL *Unlock)(JNIEnv* env);268/*269* Since 1.4270* Returns a reference to a java.awt.Component from a native271* platform handle. On Windows, this corresponds to an HWND;272* on Solaris and Linux, this is a Drawable. For other platforms,273* see the appropriate machine-dependent header file for a description.274* The reference returned by this function is a local275* reference that is only valid in this environment.276* This function returns a NULL reference if no component could be277* found with matching platform information.278*/279jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);280281} JAWT;282283/*284* Get the AWT native structure. This function returns JNI_FALSE if285* an error occurs.286*/287_JNI_IMPORT_OR_EXPORT_288jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt);289290#define JAWT_VERSION_1_3 0x00010003291#define JAWT_VERSION_1_4 0x00010004292#define JAWT_VERSION_1_7 0x00010007293294#ifdef __cplusplus295} /* extern "C" */296#endif297298#endif /* !_JAVASOFT_JAWT_H_ */299300301