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])){ 173 *scaleFactor = 2; 174 scaledFile = strdup([fileName2x UTF8String]); 175 } 176 } 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()) { | 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 void SplashGetScaledImageName(const char* jar, const char* file, 137 float *scaleFactor, char *scaledFile, 138 const size_t scaledImageLength) { 139 *scaleFactor = 1; 140 141 if(isSWTRunning()){ 142 return; 143 } 144 145 NSAutoreleasePool *pool = [NSAutoreleasePool new]; 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])){ 173 if(strlen([fileName2x UTF8String]) > scaledImageLength) { 174 [pool drain]; 175 return; 176 } 177 *scaleFactor = 2; 178 strcpy(scaledFile, [fileName2x UTF8String]); 179 } 180 } 181 [pool drain]; 182 return; 183 } 184 185 void 186 SplashInitPlatform(Splash * splash) { 187 pthread_mutex_init(&splash->lock, NULL); 188 189 splash->maskRequired = 0; 190 191 192 //TODO: the following is too much of a hack but should work in 90% cases. 193 // besides we don't use device-dependant drawing, so probably 194 // that's very fine indeed 195 splash->byteAlignment = 1; 196 initFormat(&splash->screenFormat, 0xff << 8, 197 0xff << 16, 0xff << 24, 0xff << 0); 198 splash->screenFormat.byteOrder = 1 ? BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST; 199 splash->screenFormat.depthBytes = 4; 200 201 // If we are running SWT we should not start a runLoop 202 if (!isSWTRunning()) { |