Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/native/libsplashscreen/java_awt_SplashScreen.c
41149 views
1
/*
2
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#include "splashscreen_impl.h"
27
#include <jlong_md.h>
28
#include <jni.h>
29
#include <jni_util.h>
30
#include <sizecalc.h>
31
#include "java_awt_SplashScreen.h"
32
33
JNIEXPORT jint JNICALL
34
DEF_JNI_OnLoad(JavaVM * vm, void *reserved)
35
{
36
return JNI_VERSION_1_2;
37
}
38
39
/* FIXME: safe_ExceptionOccured, why and how? */
40
41
/*
42
* Class: java_awt_SplashScreen
43
* Method: _update
44
* Signature: (J[IIIIII)V
45
*/
46
JNIEXPORT void JNICALL
47
Java_java_awt_SplashScreen__1update(JNIEnv * env, jclass thisClass,
48
jlong jsplash, jintArray data,
49
jint x, jint y, jint width, jint height,
50
jint stride)
51
{
52
Splash *splash = (Splash *) jlong_to_ptr(jsplash);
53
int dataSize;
54
55
if (!splash) {
56
return;
57
}
58
SplashLock(splash);
59
dataSize = (*env)->GetArrayLength(env, data);
60
if (splash->overlayData) {
61
free(splash->overlayData);
62
}
63
splash->overlayData = SAFE_SIZE_ARRAY_ALLOC(malloc, dataSize, sizeof(rgbquad_t));
64
if (splash->overlayData) {
65
/* we need a copy anyway, so we'll be using GetIntArrayRegion */
66
(*env)->GetIntArrayRegion(env, data, 0, dataSize,
67
(jint *) splash->overlayData);
68
initFormat(&splash->overlayFormat, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
69
initRect(&splash->overlayRect, x, y, width, height, 1,
70
stride * sizeof(rgbquad_t), splash->overlayData,
71
&splash->overlayFormat);
72
SplashUpdate(splash);
73
}
74
SplashUnlock(splash);
75
}
76
77
78
/*
79
* Class: java_awt_SplashScreen
80
* Method: _isVisible
81
* Signature: (J)Z
82
*/
83
JNIEXPORT jboolean JNICALL
84
Java_java_awt_SplashScreen__1isVisible(JNIEnv * env, jclass thisClass,
85
jlong jsplash)
86
{
87
Splash *splash = (Splash *) jlong_to_ptr(jsplash);
88
89
if (!splash) {
90
return JNI_FALSE;
91
}
92
return splash->isVisible>0 ? JNI_TRUE : JNI_FALSE;
93
}
94
95
/*
96
* Class: java_awt_SplashScreen
97
* Method: _getBounds
98
* Signature: (J)Ljava/awt/Rectangle;
99
*/
100
JNIEXPORT jobject JNICALL
101
Java_java_awt_SplashScreen__1getBounds(JNIEnv * env, jclass thisClass,
102
jlong jsplash)
103
{
104
Splash *splash = (Splash *) jlong_to_ptr(jsplash);
105
static jclass clazz = NULL;
106
static jmethodID mid = NULL;
107
jobject bounds = NULL;
108
109
if (!splash) {
110
return NULL;
111
}
112
SplashLock(splash);
113
if (!clazz) {
114
clazz = (*env)->FindClass(env, "java/awt/Rectangle");
115
if (clazz) {
116
clazz = (*env)->NewGlobalRef(env, clazz);
117
}
118
}
119
if (clazz && !mid) {
120
mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");
121
}
122
if (clazz && mid) {
123
bounds = (*env)->NewObject(env, clazz, mid, splash->x, splash->y,
124
splash->width, splash->height);
125
if ((*env)->ExceptionOccurred(env)) {
126
bounds = NULL;
127
(*env)->ExceptionDescribe(env);
128
(*env)->ExceptionClear(env);
129
}
130
}
131
SplashUnlock(splash);
132
return bounds;
133
}
134
135
/*
136
* Class: java_awt_SplashScreen
137
* Method: _getInstance
138
* Signature: ()J
139
*/
140
JNIEXPORT jlong JNICALL
141
Java_java_awt_SplashScreen__1getInstance(JNIEnv * env, jclass thisClass)
142
{
143
return ptr_to_jlong(SplashGetInstance());
144
}
145
146
/*
147
* Class: java_awt_SplashScreen
148
* Method: _close
149
* Signature: (J)V
150
*/
151
JNIEXPORT void JNICALL
152
Java_java_awt_SplashScreen__1close(JNIEnv * env, jclass thisClass,
153
jlong jsplash)
154
{
155
Splash *splash = (Splash *) jlong_to_ptr(jsplash);
156
157
if (!splash) {
158
return;
159
}
160
SplashLock(splash);
161
SplashClosePlatform(splash);
162
SplashUnlock(splash);
163
}
164
165
/*
166
* Class: java_awt_SplashScreen
167
* Method: _getImageFileName
168
* Signature: (J)Ljava/lang/String;
169
*/
170
JNIEXPORT jstring JNICALL Java_java_awt_SplashScreen__1getImageFileName
171
(JNIEnv * env, jclass thisClass, jlong jsplash)
172
{
173
Splash *splash = (Splash *) jlong_to_ptr(jsplash);
174
175
176
if (!splash || !splash->fileName) {
177
return NULL;
178
}
179
/* splash->fileName is of type char*, but in fact it contains jchars */
180
return (*env)->NewString(env, (const jchar*)splash->fileName,
181
splash->fileNameLen);
182
}
183
184
/*
185
* Class: java_awt_SplashScreen
186
* Method: _getImageJarName
187
* Signature: (J)Ljava/lang/String;
188
*/
189
JNIEXPORT jstring JNICALL Java_java_awt_SplashScreen__1getImageJarName
190
(JNIEnv * env, jclass thisClass, jlong jsplash)
191
{
192
Splash *splash = (Splash *) jlong_to_ptr(jsplash);
193
194
if (!splash || !splash->jarName) {
195
return NULL;
196
}
197
/* splash->jarName is of type char*, but in fact it contains jchars */
198
return (*env)->NewString(env, (const jchar*)splash->jarName,
199
splash->jarNameLen);
200
}
201
202
/*
203
* Class: java_awt_SplashScreen
204
* Method: _setImageData
205
* Signature: (J[B)Z
206
*/
207
JNIEXPORT jboolean JNICALL Java_java_awt_SplashScreen__1setImageData
208
(JNIEnv * env, jclass thisClass, jlong jsplash, jbyteArray data)
209
{
210
Splash *splash = (Splash *) jlong_to_ptr(jsplash);
211
int size, rc;
212
jbyte* pBytes;
213
214
if (!splash) {
215
return JNI_FALSE;
216
}
217
pBytes = (*env)->GetByteArrayElements(env, data, NULL);
218
CHECK_NULL_RETURN(pBytes, JNI_FALSE);
219
size = (*env)->GetArrayLength(env, data);
220
rc = SplashLoadMemory(pBytes, size);
221
(*env)->ReleaseByteArrayElements(env, data, pBytes, JNI_ABORT);
222
return rc ? JNI_TRUE : JNI_FALSE;
223
}
224
225
/*
226
* Class: java_awt_SplashScreen
227
* Method: _getScaleFactor
228
* Signature: (J)F
229
*/
230
JNIEXPORT jfloat JNICALL Java_java_awt_SplashScreen__1getScaleFactor
231
(JNIEnv *env, jclass thisClass, jlong jsplash)
232
{
233
Splash *splash = (Splash *) jlong_to_ptr(jsplash);
234
if (!splash) {
235
return 1;
236
}
237
return splash->scaleFactor;
238
}
239
240