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