< prev index next >

src/java.desktop/share/native/libsplashscreen/splashscreen_impl.c

Print this page




  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
  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
  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
  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 


 246 {
 247     int sign;
 248     int (*decodeStream) (Splash * splash, SplashStream * stream);
 249 } FILEFORMAT;
 250 
 251 static const FILEFORMAT formats[] = {
 252     {0x47, SplashDecodeGifStream},
 253     {0x89, SplashDecodePngStream},
 254     {0xFF, SplashDecodeJpegStream}
 255 };
 256 
 257 static int
 258 SplashLoadStream(SplashStream * stream)
 259 {
 260     int success = 0;
 261     int c;
 262     size_t i;
 263 
 264     Splash *splash = SplashGetInstance();
 265     if (splash->isVisible < 0) {

 266         return 0;
 267     }
 268 
 269     SplashLock(splash);
 270 
 271     /* the formats we support can be easily distinguished by the first byte */
 272     c = stream->peek(stream);
 273     if (c != -1) {
 274         for (i = 0; i < sizeof(formats) / sizeof(FILEFORMAT); i++) {
 275             if (c == formats[i].sign) {
 276                 success = formats[i].decodeStream(splash, stream);
 277                 break;
 278             }
 279         }
 280     }
 281     stream->close(stream);
 282 
 283     if (!success) {             // failed to decode
 284         if (splash->isVisible == 0) {
 285             SplashCleanup(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
  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 int
  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     return SplashInitPlatform(splash);
  71 }
  72 
  73 JNIEXPORT 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 


 246 {
 247     int sign;
 248     int (*decodeStream) (Splash * splash, SplashStream * stream);
 249 } FILEFORMAT;
 250 
 251 static const FILEFORMAT formats[] = {
 252     {0x47, SplashDecodeGifStream},
 253     {0x89, SplashDecodePngStream},
 254     {0xFF, SplashDecodeJpegStream}
 255 };
 256 
 257 static int
 258 SplashLoadStream(SplashStream * stream)
 259 {
 260     int success = 0;
 261     int c;
 262     size_t i;
 263 
 264     Splash *splash = SplashGetInstance();
 265     if (splash->isVisible < 0) {
 266         stream->close(stream);
 267         return 0;
 268     }
 269 
 270     SplashLock(splash);
 271 
 272     /* the formats we support can be easily distinguished by the first byte */
 273     c = stream->peek(stream);
 274     if (c != -1) {
 275         for (i = 0; i < sizeof(formats) / sizeof(FILEFORMAT); i++) {
 276             if (c == formats[i].sign) {
 277                 success = formats[i].decodeStream(splash, stream);
 278                 break;
 279             }
 280         }
 281     }
 282     stream->close(stream);
 283 
 284     if (!success) {             // failed to decode
 285         if (splash->isVisible == 0) {
 286             SplashCleanup(splash);


< prev index next >