test/java/awt/Cursor/MultiResolutionCursorTest/MultiResolutionCursorTest.java

Print this page

        

@@ -30,16 +30,21 @@
 import java.awt.Image;
 import java.awt.Label;
 import java.awt.Point;
 import java.awt.TextArea;
 import java.awt.Toolkit;
+import java.awt.geom.AffineTransform;
 import java.awt.image.BufferedImage;
 import java.util.LinkedList;
 import java.util.List;
 import javax.swing.JApplet;
 import sun.awt.OSInfo;
-import sun.awt.image.MultiResolutionImage;
+import java.awt.image.MultiResolutionImage;
+import sun.awt.image.ImageResolutionHelper;
+import sun.awt.image.ImageResolutionHelperType;
+import static sun.awt.image.ImageResolutionHelperType.DPI_AWARE;
+import static sun.awt.image.ImageResolutionHelperType.TRANSFORM_AWARE;
 
 /**
  * @test
  * @bug 8028212
  * @summary [macosx] Custom Cursor HiDPI support

@@ -117,11 +122,19 @@
                 highResolutionImages.add(highResolutionImage);
             }
         }
 
         @Override
-        public Image getResolutionVariant(int width, int height) {
+        public Image getResolutionVariant(float logicalDPIX, float logicalDPIY,
+                float baseWidth, float baseHeight, float destWidth, float destHeight) {
+            ImageResolutionHelper helper = getPlatformHelper();
+            float w = helper.getHiDPISize(logicalDPIX, baseWidth, destWidth);
+            float h = helper.getHiDPISize(logicalDPIY, baseHeight, destHeight);
+            return getResolutionVariant(w, h);
+        }
+
+        private Image getResolutionVariant(float width, float height) {
 
             for (int i = 0; i < sizes.length; i++) {
                 Image image = highResolutionImages.get(i);
                 int w = image.getWidth(null);
                 int h = image.getHeight(null);

@@ -143,10 +156,16 @@
 
         @Override
         public List<Image> getResolutionVariants() {
             return highResolutionImages;
         }
+
+        static ImageResolutionHelper getPlatformHelper() {
+            return OSInfo.OSType.WINDOWS.equals(OSInfo.getOSType())
+                    ? DPI_AWARE : TRANSFORM_AWARE;
+        }
+
     }
 }// class BlockedWindowTest
 
 /* Place other classes related to the test after this line */
 /**