< prev index next >

src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c

Print this page




 780 void
 781 SplashUnlock(Splash * splash) {
 782     pthread_mutex_unlock(&splash->lock);
 783 }
 784 
 785 void
 786 SplashClosePlatform(Splash * splash) {
 787     sendctl(splash, SPLASHCTL_QUIT);
 788 }
 789 
 790 void
 791 SplashUpdate(Splash * splash) {
 792     sendctl(splash, SPLASHCTL_UPDATE);
 793 }
 794 
 795 void
 796 SplashReconfigure(Splash * splash) {
 797     sendctl(splash, SPLASHCTL_RECONFIGURE);
 798 }
 799 
 800 SPLASHEXPORT char*
 801 SplashGetScaledImageName(const char* jarName, const char* fileName,
 802                            float *scaleFactor)

 803 {
 804     *scaleFactor = 1;
 805 #ifndef __linux__
 806     return NULL;
 807 #endif
 808     *scaleFactor = getNativeScaleFactor();
 809     if (*scaleFactor == 2.0) {
 810         char *scaledImgName = NULL;
 811         size_t length = 0;
 812         char *stringToAppend = ".java-scale2x";
 813         char *dupFileName = strdup(fileName);
 814         char *fileExtension = strrchr(dupFileName, '.');
 815         if (fileExtension == NULL) {
 816             length = strlen(dupFileName) + strlen(stringToAppend) + 1;
 817             scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof (char));




 818             int retVal = snprintf(scaledImgName, length, "%s%s",
 819                     dupFileName, stringToAppend);
 820             if(retVal < 0 || (retVal != length - 1)) {
 821                 free(scaledImgName);
 822                 free(dupFileName);
 823                 *scaleFactor = 1;
 824                 return NULL;
 825             }
 826         } else {
 827             int length_without_ext = fileExtension - dupFileName;
 828             length = length_without_ext +
 829                     strlen(stringToAppend) + strlen(fileExtension) + 1;
 830             scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof (char));




 831             int retVal = snprintf(scaledImgName, length, "%.*s%s%s",
 832                     length_without_ext, dupFileName, stringToAppend, fileExtension);
 833             if(retVal < 0 || retVal != length - 1) {
 834                 free(scaledImgName);
 835                 free(dupFileName);
 836                 *scaleFactor = 1;
 837                 return NULL;
 838             }
 839         }
 840         free(dupFileName);
 841         FILE *fp;
 842         if (!(fp = fopen(scaledImgName, "r"))) {
 843             *scaleFactor = 1;
 844             free(scaledImgName);
 845             return NULL;
 846         }
 847         fclose(fp);
 848         return scaledImgName;
 849     }
 850     return NULL;
 851 }
 852 


 780 void
 781 SplashUnlock(Splash * splash) {
 782     pthread_mutex_unlock(&splash->lock);
 783 }
 784 
 785 void
 786 SplashClosePlatform(Splash * splash) {
 787     sendctl(splash, SPLASHCTL_QUIT);
 788 }
 789 
 790 void
 791 SplashUpdate(Splash * splash) {
 792     sendctl(splash, SPLASHCTL_UPDATE);
 793 }
 794 
 795 void
 796 SplashReconfigure(Splash * splash) {
 797     sendctl(splash, SPLASHCTL_RECONFIGURE);
 798 }
 799 
 800 SPLASHEXPORT jboolean
 801 SplashGetScaledImageName(const char* jarName, const char* fileName,
 802                            float *scaleFactor, char *scaledImgName,
 803                            const size_t scaledImageNameLength)
 804 {
 805     *scaleFactor = 1;
 806 #ifndef __linux__
 807     return JNI_FALSE;
 808 #endif
 809     *scaleFactor = getNativeScaleFactor();
 810     if (*scaleFactor == 2.0) {

 811         size_t length = 0;
 812         char *stringToAppend = ".java-scale2x";
 813         char *dupFileName = strdup(fileName);
 814         char *fileExtension = strrchr(dupFileName, '.');
 815         if (fileExtension == NULL) {
 816             length = strlen(dupFileName) + strlen(stringToAppend) + 1;
 817             if (length > scaledImageNameLength) {
 818                 *scaleFactor = 1;
 819                 free(dupFileName);
 820                 return JNI_FALSE;
 821             }
 822             int retVal = snprintf(scaledImgName, length, "%s%s",
 823                 dupFileName, stringToAppend);
 824             if (retVal < 0 || (retVal != length - 1)) {

 825                 free(dupFileName);
 826                 *scaleFactor = 1;
 827                 return JNI_FALSE;
 828             }
 829         } else {
 830             int length_without_ext = fileExtension - dupFileName;
 831             length = length_without_ext +
 832                 strlen(stringToAppend) + strlen(fileExtension) + 1;
 833             if (length > scaledImageNameLength) {
 834                 *scaleFactor = 1;
 835                 free(dupFileName);
 836                 return JNI_FALSE;
 837             }
 838             int retVal = snprintf(scaledImgName, length, "%.*s%s%s",
 839                 length_without_ext, dupFileName, stringToAppend, fileExtension);
 840             if (retVal < 0 || retVal != length - 1) {

 841                 free(dupFileName);
 842                 *scaleFactor = 1;
 843                 return JNI_FALSE;
 844             }
 845         }
 846         free(dupFileName);
 847         FILE *fp;
 848         if (!(fp = fopen(scaledImgName, "r"))) {
 849             *scaleFactor = 1;
 850             return JNI_FALSE;

 851         }
 852         fclose(fp);
 853         return JNI_TRUE;
 854     }
 855     return JNI_FALSE;
 856 }

< prev index next >