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 
  33 SPLASHEXPORT int SplashLoadMemory(void *pdata, int size); /* requires preloading the file */
  34 SPLASHEXPORT int SplashLoadFile(const char *filename);  // FIXME: range checking for SplashLoadMemory
  35 
  36 SPLASHEXPORT void SplashInit(void);
  37 SPLASHEXPORT void SplashClose(void);
  38 
  39 SPLASHEXPORT void SplashSetScaleFactor(float);
  40 SPLASHEXPORT jboolean SplashGetScaledImageName(const char*, const char*,
  41                               float*, char*, const size_t scaledImageNameLength);
  42 
  43 SPLASHEXPORT void
  44 SplashSetFileJarName(const char* fileName, const char* jarName);
  45 
  46 SPLASHEXPORT int
  47 SplashGetScaledImgNameMaxPstfixLen(const char*);
  48 typedef 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 
  62 typedef 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 
 119 void SplashInitPlatform(Splash * splash);
 120 void SplashCreateThread(Splash * splash);
 121 void SplashCleanupPlatform(Splash * splash);
 122 void SplashDonePlatform(Splash * splash);
 123 
 124 unsigned SplashTime();
 125 char* SplashConvertStringAlloc(const char* in, int *size);
 126 jboolean SplashGetScaledImageName(const char* jarName,
 127                  const char* fileName, float *scaleFactor,
 128                  char *scaleImageName, const size_t scaledImageNameLength);
 129 void SplashLock(Splash * splash);
 130 void SplashUnlock(Splash * splash);
 131 
 132 void SplashInitFrameShape(Splash * splash, int imageIndex);
 133 
 134 void SplashUpdate(Splash * splash);
 135 void SplashReconfigure(Splash * splash);
 136 void SplashClosePlatform(Splash * splash);
 137 
 138 
 139 
 140 /********************* Shared **********************/
 141 Splash *SplashGetInstance();
 142 
 143 int SplashIsStillLooping(Splash * splash);
 144 void SplashNextFrame(Splash * splash);
 145 void SplashStart(Splash * splash);
 146 void SplashDone(Splash * splash);
 147 
 148 void SplashUpdateScreenData(Splash * splash);
 149 
 150 void SplashCleanup(Splash * splash);
 151 void SplashSetScaleFactor(float scaleFactor);
 152 int  SplashGetScaledImgNameMaxPstfixLen(const char *fileName);
 153 void cleanUp(char *fName, char *xName, char *pctName, float *scaleFactor);
 154 jboolean GetScaledImageName(const char *fileName, char *scaledImgName,
 155                   float *scaleFactor, const size_t scaledImageLength);
 156 typedef 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 
 171 int SplashStreamInitFile(SplashStream * stream, const char* filename);
 172 int SplashStreamInitMemory(SplashStream * stream, void * pData, int size);
 173 
 174 /* image decoding */
 175 int SplashDecodeGifStream(Splash * splash, SplashStream * stream);
 176 int SplashDecodeJpegStream(Splash * splash, SplashStream * stream);
 177 int SplashDecodePngStream(Splash * splash, SplashStream * stream);
 178 
 179 /* utility functions */
 180 
 181 int 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
--- EOF ---