--- old/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.c 2016-08-26 12:09:41.313411000 +0530 +++ new/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.c 2016-08-26 12:09:41.073291000 +0530 @@ -25,7 +25,12 @@ #include "splashscreen_impl.h" #include "splashscreen_gfx_impl.h" - +#define BUFF_SIZE 1024 +#ifdef _MSC_VER +# ifndef snprintf +# define snprintf _snprintf +# endif +#endif int splashIsVisible = 0; Splash * @@ -392,5 +397,101 @@ SPLASHEXPORT int SplashGetScaledImgNameMaxPstfixLen(const char *fileName){ - return strlen(fileName) + strlen(".java-scale-200") + 1; + return strlen(fileName) + strlen("@100pct") + 1; } + +jboolean GetScaledImageName(const char *fileName, char *scaleImageName, + float *scaleFactor, const size_t scaledImageLength) { + if (*scaleFactor > 1.0) { + FILE *fp = NULL; + char scaledImgPct[BUFF_SIZE]; + char scaledImgX[BUFF_SIZE]; + char *scaledImageXName = NULL; + char *scaledImagePctName = malloc(scaledImageLength); + char *dupFileName = strdup(fileName); + char *fileExtension = strrchr(dupFileName, '.'); + size_t lengthPct = 0; + size_t lengthX = 0; + int retValPct = 0; + int retValX = 0; + jboolean isPctScaledImage = (*scaleFactor * 100) != ((int) (*scaleFactor)) *100; + snprintf(scaledImgPct, BUFF_SIZE, "%s%d%s", "@", (int) (*scaleFactor * 100), "pct"); + if (!isPctScaledImage) { + scaledImageXName = malloc(scaledImageLength); + snprintf(scaledImgX, BUFF_SIZE, "%s%d%s", "@", (int) (*scaleFactor), "x"); + } + /*File is missing extension */ + if (fileExtension == NULL) { + lengthPct = strlen(dupFileName) + + strlen(scaledImgPct) + 1; + if (!isPctScaledImage) { + lengthX = strlen(dupFileName) + + strlen(scaledImgX) + 1; + } + if (lengthPct > scaledImageLength || lengthX > scaledImageLength) { + cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor); + return JNI_FALSE; + } + retValPct = snprintf(scaledImagePctName, lengthPct, "%s%s", dupFileName, + scaledImgPct); + if (!isPctScaledImage) { + retValX = snprintf(scaledImageXName, lengthX, "%s%s", dupFileName, + scaledImgX); + } + if ((retValPct < 0 || (retValPct > lengthPct - 1)) || + (retValX < 0 || (retValX > lengthX - 1))) { + cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor); + return JNI_FALSE; + } + } else { + int length_Without_Ext = fileExtension - dupFileName; + lengthPct = length_Without_Ext + strlen(scaledImgPct) + + strlen(fileExtension) + 1; + if (!isPctScaledImage) { + lengthX = length_Without_Ext + strlen(scaledImgX) + + strlen(fileExtension) + 1; + } + if (lengthPct > scaledImageLength || lengthX > scaledImageLength) { + cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor); + return JNI_FALSE; + } + retValPct = snprintf(scaledImagePctName, lengthPct, "%.*s%s%s", + length_Without_Ext, dupFileName, scaledImgPct, fileExtension); + if(!isPctScaledImage) { + retValX = snprintf(scaledImageXName, lengthX, "%.*s%s%s", + length_Without_Ext, dupFileName, scaledImgX, fileExtension); + } + if ((retValPct < 0 || (retValPct > lengthPct - 1)) || + (retValX < 0 || (retValX > lengthX - 1))) { + cleanUp(dupFileName, scaledImageXName, scaledImagePctName, scaleFactor); + return JNI_FALSE; + } + } + free(dupFileName); + if (!(fp = fopen(scaledImagePctName, "r"))) { + if (!isPctScaledImage && (fp = fopen(scaledImageXName, "r"))) { + fclose(fp); + strcpy(scaleImageName, scaledImageXName); + free(scaledImageXName); + free(scaledImagePctName); + return JNI_TRUE; + } + cleanUp(NULL,scaledImageXName, scaledImagePctName, scaleFactor); + return JNI_FALSE; + } + fclose(fp); + strcpy(scaleImageName, scaledImagePctName); + free(scaledImageXName); + free(scaledImagePctName); + return JNI_TRUE; + } + return JNI_FALSE; +} + +void cleanUp(char *fName, char *xName, char *pctName, float *scaleFactor) { + *scaleFactor = 1; + free(fName); + free(xName); + free(pctName); +} + --- old/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.h 2016-08-26 12:09:41.921715000 +0530 +++ new/src/java.desktop/share/native/libsplashscreen/splashscreen_impl.h 2016-08-26 12:09:41.693601000 +0530 @@ -150,7 +150,9 @@ void SplashCleanup(Splash * splash); void SplashSetScaleFactor(float scaleFactor); int SplashGetScaledImgNameMaxPstfixLen(const char *fileName); - +void cleanUp(char *fName, char *xName, char *pctName, float *scaleFactor); +jboolean GetScaledImageName(const char *fileName, char *scaledImgName, + float *scaleFactor, const size_t scaledImageLength); typedef struct SplashStream { int (*read)(void* pStream, void* pData, int nBytes); int (*peek)(void* pStream); --- old/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c 2016-08-26 12:09:42.538023000 +0530 +++ new/src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c 2016-08-26 12:09:42.313911000 +0530 @@ -753,6 +753,9 @@ XMapRaised(splash->display, splash->window); SplashUpdateShape(splash); SplashRedrawWindow(splash); + //map the splash co-ordinates as per system scale + splash->x /= splash->scaleFactor; + splash->y /= splash->scaleFactor; SplashEventLoop(splash); } SplashUnlock(splash); @@ -806,51 +809,6 @@ #ifndef __linux__ return JNI_FALSE; #endif - *scaleFactor = getNativeScaleFactor(); - if (*scaleFactor == 2.0) { - size_t length = 0; - char *stringToAppend = ".java-scale2x"; - char *dupFileName = strdup(fileName); - char *fileExtension = strrchr(dupFileName, '.'); - if (fileExtension == NULL) { - length = strlen(dupFileName) + strlen(stringToAppend) + 1; - if (length > scaledImageNameLength) { - *scaleFactor = 1; - free(dupFileName); - return JNI_FALSE; - } - int retVal = snprintf(scaledImgName, length, "%s%s", - dupFileName, stringToAppend); - if (retVal < 0 || (retVal != length - 1)) { - free(dupFileName); - *scaleFactor = 1; - return JNI_FALSE; - } - } else { - int length_without_ext = fileExtension - dupFileName; - length = length_without_ext + - strlen(stringToAppend) + strlen(fileExtension) + 1; - if (length > scaledImageNameLength) { - *scaleFactor = 1; - free(dupFileName); - return JNI_FALSE; - } - int retVal = snprintf(scaledImgName, length, "%.*s%s%s", - length_without_ext, dupFileName, stringToAppend, fileExtension); - if (retVal < 0 || retVal != length - 1) { - free(dupFileName); - *scaleFactor = 1; - return JNI_FALSE; - } - } - free(dupFileName); - FILE *fp; - if (!(fp = fopen(scaledImgName, "r"))) { - *scaleFactor = 1; - return JNI_FALSE; - } - fclose(fp); - return JNI_TRUE; - } - return JNI_FALSE; + *scaleFactor = getNativeScaleFactor(NULL); + return GetScaledImageName(fileName, scaledImgName, scaleFactor, scaledImageNameLength); } --- old/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c 2016-08-26 12:09:43.142324999 +0530 +++ new/src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c 2016-08-26 12:09:42.910208999 +0530 @@ -535,6 +535,9 @@ splash->hWnd = SplashCreateWindow(splash); if (splash->hWnd) { SplashRedrawWindow(splash); + //map the splash co-ordinates as per system scale + splash->x /= splash->scaleFactor; + splash->y /= splash->scaleFactor; SplashUnlock(splash); SplashMessagePump(); SplashLock(splash); @@ -582,55 +585,8 @@ *scaleFactor = 1.0; GetScreenDpi(getPrimaryMonitor(), &dpiScaleX, &dpiScaleY); *scaleFactor = dpiScaleX > 0 ? dpiScaleX / 96 : *scaleFactor; - if (*scaleFactor > 1.0) { - char strDpi[BUFF_SIZE]; - char *dupFileName = strdup(fileName); - char *fileExtension = strrchr(dupFileName, '.'); - char *nameToAppend = ".scale-"; - size_t length = 0; - int retVal = 0; - _snprintf(strDpi, BUFF_SIZE, "%d", (int)dpiScaleX); - /*File is missing extension */ - if (fileExtension == NULL) { - length = strlen(dupFileName) + strlen(nameToAppend) + - strlen(strDpi) + 1; - if (length > scaledImageLength) { - *scaleFactor = 1; - free(dupFileName); - return JNI_FALSE; - } - retVal = _snprintf(scaleImageName, length, "%s%s%s", dupFileName, - nameToAppend, strDpi); - if (retVal < 0 || (retVal != length - 1)) { - *scaleFactor = 1; - free(dupFileName); - return JNI_FALSE; - } - } - else { - size_t length_Without_Ext = fileExtension - dupFileName; - length = length_Without_Ext + strlen(nameToAppend) + strlen(strDpi) + - strlen(fileExtension) + 1; - if (length > scaledImageLength) { - *scaleFactor = 1; - free(dupFileName); - return JNI_FALSE; - } - retVal = _snprintf(scaleImageName, length, "%.*s%s%s%s", - length_Without_Ext, dupFileName, nameToAppend, strDpi, fileExtension); - if (retVal < 0 || (retVal != length - 1)) { - *scaleFactor = 1; - free(dupFileName); - return JNI_FALSE; - } - } - free(dupFileName); - if (!(fp = fopen(scaleImageName, "r"))) { - *scaleFactor = 1; - return JNI_FALSE; - } - fclose(fp); - return JNI_TRUE; - } - return JNI_FALSE; + return GetScaledImageName(fileName, scaleImageName, + scaleFactor, scaledImageLength); + } + --- old/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m 2016-08-26 12:09:43.702605000 +0530 +++ new/src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m 2016-08-26 12:09:43.466487000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -47,6 +47,10 @@ #include #import "ThreadUtilities.h" +NSString* findScaledImageName(NSString *fileName, + NSUInteger dotIndex, + NSString *strToAppend); + static NSScreen* SplashNSScreen() { return [[NSScreen screens] objectAtIndex: 0]; @@ -134,8 +138,8 @@ } jboolean SplashGetScaledImageName(const char* jar, const char* file, - float *scaleFactor, char *scaledFile, - const size_t scaledImageLength) { + float *scaleFactor, char *scaledFile, + const size_t scaledImageLength) { *scaleFactor = 1; if(isSWTRunning()){ @@ -158,18 +162,14 @@ options:NSBackwardsSearch]; NSUInteger dotIndex = range.location; NSString *fileName2x = nil; - - if (dotIndex == NSNotFound) { - fileName2x = [fileName stringByAppendingString: @"@2x"]; - } else { - fileName2x = [fileName substringToIndex: dotIndex]; - fileName2x = [fileName2x stringByAppendingString: @"@2x"]; - fileName2x = [fileName2x stringByAppendingString: - [fileName substringFromIndex: dotIndex]]; + + fileName2x = findScaledImageName(fileName, dotIndex, @"@2x"); + if(![[NSFileManager defaultManager] + fileExistsAtPath: fileName2x]) { + fileName2x = findScaledImageName(fileName, dotIndex, @"@200pct"); } - - if ((fileName2x != nil) && (jar || [[NSFileManager defaultManager] - fileExistsAtPath: fileName2x])){ + if (jar || [[NSFileManager defaultManager] + fileExistsAtPath: fileName2x]){ if (strlen([fileName2x UTF8String]) > scaledImageLength) { [pool drain]; return JNI_FALSE; @@ -458,3 +458,16 @@ sendctl(splash, SPLASHCTL_RECONFIGURE); } +NSString* findScaledImageName(NSString *fileName, NSUInteger dotIndex, NSString *strToAppend) { + NSString *fileName2x = nil; + if (dotIndex == NSNotFound) { + fileName2x = [fileName stringByAppendingString: strToAppend]; + } else { + fileName2x = [fileName substringToIndex: dotIndex]; + fileName2x = [fileName2x stringByAppendingString: strToAppend]; + fileName2x = [fileName2x stringByAppendingString: + [fileName substringFromIndex: dotIndex]]; + } + return fileName2x; +} + --- old/src/java.base/share/classes/sun/launcher/resources/launcher.properties 2016-08-26 12:09:44.314911000 +0530 +++ new/src/java.base/share/classes/sun/launcher/resources/launcher.properties 2016-08-26 12:09:44.094801000 +0530 @@ -90,6 +90,16 @@ \ load Java programming language agent, see java.lang.instrument\n\ \ -splash:\n\ \ show splash screen with specified image\n\ +\ HiDPI scaled image is also supported\n\ +\ Unscaled image name i.e. image.ext should be passed to -splash option for all image types\n\ +\ irrespective of HiDPI and Non-HiDPI\n\ +\ Scaled images should be provided in the directory \n\ +\ Following is the naming convention for scaled images. \n\ +\ Screen scale 1.25: image@125pct.ext\n\ +\ Screen scale 1.50: image@150pct.ext\n\ +\ Screen scale 2: image@200pct.ext and image@2x.ext both are supported \n\ +\ Screen scale 2.50: image@250pct.ext\n\ +\ Screen scale 3: image@300pct.ext and image@3x.ext both are supported\n\ \ @ read options from the specified file\n\ See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details. --- old/make/mapfiles/libsplashscreen/mapfile-vers 2016-08-26 12:09:44.867186999 +0530 +++ new/make/mapfiles/libsplashscreen/mapfile-vers 2016-08-26 12:09:44.647077000 +0530 @@ -44,6 +44,7 @@ SplashSetFileJarName; SplashSetScaleFactor; SplashGetScaledImageName; + SplashGetScaledImgNameMaxPstfixLen; local: *; }; --- old/test/java/awt/SplashScreen/MultiResolutionSplash/unix/UnixMultiResolutionSplashTest.java 2016-08-26 12:09:45.427467000 +0530 +++ new/test/java/awt/SplashScreen/MultiResolutionSplash/unix/UnixMultiResolutionSplashTest.java 2016-08-26 12:09:45.199352999 +0530 @@ -44,7 +44,7 @@ import javax.imageio.ImageIO; /** - * @test @bug 8145174 + * @test @bug 8145174 8151787 * @summary HiDPI splash screen support on Linux * @modules java.desktop/sun.java2d * @run main UnixMultiResolutionSplashTest @@ -55,9 +55,9 @@ private static final int IMAGE_HEIGHT = 200; private static int inx = 0; private static final ImageInfo[] tests = { - new ImageInfo("splash1.png", "splash1.java-scale2x.png", Color.BLUE, Color.GREEN), - new ImageInfo("splash2", "splash2.java-scale2x", Color.WHITE, Color.BLACK), - new ImageInfo("splash3.", "splash3.java-scale2x.", Color.YELLOW, Color.RED) + new ImageInfo("splash1.png", "splash1@200pct.png", Color.BLUE, Color.GREEN), + new ImageInfo("splash2", "splash2@2x", Color.WHITE, Color.BLACK), + new ImageInfo("splash3.", "splash3@200pct.", Color.YELLOW, Color.RED) }; public static void main(String[] args) throws Exception { @@ -96,8 +96,6 @@ Rectangle splashBounds = splashScreen.getBounds(); int screenX = (int) splashBounds.getCenterX(); int screenY = (int) splashBounds.getCenterY(); - System.out.println(screenX); - System.out.println(screenY); Robot robot = new Robot(); Color splashScreenColor = robot.getPixelColor(screenX, screenY); --- old/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java 2016-08-26 12:09:46.027766999 +0530 +++ new/test/java/awt/SplashScreen/MultiResolutionSplash/MultiResolutionSplashTest.java 2016-08-26 12:09:45.787646999 +0530 @@ -43,7 +43,7 @@ /** * @test * @key headful - * @bug 8043869 8075244 8078082 8145173 + * @bug 8043869 8075244 8078082 8145173 8151787 * @summary Tests the HiDPI splash screen support for windows and MAC * @modules java.desktop/sun.java2d * @run main MultiResolutionSplashTest GENERATE_IMAGES @@ -56,27 +56,20 @@ private static final int IMAGE_WIDTH = 300; private static final int IMAGE_HEIGHT = 200; + private static boolean isMac; - private static final ImageInfo[] macTests = { + static { + isMac = System.getProperty("os.name").contains("OS X"); + } + private static final ImageInfo[] tests = { 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.contains("OS X")) { - tests = macTests; - } switch (test) { case "GENERATE_IMAGES": generateImages(); @@ -104,12 +97,10 @@ Rectangle splashBounds = splashScreen.getBounds(); int screenX = (int) splashBounds.getCenterX(); int screenY = (int) splashBounds.getCenterY(); - if (splashBounds.width != IMAGE_WIDTH) { throw new RuntimeException( "SplashScreen#getBounds has wrong width"); } - if (splashBounds.height != IMAGE_HEIGHT) { throw new RuntimeException( "SplashScreen#getBounds has wrong height"); @@ -117,7 +108,6 @@ Robot robot = new Robot(); Color splashScreenColor = robot.getPixelColor(screenX, screenY); - float scaleFactor = getScaleFactor(); Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x; @@ -129,7 +119,6 @@ static void testFocus() throws Exception { - System.out.println("Focus Test!"); Robot robot = new Robot(); robot.setAutoDelay(50); @@ -150,18 +139,18 @@ frame.dispose(); - if(!textField.getText().equals("ab")){ + if (!textField.getText().equals("ab")) { throw new RuntimeException("Focus is lost!"); } } - static boolean compare(Color c1, Color c2){ + static boolean compare(Color c1, Color c2) { return compare(c1.getRed(), c2.getRed()) && compare(c1.getGreen(), c2.getGreen()) && compare(c1.getBlue(), c2.getBlue()); } - static boolean compare(int n, int m){ + static boolean compare(int n, int m) { return Math.abs(n - m) <= 50; } @@ -177,10 +166,7 @@ public void paint(Graphics g) { float scaleFactor = 1; if (g instanceof SunGraphics2D) { - scaleFactor = (float)GraphicsEnvironment. - getLocalGraphicsEnvironment(). - getDefaultScreenDevice().getDefaultConfiguration(). - getDefaultTransform().getScaleX(); + scaleFactor = getScreenScaleFactor(); } scaleFactors[0] = scaleFactor; dialog.setVisible(false); @@ -197,23 +183,30 @@ static void generateImages() throws Exception { for (ImageInfo test : tests) { generateImage(test.name1x, test.color1x, 1); - generateImage(test.name2x, test.color2x, 2); + generateImage(test.name2x, test.color2x, getScreenScaleFactor()); } } - static void generateImage(String name, Color color, int scale) throws Exception { + static void generateImage(String name, Color color, float scale) throws Exception { File file = new File(name); if (file.exists()) { return; } - BufferedImage image = new BufferedImage(scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); + BufferedImage image = new BufferedImage((int) (scale * IMAGE_WIDTH), + (int) (scale * IMAGE_HEIGHT), BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setColor(color); - g.fillRect(0, 0, scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT); + g.fillRect(0, 0, (int) (scale * IMAGE_WIDTH), (int) (scale * IMAGE_HEIGHT)); ImageIO.write(image, "png", file); } + static float getScreenScaleFactor() { + return (float) GraphicsEnvironment. + getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(). + getDefaultTransform().getScaleX(); + } + static class ImageInfo { final String name1x; @@ -223,9 +216,32 @@ public ImageInfo(String name1x, String name2x, Color color1x, Color color2x) { this.name1x = name1x; - this.name2x = name2x; + if (!isMac) { + float scale = getScreenScaleFactor(); + StringBuffer buff = new StringBuffer(); + if (scale - (int) scale > 0) { + buff.append("@").append((int) (scale * 100)).append("pct"); + } else { + buff.append("@").append((int) scale).append("x"); + } + StringBuffer buffer = new StringBuffer(); + String[] splitStr = name1x.split("\\."); + if (splitStr.length == 2) { + this.name2x = buffer.append(splitStr[0]).append(buff) + .append(".").append(splitStr[1]).toString(); + } else { + if (name1x.indexOf(".") > 0) { + this.name2x = buffer.append(splitStr[0]).append(buff).append(".").toString(); + } else { + this.name2x = buffer.append(splitStr[0]).append(buff).toString(); + } + } + } else { + this.name2x = name2x; + } this.color1x = color1x; this.color2x = color2x; } } } +