blob: 6d61645e87cb3b714f6b21d3ec5f4f31c5897f7c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 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#include "splashscreen_impl.h"
27#include <jni.h>
28#include <jlong_md.h>
29
30JNIEXPORT jint JNICALL
31JNI_OnLoad(JavaVM * vm, void *reserved)
32{
33 return JNI_VERSION_1_2;
34}
35
36/* FIXME: safe_ExceptionOccured, why and how? */
37
38/*
39* Class: java_awt_SplashScreen
40* Method: _update
41* Signature: (J[IIIIII)V
42*/
43JNIEXPORT void JNICALL
44Java_java_awt_SplashScreen__1update(JNIEnv * env, jclass thisClass,
45 jlong jsplash, jintArray data,
46 jint x, jint y, jint width, jint height,
47 jint stride)
48{
49 Splash *splash = (Splash *) jlong_to_ptr(jsplash);
50 int dataSize;
51
52 if (!splash) {
53 return;
54 }
55 SplashLock(splash);
56 dataSize = (*env)->GetArrayLength(env, data);
57 if (splash->overlayData) {
58 free(splash->overlayData);
59 }
60 splash->overlayData = malloc(dataSize * sizeof(rgbquad_t));
61 if (splash->overlayData) {
62 /* we need a copy anyway, so we'll be using GetIntArrayRegion */
63 (*env)->GetIntArrayRegion(env, data, 0, dataSize,
64 (jint *) splash->overlayData);
65 initFormat(&splash->overlayFormat, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
66 initRect(&splash->overlayRect, x, y, width, height, 1,
67 stride * sizeof(rgbquad_t), splash->overlayData,
68 &splash->overlayFormat);
69 SplashUpdate(splash);
70 }
71 SplashUnlock(splash);
72}
73
74
75/*
76* Class: java_awt_SplashScreen
77* Method: _isVisible
78* Signature: (J)Z
79*/
80JNIEXPORT jboolean JNICALL
81Java_java_awt_SplashScreen__1isVisible(JNIEnv * env, jclass thisClass,
82 jlong jsplash)
83{
84 Splash *splash = (Splash *) jlong_to_ptr(jsplash);
85
86 if (!splash) {
87 return JNI_FALSE;
88 }
89 return splash->isVisible>0 ? JNI_TRUE : JNI_FALSE;
90}
91
92/*
93* Class: java_awt_SplashScreen
94* Method: _getBounds
95* Signature: (J)Ljava/awt/Rectangle;
96*/
97JNIEXPORT jobject JNICALL
98Java_java_awt_SplashScreen__1getBounds(JNIEnv * env, jclass thisClass,
99 jlong jsplash)
100{
101 Splash *splash = (Splash *) jlong_to_ptr(jsplash);
102 static jclass clazz = NULL;
103 static jmethodID mid = NULL;
104 jobject bounds = NULL;
105
106 if (!splash) {
107 return NULL;
108 }
109 SplashLock(splash);
110 if (!clazz) {
111 clazz = (*env)->FindClass(env, "java/awt/Rectangle");
112 if (clazz) {
113 clazz = (*env)->NewGlobalRef(env, clazz);
114 }
115 }
116 if (clazz && !mid) {
117 mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");
118 }
119 if (clazz && mid) {
120 bounds = (*env)->NewObject(env, clazz, mid, splash->x, splash->y,
121 splash->width, splash->height);
122 if ((*env)->ExceptionOccurred(env)) {
123 bounds = NULL;
124 (*env)->ExceptionDescribe(env);
125 (*env)->ExceptionClear(env);
126 }
127 }
128 SplashUnlock(splash);
129 return bounds;
130}
131
132/*
133* Class: java_awt_SplashScreen
134* Method: _getInstance
135* Signature: ()J
136*/
137JNIEXPORT jlong JNICALL
138Java_java_awt_SplashScreen__1getInstance(JNIEnv * env, jclass thisClass)
139{
140 return ptr_to_jlong(SplashGetInstance());
141}
142
143/*
144* Class: java_awt_SplashScreen
145* Method: _close
146* Signature: (J)V
147*/
148JNIEXPORT void JNICALL
149Java_java_awt_SplashScreen__1close(JNIEnv * env, jclass thisClass,
150 jlong jsplash)
151{
152 Splash *splash = (Splash *) jlong_to_ptr(jsplash);
153
154 if (!splash) {
155 return;
156 }
157 SplashLock(splash);
158 SplashClosePlatform(splash);
159 SplashUnlock(splash);
160}
161
162/*
163 * Class: java_awt_SplashScreen
164 * Method: _getImageFileName
165 * Signature: (J)Ljava/lang/String;
166 */
167JNIEXPORT jstring JNICALL Java_java_awt_SplashScreen__1getImageFileName
168 (JNIEnv * env, jclass thisClass, jlong jsplash)
169{
170 Splash *splash = (Splash *) jlong_to_ptr(jsplash);
171
172
173 if (!splash || !splash->fileName) {
174 return NULL;
175 }
176 /* splash->fileName is of type char*, but in fact it contains jchars */
177 return (*env)->NewString(env, (const jchar*)splash->fileName,
178 splash->fileNameLen);
179}
180
181/*
182 * Class: java_awt_SplashScreen
183 * Method: _getImageJarName
184 * Signature: (J)Ljava/lang/String;
185 */
186JNIEXPORT jstring JNICALL Java_java_awt_SplashScreen__1getImageJarName
187 (JNIEnv * env, jclass thisClass, jlong jsplash)
188{
189 Splash *splash = (Splash *) jlong_to_ptr(jsplash);
190
191 if (!splash || !splash->jarName) {
192 return NULL;
193 }
194 /* splash->jarName is of type char*, but in fact it contains jchars */
195 return (*env)->NewString(env, (const jchar*)splash->jarName,
196 splash->jarNameLen);
197}
198
199/*
200 * Class: java_awt_SplashScreen
201 * Method: _setImageData
202 * Signature: (J[B)Z
203 */
204JNIEXPORT jboolean JNICALL Java_java_awt_SplashScreen__1setImageData
205 (JNIEnv * env, jclass thisClass, jlong jsplash, jbyteArray data)
206{
207 Splash *splash = (Splash *) jlong_to_ptr(jsplash);
208 int size, rc;
209 jbyte* pBytes;
210
211 if (!splash) {
212 return JNI_FALSE;
213 }
214 size = (*env)->GetArrayLength(env, data);
215 pBytes = (*env)->GetByteArrayElements(env, data, NULL);
216 rc = SplashLoadMemory(pBytes, size);
217 (*env)->ReleaseByteArrayElements(env, data, pBytes, JNI_ABORT);
218 return rc ? JNI_TRUE : JNI_FALSE;
219}