Path: blob/master/src/java.desktop/share/native/libsplashscreen/java_awt_SplashScreen.c
41149 views
/*1* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "splashscreen_impl.h"26#include <jlong_md.h>27#include <jni.h>28#include <jni_util.h>29#include <sizecalc.h>30#include "java_awt_SplashScreen.h"3132JNIEXPORT jint JNICALL33DEF_JNI_OnLoad(JavaVM * vm, void *reserved)34{35return JNI_VERSION_1_2;36}3738/* FIXME: safe_ExceptionOccured, why and how? */3940/*41* Class: java_awt_SplashScreen42* Method: _update43* Signature: (J[IIIIII)V44*/45JNIEXPORT void JNICALL46Java_java_awt_SplashScreen__1update(JNIEnv * env, jclass thisClass,47jlong jsplash, jintArray data,48jint x, jint y, jint width, jint height,49jint stride)50{51Splash *splash = (Splash *) jlong_to_ptr(jsplash);52int dataSize;5354if (!splash) {55return;56}57SplashLock(splash);58dataSize = (*env)->GetArrayLength(env, data);59if (splash->overlayData) {60free(splash->overlayData);61}62splash->overlayData = SAFE_SIZE_ARRAY_ALLOC(malloc, dataSize, sizeof(rgbquad_t));63if (splash->overlayData) {64/* we need a copy anyway, so we'll be using GetIntArrayRegion */65(*env)->GetIntArrayRegion(env, data, 0, dataSize,66(jint *) splash->overlayData);67initFormat(&splash->overlayFormat, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);68initRect(&splash->overlayRect, x, y, width, height, 1,69stride * sizeof(rgbquad_t), splash->overlayData,70&splash->overlayFormat);71SplashUpdate(splash);72}73SplashUnlock(splash);74}757677/*78* Class: java_awt_SplashScreen79* Method: _isVisible80* Signature: (J)Z81*/82JNIEXPORT jboolean JNICALL83Java_java_awt_SplashScreen__1isVisible(JNIEnv * env, jclass thisClass,84jlong jsplash)85{86Splash *splash = (Splash *) jlong_to_ptr(jsplash);8788if (!splash) {89return JNI_FALSE;90}91return splash->isVisible>0 ? JNI_TRUE : JNI_FALSE;92}9394/*95* Class: java_awt_SplashScreen96* Method: _getBounds97* Signature: (J)Ljava/awt/Rectangle;98*/99JNIEXPORT jobject JNICALL100Java_java_awt_SplashScreen__1getBounds(JNIEnv * env, jclass thisClass,101jlong jsplash)102{103Splash *splash = (Splash *) jlong_to_ptr(jsplash);104static jclass clazz = NULL;105static jmethodID mid = NULL;106jobject bounds = NULL;107108if (!splash) {109return NULL;110}111SplashLock(splash);112if (!clazz) {113clazz = (*env)->FindClass(env, "java/awt/Rectangle");114if (clazz) {115clazz = (*env)->NewGlobalRef(env, clazz);116}117}118if (clazz && !mid) {119mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");120}121if (clazz && mid) {122bounds = (*env)->NewObject(env, clazz, mid, splash->x, splash->y,123splash->width, splash->height);124if ((*env)->ExceptionOccurred(env)) {125bounds = NULL;126(*env)->ExceptionDescribe(env);127(*env)->ExceptionClear(env);128}129}130SplashUnlock(splash);131return bounds;132}133134/*135* Class: java_awt_SplashScreen136* Method: _getInstance137* Signature: ()J138*/139JNIEXPORT jlong JNICALL140Java_java_awt_SplashScreen__1getInstance(JNIEnv * env, jclass thisClass)141{142return ptr_to_jlong(SplashGetInstance());143}144145/*146* Class: java_awt_SplashScreen147* Method: _close148* Signature: (J)V149*/150JNIEXPORT void JNICALL151Java_java_awt_SplashScreen__1close(JNIEnv * env, jclass thisClass,152jlong jsplash)153{154Splash *splash = (Splash *) jlong_to_ptr(jsplash);155156if (!splash) {157return;158}159SplashLock(splash);160SplashClosePlatform(splash);161SplashUnlock(splash);162}163164/*165* Class: java_awt_SplashScreen166* Method: _getImageFileName167* Signature: (J)Ljava/lang/String;168*/169JNIEXPORT jstring JNICALL Java_java_awt_SplashScreen__1getImageFileName170(JNIEnv * env, jclass thisClass, jlong jsplash)171{172Splash *splash = (Splash *) jlong_to_ptr(jsplash);173174175if (!splash || !splash->fileName) {176return NULL;177}178/* splash->fileName is of type char*, but in fact it contains jchars */179return (*env)->NewString(env, (const jchar*)splash->fileName,180splash->fileNameLen);181}182183/*184* Class: java_awt_SplashScreen185* Method: _getImageJarName186* Signature: (J)Ljava/lang/String;187*/188JNIEXPORT jstring JNICALL Java_java_awt_SplashScreen__1getImageJarName189(JNIEnv * env, jclass thisClass, jlong jsplash)190{191Splash *splash = (Splash *) jlong_to_ptr(jsplash);192193if (!splash || !splash->jarName) {194return NULL;195}196/* splash->jarName is of type char*, but in fact it contains jchars */197return (*env)->NewString(env, (const jchar*)splash->jarName,198splash->jarNameLen);199}200201/*202* Class: java_awt_SplashScreen203* Method: _setImageData204* Signature: (J[B)Z205*/206JNIEXPORT jboolean JNICALL Java_java_awt_SplashScreen__1setImageData207(JNIEnv * env, jclass thisClass, jlong jsplash, jbyteArray data)208{209Splash *splash = (Splash *) jlong_to_ptr(jsplash);210int size, rc;211jbyte* pBytes;212213if (!splash) {214return JNI_FALSE;215}216pBytes = (*env)->GetByteArrayElements(env, data, NULL);217CHECK_NULL_RETURN(pBytes, JNI_FALSE);218size = (*env)->GetArrayLength(env, data);219rc = SplashLoadMemory(pBytes, size);220(*env)->ReleaseByteArrayElements(env, data, pBytes, JNI_ABORT);221return rc ? JNI_TRUE : JNI_FALSE;222}223224/*225* Class: java_awt_SplashScreen226* Method: _getScaleFactor227* Signature: (J)F228*/229JNIEXPORT jfloat JNICALL Java_java_awt_SplashScreen__1getScaleFactor230(JNIEnv *env, jclass thisClass, jlong jsplash)231{232Splash *splash = (Splash *) jlong_to_ptr(jsplash);233if (!splash) {234return 1;235}236return splash->scaleFactor;237}238239240