--- old/src/java.desktop/windows/native/libsplashscreen/splashscreen_config.h 2016-02-16 14:27:45.691855170 +0530 +++ new/src/java.desktop/windows/native/libsplashscreen/splashscreen_config.h 2016-02-16 14:27:45.475855165 +0530 @@ -55,6 +55,13 @@ #define INLINE __inline #define SPLASHEXPORT __declspec(dllexport) - - #endif +#ifdef __cplusplus + extern "C" { +#endif + float GetScreenDpi(); + HMONITOR WINAPI getPrimaryMonitor(); +#ifdef __cplusplus + } +#endif + --- old/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c 2016-02-16 14:27:46.295855183 +0530 +++ new/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c 2016-02-16 14:27:46.047855178 +0530 @@ -58,6 +58,8 @@ #define WM_SPLASHUPDATE WM_USER+1 #define WM_SPLASHRECONFIGURE WM_USER+2 +#define BUFF_SIZE 1024 + /* Could use npt but decided to cut down on linked code size */ char* SplashConvertStringAlloc(const char* in, int *size) { int len, outChars, rc; @@ -573,6 +575,51 @@ SplashGetScaledImageName(const char* jarName, const char* fileName, float *scaleFactor) { - *scaleFactor = 1; + *scaleFactor = 1.0; + float dpiScale = -1.0f; + + dpiScale = GetScreenDpi(); + *scaleFactor = dpiScale > 0 ? dpiScale / 96 : *scaleFactor; + + if (*scaleFactor > 1.0) { + + char strDpi[BUFF_SIZE]; + _snprintf(strDpi, BUFF_SIZE, "%d", (int)dpiScale); + char *dupFileName = strdup(fileName); + char *fileExtension = strrchr(dupFileName, '.'); + char *scaledImgName = NULL; + char *nameToAppend = ".scale-"; + size_t length = 0; + + /*File is missing extension */ + if (fileExtension == NULL) { + length = strlen(dupFileName) + strlen(nameToAppend) + + strlen(strDpi) + 1; + scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc,length, sizeof(char)); + _snprintf(scaledImgName, length, "%s%s%s", dupFileName, + nameToAppend, strDpi); + } else { + length = fileExtension - dupFileName + 1; + char *fNameWithoutExt = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char)); + memcpy(fNameWithoutExt, dupFileName, length); + fNameWithoutExt[length - 1] = '\0'; + length = length + strlen(nameToAppend) + strlen(strDpi) + + strlen(fileExtension) + 1; + scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char)); + _snprintf(scaledImgName, length, "%s%s%s%s", + fNameWithoutExt, nameToAppend, strDpi, fileExtension); + free(fNameWithoutExt); + } + free(dupFileName); + FILE *fp = NULL; + if (!(fp = fopen(scaledImgName, "r"))) { + *scaleFactor = 1; + free(scaledImgName); + return NULL; + } + fclose(fp); + return scaledImgName; + } return NULL; } + --- /dev/null 2016-02-16 11:55:10.499659053 +0530 +++ new/src/java.desktop/windows/native/libsplashscreen/splashscreen_helper.cpp 2016-02-16 14:27:46.735855192 +0530 @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* This code is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 only, as +* published by the Free Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* version 2 for more details (a copy is included in the LICENSE file that +* accompanied this code). +* +* You should have received a copy of the GNU General Public License version +* 2 along with this work; if not, write to the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +* +* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +* or visit www.oracle.com if you need additional information or have any +* questions. +*/ + +#include +#include +#pragma comment(lib, "d2d1") +#include +#include +#ifndef MDT_EFFECTIVE_DPI +#define MDT_EFFECTIVE_DPI 0 +#endif + +float GetScreenDpi() +{ + float dpiX = -1.0f; + float dpiY = -1.0f; + if (IsWindows8OrGreater()) { + unsigned x = 0; + unsigned y = 0; + typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*); + static HMODULE sHCoreDll = NULL; + static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL; + + if (sHCoreDll == NULL) { + sHCoreDll = JDK_LoadSystemLibrary("shcore.dll"); + if (sHCoreDll != NULL) { + lpGetDpiForMonitor = (GetDpiForMonitorFunc*)GetProcAddress( + sHCoreDll, "GetDpiForMonitor"); + } + } + if (lpGetDpiForMonitor != NULL) { + HMONITOR hmon = getPrimaryMonitor(); + HRESULT hResult = lpGetDpiForMonitor(hmon, + MDT_EFFECTIVE_DPI, &x, &y); + if (hResult == S_OK) { + dpiX = static_cast(x); + dpiY = static_cast(y); + } + } + return dpiX; + } + else if (IsWindows7OrGreater()) { + ID2D1Factory* m_pDirect2dFactory; + HRESULT res = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, + &m_pDirect2dFactory); + if (res == S_OK) { + m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY); + m_pDirect2dFactory->Release(); + } + return dpiX; + } + return 1.0; +} + +HMONITOR WINAPI getPrimaryMonitor() +{ + const POINT point = { 0, 0 }; + return MonitorFromPoint(point, MONITOR_DEFAULTTOPRIMARY); +} + --- old/make/lib/Awt2dLibraries.gmk 2016-02-16 14:27:47.487855208 +0530 +++ new/make/lib/Awt2dLibraries.gmk 2016-02-16 14:27:47.255855203 +0530 @@ -896,7 +896,7 @@ -framework JavaNativeFoundation else ifeq ($(OPENJDK_TARGET_OS), windows) LIBSPLASHSCREEN_LDFLAGS := -delayload:user32.dll - LIBSPLASHSCREEN_LIBS += kernel32.lib user32.lib gdi32.lib delayimp.lib + LIBSPLASHSCREEN_LIBS += kernel32.lib user32.lib gdi32.lib delayimp.lib $(WIN_JAVA_LIB) jvm.lib else LIBSPLASHSCREEN_LIBS += $(X_LIBS) -lX11 -lXext $(LIBM) -lpthread endif --- old/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java 2016-02-16 14:27:48.063855221 +0530 +++ new/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java 2016-02-16 14:27:47.843855216 +0530 @@ -40,10 +40,8 @@ /** * @test - * @bug 8043869 8075244 8078082 - * @author Alexander Scherbatiy - * @summary [macosx] java -splash does not honor 2x hi dpi notation for retina - * support + * @bug 8043869 8075244 8078082 8145173 + * @summary Tests the HiDPI splash screen support for windows and MAC * @modules java.desktop/sun.java2d * @run main MultiResolutionSplashTest GENERATE_IMAGES * @run main/othervm -splash:splash1.png MultiResolutionSplashTest TEST_SPLASH 0 @@ -56,16 +54,26 @@ private static final int IMAGE_WIDTH = 300; private static final int IMAGE_HEIGHT = 200; - private static final ImageInfo[] tests = { + private static final ImageInfo[] macTests = { new ImageInfo("splash1.png", "splash1@2x.png", Color.BLUE, Color.GREEN), new ImageInfo("splash2", "splash2@2x", Color.WHITE, Color.BLACK), new ImageInfo("splash3.", "splash3@2x.", Color.YELLOW, Color.RED) }; + private static final ImageInfo[] windowsTests = { + new ImageInfo("splash1.png", "splash1.scale-120.png", Color.BLUE, Color.GREEN), + new ImageInfo("splash2", "splash2.scale-120", Color.WHITE, Color.BLACK), + new ImageInfo("splash3.", "splash3.scale-120.", Color.YELLOW, Color.RED) + }; + private static ImageInfo[] tests; public static void main(String[] args) throws Exception { String test = args[0]; - + tests = windowsTests; + String osName = System.getProperty("os.name"); + if(osName != null && osName.equalsIgnoreCase("mac")) { + tests = macTests; + } switch (test) { case "GENERATE_IMAGES": generateImages(); @@ -156,7 +164,7 @@ public void paint(Graphics g) { float scaleFactor = 1; if (g instanceof SunGraphics2D) { - scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale(); + scaleFactor = (float)((SunGraphics2D) g).surfaceData.getDefaultScaleX(); } scaleFactors[0] = scaleFactor; dialog.setVisible(false);