jdk/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.c
author rchamyal
Thu, 24 Mar 2016 14:06:32 +0530
changeset 36907 c3d8383e3efb
parent 25859 3317bb8137f4
child 41776 71e2575dd727
permissions -rw-r--r--
8145173: HiDPI splash screen support on Windows Reviewed-by: serb, alexsch, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "splashscreen_impl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "splashscreen_gfx_impl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
int splashIsVisible = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
Splash *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
SplashGetInstance()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    static Splash splash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    static int preInitialized = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    if (!preInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        memset(&splash, 0, sizeof(Splash));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        splash.currentFrame = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        preInitialized = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    return &splash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
SPLASHEXPORT void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
SplashSetFileJarName(const char* fileName, const char* jarName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    Splash *splash = SplashGetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    free(splash->fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    splash->fileName = SplashConvertStringAlloc(fileName, &splash->fileNameLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    free(splash->jarName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    splash->jarName = SplashConvertStringAlloc(jarName, &splash->jarNameLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
SPLASHEXPORT void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
SplashInit()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    Splash *splash = SplashGetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    memset(splash, 0, sizeof(Splash));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    splash->currentFrame = -1;
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
    62
    splash->scaleFactor = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    initFormat(&splash->imageFormat, QUAD_RED_MASK, QUAD_GREEN_MASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        QUAD_BLUE_MASK, QUAD_ALPHA_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    SplashInitPlatform(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
SPLASHEXPORT void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
SplashClose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    Splash *splash = SplashGetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    if (splash->isVisible > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        splash->isVisible = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        SplashClosePlatform(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        SplashUnlock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
SplashCleanup(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    splash->currentFrame = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    SplashCleanupPlatform(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    if (splash->frames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        for (i = 0; i < splash->frameCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (splash->frames[i].bitmapBits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                free(splash->frames[i].bitmapBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                splash->frames[i].bitmapBits = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        free(splash->frames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        splash->frames = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if (splash->overlayData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        free(splash->overlayData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        splash->overlayData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    SplashSetFileJarName(NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   105
SPLASHEXPORT void
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   106
SplashSetScaleFactor(float scaleFactor)
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   107
{
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   108
    Splash *splash = SplashGetInstance();
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   109
    splash->scaleFactor = scaleFactor;
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   110
}
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 22312
diff changeset
   111
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
SplashDone(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    SplashCleanup(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    SplashDonePlatform(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
SplashIsStillLooping(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
{
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   122
    if (splash->currentFrame < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return 0;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   124
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    return splash->loopCount != 1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        splash->currentFrame + 1 < splash->frameCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
SplashUpdateScreenData(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    ImageRect srcRect, dstRect;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   133
    if (splash->currentFrame < 0) {
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   134
        return;
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   135
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    initRect(&srcRect, 0, 0, splash->width, splash->height, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        splash->width * sizeof(rgbquad_t),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        splash->frames[splash->currentFrame].bitmapBits, &splash->imageFormat);
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   140
    if (splash->screenData) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        free(splash->screenData);
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   142
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    splash->screenStride = splash->width * splash->screenFormat.depthBytes;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   144
    if (splash->byteAlignment > 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        splash->screenStride =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            (splash->screenStride + splash->byteAlignment - 1) &
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            ~(splash->byteAlignment - 1);
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   148
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    splash->screenData = malloc(splash->height * splash->screenStride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    initRect(&dstRect, 0, 0, splash->width, splash->height, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        splash->screenStride, splash->screenData, &splash->screenFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    if (splash->overlayData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        convertRect2(&srcRect, &dstRect, CVT_BLEND, &splash->overlayRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        convertRect(&srcRect, &dstRect, CVT_COPY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
SplashNextFrame(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   163
    if (splash->currentFrame < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   165
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    do {
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   167
        if (!SplashIsStillLooping(splash)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            return;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   169
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        splash->time += splash->frames[splash->currentFrame].delay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (++splash->currentFrame >= splash->frameCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            splash->currentFrame = 0;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   173
            if (splash->loopCount > 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                splash->loopCount--;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   175
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    } while (splash->time + splash->frames[splash->currentFrame].delay -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        SplashTime() <= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
BitmapToYXBandedRectangles(ImageRect * pSrcRect, RECT_T * out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    RECT_T *pPrevLine = NULL, *pFirst = out, *pThis = pFirst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    int i, j, i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    int length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    for (j = 0; j < pSrcRect->numLines; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        /* generate data for a scanline */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        byte_t *pSrc = (byte_t *) pSrcRect->pBits + j * pSrcRect->stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        RECT_T *pLine = pThis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            while (i < pSrcRect->numSamples &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                   getRGBA(pSrc, pSrcRect->format) < ALPHA_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                pSrc += pSrcRect->depthBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                ++i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   203
            if (i >= pSrcRect->numSamples) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                break;
22312
dd65107de257 8023057: Enhance start up image display
vadim
parents: 5506
diff changeset
   205
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            i0 = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            while (i < pSrcRect->numSamples &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                   getRGBA(pSrc, pSrcRect->format) >= ALPHA_THRESHOLD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                pSrc += pSrcRect->depthBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                ++i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            RECT_SET(*pThis, i0, j, i - i0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            ++pThis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        } while (i < pSrcRect->numSamples);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        /*  check if the previous scanline is exactly the same, merge if so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
           (this is the only optimization we can use for YXBanded rectangles, and win32 supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
           YXBanded only */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        length = pThis - pLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (pPrevLine && pLine - pPrevLine == length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            for (i = 0; i < length && RECT_EQ_X(pPrevLine[i], pLine[i]); ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (i == pLine - pPrevLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                // do merge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                for (i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    RECT_INC_HEIGHT(pPrevLine[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                pThis = pLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        /* or else use the generated scanline */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        pPrevLine = pLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    return pThis - pFirst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
typedef struct FILEFORMAT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    int sign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    int (*decodeStream) (Splash * splash, SplashStream * stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
} FILEFORMAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
static const FILEFORMAT formats[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    {0x47, SplashDecodeGifStream},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    {0x89, SplashDecodePngStream},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    {0xFF, SplashDecodeJpegStream}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
SplashLoadStream(SplashStream * stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    int success = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    int c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    size_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    Splash *splash = SplashGetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    if (splash->isVisible < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /* the formats we support can be easily distinguished by the first byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    c = stream->peek(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    if (c != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        for (i = 0; i < sizeof(formats) / sizeof(FILEFORMAT); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (c == formats[i].sign) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                success = formats[i].decodeStream(splash, stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    stream->close(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    if (!success) {             // failed to decode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        if (splash->isVisible == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            SplashCleanup(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        SplashUnlock(splash);   // SplashClose locks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (splash->isVisible == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            SplashClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        splash->currentFrame = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (splash->isVisible == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            SplashStart(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            SplashReconfigure(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            splash->time = SplashTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        SplashUnlock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    return success;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
SPLASHEXPORT int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
SplashLoadFile(const char *filename)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    SplashStream stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    return SplashStreamInitFile(&stream, filename) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                SplashLoadStream(&stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
SPLASHEXPORT int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
SplashLoadMemory(void *data, int size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    SplashStream stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    return SplashStreamInitMemory(&stream, data, size) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                SplashLoadStream(&stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
/* SplashStart MUST be called from under the lock */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
SplashStart(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    if (splash->isVisible == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        SplashCreateThread(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        splash->isVisible = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
/* SplashStream functions */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
static int readFile(void* pStream, void* pData, int nBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    FILE* f = ((SplashStream*)pStream)->arg.stdio.f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    return fread(pData, 1, nBytes, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
static int peekFile(void* pStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    FILE* f = ((SplashStream*)pStream)->arg.stdio.f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    int c = fgetc(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    if (c != EOF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        ungetc(c, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
static void closeFile(void* pStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    FILE* f = ((SplashStream*)pStream)->arg.stdio.f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    fclose(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
static int readMem(void* pStream, void* pData, int nBytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    unsigned char* pSrc = (unsigned char*)(((SplashStream*)pStream)->arg.mem.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    unsigned char* pSrcEnd = (unsigned char*)(((SplashStream*)pStream)->arg.mem.pDataEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    if (nBytes > pSrcEnd - pSrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        nBytes = pSrcEnd - pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    if (nBytes>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        memcpy(pData, pSrc, nBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        pSrc += nBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        ((SplashStream*)pStream)->arg.mem.pData = (void*)pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    return nBytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
static int peekMem(void* pStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    unsigned char* pSrc = (unsigned char*)(((SplashStream*)pStream)->arg.mem.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    unsigned char* pSrcEnd = (unsigned char*)(((SplashStream*)pStream)->arg.mem.pDataEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    if (pSrc >= pSrcEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return (int)*pSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
static void closeMem(void* pStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
int SplashStreamInitFile(SplashStream * pStream, const char* filename) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    pStream->arg.stdio.f = fopen(filename, "rb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    pStream->read = readFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    pStream->peek = peekFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    pStream->close = closeFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    return pStream->arg.stdio.f != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
int SplashStreamInitMemory(SplashStream * pStream, void* pData, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    pStream->arg.mem.pData = (unsigned char*)pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    pStream->arg.mem.pDataEnd = (unsigned char*)pData + size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    pStream->read = readMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    pStream->peek = peekMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    pStream->close = closeMem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
}
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   392
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   393
SPLASHEXPORT int
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   394
SplashGetScaledImgNameMaxPstfixLen(const char *fileName){
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   395
    return strlen(fileName) + strlen(".java-scale-200") + 1;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 25859
diff changeset
   396
}