src/macosx/native/sun/awt/splashscreen/splashscreen_sys.m

Print this page




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






























 128 
 129 void
 130 SplashInitPlatform(Splash * splash) {
 131     pthread_mutex_init(&splash->lock, NULL);
 132 
 133     splash->maskRequired = 0;
 134 
 135 
 136     //TODO: the following is too much of a hack but should work in 90% cases.
 137     //      besides we don't use device-dependant drawing, so probably
 138     //      that's very fine indeed
 139     splash->byteAlignment = 1;
 140     initFormat(&splash->screenFormat, 0xff << 8,
 141             0xff << 16, 0xff << 24, 0xff << 0);
 142     splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
 143     splash->screenFormat.depthBytes = 4;
 144 
 145     // If this property is present we are running SWT and should not start a runLoop
 146     // Can't check if running SWT in webstart, so splash screen in webstart SWT
 147     // applications is not supported


 208     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 209         // NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ?
 210         NSBitmapImageRep * rep = [[NSBitmapImageRep alloc]
 211             initWithBitmapDataPlanes: (unsigned char**)&splash->screenData
 212                           pixelsWide: splash->width
 213                           pixelsHigh: splash->height
 214                        bitsPerSample: 8
 215                      samplesPerPixel: 4
 216                             hasAlpha: YES
 217                             isPlanar: NO
 218                       colorSpaceName: NSDeviceRGBColorSpace
 219                         bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat
 220                          bytesPerRow: splash->width * 4
 221                         bitsPerPixel: 32];
 222 
 223         NSImage * image = [[NSImage alloc]
 224             initWithSize: NSMakeSize(splash->width, splash->height)];
 225         [image setBackgroundColor: [NSColor clearColor]];
 226 
 227         [image addRepresentation: rep];








 228 
 229         NSImageView * view = [[NSImageView alloc] init];
 230 
 231         [view setImage: image];
 232         [view setEditable: NO];
 233         //NOTE: we don't set a 'wait cursor' for the view because:
 234         //      1. The Cocoa GUI guidelines suggest to avoid it, and use a progress
 235         //         bar instead.
 236         //      2. There simply isn't an instance of NSCursor that represent
 237         //         the 'wait cursor'. So that is undoable.
 238 
 239         //TODO: only the first image in an animated gif preserves transparency.
 240         //      Loos like the splash->screenData contains inappropriate data
 241         //      for all but the first frame.
 242 
 243         [image release];
 244         [rep release];
 245 
 246         [splash->window setContentView: view];
 247         [splash->window orderFrontRegardless];




 108                         // 2 bytes per source byte max
 109     out = buf; outSize = bufSize;
 110     /* linux iconv wants char** source and solaris wants const char**...
 111        cast to void* */
 112     rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
 113     iconv_close(cd);
 114 
 115     if (rc == (size_t)-1) {
 116         free(buf);
 117         buf = NULL;
 118     } else {
 119         if (size) {
 120             *size = (bufSize-outSize)/2; /* bytes to wchars */
 121         }
 122     }
 123 done:
 124     setlocale(LC_ALL, old_locale);
 125     return buf;
 126 }
 127 
 128 char* SplashGetScaledImageName(const char* jar, const char* file,
 129                                float *scaleFactor) {
 130     NSString *fileName = [[[NSString alloc] initWithUTF8String: file]
 131                           autorelease];
 132     NSUInteger length = [fileName length];
 133     *scaleFactor = 1;
 134     float screenScaleFactor = [[NSScreen mainScreen] backingScaleFactor];
 135     
 136     if (1 < screenScaleFactor) {
 137         NSRange range = [fileName rangeOfString: @"."
 138                                         options:NSBackwardsSearch];
 139         int index = range.location;
 140         
 141         if (index != NSNotFound && index != 0 && index != length-1) {
 142             NSString *fileName2x = [fileName substringToIndex: index];
 143             fileName2x = [fileName2x stringByAppendingString: @"@2x"];
 144             fileName2x = [fileName2x stringByAppendingString:
 145                           [fileName substringFromIndex: index]];
 146             
 147             if (!jar && ![[NSFileManager defaultManager]
 148                           fileExistsAtPath: fileName2x]){
 149                 return nil;
 150             }
 151 
 152             *scaleFactor = 2;
 153             return strdup([fileName2x UTF8String]);
 154         }
 155     }
 156     return nil;
 157 }
 158 
 159 void
 160 SplashInitPlatform(Splash * splash) {
 161     pthread_mutex_init(&splash->lock, NULL);
 162 
 163     splash->maskRequired = 0;
 164 
 165     
 166     //TODO: the following is too much of a hack but should work in 90% cases.
 167     //      besides we don't use device-dependant drawing, so probably
 168     //      that's very fine indeed
 169     splash->byteAlignment = 1;
 170     initFormat(&splash->screenFormat, 0xff << 8,
 171             0xff << 16, 0xff << 24, 0xff << 0);
 172     splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
 173     splash->screenFormat.depthBytes = 4;
 174 
 175     // If this property is present we are running SWT and should not start a runLoop
 176     // Can't check if running SWT in webstart, so splash screen in webstart SWT
 177     // applications is not supported


 238     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 239         // NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ?
 240         NSBitmapImageRep * rep = [[NSBitmapImageRep alloc]
 241             initWithBitmapDataPlanes: (unsigned char**)&splash->screenData
 242                           pixelsWide: splash->width
 243                           pixelsHigh: splash->height
 244                        bitsPerSample: 8
 245                      samplesPerPixel: 4
 246                             hasAlpha: YES
 247                             isPlanar: NO
 248                       colorSpaceName: NSDeviceRGBColorSpace
 249                         bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat
 250                          bytesPerRow: splash->width * 4
 251                         bitsPerPixel: 32];
 252 
 253         NSImage * image = [[NSImage alloc]
 254             initWithSize: NSMakeSize(splash->width, splash->height)];
 255         [image setBackgroundColor: [NSColor clearColor]];
 256 
 257         [image addRepresentation: rep];
 258         float scaleFactor = splash->scaleFactor;
 259         if (scaleFactor != 1) {
 260             [image setScalesWhenResized:YES];
 261             NSSize size = [image size];
 262             size.width /= scaleFactor;
 263             size.height /= scaleFactor;
 264             [image setSize: size];
 265         }
 266         
 267         NSImageView * view = [[NSImageView alloc] init];
 268 
 269         [view setImage: image];
 270         [view setEditable: NO];
 271         //NOTE: we don't set a 'wait cursor' for the view because:
 272         //      1. The Cocoa GUI guidelines suggest to avoid it, and use a progress
 273         //         bar instead.
 274         //      2. There simply isn't an instance of NSCursor that represent
 275         //         the 'wait cursor'. So that is undoable.
 276 
 277         //TODO: only the first image in an animated gif preserves transparency.
 278         //      Loos like the splash->screenData contains inappropriate data
 279         //      for all but the first frame.
 280 
 281         [image release];
 282         [rep release];
 283 
 284         [splash->window setContentView: view];
 285         [splash->window orderFrontRegardless];