src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 47020 jdk/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m@2c55106dc37b
child 55189 fdaf7287ea3a
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
46874
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 41776
diff changeset
     2
 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#include "splashscreen_impl.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#import <Cocoa/Cocoa.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
#import <objc/objc-auto.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#import <JavaNativeFoundation/JavaNativeFoundation.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#import "NSApplicationAWT.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
#include <sys/time.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
#include <pthread.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
#include <iconv.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
#include <langinfo.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
#include <locale.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
#include <fcntl.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
#include <poll.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
#include <errno.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
#include <sys/types.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
#include <signal.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
#include <unistd.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
#include <dlfcn.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
    47
#include <sizecalc.h>
25769
f18107faec8f 8049198: [macosx] Incorrect thread access when showing splash screen
alexsch
parents: 25552
diff changeset
    48
#import "ThreadUtilities.h"
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
41776
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    50
NSString* findScaledImageName(NSString *fileName,
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    51
                              NSUInteger dotIndex,
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    52
                              NSString *strToAppend);
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
    53
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
static NSScreen* SplashNSScreen()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
    return [[NSScreen screens] objectAtIndex: 0];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
static void SplashCenter(Splash * splash)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    NSRect screenFrame = [SplashNSScreen() frame];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    splash->x = (screenFrame.size.width - splash->width) / 2;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
    splash->y = (screenFrame.size.height - splash->height) / 2 + screenFrame.origin.y;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
unsigned
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
SplashTime(void) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    struct timeval tv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
    struct timezone tz;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    unsigned long long msec;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    gettimeofday(&tv, &tz);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
    msec = (unsigned long long) tv.tv_sec * 1000 +
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
        (unsigned long long) tv.tv_usec / 1000;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
    return (unsigned) msec;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
/* Could use npt but decided to cut down on linked code size */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
char* SplashConvertStringAlloc(const char* in, int* size) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    const char     *codeset;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    const char     *codeset_out;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
    iconv_t         cd;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
    size_t          rc;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
    char           *buf = NULL, *out;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    size_t          bufSize, inSize, outSize;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
    const char* old_locale;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
    if (!in) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
    old_locale = setlocale(LC_ALL, "");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
    codeset = nl_langinfo(CODESET);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
    if ( codeset == NULL || codeset[0] == 0 ) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
        goto done;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
    /* we don't need BOM in output so we choose native BE or LE encoding here */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
    codeset_out = (platformByteOrder()==BYTE_ORDER_MSBFIRST) ?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
        "UCS-2BE" : "UCS-2LE";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
    cd = iconv_open(codeset_out, codeset);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
    if (cd == (iconv_t)-1 ) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
        goto done;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    inSize = strlen(in);
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
   108
    buf = SAFE_SIZE_ARRAY_ALLOC(malloc, inSize, 2);
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
   109
    if (!buf) {
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
   110
        return NULL;
b538b71fb429 8009071: Improve shape handling
anthony
parents: 12047
diff changeset
   111
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
    bufSize = inSize*2; // need 2 bytes per char for UCS-2, this is
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
                        // 2 bytes per source byte max
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    out = buf; outSize = bufSize;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
    /* linux iconv wants char** source and solaris wants const char**...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
       cast to void* */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
    rc = iconv(cd, (void*)&in, &inSize, &out, &outSize);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
    iconv_close(cd);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
    if (rc == (size_t)-1) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
        free(buf);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
        buf = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
        if (size) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
            *size = (bufSize-outSize)/2; /* bytes to wchars */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
done:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
    setlocale(LC_ALL, old_locale);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
    return buf;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
29736
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   133
BOOL isSWTRunning() {
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   134
    char envVar[80];
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   135
    // If this property is present we are running SWT
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   136
    snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   137
    return getenv(envVar) != NULL;
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   138
}
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   139
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   140
jboolean SplashGetScaledImageName(const char* jar, const char* file,
41776
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   141
                                  float *scaleFactor, char *scaledFile,
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   142
                                  const size_t scaledImageLength) {
29736
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   143
    *scaleFactor = 1;
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   144
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   145
    if(isSWTRunning()){
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   146
        return JNI_FALSE;
29736
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   147
    }
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   148
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   149
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
29736
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   150
    __block float screenScaleFactor = 1;
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   151
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   152
    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   153
        // initialize NSApplication and AWT stuff
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   154
        [NSApplicationAWT sharedApplication];
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   155
        screenScaleFactor = [SplashNSScreen() backingScaleFactor];
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   156
    }];
25769
f18107faec8f 8049198: [macosx] Incorrect thread access when showing splash screen
alexsch
parents: 25552
diff changeset
   157
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   158
    if (screenScaleFactor > 1) {
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   159
        NSString *fileName = [NSString stringWithUTF8String: file];
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   160
        NSUInteger length = [fileName length];
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   161
        NSRange range = [fileName rangeOfString: @"."
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   162
                                        options:NSBackwardsSearch];
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   163
        NSUInteger dotIndex = range.location;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   164
        NSString *fileName2x = nil;
41776
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   165
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   166
        fileName2x = findScaledImageName(fileName, dotIndex, @"@2x");
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   167
        if(![[NSFileManager defaultManager]
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   168
                fileExistsAtPath: fileName2x]) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   169
            fileName2x = findScaledImageName(fileName, dotIndex, @"@200pct");
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   170
        }
