src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m

Print this page




 109                         // 2 bytes per source byte max
 110     out = buf; outSize = bufSize;
 111     /* linux iconv wants char** source and solaris wants const char**...
 112        cast to void* */
 113     rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
 114     iconv_close(cd);
 115 
 116     if (rc == (size_t)-1) {
 117         free(buf);
 118         buf = NULL;
 119     } else {
 120         if (size) {
 121             *size = (bufSize-outSize)/2; /* bytes to wchars */
 122         }
 123     }
 124 done:
 125     setlocale(LC_ALL, old_locale);
 126     return buf;
 127 }
 128 







 129 char* SplashGetScaledImageName(const char* jar, const char* file,
 130                                float *scaleFactor) {
 131     NSAutoreleasePool *pool = [NSAutoreleasePool new];
 132     *scaleFactor = 1;






 133     char* scaledFile = nil;
 134     float screenScaleFactor = 1;






 135 
 136     if (screenScaleFactor > 1) {
 137         NSString *fileName = [NSString stringWithUTF8String: file];
 138         NSUInteger length = [fileName length];
 139         NSRange range = [fileName rangeOfString: @"."
 140                                         options:NSBackwardsSearch];
 141         NSUInteger dotIndex = range.location;
 142         NSString *fileName2x = nil;
 143         
 144         if (dotIndex == NSNotFound) {
 145             fileName2x = [fileName stringByAppendingString: @"@2x"];
 146         } else {
 147             fileName2x = [fileName substringToIndex: dotIndex];
 148             fileName2x = [fileName2x stringByAppendingString: @"@2x"];
 149             fileName2x = [fileName2x stringByAppendingString:
 150                           [fileName substringFromIndex: dotIndex]];
 151         }
 152         
 153         if ((fileName2x != nil) && (jar || [[NSFileManager defaultManager]
 154                     fileExistsAtPath: fileName2x])){


 159     [pool drain];
 160     return scaledFile;
 161 }
 162 
 163 void
 164 SplashInitPlatform(Splash * splash) {
 165     pthread_mutex_init(&splash->lock, NULL);
 166 
 167     splash->maskRequired = 0;
 168 
 169     
 170     //TODO: the following is too much of a hack but should work in 90% cases.
 171     //      besides we don't use device-dependant drawing, so probably
 172     //      that's very fine indeed
 173     splash->byteAlignment = 1;
 174     initFormat(&splash->screenFormat, 0xff << 8,
 175             0xff << 16, 0xff << 24, 0xff << 0);
 176     splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
 177     splash->screenFormat.depthBytes = 4;
 178 
 179     // If this property is present we are running SWT and should not start a runLoop
 180     // Can't check if running SWT in webstart, so splash screen in webstart SWT
 181     // applications is not supported
 182     char envVar[80];
 183     snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
 184     if (getenv(envVar) == NULL) {
 185         [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
 186             [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]];
 187         }];
 188     }
 189 }
 190 
 191 void
 192 SplashCleanupPlatform(Splash * splash) {
 193     splash->maskRequired = 0;
 194 }
 195 
 196 void
 197 SplashDonePlatform(Splash * splash) {
 198     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 199 
 200     pthread_mutex_destroy(&splash->lock);
 201     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 202         if (splash->window) {
 203             [splash->window orderOut:nil];
 204             [splash->window release];




 109                         // 2 bytes per source byte max
 110     out = buf; outSize = bufSize;
 111     /* linux iconv wants char** source and solaris wants const char**...
 112        cast to void* */
 113     rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
 114     iconv_close(cd);
 115 
 116     if (rc == (size_t)-1) {
 117         free(buf);
 118         buf = NULL;
 119     } else {
 120         if (size) {
 121             *size = (bufSize-outSize)/2; /* bytes to wchars */
 122         }
 123     }
 124 done:
 125     setlocale(LC_ALL, old_locale);
 126     return buf;
 127 }
 128 
 129 BOOL isSWTRunning() {
 130     char envVar[80];
 131     // If this property is present we are running SWT
 132     snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
 133     return getenv(envVar) != NULL;
 134 }
 135 
 136 char* SplashGetScaledImageName(const char* jar, const char* file,
 137                                float *scaleFactor) {

 138     *scaleFactor = 1;
 139 
 140     if(isSWTRunning()){
 141         return nil;
 142     }
 143 
 144     NSAutoreleasePool *pool = [NSAutoreleasePool new];
 145     char* scaledFile = nil;
 146     __block float screenScaleFactor = 1;
 147 
 148     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 149         // initialize NSApplication and AWT stuff
 150         [NSApplicationAWT sharedApplication];
 151         screenScaleFactor = [SplashNSScreen() backingScaleFactor];
 152     }];
 153 
 154     if (screenScaleFactor > 1) {
 155         NSString *fileName = [NSString stringWithUTF8String: file];
 156         NSUInteger length = [fileName length];
 157         NSRange range = [fileName rangeOfString: @"."
 158                                         options:NSBackwardsSearch];
 159         NSUInteger dotIndex = range.location;
 160         NSString *fileName2x = nil;
 161         
 162         if (dotIndex == NSNotFound) {
 163             fileName2x = [fileName stringByAppendingString: @"@2x"];
 164         } else {
 165             fileName2x = [fileName substringToIndex: dotIndex];
 166             fileName2x = [fileName2x stringByAppendingString: @"@2x"];
 167             fileName2x = [fileName2x stringByAppendingString:
 168                           [fileName substringFromIndex: dotIndex]];
 169         }
 170         
 171         if ((fileName2x != nil) && (jar || [[NSFileManager defaultManager]
 172                     fileExistsAtPath: fileName2x])){


 177     [pool drain];
 178     return scaledFile;
 179 }
 180 
 181 void
 182 SplashInitPlatform(Splash * splash) {
 183     pthread_mutex_init(&splash->lock, NULL);
 184 
 185     splash->maskRequired = 0;
 186 
 187     
 188     //TODO: the following is too much of a hack but should work in 90% cases.
 189     //      besides we don't use device-dependant drawing, so probably
 190     //      that's very fine indeed
 191     splash->byteAlignment = 1;
 192     initFormat(&splash->screenFormat, 0xff << 8,
 193             0xff << 16, 0xff << 24, 0xff << 0);
 194     splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
 195     splash->screenFormat.depthBytes = 4;
 196 
 197     // If we are running SWT we should not start a runLoop
 198     if (!isSWTRunning()) {




 199         [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
 200             [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]];
 201         }];
 202     }
 203 }
 204 
 205 void
 206 SplashCleanupPlatform(Splash * splash) {
 207     splash->maskRequired = 0;
 208 }
 209 
 210 void
 211 SplashDonePlatform(Splash * splash) {
 212     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 213 
 214     pthread_mutex_destroy(&splash->lock);
 215     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 216         if (splash->window) {
 217             [splash->window orderOut:nil];
 218             [splash->window release];