jdk/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c
author rchamyal
Thu, 24 Mar 2016 14:06:32 +0530
changeset 36907 c3d8383e3efb
parent 27079 05150f708e53
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
/*
27079
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
     2
 * Copyright (c) 2005, 2014, 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: 1954
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: 1954
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: 1954
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1954
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1954
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    26
// copy from awt.h
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    27
#ifndef _WIN32_WINNT
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    28
#define _WIN32_WINNT 0x0600
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    29
#endif
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    30
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    31
// copy from awt.h
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    32
#ifndef _WIN32_IE
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    33
#define _WIN32_IE 0x0600
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    34
#endif
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 2
diff changeset
    35
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "splashscreen_impl.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <windowsx.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <winuser.h>
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
    40
#include "sizecalc.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#ifndef WS_EX_LAYERED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#define WS_EX_LAYERED 0x80000
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#ifndef ULW_ALPHA
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#define ULW_ALPHA               0x00000002
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#ifndef AC_SRC_OVER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define AC_SRC_OVER                 0x00
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#ifndef AC_SRC_ALPHA
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#define AC_SRC_ALPHA                0x01
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#define WM_SPLASHUPDATE         WM_USER+1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#define WM_SPLASHRECONFIGURE    WM_USER+2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
    61
#define BUFF_SIZE 1024
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/* Could use npt but decided to cut down on linked code size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
char* SplashConvertStringAlloc(const char* in, int *size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    int len, outChars, rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    WCHAR* buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    if (!in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    len = strlen(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    outChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in, len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                       NULL, 0);
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
    73
    buf = (WCHAR*) SAFE_SIZE_ARRAY_ALLOC(malloc, outChars, sizeof(WCHAR));
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
    74
    if (!buf) {
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
    75
        return NULL;
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
    76
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    rc = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in, len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                 buf, outChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    if (rc==0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        free(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            *size = rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return (char*)buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
unsigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
SplashTime(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    return GetTickCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
SplashInitFrameShape(Splash * splash, int imageIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    RGNDATA *pRgnData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    RGNDATAHEADER *pRgnHdr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    ImageRect maskRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    if (!splash->maskRequired)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /* reserving memory for the worst case */
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   107
    if (!IS_SAFE_SIZE_MUL(splash->width / 2 + 1, splash->height)) {
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   108
        return;
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   109
    }
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   110
    pRgnData = (RGNDATA *) SAFE_SIZE_STRUCT_ALLOC(malloc, sizeof(RGNDATAHEADER),
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   111
            sizeof(RECT), (splash->width / 2 + 1) * splash->height);
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   112
    if (!pRgnData) {
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   113
        return;
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   114
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    pRgnHdr = (RGNDATAHEADER *) pRgnData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    initRect(&maskRect, 0, 0, splash->width, splash->height, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            splash->width * splash->imageFormat.depthBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            splash->frames[imageIndex].bitmapBits, &splash->imageFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    pRgnHdr->dwSize = sizeof(RGNDATAHEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    pRgnHdr->iType = RDH_RECTANGLES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    pRgnHdr->nRgnSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    pRgnHdr->rcBound.top = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    pRgnHdr->rcBound.left = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    pRgnHdr->rcBound.bottom = splash->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    pRgnHdr->rcBound.right = splash->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    pRgnHdr->nCount = BitmapToYXBandedRectangles(&maskRect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            (RECT *) (((BYTE *) pRgnData) + sizeof(RGNDATAHEADER)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    splash->frames[imageIndex].hRgn = ExtCreateRegion(NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            sizeof(RGNDATAHEADER) + sizeof(RECT) * pRgnHdr->nCount, pRgnData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    free(pRgnData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
/* paint current splash screen frame to hdc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
   this function is unused in layered window mode */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
SplashPaint(Splash * splash, HDC hdc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    unsigned numColors = splash->screenFormat.colorMap ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        splash->screenFormat.numColors : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    BITMAPV4HEADER *pBmi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    HPALETTE hOldPal = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    if (!splash->frames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    if (splash->currentFrame < 0 || splash->currentFrame >= splash->frameCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return;
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   152
    pBmi = (BITMAPV4HEADER *) SAFE_SIZE_STRUCT_ALLOC(alloca, sizeof(BITMAPV4HEADER),
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   153
            sizeof(RGBQUAD), numColors);
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   154
    if (!pBmi) {
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   155
        return;
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   156
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    memset(pBmi, 0, sizeof(BITMAPV4HEADER));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    if (splash->screenFormat.colorMap)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        memcpy(((BYTE *) pBmi) + sizeof(BITMAPV4HEADER),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                splash->screenFormat.colorMap, sizeof(RGBQUAD) * numColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    pBmi->bV4Size = sizeof(BITMAPV4HEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    pBmi->bV4Width = splash->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    pBmi->bV4Height = -splash->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    pBmi->bV4Planes = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    pBmi->bV4BitCount = (WORD) (splash->screenFormat.depthBytes * 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /* we're ALWAYS using BGRA in screenFormat */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    pBmi->bV4V4Compression = BI_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    pBmi->bV4ClrUsed = numColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    pBmi->bV4ClrImportant = numColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    pBmi->bV4AlphaMask = splash->screenFormat.mask[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    pBmi->bV4RedMask = splash->screenFormat.mask[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    pBmi->bV4GreenMask = splash->screenFormat.mask[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    pBmi->bV4BlueMask = splash->screenFormat.mask[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /*  creating the palette in SplashInitPlatform does not work, so I'm creating it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
       here on demand */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    if (!splash->hPalette) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        unsigned i;
18232
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   180
        LOGPALETTE *pLogPal = (LOGPALETTE *) SAFE_SIZE_STRUCT_ALLOC(malloc,
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   181
                sizeof(LOGPALETTE), sizeof(PALETTEENTRY), numColors);
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   182
        if (!pLogPal) {
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   183
            return;
b538b71fb429 8009071: Improve shape handling
anthony
parents: 5506
diff changeset
   184
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        pLogPal->palVersion = 0x300;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        pLogPal->palNumEntries = (WORD) numColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        for (i = 0; i < numColors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            pLogPal->palPalEntry[i].peRed = (BYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                QUAD_RED(splash->colorMap[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            pLogPal->palPalEntry[i].peGreen = (BYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                QUAD_GREEN(splash->colorMap[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            pLogPal->palPalEntry[i].peBlue = (BYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                QUAD_BLUE(splash->colorMap[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            pLogPal->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        splash->hPalette = CreatePalette(pLogPal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        free(pLogPal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    if (splash->hPalette) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        hOldPal = SelectPalette(hdc, splash->hPalette, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        RealizePalette(hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    StretchDIBits(hdc, 0, 0, splash->width, splash->height, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            splash->width, splash->height, splash->screenData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            (BITMAPINFO *) pBmi, DIB_RGB_COLORS, SRCCOPY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    if (hOldPal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        SelectPalette(hdc, hOldPal, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
/* The function makes the window visible if it is hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 or is not yet shown. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
SplashRedrawWindow(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
{
27079
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
   218
    if (!SplashIsStillLooping(splash)) {
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
   219
        KillTimer(splash->hWnd, 0);
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
   220
    }
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
   221
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
   222
    if (splash->currentFrame < 0) {
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
   223
        return;
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
   224
    }
05150f708e53 8042609: Limit splashiness of splash images
azvegint
parents: 25859
diff changeset
   225
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    SplashUpdateScreenData(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    if (splash->isLayered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        BLENDFUNCTION bf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        POINT ptSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        HDC hdcSrc = CreateCompatibleDC(NULL), hdcDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        BITMAPINFOHEADER bmi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        void *bitmapBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        HBITMAP hBitmap, hOldBitmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        RECT rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        POINT ptDst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        SIZE size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        bf.BlendOp = AC_SRC_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        bf.BlendFlags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        bf.AlphaFormat = AC_SRC_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        bf.SourceConstantAlpha = 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        ptSrc.x = ptSrc.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        memset(&bmi, 0, sizeof(bmi));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        bmi.biSize = sizeof(BITMAPINFOHEADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        bmi.biWidth = splash->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        bmi.biHeight = -splash->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        bmi.biPlanes = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        bmi.biBitCount = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        bmi.biCompression = BI_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        //      FIXME: this is somewhat ineffective
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        //      maybe if we allocate memory for all frames as DIBSections,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        //      then we could select the frames into the DC directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        hBitmap = CreateDIBSection(NULL, (BITMAPINFO *) & bmi, DIB_RGB_COLORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                &bitmapBits, NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        memcpy(bitmapBits, splash->screenData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                splash->screenStride * splash->height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        hOldBitmap = (HBITMAP) SelectObject(hdcSrc, hBitmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        hdcDst = GetDC(splash->hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        GetWindowRect(splash->hWnd, &rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        ptDst.x = rect.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        ptDst.y = rect.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        size.cx = splash->width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        size.cy = splash->height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        UpdateLayeredWindow(splash->hWnd, hdcDst, &ptDst, &size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                hdcSrc, &ptSrc, 0, &bf, ULW_ALPHA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        ReleaseDC(splash->hWnd, hdcDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        SelectObject(hdcSrc, hOldBitmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        DeleteObject(hBitmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        DeleteDC(hdcSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
       InvalidateRect(splash->hWnd, NULL, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
       if (splash->maskRequired) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            CombineRgn(hRgn, splash->frames[splash->currentFrame].hRgn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    splash->frames[splash->currentFrame].hRgn, RGN_COPY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            SetWindowRgn(splash->hWnd, hRgn, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            SetWindowRgn(splash->hWnd, NULL, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        UpdateWindow(splash->hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    if (!IsWindowVisible(splash->hWnd)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        POINT cursorPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        ShowWindow(splash->hWnd, SW_SHOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        // Windows won't update the cursor after the window is shown,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        // if the cursor is already above the window. need to do this manually.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        GetCursorPos(&cursorPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (WindowFromPoint(cursorPos) == splash->hWnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            // unfortunately Windows fail to understand that the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            // thread should own the cursor, even though the mouse pointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            // is over the window, until the mouse has been moved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // we're using SetCursorPos here to fake the mouse movement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            // and enable proper update of the cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            SetCursorPos(cursorPos.x, cursorPos.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            SetCursor(LoadCursor(NULL, IDC_WAIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    if (SplashIsStillLooping(splash)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        int time = splash->time +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            splash->frames[splash->currentFrame].delay - SplashTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (time < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            time = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        SetTimer(splash->hWnd, 0, time, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
void SplashReconfigureNow(Splash * splash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    splash->x = (GetSystemMetrics(SM_CXSCREEN) - splash->width) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    splash->y = (GetSystemMetrics(SM_CYSCREEN) - splash->height) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    if (splash->hWnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        //Fixed 6474657: splash screen image jumps towards left while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        //    setting the new image using setImageURL()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        // We may safely hide the splash window because SplashRedrawWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        //    will show the window again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        ShowWindow(splash->hWnd, SW_HIDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        MoveWindow(splash->hWnd, splash->x, splash->y, splash->width, splash->height, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
static LRESULT CALLBACK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
SplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    PAINTSTRUCT ps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    HDC hdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    switch (message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    case WM_ERASEBKGND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return TRUE;            // to avoid flicker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    case WM_SYSCOMMAND:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (wParam==SC_CLOSE||wParam==SC_DEFAULT||wParam==SC_HOTKEY||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            wParam==SC_KEYMENU||wParam==SC_MAXIMIZE||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            wParam==SC_MINIMIZE||wParam==SC_MOUSEMENU||wParam==SC_MOVE||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            wParam==SC_RESTORE||wParam==SC_SIZE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /* double switch to avoid prologue/epilogue duplication */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    case WM_TIMER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    case WM_SPLASHUPDATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    case WM_PAINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    case WM_SPLASHRECONFIGURE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            Splash *splash = (Splash *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            if (splash->isVisible>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                switch(message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                case WM_TIMER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    SplashNextFrame(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                case WM_SPLASHUPDATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                case WM_PAINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    hdc = BeginPaint(hWnd, &ps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    SplashPaint(splash, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    EndPaint(hWnd, &ps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                case WM_SPLASHRECONFIGURE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    SplashReconfigureNow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            SplashUnlock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    case WM_DESTROY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        PostQuitMessage(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return DefWindowProc(hWnd, message, wParam, lParam);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
HWND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
SplashCreateWindow(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    WNDCLASSEX wcex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    ATOM wndClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    DWORD style, exStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    HWND hWnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    ZeroMemory(&wcex, sizeof(WNDCLASSEX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    wcex.cbSize = sizeof(WNDCLASSEX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    wcex.style = CS_HREDRAW | CS_VREDRAW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    wcex.lpfnWndProc = (WNDPROC) SplashWndProc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    wcex.hInstance = GetModuleHandle(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    wcex.lpszClassName = "JavaSplash";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    wcex.hCursor = LoadCursor(NULL, IDC_WAIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    wndClass = RegisterClassEx(&wcex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    if (!wndClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    splash->x = (GetSystemMetrics(SM_CXSCREEN) - splash->width) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    splash->y = (GetSystemMetrics(SM_CYSCREEN) - splash->height) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    exStyle = splash->isLayered ? WS_EX_LAYERED : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    exStyle |= WS_EX_TOOLWINDOW;        /* don't show the window on taskbar */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    style = WS_POPUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    hWnd = CreateWindowEx(exStyle, (LPCSTR) wndClass, "", style,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            splash->x, splash->y, splash->width, splash->height, NULL, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            wcex.hInstance, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    return hWnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
SplashLock(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    EnterCriticalSection(&splash->lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
SplashUnlock(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    LeaveCriticalSection(&splash->lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
SplashInitPlatform(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    HDC hdc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    int paletteMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    InitializeCriticalSection(&splash->lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    splash->isLayered = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    hdc = GetDC(NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    paletteMode = (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    if (UpdateLayeredWindow && !paletteMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        splash->isLayered = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    splash->byteAlignment = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    if (splash->isLayered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        initFormat(&splash->screenFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        splash->screenFormat.premultiplied = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        splash->maskRequired = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        splash->maskRequired = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (paletteMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            int numColors = GetDeviceCaps(hdc, SIZEPALETTE) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                GetDeviceCaps(hdc, NUMRESERVED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            int numComponents[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            initFormat(&splash->screenFormat, 0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            /*      FIXME: maybe remapping to non-reserved colors would improve performance */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            for (i = 0; i < numColors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                splash->colorIndex[i] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            numColors = quantizeColors(numColors, numComponents);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            initColorCube(numComponents, splash->colorMap, splash->dithers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    splash->colorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            splash->screenFormat.colorIndex = splash->colorIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            splash->screenFormat.depthBytes = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            splash->screenFormat.colorMap = splash->colorMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            splash->screenFormat.dithers = splash->dithers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            splash->screenFormat.numColors = numColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            splash->hPalette = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            initFormat(&splash->screenFormat,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    ReleaseDC(NULL, hdc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
SplashCleanupPlatform(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    if (splash->frames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        for (i = 0; i < splash->frameCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            if (splash->frames[i].hRgn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                DeleteObject(splash->frames[i].hRgn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                splash->frames[i].hRgn = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    if (splash->hPalette)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        DeleteObject(splash->hPalette);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    splash->maskRequired = !splash->isLayered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
SplashDonePlatform(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    if (splash->hWnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        DestroyWindow(splash->hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
SplashMessagePump()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    MSG msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    while (GetMessage(&msg, NULL, 0, 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        TranslateMessage(&msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        DispatchMessage(&msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
DWORD WINAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
SplashScreenThread(LPVOID param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    Splash *splash = (Splash *) param;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    splash->currentFrame = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    splash->time = SplashTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    splash->hWnd = SplashCreateWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    if (splash->hWnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        SplashRedrawWindow(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        SplashUnlock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        SplashMessagePump();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        SplashLock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    SplashDone(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    splash->isVisible = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    SplashUnlock(splash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
SplashCreateThread(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    DWORD threadId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    CreateThread(NULL, 0, SplashScreenThread, (LPVOID) splash, 0, &threadId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
SplashClosePlatform(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    PostMessage(splash->hWnd, WM_QUIT, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
SplashUpdate(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    PostMessage(splash->hWnd, WM_SPLASHUPDATE, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
SplashReconfigure(Splash * splash)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    PostMessage(splash->hWnd, WM_SPLASHRECONFIGURE, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
}
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 23010
diff changeset
   573
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   574
jboolean
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 23010
diff changeset
   575
SplashGetScaledImageName(const char* jarName, const char* fileName,
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   576
                           float *scaleFactor, char *scaleImageName,
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   577
                           const size_t scaledImageLength)
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 23010
diff changeset
   578
{
36907
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   579
    float dpiScaleX = -1.0f;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   580
    float dpiScaleY = -1.0f;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   581
    FILE *fp = NULL;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   582
    *scaleFactor = 1.0;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   583
    GetScreenDpi(getPrimaryMonitor(), &dpiScaleX, &dpiScaleY);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   584
    *scaleFactor = dpiScaleX > 0 ? dpiScaleX / 96 : *scaleFactor;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   585
    if (*scaleFactor > 1.0) {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   586
        char strDpi[BUFF_SIZE];
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   587
        char *dupFileName = strdup(fileName);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   588
        char *fileExtension = strrchr(dupFileName, '.');
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   589
        char *nameToAppend = ".scale-";
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   590
        size_t length = 0;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   591
        int retVal = 0;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   592
        _snprintf(strDpi, BUFF_SIZE, "%d", (int)dpiScaleX);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   593
        /*File is missing extension */
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   594
        if (fileExtension == NULL) {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   595
            length = strlen(dupFileName) + strlen(nameToAppend) +
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   596
                strlen(strDpi) + 1;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   597
            if (length > scaledImageLength) {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   598
                *scaleFactor = 1;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   599
                free(dupFileName);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   600
                return JNI_FALSE;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   601
            }
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   602
            retVal = _snprintf(scaleImageName, length, "%s%s%s", dupFileName,
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   603
                nameToAppend, strDpi);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   604
            if (retVal < 0 || (retVal != length - 1)) {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   605
                *scaleFactor = 1;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   606
                free(dupFileName);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   607
                return JNI_FALSE;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   608
            }
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   609
        }
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   610
        else {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   611
            size_t length_Without_Ext = fileExtension - dupFileName;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   612
            length = length_Without_Ext + strlen(nameToAppend) + strlen(strDpi) +
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   613
                strlen(fileExtension) + 1;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   614
            if (length > scaledImageLength) {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   615
                *scaleFactor = 1;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   616
                free(dupFileName);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   617
                return JNI_FALSE;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   618
            }
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   619
            retVal = _snprintf(scaleImageName, length, "%.*s%s%s%s",
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   620
                length_Without_Ext, dupFileName, nameToAppend, strDpi, fileExtension);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   621
            if (retVal < 0 || (retVal != length - 1)) {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   622
                *scaleFactor = 1;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   623
                free(dupFileName);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   624
                return JNI_FALSE;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   625
            }
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   626
        }
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   627
        free(dupFileName);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   628
        if (!(fp = fopen(scaleImageName, "r"))) {
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   629
            *scaleFactor = 1;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   630
            return JNI_FALSE;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   631
        }
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   632
        fclose(fp);
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   633
        return JNI_TRUE;
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   634
    }
c3d8383e3efb 8145173: HiDPI splash screen support on Windows
rchamyal
parents: 27079
diff changeset
   635
    return JNI_FALSE;
25552
96abb01815f6 8043869: [macosx] java -splash does not honor @2x hi dpi notation for retina support
alexsch
parents: 23010
diff changeset
   636
}