< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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


  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 static NSScreen* SplashNSScreen()
  51 {
  52     return [[NSScreen screens] objectAtIndex: 0];
  53 }
  54 
  55 static void SplashCenter(Splash * splash)
  56 {
  57     NSRect screenFrame = [SplashNSScreen() frame];
  58 
  59     splash->x = (screenFrame.size.width - splash->width) / 2;
  60     splash->y = (screenFrame.size.height - splash->height) / 2 + screenFrame.origin.y;
  61 }
  62 
  63 unsigned
  64 SplashTime(void) {
  65     struct timeval tv;
  66     struct timezone tz;
  67     unsigned long long msec;
  68 
  69     gettimeofday(&tv, &tz);


 142         return JNI_FALSE;
 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 JNI_FALSE;
 176             }
 177             *scaleFactor = 2;
 178             strcpy(scaledFile, [fileName2x UTF8String]);
 179             [pool drain];
 180             return JNI_TRUE;
 181         }
 182     }
 183     [pool drain];
 184     return JNI_FALSE;
 185 }
 186 
 187 void
 188 SplashInitPlatform(Splash * splash) {
 189     pthread_mutex_init(&splash->lock, NULL);
 190 
 191     splash->maskRequired = 0;
 192 


 439 void
 440 sendctl(Splash * splash, char code) {
 441     if (splash && splash->controlpipe[1]) {
 442         write(splash->controlpipe[1], &code, 1);
 443     }
 444 }
 445 
 446 void
 447 SplashClosePlatform(Splash * splash) {
 448     sendctl(splash, SPLASHCTL_QUIT);
 449 }
 450 
 451 void
 452 SplashUpdate(Splash * splash) {
 453     sendctl(splash, SPLASHCTL_UPDATE);
 454 }
 455 
 456 void
 457 SplashReconfigure(Splash * splash) {
 458     sendctl(splash, SPLASHCTL_RECONFIGURE);













 459 }
 460 
   1 /*
   2  * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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


  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,
  52                               NSString *strToAppend);
  53 
  54 static NSScreen* SplashNSScreen()
  55 {
  56     return [[NSScreen screens] objectAtIndex: 0];
  57 }
  58 
  59 static void SplashCenter(Splash * splash)
  60 {
  61     NSRect screenFrame = [SplashNSScreen() frame];
  62 
  63     splash->x = (screenFrame.size.width - splash->width) / 2;
  64     splash->y = (screenFrame.size.height - splash->height) / 2 + screenFrame.origin.y;
  65 }
  66 
  67 unsigned
  68 SplashTime(void) {
  69     struct timeval tv;
  70     struct timezone tz;
  71     unsigned long long msec;
  72 
  73     gettimeofday(&tv, &tz);


 146         return JNI_FALSE;
 147     }
 148 
 149     NSAutoreleasePool *pool = [NSAutoreleasePool new];
 150     __block float screenScaleFactor = 1;
 151 
 152     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 153         // initialize NSApplication and AWT stuff
 154         [NSApplicationAWT sharedApplication];
 155         screenScaleFactor = [SplashNSScreen() backingScaleFactor];
 156     }];
 157 
 158     if (screenScaleFactor > 1) {
 159         NSString *fileName = [NSString stringWithUTF8String: file];
 160         NSUInteger length = [fileName length];
 161         NSRange range = [fileName rangeOfString: @"."
 162                                         options:NSBackwardsSearch];
 163         NSUInteger dotIndex = range.location;
 164         NSString *fileName2x = nil;
 165 
 166         fileName2x = findScaledImageName(fileName, dotIndex, @"@2x");
 167         if(![[NSFileManager defaultManager]
 168                 fileExistsAtPath: fileName2x]) {
 169             fileName2x = findScaledImageName(fileName, dotIndex, @"@200pct");



 170         }
 171         if (jar || [[NSFileManager defaultManager]
 172                 fileExistsAtPath: fileName2x]){

 173             if (strlen([fileName2x UTF8String]) > scaledImageLength) {
 174                 [pool drain];
 175                 return JNI_FALSE;
 176             }
 177             *scaleFactor = 2;
 178             strcpy(scaledFile, [fileName2x UTF8String]);
 179             [pool drain];
 180             return JNI_TRUE;
 181         }
 182     }
 183     [pool drain];
 184     return JNI_FALSE;
 185 }
 186 
 187 void
 188 SplashInitPlatform(Splash * splash) {
 189     pthread_mutex_init(&splash->lock, NULL);
 190 
 191     splash->maskRequired = 0;
 192 


 439 void
 440 sendctl(Splash * splash, char code) {
 441     if (splash && splash->controlpipe[1]) {
 442         write(splash->controlpipe[1], &code, 1);
 443     }
 444 }
 445 
 446 void
 447 SplashClosePlatform(Splash * splash) {
 448     sendctl(splash, SPLASHCTL_QUIT);
 449 }
 450 
 451 void
 452 SplashUpdate(Splash * splash) {
 453     sendctl(splash, SPLASHCTL_UPDATE);
 454 }
 455 
 456 void
 457 SplashReconfigure(Splash * splash) {
 458     sendctl(splash, SPLASHCTL_RECONFIGURE);
 459 }
 460 
 461 NSString* findScaledImageName(NSString *fileName, NSUInteger dotIndex, NSString *strToAppend) {
 462     NSString *fileName2x = nil;
 463     if (dotIndex == NSNotFound) {
 464         fileName2x = [fileName stringByAppendingString: strToAppend];
 465     } else {
 466         fileName2x = [fileName substringToIndex: dotIndex];
 467         fileName2x = [fileName2x stringByAppendingString: strToAppend];
 468         fileName2x = [fileName2x stringByAppendingString:
 469                       [fileName substringFromIndex: dotIndex]];
 470     }
 471     return fileName2x;
 472 }
 473 
< prev index next >