2005-05-27 Thomas Koenig <Thomas.Koenig@online.de>
[official-gcc.git] / libjava / jawt.c
blobbb03c638e55ffd763cbca16f6cf61a1ba7829b40
1 /* jawt.c -- X11 implementation of the AWT Native Interface
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 #include <stdlib.h>
39 #include <jni.h>
40 #include <jawt.h>
41 #include <jawt_md.h>
42 #include "classpath_jawt.h"
43 #include <malloc.h>
45 static jint (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface);
46 static void (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface);
47 static JAWT_DrawingSurfaceInfo* (JNICALL _Jv_GetDrawingSurfaceInfo)
48 (JAWT_DrawingSurface* surface);
49 static void (JNICALL _Jv_FreeDrawingSurfaceInfo)
50 (JAWT_DrawingSurfaceInfo* surface_info);
51 static JAWT_DrawingSurface* (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env,
52 jobject canvas);
53 static void (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface);
54 static void (JNICALL _Jv_AWTLock) (JNIEnv*);
55 static void (JNICALL _Jv_AWTUnlock) (JNIEnv*);
57 JNIEXPORT jboolean JNICALL
58 JAWT_GetAWT (JNIEnv* env, JAWT* awt)
60 jint retrieved_version;
62 retrieved_version = classpath_jawt_get_awt_version ();
64 if (awt->version > retrieved_version)
65 return JNI_FALSE;
67 awt->GetDrawingSurface = _Jv_GetDrawingSurface;
68 awt->FreeDrawingSurface = _Jv_FreeDrawingSurface;
69 awt->Lock = _Jv_AWTLock;
70 awt->Unlock = _Jv_AWTUnlock;
72 return JNI_TRUE;
75 /* JAWT_DrawingSurface functions */
77 static jint
78 (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface)
80 return classpath_jawt_object_lock (surface->lock);
83 static void
84 (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface)
86 classpath_jawt_object_unlock (surface->lock);
89 static JAWT_DrawingSurfaceInfo*
90 (JNICALL _Jv_GetDrawingSurfaceInfo) (JAWT_DrawingSurface* surface)
92 if (surface == NULL)
93 return NULL;
95 return surface->surface_info;
98 static void
99 (JNICALL _Jv_FreeDrawingSurfaceInfo) (JAWT_DrawingSurfaceInfo* surface_info)
101 JAWT_X11DrawingSurfaceInfo* surface_info_x11;
103 if (surface_info == NULL)
104 return;
106 surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
108 surface_info_x11->display = NULL;
109 surface_info_x11->drawable = 0;
110 surface_info_x11->visualID = 0;
112 free (surface_info->platformInfo);
113 free (surface_info);
114 surface_info = NULL;
117 /* JAWT functions */
119 static JAWT_DrawingSurface*
120 (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env, jobject canvas)
122 JAWT_DrawingSurface* surface;
123 JAWT_X11DrawingSurfaceInfo* surface_info_x11;
125 surface = (JAWT_DrawingSurface*) malloc (sizeof (JAWT_DrawingSurface));
127 if (surface == NULL)
128 return NULL;
130 /* initialize function pointers */
131 surface->GetDrawingSurfaceInfo = _Jv_GetDrawingSurfaceInfo;
132 surface->FreeDrawingSurfaceInfo = _Jv_FreeDrawingSurfaceInfo;
134 surface->Lock = _Jv_Lock;
135 surface->Unlock = _Jv_Unlock;
137 surface->surface_info = (JAWT_DrawingSurfaceInfo*) malloc (sizeof (JAWT_DrawingSurfaceInfo));
139 surface->lock = classpath_jawt_create_lock ();
141 if (surface->surface_info == NULL)
142 return NULL;
144 surface->surface_info->platformInfo = malloc (sizeof (JAWT_X11DrawingSurfaceInfo));
146 if (surface->surface_info->platformInfo == NULL)
147 return NULL;
149 surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface->surface_info->platformInfo;
151 surface_info_x11->display = classpath_jawt_get_default_display (env, canvas);
152 surface_info_x11->drawable = classpath_jawt_get_drawable (env, canvas);
153 surface_info_x11->visualID = classpath_jawt_get_visualID (env, canvas);
155 /* FIXME: also include bounding rectangle of drawing surface */
156 /* FIXME: also include current clipping region */
158 return surface;
161 static void
162 (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface)
164 classpath_jawt_destroy_lock (surface->lock);
165 free (surface);
168 static void
169 (JNICALL _Jv_AWTLock) (JNIEnv* env)
171 classpath_jawt_lock ();
174 static void
175 (JNICALL _Jv_AWTUnlock) (JNIEnv* env)
177 classpath_jawt_unlock ();