--- old/src/java.desktop/windows/native/libsplashscreen/splashscreen_config.h 2016-03-10 16:23:52.533372067 +0530 +++ new/src/java.desktop/windows/native/libsplashscreen/splashscreen_config.h 2016-03-10 16:23:52.297372060 +0530 @@ -41,6 +41,7 @@ #include #include #include +#include "systemScale.h" typedef DWORD rgbquad_t; typedef WORD word_t; @@ -56,5 +57,4 @@ #define SPLASHEXPORT __declspec(dllexport) - #endif --- old/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c 2016-03-10 16:23:53.153372086 +0530 +++ new/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c 2016-03-10 16:23:52.909372078 +0530 @@ -38,7 +38,6 @@ #include #include #include "sizecalc.h" - #ifndef WS_EX_LAYERED #define WS_EX_LAYERED 0x80000 #endif @@ -58,6 +57,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; @@ -571,8 +572,57 @@ SPLASHEXPORT char* SplashGetScaledImageName(const char* jarName, const char* fileName, - float *scaleFactor) +float *scaleFactor) { - *scaleFactor = 1; + *scaleFactor = 1.0; + float dpiScaleX = -1.0f; + float dpiScaleY = -1.0f; + GetScreenDpi(getPrimaryMonitor(), &dpiScaleX, &dpiScaleY); + *scaleFactor = dpiScaleX > 0 ? dpiScaleX / 96 : *scaleFactor; + + if (*scaleFactor > 1.0) { + char strDpi[BUFF_SIZE]; + _snprintf(strDpi, BUFF_SIZE, "%d", (int)dpiScaleX); + 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)); + int retVal = _snprintf(scaledImgName, length, "%s%s%s", dupFileName, + nameToAppend, strDpi); + if (retVal < 0 || (retVal != length - 1)) { + *scaleFactor = 1; + free(scaledImgName); + return NULL; + } + } + else { + size_t length_Without_Ext = fileExtension - dupFileName; + length = length_Without_Ext + strlen(nameToAppend) + strlen(strDpi) + + strlen(fileExtension) + 1; + scaledImgName = SAFE_SIZE_ARRAY_ALLOC(malloc, length, sizeof(char)); + int retVal = _snprintf(scaledImgName, length, "%.*s%s%s%s", + length_Without_Ext, dupFileName, nameToAppend, strDpi, fileExtension); + if (retVal < 0 || (retVal != length - 1)) { + *scaleFactor = 1; + free(scaledImgName); + return NULL; + } + } + free(dupFileName); + FILE *fp = NULL; + if (!(fp = fopen(scaledImgName, "r"))) { + *scaleFactor = 1; + free(scaledImgName); + return NULL; + } + fclose(fp); + return scaledImgName; + } return NULL; } --- old/make/lib/Awt2dLibraries.gmk 2016-03-10 16:23:53.757372104 +0530 +++ new/make/lib/Awt2dLibraries.gmk 2016-03-10 16:23:53.517372097 +0530 @@ -203,11 +203,13 @@ ifeq ($(OPENJDK_TARGET_OS), windows) LIBAWT_DIRS += $(JDK_TOPDIR)/src/java.desktop/share/native/common/font \ - $(JDK_TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \ + $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt/systemscale \ + $(JDK_TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \ # Why does libawt need java.base headers? LIBAWT_CFLAGS += -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/font \ -I$(JDK_TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \ -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/opengl \ + -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt/systemscale \ -I$(JDK_TOPDIR)/src/java.desktop/windows/native/include \ -I$(JDK_TOPDIR)/src/java.desktop/share/native/include \ -I$(SUPPORT_OUTPUTDIR)/headers/java.base \ @@ -322,10 +324,14 @@ -I$(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/font \ $(LIBJAVA_HEADER_FLAGS) # - + LIBAWT_XAWT_CFLAGS += -DXAWT -DXAWT_HACK \ -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \ $(CUPS_CFLAGS) + ifneq (,$(filter $(OPENJDK_TARGET_OS),linux solaris)) + LIBAWT_XAWT_DIRS += $(JDK_TOPDIR)/src/java.desktop/unix/native/common/awt/systemscale + LIBAWT_XAWT_CFLAGS += -I$(JDK_TOPDIR)/src/java.desktop/unix/native/common/awt/systemscale + endif ifeq ($(OPENJDK_TARGET_OS), solaris) LIBAWT_XAWT_CFLAGS += -DFUNCPROTO=15 @@ -855,12 +861,21 @@ else LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/java.desktop/macosx/native/libsplashscreen endif - + ifeq ($(OPENJDK_TARGET_OS), windows) + LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/java.desktop/windows/native/common/awt/systemscale + LIBSPLASHSCREEN_CFLAGS += -I$(JDK_TOPDIR)/src/java.desktop/windows/native/common/awt/systemscale + endif + LIBSPLASHSCREEN_CFLAGS += -DSPLASHSCREEN -DPNG_NO_MMX_CODE -DPNG_ARM_NEON_OPT=0 \ $(addprefix -I, $(LIBSPLASHSCREEN_DIRS)) \ $(LIBJAVA_HEADER_FLAGS) \ # + ifneq (,$(filter $(OPENJDK_TARGET_OS),linux solaris)) + LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/java.desktop/unix/native/common/awt/systemscale + LIBSPLASHSCREEN_CFLAGS += -I$(JDK_TOPDIR)/src/java.desktop/unix/native/common/awt/systemscale + endif + ifeq ($(OPENJDK_TARGET_OS), macosx) LIBSPLASHSCREEN_CFLAGS += -DWITH_MACOSX LIBSPLASHSCREEN_CFLAGS += -I$(JDK_TOPDIR)/src/java.desktop/macosx/native/libosxapp @@ -896,7 +911,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-03-10 16:23:54.421372124 +0530 +++ new/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java 2016-03-10 16:23:54.177372117 +0530 @@ -26,6 +26,7 @@ import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.GraphicsEnvironment; import java.awt.Panel; import java.awt.Rectangle; import java.awt.Robot; @@ -40,10 +41,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 +55,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.equalsIgnoreCase("mac")) { + tests = macTests; + } switch (test) { case "GENERATE_IMAGES": generateImages(); @@ -156,7 +165,10 @@ public void paint(Graphics g) { float scaleFactor = 1; if (g instanceof SunGraphics2D) { - scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale(); + scaleFactor = (float)GraphicsEnvironment. + getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(). + getDefaultTransform().getScaleX(); } scaleFactors[0] = scaleFactor; dialog.setVisible(false); --- old/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp 2016-03-10 16:23:55.013372142 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsDevice.cpp 2016-03-10 16:23:54.757372134 +0530 @@ -51,10 +51,7 @@ #include "Devices.h" #include #pragma comment(lib, "d2d1") - -#ifndef MDT_Effective_DPI -#define MDT_Effective_DPI 0 -#endif +#include "systemScale.h" uns_ordered_dither_array img_oda_alpha; @@ -655,58 +652,9 @@ void AwtWin32GraphicsDevice::InitDesktopScales() { - unsigned x = 0; - unsigned y = 0; float dpiX = -1.0f; float dpiY = -1.0f; - - // for debug purposes - static float scale = -2.0f; - if (scale == -2) { - scale = -1; - char *uiScale = getenv("J2D_UISCALE"); - if (uiScale != NULL) { - scale = (float)strtod(uiScale, NULL); - if (errno == ERANGE || scale <= 0) { - scale = -1; - } - } - } - - if (scale > 0) { - SetScale(scale, scale); - return; - } - - typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*); - static HMODULE hLibSHCoreDll = NULL; - static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL; - - if (hLibSHCoreDll == NULL) { - hLibSHCoreDll = JDK_LoadSystemLibrary("shcore.dll"); - if (hLibSHCoreDll != NULL) { - lpGetDpiForMonitor = (GetDpiForMonitorFunc*)GetProcAddress( - hLibSHCoreDll, "GetDpiForMonitor"); - } - } - - if (lpGetDpiForMonitor != NULL) { - HRESULT hResult = lpGetDpiForMonitor(GetMonitor(), - MDT_Effective_DPI, &x, &y); - if (hResult == S_OK) { - dpiX = static_cast(x); - dpiY = static_cast(y); - } - } else { - 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(); - } - } - + GetScreenDpi(GetMonitor(), &dpiX, &dpiY); if (dpiX > 0 && dpiY > 0) { SetScale(dpiX / 96, dpiY / 96); } @@ -1471,4 +1419,4 @@ if (device != NULL) { device->InitDesktopScales(); } -} \ No newline at end of file +} --- /dev/null 2016-03-10 15:30:05.197274064 +0530 +++ new/src/java.desktop/windows/native/common/awt/systemscale/systemScale.h 2016-03-10 16:23:55.433372155 +0530 @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2016, 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. +*/ +#ifndef _AWT_SYSTEM_SCALE_H +#define _AWT_SYSTEM_SCALE_H +#include +#ifdef __cplusplus +extern "C" { +#endif + void GetScreenDpi(HMONITOR mon, float *dpiX, float *dpiY); + HMONITOR WINAPI getPrimaryMonitor(); +#ifdef __cplusplus +} +#endif +#endif --- /dev/null 2016-03-10 15:30:05.197274064 +0530 +++ new/src/java.desktop/windows/native/common/awt/systemscale/systemScale.cpp 2016-03-10 16:23:56.137372176 +0530 @@ -0,0 +1,89 @@ +/* +* 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 "systemScale.h" +#include +#pragma comment(lib, "d2d1") +#include +#ifndef MDT_EFFECTIVE_DPI +#define MDT_EFFECTIVE_DPI 0 +#endif + +void GetScreenDpi(HMONITOR hmon, float *dpiX, float *dpiY) +{ + unsigned x = 0; + unsigned y = 0; + + // for debug purposes + static float scale = -2.0f; + if (scale == -2) { + scale = -1; + char *uiScale = getenv("J2D_UISCALE"); + if (uiScale != NULL) { + scale = (float)strtod(uiScale, NULL); + if (errno == ERANGE || scale <= 0) { + scale = -1; + } + } + } + + if (scale > 0) { + *dpiX = *dpiY = scale; + return; + } + + typedef HRESULT(WINAPI GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*); + static HMODULE hLibSHCoreDll = NULL; + static GetDpiForMonitorFunc *lpGetDpiForMonitor = NULL; + + if (hLibSHCoreDll == NULL) { + hLibSHCoreDll = JDK_LoadSystemLibrary("shcore.dll"); + if (hLibSHCoreDll != NULL) { + lpGetDpiForMonitor = (GetDpiForMonitorFunc*)GetProcAddress( + hLibSHCoreDll, "GetDpiForMonitor"); + } + } + + if (lpGetDpiForMonitor != NULL) { + HRESULT hResult = lpGetDpiForMonitor(hmon, + MDT_EFFECTIVE_DPI, &x, &y); + if (hResult == S_OK) { + *dpiX = static_cast(x); + *dpiY = static_cast(y); + } + } else { + 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; +} + +HMONITOR WINAPI getPrimaryMonitor() +{ + const POINT point = { 0, 0 }; + return MonitorFromPoint(point, MONITOR_DEFAULTTOPRIMARY); +}