41776
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   171
        if (jar || [[NSFileManager defaultManager]
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   172
                fileExistsAtPath: fileName2x]){
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   173
            if (strlen([fileName2x UTF8String]) > scaledImageLength) {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   174
                [pool drain];
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   175
                return JNI_FALSE;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   176
            }
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   177
            *scaleFactor = 2;
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   178
            strcpy(scaledFile, [fileName2x UTF8String]);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   179
            [pool drain];
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   180
            return JNI_TRUE;
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   181
        }
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   182
    }
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   183
    [pool drain];
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 31651
diff changeset
   184
    return JNI_FALSE;
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   185
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
SplashInitPlatform(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
    pthread_mutex_init(&splash->lock, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
    splash->maskRequired = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   193
    
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
    //TODO: the following is too much of a hack but should work in 90% cases.
47020
2c55106dc37b 8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents: 46874
diff changeset
   195
    //      besides we don't use device-dependent drawing, so probably
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
    //      that's very fine indeed
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
    splash->byteAlignment = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    initFormat(&splash->screenFormat, 0xff << 8,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
            0xff << 16, 0xff << 24, 0xff << 0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    splash->screenFormat.byteOrder = 1 ?  BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    splash->screenFormat.depthBytes = 4;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
29736
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   203
    // If we are running SWT we should not start a runLoop
83a76fe84763 8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents: 29726
diff changeset
   204
    if (!isSWTRunning()) {
24190
bbd2288a8a29 8039926: -spash:<image> can't be combined with -xStartOnFirstThread since JDK 7
pchelko
parents: 23328
diff changeset
   205
        [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() {
bbd2288a8a29 8039926: -spash:<image> can't be combined with -xStartOnFirstThread since JDK 7
pchelko
parents: 23328
diff changeset
   206
            [NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]];
bbd2288a8a29 8039926: -spash:<image> can't be combined with -xStartOnFirstThread since JDK 7
pchelko
parents: 23328
diff changeset
   207
        }];
bbd2288a8a29 8039926: -spash:<image> can't be combined with -xStartOnFirstThread since JDK 7
pchelko
parents: 23328
diff changeset
   208
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
SplashCleanupPlatform(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
    splash->maskRequired = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
SplashDonePlatform(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
    pthread_mutex_destroy(&splash->lock);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
        if (splash->window) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
            [splash->window orderOut:nil];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
            [splash->window release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    [pool drain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
SplashLock(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
    pthread_mutex_lock(&splash->lock);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   235
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   236
SplashUnlock(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
    pthread_mutex_unlock(&splash->lock);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
SplashInitFrameShape(Splash * splash, int imageIndex) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
    // No shapes, we rely on alpha compositing
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
void * SplashScreenThread(void *param);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
SplashCreateThread(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
    pthread_t thr;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
    pthread_attr_t attr;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
    int rc;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
    pthread_attr_init(&attr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   257
SplashRedrawWindow(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
    SplashUpdateScreenData(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
        // NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
        NSBitmapImageRep * rep = [[NSBitmapImageRep alloc]
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
            initWithBitmapDataPlanes: (unsigned char**)&splash->screenData
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
                          pixelsWide: splash->width
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
                          pixelsHigh: splash->height
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
                       bitsPerSample: 8
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
                     samplesPerPixel: 4
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
                            hasAlpha: YES
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
                            isPlanar: NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
                      colorSpaceName: NSDeviceRGBColorSpace
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
                        bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
                         bytesPerRow: splash->width * 4
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
                        bitsPerPixel: 32];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
        NSImage * image = [[NSImage alloc]
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
            initWithSize: NSMakeSize(splash->width, splash->height)];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
        [image setBackgroundColor: [NSColor clearColor]];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
        [image addRepresentation: rep];
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   282
        float scaleFactor = splash->scaleFactor;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   283
        if (scaleFactor > 0 && scaleFactor != 1) {
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   284
            NSSize size = [image size];
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   285
            size.width /= scaleFactor;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   286
            size.height /= scaleFactor;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   287
            [image setSize: size];
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   288
        }
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 24190
diff changeset
   289
        
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
        NSImageView * view = [[NSImageView alloc] init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
        [view setImage: image];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
        [view setEditable: NO];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   294
        //NOTE: we don't set a 'wait cursor' for the view because:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   295
        //      1. The Cocoa GUI guidelines suggest to avoid it, and use a progress
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   296
        //         bar instead.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   297
        //      2. There simply isn't an instance of NSCursor that represent
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
        //         the 'wait cursor'. So that is undoable.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   299
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
        //TODO: only the first image in an animated gif preserves transparency.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
        //      Loos like the splash->screenData contains inappropriate data
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
        //      for all but the first frame.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
        [image release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
        [rep release];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
        [splash->window setContentView: view];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
        [splash->window orderFrontRegardless];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
    [pool drain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
void SplashReconfigureNow(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
        SplashCenter(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
        if (!splash->window) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
            return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
        [splash->window orderOut:nil];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
        [splash->window setFrame: NSMakeRect(splash->x, splash->y, splash->width, splash->height)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
                         display: NO];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
    [pool drain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
    SplashRedrawWindow(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
SplashEventLoop(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
    /* we should have splash _locked_ on entry!!! */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
    while (1) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
        struct pollfd pfd[1];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
        int timeout = -1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
        int ctl = splash->controlpipe[0];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
        int rc;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
        int pipes_empty;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
        pfd[0].fd = ctl;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
        pfd[0].events = POLLIN | POLLPRI;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
        errno = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
        if (splash->isVisible>0 && SplashIsStillLooping(splash)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
            timeout = splash->time + splash->frames[splash->currentFrame].delay
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
                - SplashTime();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
            if (timeout < 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
                timeout = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
        SplashUnlock(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
        rc = poll(pfd, 1, timeout);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
        SplashLock(splash);
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 18232
diff changeset
   360
        if (splash->isVisible > 0 && splash->currentFrame >= 0 &&
dd65107de257 8023057: Enhance start up image display
vadim
parents: 18232
diff changeset
   361
                SplashTime() >= splash->time + splash->frames[splash->currentFrame].delay) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
            SplashNextFrame(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
            SplashRedrawWindow(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
        if (rc <= 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
            errno = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   367
            continue;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   368
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   369
        pipes_empty = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
        while(!pipes_empty) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   371
            char buf;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   372
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   373
            pipes_empty = 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   374
            if (read(ctl, &buf, sizeof(buf)) > 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   375
                pipes_empty = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   376
                switch (buf) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   377
                case SPLASHCTL_UPDATE:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   378
                    if (splash->isVisible>0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   379
                        SplashRedrawWindow(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   380
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
                    break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
                case SPLASHCTL_RECONFIGURE:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   383
                    if (splash->isVisible>0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   384
                        SplashReconfigureNow(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   385
                    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   386
                    break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   387
                case SPLASHCTL_QUIT:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   388
                    return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   389
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   390
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   391
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   392
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   393
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   394
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   395
void *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   396
SplashScreenThread(void *param) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   397
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   398
    Splash *splash = (Splash *) param;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   399
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   400
    SplashLock(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   401
    pipe(splash->controlpipe);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   402
    fcntl(splash->controlpipe[0], F_SETFL,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   403
        fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   404
    splash->time = SplashTime();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   405
    splash->currentFrame = 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   406
    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
        SplashCenter(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
        splash->window = (void*) [[NSWindow alloc]
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
            initWithContentRect: NSMakeRect(splash->x, splash->y, splash->width, splash->height)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
                      styleMask: NSBorderlessWindowMask
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
                        backing: NSBackingStoreBuffered
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
                          defer: NO
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   414
                         screen: SplashNSScreen()];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   415
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
        [splash->window setOpaque: NO];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
        [splash->window setBackgroundColor: [NSColor clearColor]];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
    }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
    fflush(stdout);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
    if (splash->window) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
        [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
            [splash->window orderFrontRegardless];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
        }];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
        SplashRedrawWindow(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   425
        SplashEventLoop(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
    SplashUnlock(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    SplashDone(splash);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   430
    splash->isVisible=-1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   431
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   432
    [pool drain];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
    return 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   436
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   437
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
sendctl(Splash * splash, char code) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
    if (splash && splash->controlpipe[1]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   440
        write(splash->controlpipe[1], &code, 1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
SplashClosePlatform(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
    sendctl(splash, SPLASHCTL_QUIT);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   447
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
SplashUpdate(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
    sendctl(splash, SPLASHCTL_UPDATE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   453
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   454
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   455
SplashReconfigure(Splash * splash) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   456
    sendctl(splash, SPLASHCTL_RECONFIGURE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   457
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   458
41776
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   459
NSString* findScaledImageName(NSString *fileName, NSUInteger dotIndex, NSString *strToAppend) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   460
    NSString *fileName2x = nil;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   461
    if (dotIndex == NSNotFound) {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   462
        fileName2x = [fileName stringByAppendingString: strToAppend];
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   463
    } else {
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   464
        fileName2x = [fileName substringToIndex: dotIndex];
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   465
        fileName2x = [fileName2x stringByAppendingString: strToAppend];
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   466
        fileName2x = [fileName2x stringByAppendingString:
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   467
                      [fileName substringFromIndex: dotIndex]];
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   468
    }
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   469
    return fileName2x;
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   470
}
71e2575dd727 8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents: 36907
diff changeset
   471