author | serb |
Wed, 27 Mar 2019 00:24:13 -0700 | |
changeset 55708 | 2b0acaf92ecc |
parent 55189 | fdaf7287ea3a |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
55708 | 2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
12047 | 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 |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#include "splashscreen_impl.h" |
|
27 |
||
28 |
#import <Cocoa/Cocoa.h> |
|
29 |
#import <objc/objc-auto.h> |
|
30 |
||
55189
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
31 |
#include <Security/AuthSession.h> |
12047 | 32 |
#import <JavaNativeFoundation/JavaNativeFoundation.h> |
33 |
#import "NSApplicationAWT.h" |
|
34 |
||
35 |
#include <sys/time.h> |
|
36 |
#include <pthread.h> |
|
37 |
#include <iconv.h> |
|
38 |
#include <langinfo.h> |
|
39 |
#include <locale.h> |
|
40 |
#include <fcntl.h> |
|
41 |
#include <poll.h> |
|
42 |
#include <errno.h> |
|
43 |
#include <sys/types.h> |
|
44 |
#include <signal.h> |
|
45 |
#include <unistd.h> |
|
46 |
#include <dlfcn.h> |
|
47 |
||
18232 | 48 |
#include <sizecalc.h> |
25769
f18107faec8f
8049198: [macosx] Incorrect thread access when showing splash screen
alexsch
parents:
25552
diff
changeset
|
49 |
#import "ThreadUtilities.h" |
12047 | 50 |
|
41776
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
51 |
NSString* findScaledImageName(NSString *fileName, |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
52 |
NSUInteger dotIndex, |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
53 |
NSString *strToAppend); |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
54 |
|
12047 | 55 |
static NSScreen* SplashNSScreen() |
56 |
{ |
|
57 |
return [[NSScreen screens] objectAtIndex: 0]; |
|
58 |
} |
|
59 |
||
60 |
static void SplashCenter(Splash * splash) |
|
61 |
{ |
|
62 |
NSRect screenFrame = [SplashNSScreen() frame]; |
|
63 |
||
64 |
splash->x = (screenFrame.size.width - splash->width) / 2; |
|
65 |
splash->y = (screenFrame.size.height - splash->height) / 2 + screenFrame.origin.y; |
|
66 |
} |
|
67 |
||
68 |
unsigned |
|
69 |
SplashTime(void) { |
|
70 |
struct timeval tv; |
|
71 |
struct timezone tz; |
|
72 |
unsigned long long msec; |
|
73 |
||
74 |
gettimeofday(&tv, &tz); |
|
75 |
msec = (unsigned long long) tv.tv_sec * 1000 + |
|
76 |
(unsigned long long) tv.tv_usec / 1000; |
|
77 |
||
78 |
return (unsigned) msec; |
|
79 |
} |
|
80 |
||
81 |
/* Could use npt but decided to cut down on linked code size */ |
|
82 |
char* SplashConvertStringAlloc(const char* in, int* size) { |
|
83 |
const char *codeset; |
|
84 |
const char *codeset_out; |
|
85 |
iconv_t cd; |
|
86 |
size_t rc; |
|
87 |
char *buf = NULL, *out; |
|
88 |
size_t bufSize, inSize, outSize; |
|
89 |
const char* old_locale; |
|
90 |
||
91 |
if (!in) { |
|
92 |
return NULL; |
|
93 |
} |
|
94 |
old_locale = setlocale(LC_ALL, ""); |
|
95 |
||
96 |
codeset = nl_langinfo(CODESET); |
|
97 |
if ( codeset == NULL || codeset[0] == 0 ) { |
|
98 |
goto done; |
|
99 |
} |
|
100 |
/* we don't need BOM in output so we choose native BE or LE encoding here */ |
|
101 |
codeset_out = (platformByteOrder()==BYTE_ORDER_MSBFIRST) ? |
|
102 |
"UCS-2BE" : "UCS-2LE"; |
|
103 |
||
104 |
cd = iconv_open(codeset_out, codeset); |
|
105 |
if (cd == (iconv_t)-1 ) { |
|
106 |
goto done; |
|
107 |
} |
|
108 |
inSize = strlen(in); |
|
18232 | 109 |
buf = SAFE_SIZE_ARRAY_ALLOC(malloc, inSize, 2); |
110 |
if (!buf) { |
|
111 |
return NULL; |
|
112 |
} |
|
12047 | 113 |
bufSize = inSize*2; // need 2 bytes per char for UCS-2, this is |
114 |
// 2 bytes per source byte max |
|
115 |
out = buf; outSize = bufSize; |
|
116 |
/* linux iconv wants char** source and solaris wants const char**... |
|
117 |
cast to void* */ |
|
118 |
rc = iconv(cd, (void*)&in, &inSize, &out, &outSize); |
|
119 |
iconv_close(cd); |
|
120 |
||
121 |
if (rc == (size_t)-1) { |
|
122 |
free(buf); |
|
123 |
buf = NULL; |
|
124 |
} else { |
|
125 |
if (size) { |
|
126 |
*size = (bufSize-outSize)/2; /* bytes to wchars */ |
|
127 |
} |
|
128 |
} |
|
129 |
done: |
|
130 |
setlocale(LC_ALL, old_locale); |
|
131 |
return buf; |
|
132 |
} |
|
133 |
||
29736
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
134 |
BOOL isSWTRunning() { |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
135 |
char envVar[80]; |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
136 |
// 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
|
137 |
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
|
138 |
return getenv(envVar) != NULL; |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
139 |
} |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
140 |
|
36907 | 141 |
jboolean SplashGetScaledImageName(const char* jar, const char* file, |
41776
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
142 |
float *scaleFactor, char *scaledFile, |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
143 |
const size_t scaledImageLength) { |
29736
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
144 |
*scaleFactor = 1; |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
145 |
|
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
146 |
if(isSWTRunning()){ |
36907 | 147 |
return JNI_FALSE; |
29736
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
148 |
} |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
149 |
|
25552
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
150 |
NSAutoreleasePool *pool = [NSAutoreleasePool new]; |
29736
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
151 |
__block float screenScaleFactor = 1; |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
152 |
|
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
153 |
[ThreadUtilities performOnMainThreadWaiting:YES block:^(){ |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
154 |
// initialize NSApplication and AWT stuff |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
155 |
[NSApplicationAWT sharedApplication]; |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
156 |
screenScaleFactor = [SplashNSScreen() backingScaleFactor]; |
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
157 |
}]; |
25769
f18107faec8f
8049198: [macosx] Incorrect thread access when showing splash screen
alexsch
parents:
25552
diff
changeset
|
158 |
|
25552
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
159 |
if (screenScaleFactor > 1) { |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
160 |
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
|
161 |
NSUInteger length = [fileName length]; |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
162 |
NSRange range = [fileName rangeOfString: @"." |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
163 |
options:NSBackwardsSearch]; |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
164 |
NSUInteger dotIndex = range.location; |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
165 |
NSString *fileName2x = nil; |
41776
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
166 |
|
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
167 |
fileName2x = findScaledImageName(fileName, dotIndex, @"@2x"); |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
168 |
if(![[NSFileManager defaultManager] |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
169 |
fileExistsAtPath: fileName2x]) { |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
170 |
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
|
171 |
} |
41776
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
172 |
if (jar || [[NSFileManager defaultManager] |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
173 |
fileExistsAtPath: fileName2x]){ |
36907 | 174 |
if (strlen([fileName2x UTF8String]) > scaledImageLength) { |
175 |
[pool drain]; |
|
176 |
return JNI_FALSE; |
|
177 |
} |
|
25552
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
178 |
*scaleFactor = 2; |
36907 | 179 |
strcpy(scaledFile, [fileName2x UTF8String]); |
180 |
[pool drain]; |
|
181 |
return JNI_TRUE; |
|
25552
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 |
} |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
184 |
[pool drain]; |
36907 | 185 |
return JNI_FALSE; |
25552
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
186 |
} |
12047 | 187 |
|
55189
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
188 |
static int isInAquaSession() { |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
189 |
// environment variable to bypass the aqua session check |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
190 |
char *ev = getenv("AWT_FORCE_HEADFUL"); |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
191 |
if (ev && (strncasecmp(ev, "true", 4) == 0)) { |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
192 |
// if "true" then tell the caller we're in |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
193 |
// an Aqua session without actually checking |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
194 |
return 1; |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
195 |
} |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
196 |
// Is the WindowServer available? |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
197 |
SecuritySessionId session_id; |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
198 |
SessionAttributeBits session_info; |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
199 |
OSStatus status = SessionGetInfo(callerSecuritySession, &session_id, &session_info); |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
200 |
if (status == noErr) { |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
201 |
if (session_info & sessionHasGraphicAccess) { |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
202 |
return 1; |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
203 |
} |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
204 |
} |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
205 |
return 0; |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
206 |
} |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
207 |
|
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
208 |
int |
12047 | 209 |
SplashInitPlatform(Splash * splash) { |
55189
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
210 |
if (!isInAquaSession()) { |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
211 |
return 0; |
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
212 |
} |
12047 | 213 |
pthread_mutex_init(&splash->lock, NULL); |
214 |
||
215 |
splash->maskRequired = 0; |
|
216 |
||
55708 | 217 |
|
12047 | 218 |
//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
|
219 |
// besides we don't use device-dependent drawing, so probably |
12047 | 220 |
// that's very fine indeed |
221 |
splash->byteAlignment = 1; |
|
222 |
initFormat(&splash->screenFormat, 0xff << 8, |
|
223 |
0xff << 16, 0xff << 24, 0xff << 0); |
|
224 |
splash->screenFormat.byteOrder = 1 ? BYTE_ORDER_LSBFIRST : BYTE_ORDER_MSBFIRST; |
|
225 |
splash->screenFormat.depthBytes = 4; |
|
226 |
||
29736
83a76fe84763
8075244: [macosx] The fix for JDK-8043869 should be reworked
alexsch
parents:
29726
diff
changeset
|
227 |
// 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
|
228 |
if (!isSWTRunning()) { |
24190
bbd2288a8a29
8039926: -spash:<image> can't be combined with -xStartOnFirstThread since JDK 7
pchelko
parents:
23328
diff
changeset
|
229 |
[JNFRunLoop performOnMainThreadWaiting:NO withBlock:^() { |
bbd2288a8a29
8039926: -spash:<image> can't be combined with -xStartOnFirstThread since JDK 7
pchelko
parents:
23328
diff
changeset
|
230 |
[NSApplicationAWT runAWTLoopWithApp:[NSApplicationAWT sharedApplication]]; |
bbd2288a8a29
8039926: -spash:<image> can't be combined with -xStartOnFirstThread since JDK 7
pchelko
parents:
23328
diff
changeset
|
231 |
}]; |
bbd2288a8a29
8039926: -spash:<image> can't be combined with -xStartOnFirstThread since JDK 7
pchelko
parents:
23328
diff
changeset
|
232 |
} |
55189
fdaf7287ea3a
8223271: SplashScreen is still shown if defaulting to headless on MacOS
prr
parents:
47216
diff
changeset
|
233 |
return 1; |
12047 | 234 |
} |
235 |
||
236 |
void |
|
237 |
SplashCleanupPlatform(Splash * splash) { |
|
238 |
splash->maskRequired = 0; |
|
239 |
} |
|
240 |
||
241 |
void |
|
242 |
SplashDonePlatform(Splash * splash) { |
|
243 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
244 |
||
245 |
pthread_mutex_destroy(&splash->lock); |
|
246 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
247 |
if (splash->window) { |
|
248 |
[splash->window orderOut:nil]; |
|
249 |
[splash->window release]; |
|
250 |
} |
|
251 |
}]; |
|
252 |
[pool drain]; |
|
253 |
} |
|
254 |
||
255 |
void |
|
256 |
SplashLock(Splash * splash) { |
|
257 |
pthread_mutex_lock(&splash->lock); |
|
258 |
} |
|
259 |
||
260 |
void |
|
261 |
SplashUnlock(Splash * splash) { |
|
262 |
pthread_mutex_unlock(&splash->lock); |
|
263 |
} |
|
264 |
||
265 |
void |
|
266 |
SplashInitFrameShape(Splash * splash, int imageIndex) { |
|
267 |
// No shapes, we rely on alpha compositing |
|
268 |
} |
|
269 |
||
270 |
void * SplashScreenThread(void *param); |
|
271 |
void |
|
272 |
SplashCreateThread(Splash * splash) { |
|
273 |
pthread_t thr; |
|
274 |
pthread_attr_t attr; |
|
275 |
int rc; |
|
276 |
||
277 |
pthread_attr_init(&attr); |
|
278 |
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash); |
|
279 |
} |
|
280 |
||
281 |
void |
|
282 |
SplashRedrawWindow(Splash * splash) { |
|
283 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
284 |
||
55708 | 285 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
286 |
// drop the reference to the old view and image |
|
287 |
[splash->window setContentView: nil]; |
|
288 |
SplashUpdateScreenData(splash); |
|
12047 | 289 |
|
290 |
// NSDeviceRGBColorSpace vs. NSCalibratedRGBColorSpace ? |
|
291 |
NSBitmapImageRep * rep = [[NSBitmapImageRep alloc] |
|
292 |
initWithBitmapDataPlanes: (unsigned char**)&splash->screenData |
|
293 |
pixelsWide: splash->width |
|
294 |
pixelsHigh: splash->height |
|
295 |
bitsPerSample: 8 |
|
296 |
samplesPerPixel: 4 |
|
297 |
hasAlpha: YES |
|
298 |
isPlanar: NO |
|
299 |
colorSpaceName: NSDeviceRGBColorSpace |
|
300 |
bitmapFormat: NSAlphaFirstBitmapFormat | NSAlphaNonpremultipliedBitmapFormat |
|
301 |
bytesPerRow: splash->width * 4 |
|
302 |
bitsPerPixel: 32]; |
|
303 |
||
304 |
NSImage * image = [[NSImage alloc] |
|
305 |
initWithSize: NSMakeSize(splash->width, splash->height)]; |
|
306 |
[image setBackgroundColor: [NSColor clearColor]]; |
|
307 |
||
308 |
[image addRepresentation: rep]; |
|
25552
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
309 |
float scaleFactor = splash->scaleFactor; |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
310 |
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
|
311 |
NSSize size = [image size]; |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
312 |
size.width /= scaleFactor; |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
313 |
size.height /= scaleFactor; |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
314 |
[image setSize: size]; |
96abb01815f6
8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents:
24190
diff
changeset
|
315 |
} |
55708 | 316 |
|
12047 | 317 |
NSImageView * view = [[NSImageView alloc] init]; |
318 |
||
319 |
[view setImage: image]; |
|
320 |
[view setEditable: NO]; |
|
321 |
//NOTE: we don't set a 'wait cursor' for the view because: |
|
322 |
// 1. The Cocoa GUI guidelines suggest to avoid it, and use a progress |
|
323 |
// bar instead. |
|
324 |
// 2. There simply isn't an instance of NSCursor that represent |
|
325 |
// the 'wait cursor'. So that is undoable. |
|
326 |
||
327 |
//TODO: only the first image in an animated gif preserves transparency. |
|
328 |
// Loos like the splash->screenData contains inappropriate data |
|
329 |
// for all but the first frame. |
|
330 |
||
331 |
[image release]; |
|
332 |
[rep release]; |
|
333 |
||
334 |
[splash->window setContentView: view]; |
|
335 |
[splash->window orderFrontRegardless]; |
|
336 |
}]; |
|
337 |
||
338 |
[pool drain]; |
|
339 |
} |
|
340 |
||
341 |
void SplashReconfigureNow(Splash * splash) { |
|
342 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
343 |
||
344 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
345 |
SplashCenter(splash); |
|
346 |
||
347 |
if (!splash->window) { |
|
348 |
return; |
|
349 |
} |
|
350 |
||
351 |
[splash->window orderOut:nil]; |
|
352 |
[splash->window setFrame: NSMakeRect(splash->x, splash->y, splash->width, splash->height) |
|
353 |
display: NO]; |
|
354 |
}]; |
|
355 |
||
356 |
[pool drain]; |
|
357 |
||
358 |
SplashRedrawWindow(splash); |
|
359 |
} |
|
360 |
||
361 |
void |
|
362 |
SplashEventLoop(Splash * splash) { |
|
363 |
||
364 |
/* we should have splash _locked_ on entry!!! */ |
|
365 |
||
366 |
while (1) { |
|
367 |
struct pollfd pfd[1]; |
|
368 |
int timeout = -1; |
|
369 |
int ctl = splash->controlpipe[0]; |
|
370 |
int rc; |
|
371 |
int pipes_empty; |
|
372 |
||
373 |
pfd[0].fd = ctl; |
|
374 |
pfd[0].events = POLLIN | POLLPRI; |
|
375 |
||
376 |
errno = 0; |
|
377 |
if (splash->isVisible>0 && SplashIsStillLooping(splash)) { |
|
378 |
timeout = splash->time + splash->frames[splash->currentFrame].delay |
|
379 |
- SplashTime(); |
|
380 |
if (timeout < 0) { |
|
381 |
timeout = 0; |
|
382 |
} |
|
383 |
} |
|
384 |
SplashUnlock(splash); |
|
385 |
rc = poll(pfd, 1, timeout); |
|
386 |
SplashLock(splash); |
|
22312 | 387 |
if (splash->isVisible > 0 && splash->currentFrame >= 0 && |
388 |
SplashTime() >= splash->time + splash->frames[splash->currentFrame].delay) { |
|
12047 | 389 |
SplashNextFrame(splash); |
390 |
SplashRedrawWindow(splash); |
|
391 |
} |
|
392 |
if (rc <= 0) { |
|
393 |
errno = 0; |
|
394 |
continue; |
|
395 |
} |
|
396 |
pipes_empty = 0; |
|
397 |
while(!pipes_empty) { |
|
398 |
char buf; |
|
399 |
||
400 |
pipes_empty = 1; |
|
401 |
if (read(ctl, &buf, sizeof(buf)) > 0) { |
|
402 |
pipes_empty = 0; |
|
403 |
switch (buf) { |
|
404 |
case SPLASHCTL_UPDATE: |
|
405 |
if (splash->isVisible>0) { |
|
406 |
SplashRedrawWindow(splash); |
|
407 |
} |
|
408 |
break; |
|
409 |
case SPLASHCTL_RECONFIGURE: |
|
410 |
if (splash->isVisible>0) { |
|
411 |
SplashReconfigureNow(splash); |
|
412 |
} |
|
413 |
break; |
|
414 |
case SPLASHCTL_QUIT: |
|
415 |
return; |
|
416 |
} |
|
417 |
} |
|
418 |
} |
|
419 |
} |
|
420 |
} |
|
421 |
||
422 |
void * |
|
423 |
SplashScreenThread(void *param) { |
|
424 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|
425 |
Splash *splash = (Splash *) param; |
|
426 |
||
427 |
SplashLock(splash); |
|
428 |
pipe(splash->controlpipe); |
|
429 |
fcntl(splash->controlpipe[0], F_SETFL, |
|
430 |
fcntl(splash->controlpipe[0], F_GETFL, 0) | O_NONBLOCK); |
|
431 |
splash->time = SplashTime(); |
|
432 |
splash->currentFrame = 0; |
|
433 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
434 |
SplashCenter(splash); |
|
435 |
||
436 |
splash->window = (void*) [[NSWindow alloc] |
|
437 |
initWithContentRect: NSMakeRect(splash->x, splash->y, splash->width, splash->height) |
|
438 |
styleMask: NSBorderlessWindowMask |
|
439 |
backing: NSBackingStoreBuffered |
|
440 |
defer: NO |
|
441 |
screen: SplashNSScreen()]; |
|
442 |
||
443 |
[splash->window setOpaque: NO]; |
|
444 |
[splash->window setBackgroundColor: [NSColor clearColor]]; |
|
445 |
}]; |
|
446 |
fflush(stdout); |
|
447 |
if (splash->window) { |
|
448 |
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){ |
|
449 |
[splash->window orderFrontRegardless]; |
|
450 |
}]; |
|
451 |
SplashRedrawWindow(splash); |
|
452 |
SplashEventLoop(splash); |
|
453 |
} |
|
454 |
SplashUnlock(splash); |
|
455 |
SplashDone(splash); |
|
456 |
||
457 |
splash->isVisible=-1; |
|
458 |
||
459 |
[pool drain]; |
|
460 |
||
461 |
return 0; |
|
462 |
} |
|
463 |
||
464 |
void |
|
465 |
sendctl(Splash * splash, char code) { |
|
466 |
if (splash && splash->controlpipe[1]) { |
|
467 |
write(splash->controlpipe[1], &code, 1); |
|
468 |
} |
|
469 |
} |
|
470 |
||
471 |
void |
|
472 |
SplashClosePlatform(Splash * splash) { |
|
473 |
sendctl(splash, SPLASHCTL_QUIT); |
|
474 |
} |
|
475 |
||
476 |
void |
|
477 |
SplashUpdate(Splash * splash) { |
|
478 |
sendctl(splash, SPLASHCTL_UPDATE); |
|
479 |
} |
|
480 |
||
481 |
void |
|
482 |
SplashReconfigure(Splash * splash) { |
|
483 |
sendctl(splash, SPLASHCTL_RECONFIGURE); |
|
484 |
} |
|
485 |
||
41776
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
486 |
NSString* findScaledImageName(NSString *fileName, NSUInteger dotIndex, NSString *strToAppend) { |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
487 |
NSString *fileName2x = nil; |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
488 |
if (dotIndex == NSNotFound) { |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
489 |
fileName2x = [fileName stringByAppendingString: strToAppend]; |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
490 |
} else { |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
491 |
fileName2x = [fileName substringToIndex: dotIndex]; |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
492 |
fileName2x = [fileName2x stringByAppendingString: strToAppend]; |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
493 |
fileName2x = [fileName2x stringByAppendingString: |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
494 |
[fileName substringFromIndex: dotIndex]]; |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
495 |
} |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
496 |
return fileName2x; |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
497 |
} |
71e2575dd727
8151787: Unify the HiDPI splash screen image naming convention
rchamyal
parents:
36907
diff
changeset
|
498 |