0N/A/*
2362N/A * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifndef _JAVASOFT_JAWT_H_
0N/A#define _JAVASOFT_JAWT_H_
0N/A
0N/A#include "jni.h"
0N/A
0N/A#ifdef __cplusplus
0N/Aextern "C" {
0N/A#endif
0N/A
0N/A/*
0N/A * AWT native interface (new in JDK 1.3)
0N/A *
0N/A * The AWT native interface allows a native C or C++ application a means
0N/A * by which to access native structures in AWT. This is to facilitate moving
0N/A * legacy C and C++ applications to Java and to target the needs of the
0N/A * community who, at present, wish to do their own native rendering to canvases
0N/A * for performance reasons. Standard extensions such as Java3D also require a
0N/A * means to access the underlying native data structures of AWT.
0N/A *
0N/A * There may be future extensions to this API depending on demand.
0N/A *
0N/A * A VM does not have to implement this API in order to pass the JCK.
0N/A * It is recommended, however, that this API is implemented on VMs that support
0N/A * standard extensions, such as Java3D.
0N/A *
0N/A * Since this is a native API, any program which uses it cannot be considered
0N/A * 100% pure java.
0N/A */
0N/A
0N/A/*
0N/A * AWT Native Drawing Surface (JAWT_DrawingSurface).
0N/A *
0N/A * For each platform, there is a native drawing surface structure. This
0N/A * platform-specific structure can be found in jawt_md.h. It is recommended
0N/A * that additional platforms follow the same model. It is also recommended
0N/A * that VMs on Win32 and Solaris support the existing structures in jawt_md.h.
0N/A *
0N/A *******************
0N/A * EXAMPLE OF USAGE:
0N/A *******************
0N/A *
0N/A * In Win32, a programmer wishes to access the HWND of a canvas to perform
0N/A * native rendering into it. The programmer has declared the paint() method
0N/A * for their canvas subclass to be native:
0N/A *
0N/A *
0N/A * MyCanvas.java:
0N/A *
0N/A * import java.awt.*;
0N/A *
0N/A * public class MyCanvas extends Canvas {
0N/A *
0N/A * static {
0N/A * System.loadLibrary("mylib");
0N/A * }
0N/A *
0N/A * public native void paint(Graphics g);
0N/A * }
0N/A *
0N/A *
0N/A * myfile.c:
0N/A *
0N/A * #include "jawt_md.h"
0N/A * #include <assert.h>
0N/A *
0N/A * JNIEXPORT void JNICALL
0N/A * Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics)
0N/A * {
0N/A * JAWT awt;
0N/A * JAWT_DrawingSurface* ds;
0N/A * JAWT_DrawingSurfaceInfo* dsi;
0N/A * JAWT_Win32DrawingSurfaceInfo* dsi_win;
0N/A * jboolean result;
0N/A * jint lock;
0N/A *
0N/A * // Get the AWT
0N/A * awt.version = JAWT_VERSION_1_3;
0N/A * result = JAWT_GetAWT(env, &awt);
0N/A * assert(result != JNI_FALSE);
0N/A *
0N/A * // Get the drawing surface
0N/A * ds = awt.GetDrawingSurface(env, canvas);
0N/A * assert(ds != NULL);
0N/A *
0N/A * // Lock the drawing surface
0N/A * lock = ds->Lock(ds);
0N/A * assert((lock & JAWT_LOCK_ERROR) == 0);
0N/A *
0N/A * // Get the drawing surface info
0N/A * dsi = ds->GetDrawingSurfaceInfo(ds);
0N/A *
0N/A * // Get the platform-specific drawing info
0N/A * dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
0N/A *
0N/A * //////////////////////////////
0N/A * // !!! DO PAINTING HERE !!! //
0N/A * //////////////////////////////
0N/A *
0N/A * // Free the drawing surface info
0N/A * ds->FreeDrawingSurfaceInfo(dsi);
0N/A *
0N/A * // Unlock the drawing surface
0N/A * ds->Unlock(ds);
0N/A *
0N/A * // Free the drawing surface
0N/A * awt.FreeDrawingSurface(ds);
0N/A * }
0N/A *
0N/A */
0N/A
0N/A/*
0N/A * JAWT_Rectangle
0N/A * Structure for a native rectangle.
0N/A */
0N/Atypedef struct jawt_Rectangle {
0N/A jint x;
0N/A jint y;
0N/A jint width;
0N/A jint height;
0N/A} JAWT_Rectangle;
0N/A
0N/Astruct jawt_DrawingSurface;
0N/A
0N/A/*
0N/A * JAWT_DrawingSurfaceInfo
0N/A * Structure for containing the underlying drawing information of a component.
0N/A */
0N/Atypedef struct jawt_DrawingSurfaceInfo {
0N/A /*
0N/A * Pointer to the platform-specific information. This can be safely
0N/A * cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a
6143N/A * JAWT_X11DrawingSurfaceInfo on Solaris. On Mac OS X, when using the
6143N/A * native Cocoa toolkit this is a pointer to a NSObject that conforms
6143N/A * to the JAWT_SurfaceLayers protocol. See jawt_md.h for details.
0N/A */
0N/A void* platformInfo;
0N/A /* Cached pointer to the underlying drawing surface */
0N/A struct jawt_DrawingSurface* ds;
0N/A /* Bounding rectangle of the drawing surface */
0N/A JAWT_Rectangle bounds;
0N/A /* Number of rectangles in the clip */
0N/A jint clipSize;
0N/A /* Clip rectangle array */
0N/A JAWT_Rectangle* clip;
0N/A} JAWT_DrawingSurfaceInfo;
0N/A
0N/A#define JAWT_LOCK_ERROR 0x00000001
0N/A#define JAWT_LOCK_CLIP_CHANGED 0x00000002
0N/A#define JAWT_LOCK_BOUNDS_CHANGED 0x00000004
0N/A#define JAWT_LOCK_SURFACE_CHANGED 0x00000008
0N/A
0N/A/*
0N/A * JAWT_DrawingSurface
0N/A * Structure for containing the underlying drawing information of a component.
0N/A * All operations on a JAWT_DrawingSurface MUST be performed from the same
0N/A * thread as the call to GetDrawingSurface.
0N/A */
0N/Atypedef struct jawt_DrawingSurface {
0N/A /*
0N/A * Cached reference to the Java environment of the calling thread.
0N/A * If Lock(), Unlock(), GetDrawingSurfaceInfo() or
0N/A * FreeDrawingSurfaceInfo() are called from a different thread,
0N/A * this data member should be set before calling those functions.
0N/A */
0N/A JNIEnv* env;
0N/A /* Cached reference to the target object */
0N/A jobject target;
0N/A /*
0N/A * Lock the surface of the target component for native rendering.
0N/A * When finished drawing, the surface must be unlocked with
0N/A * Unlock(). This function returns a bitmask with one or more of the
0N/A * following values:
0N/A *
0N/A * JAWT_LOCK_ERROR - When an error has occurred and the surface could not
0N/A * be locked.
0N/A *
0N/A * JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
0N/A *
0N/A * JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
0N/A *
0N/A * JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
0N/A */
0N/A jint (JNICALL *Lock)
0N/A (struct jawt_DrawingSurface* ds);
0N/A /*
0N/A * Get the drawing surface info.
0N/A * The value returned may be cached, but the values may change if
0N/A * additional calls to Lock() or Unlock() are made.
0N/A * Lock() must be called before this can return a valid value.
0N/A * Returns NULL if an error has occurred.
0N/A * When finished with the returned value, FreeDrawingSurfaceInfo must be
0N/A * called.
0N/A */
0N/A JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo)
0N/A (struct jawt_DrawingSurface* ds);
0N/A /*
0N/A * Free the drawing surface info.
0N/A */
0N/A void (JNICALL *FreeDrawingSurfaceInfo)
0N/A (JAWT_DrawingSurfaceInfo* dsi);
0N/A /*
0N/A * Unlock the drawing surface of the target component for native rendering.
0N/A */
0N/A void (JNICALL *Unlock)
0N/A (struct jawt_DrawingSurface* ds);
0N/A} JAWT_DrawingSurface;
0N/A
0N/A/*
0N/A * JAWT
0N/A * Structure for containing native AWT functions.
0N/A */
0N/Atypedef struct jawt {
0N/A /*
0N/A * Version of this structure. This must always be set before
0N/A * calling JAWT_GetAWT()
0N/A */
0N/A jint version;
0N/A /*
0N/A * Return a drawing surface from a target jobject. This value
0N/A * may be cached.
0N/A * Returns NULL if an error has occurred.
0N/A * Target must be a java.awt.Component (should be a Canvas
0N/A * or Window for native rendering).
0N/A * FreeDrawingSurface() must be called when finished with the
0N/A * returned JAWT_DrawingSurface.
0N/A */
0N/A JAWT_DrawingSurface* (JNICALL *GetDrawingSurface)
0N/A (JNIEnv* env, jobject target);
0N/A /*
0N/A * Free the drawing surface allocated in GetDrawingSurface.
0N/A */
0N/A void (JNICALL *FreeDrawingSurface)
0N/A (JAWT_DrawingSurface* ds);
0N/A /*
0N/A * Since 1.4
0N/A * Locks the entire AWT for synchronization purposes
0N/A */
0N/A void (JNICALL *Lock)(JNIEnv* env);
0N/A /*
0N/A * Since 1.4
0N/A * Unlocks the entire AWT for synchronization purposes
0N/A */
0N/A void (JNICALL *Unlock)(JNIEnv* env);
0N/A /*
0N/A * Since 1.4
0N/A * Returns a reference to a java.awt.Component from a native
0N/A * platform handle. On Windows, this corresponds to an HWND;
0N/A * on Solaris and Linux, this is a Drawable. For other platforms,
0N/A * see the appropriate machine-dependent header file for a description.
0N/A * The reference returned by this function is a local
0N/A * reference that is only valid in this environment.
0N/A * This function returns a NULL reference if no component could be
0N/A * found with matching platform information.
0N/A */
0N/A jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);
0N/A
0N/A} JAWT;
0N/A
0N/A/*
0N/A * Get the AWT native structure. This function returns JNI_FALSE if
0N/A * an error occurs.
0N/A */
0N/A_JNI_IMPORT_OR_EXPORT_
0N/Ajboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt);
0N/A
0N/A#define JAWT_VERSION_1_3 0x00010003
0N/A#define JAWT_VERSION_1_4 0x00010004
4632N/A#define JAWT_VERSION_1_7 0x00010007
0N/A
0N/A#ifdef __cplusplus
0N/A} /* extern "C" */
0N/A#endif
0N/A
0N/A#endif /* !_JAVASOFT_JAWT_H_ */