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