Path: blob/master/src/java.desktop/share/native/include/jawt.h
41152 views
/*1* Copyright (c) 1999, 2017, 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.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* developers who need to do their own native rendering to canvases41* for performance or other reasons.42*43* Conversely it also provides mechanisms for an application which already44* has a native window to provide that to AWT for AWT rendering.45*46* Since every platform may be different in its native data structures47* and APIs for windowing systems the application must necessarily48* provided per-platform source and compile and deliver per-platform49* native code to use this API.50*51* These interfaces are not part of the Java SE specification and52* a VM is not required to implement this API. However it is strongly53* recommended that all implementations which support headful AWT54* also support these interfaces.55*56*/5758/*59* AWT Native Drawing Surface (JAWT_DrawingSurface).60*61* For each platform, there is a native drawing surface structure. This62* platform-specific structure can be found in jawt_md.h. It is recommended63* that additional platforms follow the same model. It is also recommended64* that VMs on all platforms support the existing structures in jawt_md.h.65*66*******************67* EXAMPLE OF USAGE:68*******************69*70* In Win32, a programmer wishes to access the HWND of a canvas to perform71* native rendering into it. The programmer has declared the paint() method72* for their canvas subclass to be native:73*74*75* MyCanvas.java:76*77* import java.awt.*;78*79* public class MyCanvas extends Canvas {80*81* static {82* System.loadLibrary("mylib");83* }84*85* public native void paint(Graphics g);86* }87*88*89* myfile.c:90*91* #include "jawt_md.h"92* #include <assert.h>93*94* JNIEXPORT void JNICALL95* Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics)96* {97* JAWT awt;98* JAWT_DrawingSurface* ds;99* JAWT_DrawingSurfaceInfo* dsi;100* JAWT_Win32DrawingSurfaceInfo* dsi_win;101* jboolean result;102* jint lock;103*104* // Get the AWT. Request version 9 to access features in that release.105* awt.version = JAWT_VERSION_9;106* result = JAWT_GetAWT(env, &awt);107* assert(result != JNI_FALSE);108*109* // Get the drawing surface110* ds = awt.GetDrawingSurface(env, canvas);111* assert(ds != NULL);112*113* // Lock the drawing surface114* lock = ds->Lock(ds);115* assert((lock & JAWT_LOCK_ERROR) == 0);116*117* // Get the drawing surface info118* dsi = ds->GetDrawingSurfaceInfo(ds);119*120* // Get the platform-specific drawing info121* dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;122*123* //////////////////////////////124* // !!! DO PAINTING HERE !!! //125* //////////////////////////////126*127* // Free the drawing surface info128* ds->FreeDrawingSurfaceInfo(dsi);129*130* // Unlock the drawing surface131* ds->Unlock(ds);132*133* // Free the drawing surface134* awt.FreeDrawingSurface(ds);135* }136*137*/138139/*140* JAWT_Rectangle141* Structure for a native rectangle.142*/143typedef struct jawt_Rectangle {144jint x;145jint y;146jint width;147jint height;148} JAWT_Rectangle;149150struct jawt_DrawingSurface;151152/*153* JAWT_DrawingSurfaceInfo154* Structure for containing the underlying drawing information of a component.155*/156typedef struct jawt_DrawingSurfaceInfo {157/*158* Pointer to the platform-specific information. This can be safely159* cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a160* JAWT_X11DrawingSurfaceInfo on Linux and Solaris. On Mac OS X this is a161* pointer to a NSObject that conforms to the JAWT_SurfaceLayers162* protocol. See jawt_md.h for details.163*/164void* platformInfo;165/* Cached pointer to the underlying drawing surface */166struct jawt_DrawingSurface* ds;167/* Bounding rectangle of the drawing surface */168JAWT_Rectangle bounds;169/* Number of rectangles in the clip */170jint clipSize;171/* Clip rectangle array */172JAWT_Rectangle* clip;173} JAWT_DrawingSurfaceInfo;174175#define JAWT_LOCK_ERROR 0x00000001176#define JAWT_LOCK_CLIP_CHANGED 0x00000002177#define JAWT_LOCK_BOUNDS_CHANGED 0x00000004178#define JAWT_LOCK_SURFACE_CHANGED 0x00000008179180/*181* JAWT_DrawingSurface182* Structure for containing the underlying drawing information of a component.183* All operations on a JAWT_DrawingSurface MUST be performed from the same184* thread as the call to GetDrawingSurface.185*/186typedef struct jawt_DrawingSurface {187/*188* Cached reference to the Java environment of the calling thread.189* If Lock(), Unlock(), GetDrawingSurfaceInfo() or190* FreeDrawingSurfaceInfo() are called from a different thread,191* this data member should be set before calling those functions.192*/193JNIEnv* env;194/* Cached reference to the target object */195jobject target;196/*197* Lock the surface of the target component for native rendering.198* When finished drawing, the surface must be unlocked with199* Unlock(). This function returns a bitmask with one or more of the200* following values:201*202* JAWT_LOCK_ERROR - When an error has occurred and the surface could not203* be locked.204*205* JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.206*207* JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.208*209* JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed210*/211jint (JNICALL *Lock)212(struct jawt_DrawingSurface* ds);213/*214* Get the drawing surface info.215* The value returned may be cached, but the values may change if216* additional calls to Lock() or Unlock() are made.217* Lock() must be called before this can return a valid value.218* Returns NULL if an error has occurred.219* When finished with the returned value, FreeDrawingSurfaceInfo must be220* called.221*/222JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo)223(struct jawt_DrawingSurface* ds);224/*225* Free the drawing surface info.226*/227void (JNICALL *FreeDrawingSurfaceInfo)228(JAWT_DrawingSurfaceInfo* dsi);229/*230* Unlock the drawing surface of the target component for native rendering.231*/232void (JNICALL *Unlock)233(struct jawt_DrawingSurface* ds);234} JAWT_DrawingSurface;235236/*237* JAWT238* Structure for containing native AWT functions.239*/240typedef struct jawt {241/*242* Version of this structure. This must always be set before243* calling JAWT_GetAWT(). It affects the functions returned.244* Must be one of the known pre-defined versions.245*/246jint version;247/*248* Return a drawing surface from a target jobject. This value249* may be cached.250* Returns NULL if an error has occurred.251* Target must be a java.awt.Component (should be a Canvas252* or Window for native rendering).253* FreeDrawingSurface() must be called when finished with the254* returned JAWT_DrawingSurface.255*/256JAWT_DrawingSurface* (JNICALL *GetDrawingSurface)257(JNIEnv* env, jobject target);258/*259* Free the drawing surface allocated in GetDrawingSurface.260*/261void (JNICALL *FreeDrawingSurface)262(JAWT_DrawingSurface* ds);263/*264* Since 1.4265* Locks the entire AWT for synchronization purposes266*/267void (JNICALL *Lock)(JNIEnv* env);268/*269* Since 1.4270* Unlocks the entire AWT for synchronization purposes271*/272void (JNICALL *Unlock)(JNIEnv* env);273/*274* Since 1.4275* Returns a reference to a java.awt.Component from a native276* platform handle. On Windows, this corresponds to an HWND;277* on Solaris and Linux, this is a Drawable. For other platforms,278* see the appropriate machine-dependent header file for a description.279* The reference returned by this function is a local280* reference that is only valid in this environment.281* This function returns a NULL reference if no component could be282* found with matching platform information.283*/284jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);285286/**287* Since 9288* Creates a java.awt.Frame placed in a native container. Container is289* referenced by the native platform handle. For example on Windows this290* corresponds to an HWND. For other platforms, see the appropriate291* machine-dependent header file for a description. The reference returned292* by this function is a local reference that is only valid in this293* environment. This function returns a NULL reference if no frame could be294* created with matching platform information.295*/296jobject (JNICALL *CreateEmbeddedFrame) (JNIEnv *env, void* platformInfo);297298/**299* Since 9300* Moves and resizes the embedded frame. The new location of the top-left301* corner is specified by x and y parameters relative to the native parent302* component. The new size is specified by width and height.303*304* The embedded frame should be created by CreateEmbeddedFrame() method, or305* this function will not have any effect.306*307* java.awt.Component.setLocation() and java.awt.Component.setBounds() for308* EmbeddedFrame really don't move it within the native parent. These309* methods always locate the embedded frame at (0, 0) for backward310* compatibility. To allow moving embedded frames this method was311* introduced, and it works just the same way as setLocation() and312* setBounds() for usual, non-embedded components.313*314* Using usual get/setLocation() and get/setBounds() together with this new315* method is not recommended.316*/317void (JNICALL *SetBounds) (JNIEnv *env, jobject embeddedFrame,318jint x, jint y, jint w, jint h);319/**320* Since 9321* Synthesize a native message to activate or deactivate an EmbeddedFrame322* window depending on the value of parameter doActivate, if "true"323* activates the window; otherwise, deactivates the window.324*325* The embedded frame should be created by CreateEmbeddedFrame() method, or326* this function will not have any effect.327*/328void (JNICALL *SynthesizeWindowActivation) (JNIEnv *env,329jobject embeddedFrame, jboolean doActivate);330} JAWT;331332/*333* Get the AWT native structure. This function returns JNI_FALSE if334* an error occurs.335*/336_JNI_IMPORT_OR_EXPORT_337jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt);338339/*340* Specify one of these constants as the JAWT.version341* Specifying an earlier version will limit the available functions to342* those provided in that earlier version of JAWT.343* See the "Since" note on each API. Methods with no "Since"344* may be presumed to be present in JAWT_VERSION_1_3.345*/346#define JAWT_VERSION_1_3 0x00010003347#define JAWT_VERSION_1_4 0x00010004348#define JAWT_VERSION_1_7 0x00010007349#define JAWT_VERSION_9 0x00090000350351#ifdef __cplusplus352} /* extern "C" */353#endif354355#endif /* !_JAVASOFT_JAWT_H_ */356357358