0N/A/*
2362N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
862N/A// copy from awt.h
862N/A#ifndef _WIN32_WINNT
862N/A#define _WIN32_WINNT 0x0600
862N/A#endif
862N/A
862N/A// copy from awt.h
862N/A#ifndef _WIN32_IE
862N/A#define _WIN32_IE 0x0600
862N/A#endif
862N/A
0N/A#include "splashscreen_impl.h"
0N/A#include <windowsx.h>
0N/A#include <windows.h>
0N/A#include <winuser.h>
6295N/A#include "sizecalc.h"
0N/A
0N/A#ifndef WS_EX_LAYERED
0N/A#define WS_EX_LAYERED 0x80000
0N/A#endif
0N/A
0N/A#ifndef ULW_ALPHA
0N/A#define ULW_ALPHA 0x00000002
0N/A#endif
0N/A
0N/A#ifndef AC_SRC_OVER
0N/A#define AC_SRC_OVER 0x00
0N/A#endif
0N/A
0N/A#ifndef AC_SRC_ALPHA
0N/A#define AC_SRC_ALPHA 0x01
0N/A#endif
0N/A
0N/A#define WM_SPLASHUPDATE WM_USER+1
0N/A#define WM_SPLASHRECONFIGURE WM_USER+2
0N/A
0N/A/* Could use npt but decided to cut down on linked code size */
0N/Achar* SplashConvertStringAlloc(const char* in, int *size) {
0N/A int len, outChars, rc;
0N/A WCHAR* buf;
0N/A if (!in) {
0N/A return NULL;
0N/A }
0N/A len = strlen(in);
0N/A outChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in, len,
0N/A NULL, 0);
6295N/A buf = (WCHAR*) SAFE_SIZE_ARRAY_ALLOC(malloc, outChars, sizeof(WCHAR));
6295N/A if (!buf) {
6295N/A return NULL;
6295N/A }
0N/A rc = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, in, len,
0N/A buf, outChars);
0N/A if (rc==0) {
0N/A free(buf);
0N/A return NULL;
0N/A } else {
0N/A if (size) {
0N/A *size = rc;
0N/A }
0N/A return (char*)buf;
0N/A }
0N/A}
0N/A
0N/Aunsigned
0N/ASplashTime(void)
0N/A{
0N/A return GetTickCount();
0N/A}
0N/A
0N/Avoid
0N/ASplashInitFrameShape(Splash * splash, int imageIndex)
0N/A{
0N/A RGNDATA *pRgnData;
0N/A RGNDATAHEADER *pRgnHdr;
0N/A ImageRect maskRect;
0N/A
0N/A if (!splash->maskRequired)
0N/A return;
0N/A
0N/A /* reserving memory for the worst case */
6295N/A if (!IS_SAFE_SIZE_MUL(splash->width / 2 + 1, splash->height)) {
6295N/A return;
6295N/A }
6295N/A pRgnData = (RGNDATA *) SAFE_SIZE_STRUCT_ALLOC(malloc, sizeof(RGNDATAHEADER),
6295N/A sizeof(RECT), (splash->width / 2 + 1) * splash->height);
6295N/A if (!pRgnData) {
6295N/A return;
6295N/A }
0N/A pRgnHdr = (RGNDATAHEADER *) pRgnData;
0N/A initRect(&maskRect, 0, 0, splash->width, splash->height, 1,
0N/A splash->width * splash->imageFormat.depthBytes,
0N/A splash->frames[imageIndex].bitmapBits, &splash->imageFormat);
0N/A
0N/A pRgnHdr->dwSize = sizeof(RGNDATAHEADER);
0N/A pRgnHdr->iType = RDH_RECTANGLES;
0N/A pRgnHdr->nRgnSize = 0;
0N/A pRgnHdr->rcBound.top = 0;
0N/A pRgnHdr->rcBound.left = 0;
0N/A pRgnHdr->rcBound.bottom = splash->height;
0N/A pRgnHdr->rcBound.right = splash->width;
0N/A
0N/A pRgnHdr->nCount = BitmapToYXBandedRectangles(&maskRect,
0N/A (RECT *) (((BYTE *) pRgnData) + sizeof(RGNDATAHEADER)));
0N/A
0N/A splash->frames[imageIndex].hRgn = ExtCreateRegion(NULL,
0N/A sizeof(RGNDATAHEADER) + sizeof(RECT) * pRgnHdr->nCount, pRgnData);
0N/A
0N/A free(pRgnData);
0N/A}
0N/A
0N/A/* paint current splash screen frame to hdc
0N/A this function is unused in layered window mode */
0N/A
0N/Avoid
0N/ASplashPaint(Splash * splash, HDC hdc)
0N/A{
0N/A unsigned numColors = splash->screenFormat.colorMap ?
0N/A splash->screenFormat.numColors : 0;
0N/A BITMAPV4HEADER *pBmi;
0N/A HPALETTE hOldPal = NULL;
0N/A
0N/A if (!splash->frames)
0N/A return;
0N/A if (splash->currentFrame < 0 || splash->currentFrame >= splash->frameCount)
0N/A return;
6295N/A pBmi = (BITMAPV4HEADER *) SAFE_SIZE_STRUCT_ALLOC(alloca, sizeof(BITMAPV4HEADER),
6295N/A sizeof(RGBQUAD), numColors);
6295N/A if (!pBmi) {
6295N/A return;
6295N/A }
0N/A memset(pBmi, 0, sizeof(BITMAPV4HEADER));
0N/A if (splash->screenFormat.colorMap)
0N/A memcpy(((BYTE *) pBmi) + sizeof(BITMAPV4HEADER),
0N/A splash->screenFormat.colorMap, sizeof(RGBQUAD) * numColors);
0N/A
0N/A pBmi->bV4Size = sizeof(BITMAPV4HEADER);
0N/A pBmi->bV4Width = splash->width;
0N/A pBmi->bV4Height = -splash->height;
0N/A pBmi->bV4Planes = 1;
0N/A pBmi->bV4BitCount = (WORD) (splash->screenFormat.depthBytes * 8);
0N/A /* we're ALWAYS using BGRA in screenFormat */
0N/A pBmi->bV4V4Compression = BI_RGB;
0N/A pBmi->bV4ClrUsed = numColors;
0N/A pBmi->bV4ClrImportant = numColors;
0N/A pBmi->bV4AlphaMask = splash->screenFormat.mask[3];
0N/A pBmi->bV4RedMask = splash->screenFormat.mask[2];
0N/A pBmi->bV4GreenMask = splash->screenFormat.mask[1];
0N/A pBmi->bV4BlueMask = splash->screenFormat.mask[0];
0N/A
0N/A /* creating the palette in SplashInitPlatform does not work, so I'm creating it
0N/A here on demand */
0N/A if (!splash->hPalette) {
0N/A unsigned i;
6295N/A LOGPALETTE *pLogPal = (LOGPALETTE *) SAFE_SIZE_STRUCT_ALLOC(malloc,
6295N/A sizeof(LOGPALETTE), sizeof(PALETTEENTRY), numColors);
6295N/A if (!pLogPal) {
6295N/A return;
6295N/A }
0N/A
0N/A pLogPal->palVersion = 0x300;
0N/A pLogPal->palNumEntries = (WORD) numColors;
0N/A for (i = 0; i < numColors; i++) {
0N/A pLogPal->palPalEntry[i].peRed = (BYTE)
0N/A QUAD_RED(splash->colorMap[i]);
0N/A pLogPal->palPalEntry[i].peGreen = (BYTE)
0N/A QUAD_GREEN(splash->colorMap[i]);
0N/A pLogPal->palPalEntry[i].peBlue = (BYTE)
0N/A QUAD_BLUE(splash->colorMap[i]);
0N/A pLogPal->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
0N/A }
0N/A splash->hPalette = CreatePalette(pLogPal);
0N/A free(pLogPal);
0N/A }
0N/A if (splash->hPalette) {
0N/A hOldPal = SelectPalette(hdc, splash->hPalette, FALSE);
0N/A RealizePalette(hdc);
0N/A }
0N/A
0N/A StretchDIBits(hdc, 0, 0, splash->width, splash->height, 0, 0,
0N/A splash->width, splash->height, splash->screenData,
0N/A (BITMAPINFO *) pBmi, DIB_RGB_COLORS, SRCCOPY);
0N/A if (hOldPal)
0N/A SelectPalette(hdc, hOldPal, FALSE);
0N/A}
0N/A
0N/A
0N/A/* The function makes the window visible if it is hidden
0N/A or is not yet shown. */
0N/Avoid
0N/ASplashRedrawWindow(Splash * splash)
0N/A{
0N/A SplashUpdateScreenData(splash);
0N/A if (splash->isLayered) {
0N/A BLENDFUNCTION bf;
0N/A POINT ptSrc;
0N/A HDC hdcSrc = CreateCompatibleDC(NULL), hdcDst;
0N/A BITMAPINFOHEADER bmi;
0N/A void *bitmapBits;
0N/A HBITMAP hBitmap, hOldBitmap;
0N/A RECT rect;
0N/A POINT ptDst;
0N/A SIZE size;
0N/A
0N/A bf.BlendOp = AC_SRC_OVER;
0N/A bf.BlendFlags = 0;
0N/A bf.AlphaFormat = AC_SRC_ALPHA;
0N/A bf.SourceConstantAlpha = 0xFF;
0N/A ptSrc.x = ptSrc.y = 0;
0N/A
0N/A memset(&bmi, 0, sizeof(bmi));
0N/A bmi.biSize = sizeof(BITMAPINFOHEADER);
0N/A bmi.biWidth = splash->width;
0N/A bmi.biHeight = -splash->height;
0N/A bmi.biPlanes = 1;
0N/A bmi.biBitCount = 32;
0N/A bmi.biCompression = BI_RGB;
0N/A
0N/A // FIXME: this is somewhat ineffective
0N/A // maybe if we allocate memory for all frames as DIBSections,
0N/A // then we could select the frames into the DC directly
0N/A
0N/A hBitmap = CreateDIBSection(NULL, (BITMAPINFO *) & bmi, DIB_RGB_COLORS,
0N/A &bitmapBits, NULL, 0);
0N/A memcpy(bitmapBits, splash->screenData,
0N/A splash->screenStride * splash->height);
0N/A hOldBitmap = (HBITMAP) SelectObject(hdcSrc, hBitmap);
0N/A hdcDst = GetDC(splash->hWnd);
0N/A
0N/A GetWindowRect(splash->hWnd, &rect);
0N/A
0N/A ptDst.x = rect.left;
0N/A ptDst.y = rect.top;
0N/A
0N/A size.cx = splash->width;
0N/A size.cy = splash->height;
0N/A
0N/A UpdateLayeredWindow(splash->hWnd, hdcDst, &ptDst, &size,
0N/A hdcSrc, &ptSrc, 0, &bf, ULW_ALPHA);
0N/A
0N/A ReleaseDC(splash->hWnd, hdcDst);
0N/A SelectObject(hdcSrc, hOldBitmap);
0N/A DeleteObject(hBitmap);
0N/A DeleteDC(hdcSrc);
0N/A }
0N/A else {
0N/A InvalidateRect(splash->hWnd, NULL, FALSE);
0N/A if (splash->maskRequired) {
0N/A HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
0N/A
0N/A CombineRgn(hRgn, splash->frames[splash->currentFrame].hRgn,
0N/A splash->frames[splash->currentFrame].hRgn, RGN_COPY);
0N/A SetWindowRgn(splash->hWnd, hRgn, TRUE);
0N/A } else {
0N/A SetWindowRgn(splash->hWnd, NULL, TRUE);
0N/A }
0N/A UpdateWindow(splash->hWnd);
0N/A }
0N/A if (!IsWindowVisible(splash->hWnd)) {
0N/A POINT cursorPos;
0N/A ShowWindow(splash->hWnd, SW_SHOW);
0N/A // Windows won't update the cursor after the window is shown,
0N/A // if the cursor is already above the window. need to do this manually.
0N/A GetCursorPos(&cursorPos);
0N/A if (WindowFromPoint(cursorPos) == splash->hWnd) {
0N/A // unfortunately Windows fail to understand that the window
0N/A // thread should own the cursor, even though the mouse pointer
0N/A // is over the window, until the mouse has been moved.
0N/A // we're using SetCursorPos here to fake the mouse movement
0N/A // and enable proper update of the cursor.
0N/A SetCursorPos(cursorPos.x, cursorPos.y);
0N/A SetCursor(LoadCursor(NULL, IDC_WAIT));
0N/A }
0N/A }
0N/A if (SplashIsStillLooping(splash)) {
0N/A int time = splash->time +
0N/A splash->frames[splash->currentFrame].delay - SplashTime();
0N/A
0N/A if (time < 0)
0N/A time = 0;
0N/A SetTimer(splash->hWnd, 0, time, NULL);
0N/A }
0N/A else {
0N/A KillTimer(splash->hWnd, 0);
0N/A }
0N/A}
0N/A
0N/Avoid SplashReconfigureNow(Splash * splash) {
0N/A splash->x = (GetSystemMetrics(SM_CXSCREEN) - splash->width) / 2;
0N/A splash->y = (GetSystemMetrics(SM_CYSCREEN) - splash->height) / 2;
0N/A if (splash->hWnd) {
0N/A //Fixed 6474657: splash screen image jumps towards left while
0N/A // setting the new image using setImageURL()
0N/A // We may safely hide the splash window because SplashRedrawWindow()
0N/A // will show the window again.
0N/A ShowWindow(splash->hWnd, SW_HIDE);
0N/A MoveWindow(splash->hWnd, splash->x, splash->y, splash->width, splash->height, FALSE);
0N/A }
0N/A SplashRedrawWindow(splash);
0N/A}
0N/A
0N/Astatic LRESULT CALLBACK
0N/ASplashWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
0N/A{
0N/A PAINTSTRUCT ps;
0N/A HDC hdc;
0N/A
0N/A
0N/A switch (message) {
0N/A
0N/A case WM_ERASEBKGND:
0N/A return TRUE; // to avoid flicker
0N/A
0N/A case WM_SYSCOMMAND:
0N/A if (wParam==SC_CLOSE||wParam==SC_DEFAULT||wParam==SC_HOTKEY||
0N/A wParam==SC_KEYMENU||wParam==SC_MAXIMIZE||
0N/A wParam==SC_MINIMIZE||wParam==SC_MOUSEMENU||wParam==SC_MOVE||
0N/A wParam==SC_RESTORE||wParam==SC_SIZE)
0N/A {
0N/A return 0;
0N/A }
0N/A
0N/A /* double switch to avoid prologue/epilogue duplication */
0N/A case WM_TIMER:
0N/A case WM_SPLASHUPDATE:
0N/A case WM_PAINT:
0N/A case WM_SPLASHRECONFIGURE:
0N/A {
0N/A Splash *splash = (Splash *) GetWindowLongPtr(hWnd, GWLP_USERDATA);
0N/A
0N/A SplashLock(splash);
0N/A if (splash->isVisible>0) {
0N/A switch(message) {
0N/A case WM_TIMER:
0N/A SplashNextFrame(splash);
0N/A SplashRedrawWindow(splash);
0N/A break;
0N/A case WM_SPLASHUPDATE:
0N/A SplashRedrawWindow(splash);
0N/A break;
0N/A case WM_PAINT:
0N/A hdc = BeginPaint(hWnd, &ps);
0N/A SplashPaint(splash, hdc);
0N/A EndPaint(hWnd, &ps);
0N/A break;
0N/A case WM_SPLASHRECONFIGURE:
0N/A SplashReconfigureNow(splash);
0N/A break;
0N/A }
0N/A }
0N/A SplashUnlock(splash);
0N/A break;
0N/A }
0N/A case WM_DESTROY:
0N/A PostQuitMessage(0);
0N/A break;
0N/A default:
0N/A return DefWindowProc(hWnd, message, wParam, lParam);
0N/A
0N/A }
0N/A return 0;
0N/A}
0N/A
0N/AHWND
0N/ASplashCreateWindow(Splash * splash)
0N/A{
0N/A WNDCLASSEX wcex;
0N/A ATOM wndClass;
0N/A DWORD style, exStyle;
0N/A HWND hWnd;
0N/A
0N/A ZeroMemory(&wcex, sizeof(WNDCLASSEX));
0N/A
0N/A wcex.cbSize = sizeof(WNDCLASSEX);
0N/A wcex.style = CS_HREDRAW | CS_VREDRAW;
0N/A wcex.lpfnWndProc = (WNDPROC) SplashWndProc;
0N/A wcex.hInstance = GetModuleHandle(NULL);
0N/A wcex.lpszClassName = "JavaSplash";
0N/A wcex.hCursor = LoadCursor(NULL, IDC_WAIT);
0N/A
0N/A wndClass = RegisterClassEx(&wcex);
0N/A if (!wndClass) {
0N/A return 0;
0N/A }
0N/A
0N/A splash->x = (GetSystemMetrics(SM_CXSCREEN) - splash->width) / 2;
0N/A splash->y = (GetSystemMetrics(SM_CYSCREEN) - splash->height) / 2;
0N/A exStyle = splash->isLayered ? WS_EX_LAYERED : 0;
0N/A exStyle |= WS_EX_TOOLWINDOW; /* don't show the window on taskbar */
0N/A style = WS_POPUP;
0N/A hWnd = CreateWindowEx(exStyle, (LPCSTR) wndClass, "", style,
0N/A splash->x, splash->y, splash->width, splash->height, NULL, NULL,
0N/A wcex.hInstance, NULL);
0N/A SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) splash);
0N/A return hWnd;
0N/A}
0N/A
0N/Avoid
0N/ASplashLock(Splash * splash)
0N/A{
0N/A EnterCriticalSection(&splash->lock);
0N/A}
0N/A
0N/Avoid
0N/ASplashUnlock(Splash * splash)
0N/A{
0N/A LeaveCriticalSection(&splash->lock);
0N/A}
0N/A
0N/Avoid
0N/ASplashInitPlatform(Splash * splash)
0N/A{
0N/A HDC hdc;
0N/A int paletteMode;
0N/A
0N/A InitializeCriticalSection(&splash->lock);
0N/A splash->isLayered = FALSE;
0N/A hdc = GetDC(NULL);
0N/A paletteMode = (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) != 0;
0N/A if (UpdateLayeredWindow && !paletteMode) {
0N/A splash->isLayered = TRUE;
0N/A }
0N/A splash->byteAlignment = 4;
0N/A if (splash->isLayered) {
0N/A initFormat(&splash->screenFormat,
0N/A 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
0N/A splash->screenFormat.premultiplied = 1;
0N/A splash->maskRequired = 0;
0N/A }
0N/A else {
0N/A splash->maskRequired = 1;
0N/A if (paletteMode) {
0N/A int numColors = GetDeviceCaps(hdc, SIZEPALETTE) -
0N/A GetDeviceCaps(hdc, NUMRESERVED);
0N/A int i;
0N/A int numComponents[3];
0N/A
0N/A initFormat(&splash->screenFormat, 0, 0, 0, 0);
0N/A /* FIXME: maybe remapping to non-reserved colors would improve performance */
0N/A for (i = 0; i < numColors; i++) {
0N/A splash->colorIndex[i] = i;
0N/A }
0N/A numColors = quantizeColors(numColors, numComponents);
0N/A initColorCube(numComponents, splash->colorMap, splash->dithers,
0N/A splash->colorIndex);
0N/A splash->screenFormat.colorIndex = splash->colorIndex;
0N/A splash->screenFormat.depthBytes = 1;
0N/A splash->screenFormat.colorMap = splash->colorMap;
0N/A splash->screenFormat.dithers = splash->dithers;
0N/A splash->screenFormat.numColors = numColors;
0N/A splash->hPalette = NULL;
0N/A }
0N/A else {
0N/A initFormat(&splash->screenFormat,
0N/A 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
0N/A }
0N/A }
0N/A ReleaseDC(NULL, hdc);
0N/A}
0N/A
0N/Avoid
0N/ASplashCleanupPlatform(Splash * splash)
0N/A{
0N/A int i;
0N/A
0N/A if (splash->frames) {
0N/A for (i = 0; i < splash->frameCount; i++) {
0N/A if (splash->frames[i].hRgn) {
0N/A DeleteObject(splash->frames[i].hRgn);
0N/A splash->frames[i].hRgn = NULL;
0N/A }
0N/A }
0N/A }
0N/A if (splash->hPalette)
0N/A DeleteObject(splash->hPalette);
0N/A splash->maskRequired = !splash->isLayered;
0N/A}
0N/A
0N/Avoid
0N/ASplashDonePlatform(Splash * splash)
0N/A{
0N/A if (splash->hWnd)
0N/A DestroyWindow(splash->hWnd);
0N/A}
0N/A
0N/Avoid
0N/ASplashMessagePump()
0N/A{
0N/A MSG msg;
0N/A
0N/A while (GetMessage(&msg, NULL, 0, 0)) {
0N/A TranslateMessage(&msg);
0N/A DispatchMessage(&msg);
0N/A }
0N/A}
0N/A
0N/ADWORD WINAPI
0N/ASplashScreenThread(LPVOID param)
0N/A{
0N/A Splash *splash = (Splash *) param;
0N/A
0N/A splash->currentFrame = 0;
0N/A SplashLock(splash);
0N/A splash->time = SplashTime();
0N/A splash->hWnd = SplashCreateWindow(splash);
0N/A if (splash->hWnd) {
0N/A SplashRedrawWindow(splash);
0N/A SplashUnlock(splash);
0N/A SplashMessagePump();
0N/A SplashLock(splash);
0N/A }
0N/A SplashDone(splash);
0N/A splash->isVisible = -1;
0N/A SplashUnlock(splash);
0N/A return 0;
0N/A}
0N/A
0N/Avoid
0N/ASplashCreateThread(Splash * splash)
0N/A{
0N/A DWORD threadId;
0N/A
0N/A CreateThread(NULL, 0, SplashScreenThread, (LPVOID) splash, 0, &threadId);
0N/A}
0N/A
0N/Avoid
0N/ASplashClosePlatform(Splash * splash)
0N/A{
0N/A PostMessage(splash->hWnd, WM_QUIT, 0, 0);
0N/A}
0N/A
0N/Avoid
0N/ASplashUpdate(Splash * splash)
0N/A{
0N/A PostMessage(splash->hWnd, WM_SPLASHUPDATE, 0, 0);
0N/A}
0N/A
0N/Avoid
0N/ASplashReconfigure(Splash * splash)
0N/A{
0N/A PostMessage(splash->hWnd, WM_SPLASHRECONFIGURE, 0, 0);
0N/A}