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