< prev index next >

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

Print this page
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "splashscreen_impl.h"
  27 
  28 #import <Cocoa/Cocoa.h>
  29 #import <objc/objc-auto.h>
  30 
  31 #import <JavaNativeFoundation/JavaNativeFoundation.h>
  32 #import "NSApplicationAWT.h"
  33 
  34 #include <sys/time.h>
  35 #include <pthread.h>
  36 #include <iconv.h>
  37 #include <langinfo.h>
  38 #include <locale.h>
  39 #include <fcntl.h>
  40 #include <poll.h>
  41 #include <errno.h>
  42 #include <sys/types.h>
  43 #include <signal.h>
  44 #include <unistd.h>
  45 #include <dlfcn.h>
  46 
  47 #include <sizecalc.h>
  48 #import "ThreadUtilities.h"
  49 
  50 NSString* findScaledImageName(NSString *fileName,
  51                               NSUInteger dotIndex,


 185 }
 186 
 187 void
 188 SplashInitPlatform(Splash * splash) {
 189     pthread_mutex_init(&splash->lock, NULL);
 190 
 191     splash->maskRequired = 0;
 192 
 193 
 194     //TODO: the following is too much of a hack but should work in 90% cases.
 195     //      besides we don't use device-dependent drawing, so probably
 196     //      that's very fine indeed
 197     splash->byteAlignment = 1;
 198     initFormat(&splash->screenFormat, 0xff << 8,
 199             0xff << 16, 0xff << 24, 0xff << 0);
 200     splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
 201     splash->screenFormat.depthBytes = 4;
 202 
 203     // If we are running SWT we should not start a runLoop
 204     if (!isSWTRunning()) {
 205         [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
 206             [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]];
 207         }];
 208     }
 209 }
 210 
 211 void
 212 SplashCleanupPlatform(Splash * splash) {
 213     splash->maskRequired = 0;
 214 }
 215 
 216 void
 217 SplashDonePlatform(Splash * splash) {
 218     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 219 
 220     pthread_mutex_destroy(&splash->lock);
 221     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 222         if (splash->window) {
 223             [splash->window orderOut:nil];
 224             [splash->window release];
 225         }
 226     }];
 227     [pool drain];
 228 }
 229 
 230 void
 231 SplashLock(Splash * splash) {
 232     pthread_mutex_lock(&splash->lock);
 233 }
 234 
 235 void
 236 SplashUnlock(Splash * splash) {
 237     pthread_mutex_unlock(&splash->lock);
 238 }
 239 
 240 void
 241 SplashInitFrameShape(Splash * splash, int imageIndex) {
 242     // No shapes, we rely on alpha compositing
 243 }
 244 
 245 void * SplashScreenThread(void *param);
 246 void
 247 SplashCreateThread(Splash * splash) {
 248     pthread_t thr;
 249     pthread_attr_t attr;
 250     int rc;
 251 
 252     pthread_attr_init(&attr);
 253     rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
 254 }
 255 
 256 void
 257 SplashRedrawWindow(Splash * splash) {
 258     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 259 
 260     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 261         // drop the reference to the old view and image
 262         [splash->window setContentView: nil];
 263         SplashUpdateScreenData(splash);
 264 
 265         // NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ?
 266         NSBitmapImageRep * rep = [[NSBitmapImageRep alloc]
 267             initWithBitmapDataPlanes: (unsigned char**)&splash->screenData
 268                           pixelsWide: splash->width
 269                           pixelsHigh: splash->height
 270                        bitsPerSample: 8
 271                      samplesPerPixel: 4
 272                             hasAlpha: YES
 273                             isPlanar: NO
 274                       colorSpaceName: NSDeviceRGBColorSpace
 275                         bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat
 276                          bytesPerRow: splash->width * 4
 277                         bitsPerPixel: 32];
 278 
 279         NSImage * image = [[NSImage alloc]
 280             initWithSize: NSMakeSize(splash->width, splash->height)];


 299         //      2. There simply isn't an instance of NSCursor that represent
 300         //         the 'wait cursor'. So that is undoable.
 301 
 302         //TODO: only the first image in an animated gif preserves transparency.
 303         //      Loos like the splash->screenData contains inappropriate data
 304         //      for all but the first frame.
 305 
 306         [image release];
 307         [rep release];
 308 
 309         [splash->window setContentView: view];
 310         [splash->window orderFrontRegardless];
 311     }];
 312 
 313     [pool drain];
 314 }
 315 
 316 void SplashReconfigureNow(Splash * splash) {
 317     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 318 
 319     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 320         SplashCenter(splash);
 321 
 322         if (!splash->window) {
 323             return;
 324         }
 325 
 326         [splash->window orderOut:nil];
 327         [splash->window setFrame: NSMakeRect(splash->x, splash->y, splash->width, splash->height)
 328                          display: NO];
 329     }];
 330 
 331     [pool drain];
 332 
 333     SplashRedrawWindow(splash);
 334 }
 335 
 336 void
 337 SplashEventLoop(Splash * splash) {
 338 
 339     /* we should have splash _locked_ on entry!!! */


 388                     break;
 389                 case SPLASHCTL_QUIT:
 390                     return;
 391                 }
 392             }
 393         }
 394     }
 395 }
 396 
 397 void *
 398 SplashScreenThread(void *param) {
 399     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 400     Splash *splash = (Splash *) param;
 401 
 402     SplashLock(splash);
 403     pipe(splash->controlpipe);
 404     fcntl(splash->controlpipe[0], F_SETFL,
 405         fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
 406     splash->time = SplashTime();
 407     splash->currentFrame = 0;
 408     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 409         SplashCenter(splash);
 410 
 411         splash->window = (void*) [[NSWindow alloc]
 412             initWithContentRect: NSMakeRect(splash->x, splash->y, splash->width, splash->height)
 413                       styleMask: NSBorderlessWindowMask
 414                         backing: NSBackingStoreBuffered
 415                           defer: NO
 416                          screen: SplashNSScreen()];
 417 
 418         [splash->window setOpaque: NO];
 419         [splash->window setBackgroundColor: [NSColor clearColor]];
 420     }];
 421     fflush(stdout);
 422     if (splash->window) {
 423         [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 424             [splash->window orderFrontRegardless];
 425         }];
 426         SplashRedrawWindow(splash);
 427         SplashEventLoop(splash);
 428     }
 429     SplashUnlock(splash);
 430     SplashDone(splash);
 431 
 432     splash->isVisible=-1;
 433 
 434     [pool drain];
 435 
 436     return 0;
 437 }
 438 
 439 void
 440 sendctl(Splash * splash, char code) {
 441     if (splash && splash->controlpipe[1]) {
 442         write(splash->controlpipe[1], &code, 1);
 443     }




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "splashscreen_impl.h"
  27 
  28 #import <Cocoa/Cocoa.h>
  29 #import <objc/objc-auto.h>
  30 

  31 #import "NSApplicationAWT.h"
  32 
  33 #include <sys/time.h>
  34 #include <pthread.h>
  35 #include <iconv.h>
  36 #include <langinfo.h>
  37 #include <locale.h>
  38 #include <fcntl.h>
  39 #include <poll.h>
  40 #include <errno.h>
  41 #include <sys/types.h>
  42 #include <signal.h>
  43 #include <unistd.h>
  44 #include <dlfcn.h>
  45 
  46 #include <sizecalc.h>
  47 #import "ThreadUtilities.h"
  48 
  49 NSString* findScaledImageName(NSString *fileName,
  50                               NSUInteger dotIndex,


 184 }
 185 
 186 void
 187 SplashInitPlatform(Splash * splash) {
 188     pthread_mutex_init(&splash->lock, NULL);
 189 
 190     splash->maskRequired = 0;
 191 
 192 
 193     //TODO: the following is too much of a hack but should work in 90% cases.
 194     //      besides we don't use device-dependent drawing, so probably
 195     //      that's very fine indeed
 196     splash->byteAlignment = 1;
 197     initFormat(&splash->screenFormat, 0xff << 8,
 198             0xff << 16, 0xff << 24, 0xff << 0);
 199     splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
 200     splash->screenFormat.depthBytes = 4;
 201 
 202     // If we are running SWT we should not start a runLoop
 203     if (!isSWTRunning()) {
 204         [ThreadUtilities performOnMainThreadWaiting:NO block:^() {
 205             [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]];
 206         }];
 207     }
 208 }
 209 
 210 void
 211 SplashCleanupPlatform(Splash * splash) {
 212     splash->maskRequired = 0;
 213 }
 214 
 215 void
 216 SplashDonePlatform(Splash * splash) {
 217     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 218 
 219     pthread_mutex_destroy(&splash->lock);
 220     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 221         if (splash->window) {
 222             [splash->window orderOut:nil];
 223             [splash->window release];
 224         }
 225     }];
 226     [pool drain];
 227 }
 228 
 229 void
 230 SplashLock(Splash * splash) {
 231     pthread_mutex_lock(&splash->lock);
 232 }
 233 
 234 void
 235 SplashUnlock(Splash * splash) {
 236     pthread_mutex_unlock(&splash->lock);
 237 }
 238 
 239 void
 240 SplashInitFrameShape(Splash * splash, int imageIndex) {
 241     // No shapes, we rely on alpha compositing
 242 }
 243 
 244 void * SplashScreenThread(void *param);
 245 void
 246 SplashCreateThread(Splash * splash) {
 247     pthread_t thr;
 248     pthread_attr_t attr;
 249     int rc;
 250 
 251     pthread_attr_init(&attr);
 252     rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
 253 }
 254 
 255 void
 256 SplashRedrawWindow(Splash * splash) {
 257     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 258 
 259     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 260         // drop the reference to the old view and image
 261         [splash->window setContentView: nil];
 262         SplashUpdateScreenData(splash);
 263 
 264         // NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ?
 265         NSBitmapImageRep * rep = [[NSBitmapImageRep alloc]
 266             initWithBitmapDataPlanes: (unsigned char**)&splash->screenData
 267                           pixelsWide: splash->width
 268                           pixelsHigh: splash->height
 269                        bitsPerSample: 8
 270                      samplesPerPixel: 4
 271                             hasAlpha: YES
 272                             isPlanar: NO
 273                       colorSpaceName: NSDeviceRGBColorSpace
 274                         bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat
 275                          bytesPerRow: splash->width * 4
 276                         bitsPerPixel: 32];
 277 
 278         NSImage * image = [[NSImage alloc]
 279             initWithSize: NSMakeSize(splash->width, splash->height)];


 298         //      2. There simply isn't an instance of NSCursor that represent
 299         //         the 'wait cursor'. So that is undoable.
 300 
 301         //TODO: only the first image in an animated gif preserves transparency.
 302         //      Loos like the splash->screenData contains inappropriate data
 303         //      for all but the first frame.
 304 
 305         [image release];
 306         [rep release];
 307 
 308         [splash->window setContentView: view];
 309         [splash->window orderFrontRegardless];
 310     }];
 311 
 312     [pool drain];
 313 }
 314 
 315 void SplashReconfigureNow(Splash * splash) {
 316     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 317 
 318     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 319         SplashCenter(splash);
 320 
 321         if (!splash->window) {
 322             return;
 323         }
 324 
 325         [splash->window orderOut:nil];
 326         [splash->window setFrame: NSMakeRect(splash->x, splash->y, splash->width, splash->height)
 327                          display: NO];
 328     }];
 329 
 330     [pool drain];
 331 
 332     SplashRedrawWindow(splash);
 333 }
 334 
 335 void
 336 SplashEventLoop(Splash * splash) {
 337 
 338     /* we should have splash _locked_ on entry!!! */


 387                     break;
 388                 case SPLASHCTL_QUIT:
 389                     return;
 390                 }
 391             }
 392         }
 393     }
 394 }
 395 
 396 void *
 397 SplashScreenThread(void *param) {
 398     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 399     Splash *splash = (Splash *) param;
 400 
 401     SplashLock(splash);
 402     pipe(splash->controlpipe);
 403     fcntl(splash->controlpipe[0], F_SETFL,
 404         fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
 405     splash->time = SplashTime();
 406     splash->currentFrame = 0;
 407     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 408         SplashCenter(splash);
 409 
 410         splash->window = (void*) [[NSWindow alloc]
 411             initWithContentRect: NSMakeRect(splash->x, splash->y, splash->width, splash->height)
 412                       styleMask: NSBorderlessWindowMask
 413                         backing: NSBackingStoreBuffered
 414                           defer: NO
 415                          screen: SplashNSScreen()];
 416 
 417         [splash->window setOpaque: NO];
 418         [splash->window setBackgroundColor: [NSColor clearColor]];
 419     }];
 420     fflush(stdout);
 421     if (splash->window) {
 422         [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 423             [splash->window orderFrontRegardless];
 424         }];
 425         SplashRedrawWindow(splash);
 426         SplashEventLoop(splash);
 427     }
 428     SplashUnlock(splash);
 429     SplashDone(splash);
 430 
 431     splash->isVisible=-1;
 432 
 433     [pool drain];
 434 
 435     return 0;
 436 }
 437 
 438 void
 439 sendctl(Splash * splash, char code) {
 440     if (splash && splash->controlpipe[1]) {
 441         write(splash->controlpipe[1], &code, 1);
 442     }


< prev index next >