OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / libjava / jawt.c
1 /* jawt.c -- X11 implementation of the AWT Native Interface
2    Copyright (C) 2005 Free Software Foundation, Inc.
3
4    This file is part of GNU Classpath.
5
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.
10
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.
15
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., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301 USA.
20
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.
25
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. */
37
38 #include <stdlib.h>
39 #include <jni.h>
40 #include <jawt.h>
41 #include <jawt_md.h>
42 #include "classpath_jawt.h"
43
44 static jint (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface);
45 static void (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface);
46 static JAWT_DrawingSurfaceInfo* (JNICALL _Jv_GetDrawingSurfaceInfo)
47      (JAWT_DrawingSurface* surface);
48 static void (JNICALL _Jv_FreeDrawingSurfaceInfo)
49      (JAWT_DrawingSurfaceInfo* surface_info);
50 static JAWT_DrawingSurface* (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env,
51                                                              jobject canvas);
52 static void (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface);
53 static void (JNICALL _Jv_AWTLock) (JNIEnv*);
54 static void (JNICALL _Jv_AWTUnlock) (JNIEnv*);
55
56 JNIEXPORT jboolean JNICALL
57 JAWT_GetAWT (JNIEnv* env, JAWT* awt)
58 {
59   jint retrieved_version;
60
61   retrieved_version = classpath_jawt_get_awt_version ();
62
63   if (awt->version > retrieved_version)
64     return JNI_FALSE;
65
66   awt->GetDrawingSurface = _Jv_GetDrawingSurface;
67   awt->FreeDrawingSurface = _Jv_FreeDrawingSurface;
68   awt->Lock = _Jv_AWTLock;
69   awt->Unlock = _Jv_AWTUnlock;
70
71   return JNI_TRUE;
72 }
73
74 /* JAWT_DrawingSurface functions */
75
76 static jint
77 (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface)
78 {
79   return classpath_jawt_object_lock (surface->lock);
80 }
81
82 static void
83 (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface)
84 {
85   classpath_jawt_object_unlock (surface->lock);
86 }
87
88 static JAWT_DrawingSurfaceInfo*
89 (JNICALL _Jv_GetDrawingSurfaceInfo) (JAWT_DrawingSurface* surface)
90 {
91   if (surface == NULL)
92     return NULL;
93
94   return surface->surface_info;
95 }
96
97 static void
98 (JNICALL _Jv_FreeDrawingSurfaceInfo) (JAWT_DrawingSurfaceInfo* surface_info)
99 {
100   JAWT_X11DrawingSurfaceInfo* surface_info_x11;
101
102   if (surface_info == NULL)
103     return;
104
105   surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
106
107   surface_info_x11->display = NULL;
108   surface_info_x11->drawable = 0;
109   surface_info_x11->visualID = 0;
110
111   free (surface_info->platformInfo);
112   free (surface_info);
113   surface_info = NULL;
114 }
115
116 /* JAWT functions */
117
118 static JAWT_DrawingSurface*
119 (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env, jobject canvas)
120 {
121   JAWT_DrawingSurface* surface;
122   JAWT_X11DrawingSurfaceInfo* surface_info_x11;
123
124   surface = (JAWT_DrawingSurface*) malloc (sizeof (JAWT_DrawingSurface));
125
126   if (surface == NULL)
127     return NULL;
128
129   /* initialize function pointers */
130   surface->GetDrawingSurfaceInfo = _Jv_GetDrawingSurfaceInfo;
131   surface->FreeDrawingSurfaceInfo = _Jv_FreeDrawingSurfaceInfo;
132
133   surface->Lock = _Jv_Lock;
134   surface->Unlock = _Jv_Unlock;
135
136   surface->surface_info = (JAWT_DrawingSurfaceInfo*) malloc (sizeof (JAWT_DrawingSurfaceInfo));
137
138   surface->lock = classpath_jawt_create_lock ();
139
140   if (surface->surface_info == NULL)
141     return NULL;
142
143   surface->surface_info->platformInfo = malloc (sizeof (JAWT_X11DrawingSurfaceInfo));
144
145   if (surface->surface_info->platformInfo == NULL)
146     return NULL;
147
148   surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface->surface_info->platformInfo;
149
150   surface_info_x11->display = classpath_jawt_get_default_display (env, canvas);
151   surface_info_x11->drawable = classpath_jawt_get_drawable (env, canvas);
152   surface_info_x11->visualID = classpath_jawt_get_visualID (env, canvas);
153
154   /* FIXME: also include bounding rectangle of drawing surface */
155   /* FIXME: also include current clipping region */
156
157   return surface;
158 }
159
160 static void
161 (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface)
162 {
163   classpath_jawt_destroy_lock (surface->lock);
164   free (surface);
165 }
166
167 static void
168 (JNICALL _Jv_AWTLock) (JNIEnv* env)
169 {
170   classpath_jawt_lock ();
171 }
172
173 static void
174 (JNICALL _Jv_AWTUnlock) (JNIEnv* env)
175 {
176   classpath_jawt_unlock ();
177 }
178