1 | /* |
2 | * Copyright (c) 2005, 2019, 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 |
23 | * questions. |
24 | */ |
25 | |
26 | #ifndef SPLASHSCREEN_IMPL_H |
27 | #define SPLASHSCREEN_IMPL_H |
28 | |
29 | #include "splashscreen_config.h" |
30 | #include "splashscreen_gfx.h" |
31 | #include "jni.h" |
32 | |
33 | JNIEXPORT int |
34 | SplashLoadMemory(void *pdata, int size); /* requires preloading the file */ |
35 | |
36 | JNIEXPORT int |
37 | SplashLoadFile(const char *filename); // FIXME: range checking for SplashLoadMemory |
38 | |
39 | JNIEXPORT int |
40 | SplashInit(void); |
41 | |
42 | JNIEXPORT void |
43 | SplashClose(void); |
44 | |
45 | JNIEXPORT void |
46 | SplashSetScaleFactor(float); |
47 | |
48 | JNIEXPORT jboolean |
49 | SplashGetScaledImageName(const char*, const char*, |
50 | float*, char*, const size_t scaledImageNameLength); |
51 | |
52 | JNIEXPORT void |
53 | SplashSetFileJarName(const char* fileName, const char* jarName); |
54 | |
55 | JNIEXPORT int |
56 | SplashGetScaledImgNameMaxPstfixLen(const char*); |
57 | typedef struct SplashImage |
58 | { |
59 | rgbquad_t *bitmapBits; |
60 | int delay; /* before next image display, in msec */ |
61 | #if defined(WITH_WIN32) |
62 | HRGN hRgn; |
63 | #elif defined(WITH_X11) |
64 | XRectangle *rects; |
65 | int numRects; |
66 | #endif |
67 | } SplashImage; |
68 | |
69 | #define SPLASH_COLOR_MAP_SIZE 0x100 |
70 | |
71 | typedef struct Splash |
72 | { |
73 | ImageFormat screenFormat; /* must be preset before image decoding */ |
74 | DitherSettings dithers[3]; |
75 | ImageFormat imageFormat; |
76 | rgbquad_t colorMap[SPLASH_COLOR_MAP_SIZE]; |
77 | int byteAlignment; /* must be preset before image decoding */ |
78 | int maskRequired; /* must be preset before image decoding */ |
79 | int width; /* in pixels */ |
80 | int height; /* in pixels */ |
81 | int frameCount; |
82 | SplashImage *frames; /* dynamically allocated array of frame descriptors */ |
83 | unsigned time; /* in msec, origin is not important */ |
84 | rgbquad_t *overlayData; /* overlay image data, always rgbquads */ |
85 | ImageRect overlayRect; |
86 | ImageFormat overlayFormat; |
87 | void *screenData; |
88 | int screenStride; /* stored scanline length in bytes */ |
89 | int currentFrame; // currentFrame==-1 means image is not loaded |
90 | int loopCount; |
91 | int x, y; |
92 | rgbquad_t colorIndex[SPLASH_COLOR_MAP_SIZE]; |
93 | int isVisible; |
94 | char* fileName; /* stored in 16-bit unicode (jchars) */ |
95 | int fileNameLen; |
96 | char* jarName; /* stored in 16-bit unicode (jchars) */ |
97 | int jarNameLen; |
98 | float scaleFactor; |
99 | #if defined(WITH_WIN32) |
100 | BOOL isLayered; |
101 | HWND hWnd; |
102 | HPALETTE hPalette; |
103 | CRITICAL_SECTION lock; |
104 | #elif defined(WITH_X11) |
105 | int controlpipe[2]; |
106 | Display *display; |
107 | Window window; |
108 | Screen *screen; |
109 | Visual *visual; |
110 | Colormap cmap; |
111 | pthread_mutex_t lock; |
112 | Cursor cursor; |
113 | XWMHints* wmHints; |
114 | #elif defined(WITH_MACOSX) |
115 | pthread_mutex_t lock; |
116 | int controlpipe[2]; |
117 | NSWindow * window; |
118 | #endif |
119 | } Splash; |
120 | |
121 | /* various shared and/or platform dependent splash screen functions */ |
122 | |
123 | /*************** Platform-specific ******************/ |
124 | |
125 | /* To be implemented in the platform-specific native code. */ |
126 | |
127 | |
128 | int SplashInitPlatform(Splash * splash); |
129 | void SplashCreateThread(Splash * splash); |
130 | void SplashCleanupPlatform(Splash * splash); |
131 | void SplashDonePlatform(Splash * splash); |
132 | |
133 | unsigned SplashTime(); |
134 | char* SplashConvertStringAlloc(const char* in, int *size); |
135 | void SplashLock(Splash * splash); |
136 | void SplashUnlock(Splash * splash); |
137 | |
138 | void SplashInitFrameShape(Splash * splash, int imageIndex); |
139 | |
140 | void SplashUpdate(Splash * splash); |
141 | void SplashReconfigure(Splash * splash); |
142 | void SplashClosePlatform(Splash * splash); |
143 | |
144 | |
145 | |
146 | /********************* Shared **********************/ |
147 | Splash *SplashGetInstance(); |
148 | |
149 | int SplashIsStillLooping(Splash * splash); |
150 | void SplashNextFrame(Splash * splash); |
151 | void SplashStart(Splash * splash); |
152 | void SplashDone(Splash * splash); |
153 | |
154 | void SplashUpdateScreenData(Splash * splash); |
155 | |
156 | void SplashCleanup(Splash * splash); |
157 | |
158 | void cleanUp(char *fName, char *xName, char *pctName, float *scaleFactor); |
159 | jboolean GetScaledImageName(const char *fileName, char *scaledImgName, |
160 | float *scaleFactor, const size_t scaledImageLength); |
161 | typedef struct SplashStream { |
162 | int (*read)(void* pStream, void* pData, int nBytes); |
163 | int (*peek)(void* pStream); |
164 | void (*close)(void* pStream); |
165 | union { |
166 | struct { |
167 | FILE* f; |
168 | } stdio; |
169 | struct { |
170 | unsigned char* pData; |
171 | unsigned char* pDataEnd; |
172 | } mem; |
173 | } arg; |
174 | } SplashStream; |
175 | |
176 | int SplashStreamInitFile(SplashStream * stream, const char* filename); |
177 | int SplashStreamInitMemory(SplashStream * stream, void * pData, int size); |
178 | |
179 | /* image decoding */ |
180 | int SplashDecodeGifStream(Splash * splash, SplashStream * stream); |
181 | int SplashDecodeJpegStream(Splash * splash, SplashStream * stream); |
182 | int SplashDecodePngStream(Splash * splash, SplashStream * stream); |
183 | |
184 | /* utility functions */ |
185 | |
186 | int BitmapToYXBandedRectangles(ImageRect * pSrcRect, RECT_T * out); |
187 | |
188 | #define SAFE_TO_ALLOC(c, sz) \ |
189 | (((c) > 0) && ((sz) > 0) && \ |
190 | ((0xffffffffu / ((unsigned int)(c))) > (unsigned int)(sz))) |
191 | |
192 | #define dbgprintf printf |
193 | |
194 | #endif |
195 | |