1 /*
2 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
29 #ifdef _MSC_VER
30 # ifndef snprintf
31 # define snprintf _snprintf
32 # endif
33 #endif
34 int splashIsVisible = 0;
35
36 Splash *
37 SplashGetInstance()
38 {
39 static Splash splash;
40 static int preInitialized = 0;
41 if (!preInitialized) {
42 memset(&splash, 0, sizeof(Splash));
43 splash.currentFrame = -1;
44 preInitialized = 1;
45 }
46 return &splash;
47 }
48
49 SPLASHEXPORT void
50 SplashSetFileJarName(const char* fileName, const char* jarName) {
51 Splash *splash = SplashGetInstance();
52
53 free(splash->fileName);
54 splash->fileName = SplashConvertStringAlloc(fileName, &splash->fileNameLen);
55
56 free(splash->jarName);
57 splash->jarName = SplashConvertStringAlloc(jarName, &splash->jarNameLen);
58 }
59
60 SPLASHEXPORT void
61 SplashInit()
62 {
63 Splash *splash = SplashGetInstance();
64
65 memset(splash, 0, sizeof(Splash));
66 splash->currentFrame = -1;
67 splash->scaleFactor = 1;
68 initFormat(&splash->imageFormat, QUAD_RED_MASK, QUAD_GREEN_MASK,
69 QUAD_BLUE_MASK, QUAD_ALPHA_MASK);
70 SplashInitPlatform(splash);
71 }
72
73 SPLASHEXPORT void
74 SplashClose()
75 {
76 Splash *splash = SplashGetInstance();
77
78 if (splash->isVisible > 0) {
79 SplashLock(splash);
80 splash->isVisible = -1;
81 SplashClosePlatform(splash);
82 SplashUnlock(splash);
83 }
84 }
85
86 void
87 SplashCleanup(Splash * splash)
88 {
89 int i;
90
91 splash->currentFrame = -1;
92 SplashCleanupPlatform(splash);
93 if (splash->frames) {
94 for (i = 0; i < splash->frameCount; i++) {
95 if (splash->frames[i].bitmapBits) {
96 free(splash->frames[i].bitmapBits);
97 splash->frames[i].bitmapBits = NULL;
98 }
99 }
100 free(splash->frames);
101 splash->frames = NULL;
102 }
103 if (splash->overlayData) {
104 free(splash->overlayData);
105 splash->overlayData = NULL;
106 }
107 SplashSetFileJarName(NULL, NULL);
108 }
109
110 SPLASHEXPORT void
111 SplashSetScaleFactor(float scaleFactor)
112 {
113 Splash *splash = SplashGetInstance();
114 splash->scaleFactor = scaleFactor;
115 }
116
117 void
118 SplashDone(Splash * splash)
119 {
120 SplashCleanup(splash);
121 SplashDonePlatform(splash);
122 }
123
124 int
125 SplashIsStillLooping(Splash * splash)
126 {
127 if (splash->currentFrame < 0) {
128 return 0;
129 }
130 return splash->loopCount != 1 ||
285 SplashCleanup(splash);
286 }
287 SplashUnlock(splash); // SplashClose locks
288 if (splash->isVisible == 0) {
289 SplashClose();
290 }
291 }
292 else {
293 splash->currentFrame = 0;
294 if (splash->isVisible == 0) {
295 SplashStart(splash);
296 } else {
297 SplashReconfigure(splash);
298 splash->time = SplashTime();
299 }
300 SplashUnlock(splash);
301 }
302 return success;
303 }
304
305 SPLASHEXPORT int
306 SplashLoadFile(const char *filename)
307 {
308 SplashStream stream;
309 return SplashStreamInitFile(&stream, filename) &&
310 SplashLoadStream(&stream);
311 }
312
313 SPLASHEXPORT int
314 SplashLoadMemory(void *data, int size)
315 {
316 SplashStream stream;
317 return SplashStreamInitMemory(&stream, data, size) &&
318 SplashLoadStream(&stream);
319 }
320
321 /* SplashStart MUST be called from under the lock */
322
323 void
324 SplashStart(Splash * splash)
325 {
326 if (splash->isVisible == 0) {
327 SplashCreateThread(splash);
328 splash->isVisible = 1;
329 }
330 }
331
332 /* SplashStream functions */
333
378 static void closeMem(void* pStream) {
379 }
380
381 int SplashStreamInitFile(SplashStream * pStream, const char* filename) {
382 pStream->arg.stdio.f = fopen(filename, "rb");
383 pStream->read = readFile;
384 pStream->peek = peekFile;
385 pStream->close = closeFile;
386 return pStream->arg.stdio.f != 0;
387 }
388
389 int SplashStreamInitMemory(SplashStream * pStream, void* pData, int size) {
390 pStream->arg.mem.pData = (unsigned char*)pData;
391 pStream->arg.mem.pDataEnd = (unsigned char*)pData + size;
392 pStream->read = readMem;
393 pStream->peek = peekMem;
394 pStream->close = closeMem;
395 return 1;
396 }
397
398 SPLASHEXPORT int
399 SplashGetScaledImgNameMaxPstfixLen(const char *fileName){
400 return strlen(fileName) + strlen("@100pct") + 1;
401 }
402
403 jboolean GetScaledImageName(const char *fileName, char *scaleImageName,
404 float *scaleFactor, const size_t scaledImageLength) {
405 if (*scaleFactor > 1.0) {
406 FILE *fp = NULL;
407 char scaledImgPct[BUFF_SIZE];
408 char scaledImgX[BUFF_SIZE];
409 char *scaledImageXName = NULL;
410 char *scaledImagePctName = malloc(scaledImageLength);
411 char *dupFileName = strdup(fileName);
412 char *fileExtension = strrchr(dupFileName, '.');
413 size_t lengthPct = 0;
414 size_t lengthX = 0;
415 int retValPct = 0;
416 int retValX = 0;
417 jboolean isPctScaledImage = (*scaleFactor * 100) != ((int) (*scaleFactor)) *100;
418 snprintf(scaledImgPct, BUFF_SIZE, "%s%d%s", "@",
|
1 /*
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
29 #ifdef _MSC_VER
30 # ifndef snprintf
31 # define snprintf _snprintf
32 # endif
33 #endif
34 int splashIsVisible = 0;
35
36 Splash *
37 SplashGetInstance()
38 {
39 static Splash splash;
40 static int preInitialized = 0;
41 if (!preInitialized) {
42 memset(&splash, 0, sizeof(Splash));
43 splash.currentFrame = -1;
44 preInitialized = 1;
45 }
46 return &splash;
47 }
48
49 JNIEXPORT void JNICALL
50 SplashSetFileJarName(const char* fileName, const char* jarName) {
51 Splash *splash = SplashGetInstance();
52
53 free(splash->fileName);
54 splash->fileName = SplashConvertStringAlloc(fileName, &splash->fileNameLen);
55
56 free(splash->jarName);
57 splash->jarName = SplashConvertStringAlloc(jarName, &splash->jarNameLen);
58 }
59
60 JNIEXPORT void JNICALL
61 SplashInit()
62 {
63 Splash *splash = SplashGetInstance();
64
65 memset(splash, 0, sizeof(Splash));
66 splash->currentFrame = -1;
67 splash->scaleFactor = 1;
68 initFormat(&splash->imageFormat, QUAD_RED_MASK, QUAD_GREEN_MASK,
69 QUAD_BLUE_MASK, QUAD_ALPHA_MASK);
70 SplashInitPlatform(splash);
71 }
72
73 JNIEXPORT void JNICALL
74 SplashClose()
75 {
76 Splash *splash = SplashGetInstance();
77
78 if (splash->isVisible > 0) {
79 SplashLock(splash);
80 splash->isVisible = -1;
81 SplashClosePlatform(splash);
82 SplashUnlock(splash);
83 }
84 }
85
86 void
87 SplashCleanup(Splash * splash)
88 {
89 int i;
90
91 splash->currentFrame = -1;
92 SplashCleanupPlatform(splash);
93 if (splash->frames) {
94 for (i = 0; i < splash->frameCount; i++) {
95 if (splash->frames[i].bitmapBits) {
96 free(splash->frames[i].bitmapBits);
97 splash->frames[i].bitmapBits = NULL;
98 }
99 }
100 free(splash->frames);
101 splash->frames = NULL;
102 }
103 if (splash->overlayData) {
104 free(splash->overlayData);
105 splash->overlayData = NULL;
106 }
107 SplashSetFileJarName(NULL, NULL);
108 }
109
110 JNIEXPORT void JNICALL
111 SplashSetScaleFactor(float scaleFactor)
112 {
113 Splash *splash = SplashGetInstance();
114 splash->scaleFactor = scaleFactor;
115 }
116
117 void
118 SplashDone(Splash * splash)
119 {
120 SplashCleanup(splash);
121 SplashDonePlatform(splash);
122 }
123
124 int
125 SplashIsStillLooping(Splash * splash)
126 {
127 if (splash->currentFrame < 0) {
128 return 0;
129 }
130 return splash->loopCount != 1 ||
285 SplashCleanup(splash);
286 }
287 SplashUnlock(splash); // SplashClose locks
288 if (splash->isVisible == 0) {
289 SplashClose();
290 }
291 }
292 else {
293 splash->currentFrame = 0;
294 if (splash->isVisible == 0) {
295 SplashStart(splash);
296 } else {
297 SplashReconfigure(splash);
298 splash->time = SplashTime();
299 }
300 SplashUnlock(splash);
301 }
302 return success;
303 }
304
305 JNIEXPORT int JNICALL
306 SplashLoadFile(const char *filename)
307 {
308 SplashStream stream;
309 return SplashStreamInitFile(&stream, filename) &&
310 SplashLoadStream(&stream);
311 }
312
313 JNIEXPORT int JNICALL
314 SplashLoadMemory(void *data, int size)
315 {
316 SplashStream stream;
317 return SplashStreamInitMemory(&stream, data, size) &&
318 SplashLoadStream(&stream);
319 }
320
321 /* SplashStart MUST be called from under the lock */
322
323 void
324 SplashStart(Splash * splash)
325 {
326 if (splash->isVisible == 0) {
327 SplashCreateThread(splash);
328 splash->isVisible = 1;
329 }
330 }
331
332 /* SplashStream functions */
333
378 static void closeMem(void* pStream) {
379 }
380
381 int SplashStreamInitFile(SplashStream * pStream, const char* filename) {
382 pStream->arg.stdio.f = fopen(filename, "rb");
383 pStream->read = readFile;
384 pStream->peek = peekFile;
385 pStream->close = closeFile;
386 return pStream->arg.stdio.f != 0;
387 }
388
389 int SplashStreamInitMemory(SplashStream * pStream, void* pData, int size) {
390 pStream->arg.mem.pData = (unsigned char*)pData;
391 pStream->arg.mem.pDataEnd = (unsigned char*)pData + size;
392 pStream->read = readMem;
393 pStream->peek = peekMem;
394 pStream->close = closeMem;
395 return 1;
396 }
397
398 JNIEXPORT int JNICALL
399 SplashGetScaledImgNameMaxPstfixLen(const char *fileName){
400 return strlen(fileName) + strlen("@100pct") + 1;
401 }
402
403 jboolean GetScaledImageName(const char *fileName, char *scaleImageName,
404 float *scaleFactor, const size_t scaledImageLength) {
405 if (*scaleFactor > 1.0) {
406 FILE *fp = NULL;
407 char scaledImgPct[BUFF_SIZE];
408 char scaledImgX[BUFF_SIZE];
409 char *scaledImageXName = NULL;
410 char *scaledImagePctName = malloc(scaledImageLength);
411 char *dupFileName = strdup(fileName);
412 char *fileExtension = strrchr(dupFileName, '.');
413 size_t lengthPct = 0;
414 size_t lengthX = 0;
415 int retValPct = 0;
416 int retValX = 0;
417 jboolean isPctScaledImage = (*scaleFactor * 100) != ((int) (*scaleFactor)) *100;
418 snprintf(scaledImgPct, BUFF_SIZE, "%s%d%s", "@",
|