test/sun/java2d/DirectX/OnScreenRenderingResizeTest/OnScreenRenderingResizeTest.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  72             } else  if ("-nocheck".equals(arg)) {
  73                 System.err.println("Test will not check rendering results");
  74                 nocheck = true;
  75             } else {
  76                 System.err.println("Usage: OnScreenRenderingResizeTest [-inf][-nocheck]");
  77             }
  78         }
  79 
  80         BufferedImage output =
  81             new BufferedImage(IMAGE_W, IMAGE_H, BufferedImage.TYPE_INT_RGB);
  82         output.setAccelerationPriority(0.0f);
  83         Graphics g = output.getGraphics();
  84         g.setColor(renderColor);
  85         g.fillRect(0, 0, output.getWidth(), output.getHeight());
  86 
  87         final Frame frame = new Frame("OnScreenRenderingResizeTest") {
  88             public void paint(Graphics g) {}
  89             public void update(Graphics g) {}
  90         };
  91         frame.setBackground(bgColor);

  92         frame.pack();
  93         frame.setSize(FRAME_W, FRAME_H);




  94         frame.addWindowListener(new WindowAdapter() {
  95             public void windowClosing(WindowEvent e) {
  96                 done = true;
  97             }
  98         });
  99         try {
 100             EventQueue.invokeAndWait(new Runnable() {
 101                 public void run() {
 102                     frame.setVisible(true);
 103                 }
 104             });
 105             // wait for Vista's effects to complete
 106             Thread.sleep(2000);
 107         } catch (Exception ex) {
 108             ex.printStackTrace();
 109         }
 110 
 111         GraphicsConfiguration gc = frame.getGraphicsConfiguration();
 112         int maxW = gc.getBounds().width /2;
 113         int maxH = gc.getBounds().height/2;
 114         int minW = frame.getWidth();
 115         int minH = frame.getHeight();
 116         int incW = 10, incH = 10, cnt = 0;
 117         Robot robot = null;
 118         if (!nocheck && gc.getColorModel().getPixelSize() > 8) {
 119             try {
 120                 robot = new Robot();
 121             } catch (AWTException ex) {
 122                 System.err.println("Robot creation failed, continuing.");
 123             }
 124         } else {
 125             System.err.println("No screen rendering checks.");
 126         }
 127 
 128         VolatileImage vi = gc.createCompatibleVolatileImage(512, 512);
 129         vi.validate(gc);
 130 
 131         long timeStarted = System.currentTimeMillis();
 132         while (!done && (System.currentTimeMillis() - timeStarted) < RUN_TIME) {
 133 


 138                     incW = -incW;
 139                 }
 140                 if (h < minH || h > maxH ) {
 141                     incH = -incH;
 142                 }
 143                 frame.setSize(w, h);
 144                 cnt = 0;
 145             }
 146 
 147             // try to put the device into non-default state, for example,
 148             // this operation below will set the transform
 149             vi.validate(gc);
 150             Graphics2D vig = (Graphics2D)vi.getGraphics();
 151             vig.rotate(30.0f, vi.getWidth()/2, vi.getHeight()/2);
 152             vig.drawImage(output, 0, 0,
 153                           vi.getWidth(), vi.getHeight(), null);
 154 
 155             Insets in = frame.getInsets();
 156             frame.getGraphics().drawImage(output, in.left, in.top, null);
 157             if (cnt == 90 && robot != null) {

 158                 // area where we blitted to should be either white or green
 159                 Point p = frame.getLocationOnScreen();
 160                 p.translate(in.left+10, in.top+10);
 161                 BufferedImage bi =
 162                     robot.createScreenCapture(
 163                         new Rectangle(p.x, p.y, IMAGE_W/2, IMAGE_H/2));
 164                 int accepted1[] = { Color.white.getRGB(), Color.green.getRGB()};
 165                 checkBI(bi, accepted1);
 166 
 167                 // the are where we didn't render should stay white
 168                 p = frame.getLocationOnScreen();
 169                 p.translate(in.left, in.top+IMAGE_H+5);
 170                 bi = robot.createScreenCapture(
 171                     new Rectangle(p.x, p.y,
 172                                   frame.getWidth()-in.left-in.right,
 173                                   frame.getHeight()-in.top-in.bottom-5-IMAGE_H));
 174                 int accepted2[] = { Color.white.getRGB() };
 175                 checkBI(bi, accepted1);
 176             }
 177 
 178             Thread.yield();
 179         }
 180         frame.dispose();
 181         System.out.println("Test Passed");
 182     }
 183 
 184     private static void checkBI(BufferedImage bi, int accepted[]) {
 185         for (int x = 0; x < bi.getWidth(); x++) {
 186             for (int y = 0; y < bi.getHeight(); y++) {
 187                 int pix = bi.getRGB(x, y);
 188                 boolean found = false;
 189                 for (int acc : accepted) {
 190                     if (pix == acc) {
 191                         found = true;
 192                         break;
 193                     }
 194                 }
 195                 if (!found) {
   1 /*
   2  * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  72             } else  if ("-nocheck".equals(arg)) {
  73                 System.err.println("Test will not check rendering results");
  74                 nocheck = true;
  75             } else {
  76                 System.err.println("Usage: OnScreenRenderingResizeTest [-inf][-nocheck]");
  77             }
  78         }
  79 
  80         BufferedImage output =
  81             new BufferedImage(IMAGE_W, IMAGE_H, BufferedImage.TYPE_INT_RGB);
  82         output.setAccelerationPriority(0.0f);
  83         Graphics g = output.getGraphics();
  84         g.setColor(renderColor);
  85         g.fillRect(0, 0, output.getWidth(), output.getHeight());
  86 
  87         final Frame frame = new Frame("OnScreenRenderingResizeTest") {
  88             public void paint(Graphics g) {}
  89             public void update(Graphics g) {}
  90         };
  91         frame.setBackground(bgColor);
  92         frame.setUndecorated(true);
  93         frame.pack();
  94 
  95         GraphicsConfiguration gc = frame.getGraphicsConfiguration();
  96         Rectangle gcBounds = gc.getBounds();
  97         frame.setBounds(gcBounds.width / 4, gcBounds.height / 4, FRAME_W, FRAME_H);
  98 
  99         frame.addWindowListener(new WindowAdapter() {
 100             public void windowClosing(WindowEvent e) {
 101                 done = true;
 102             }
 103         });
 104         try {
 105             EventQueue.invokeAndWait(new Runnable() {
 106                 public void run() {
 107                     frame.setVisible(true);
 108                 }
 109             });
 110             // wait for Vista's effects to complete
 111             Thread.sleep(2000);
 112         } catch (Exception ex) {
 113             ex.printStackTrace();
 114         }
 115 
 116         int maxW = gcBounds.width /2;
 117         int maxH = gcBounds.height/2;

 118         int minW = frame.getWidth();
 119         int minH = frame.getHeight();
 120         int incW = 10, incH = 10, cnt = 0;
 121         Robot robot = null;
 122         if (!nocheck && gc.getColorModel().getPixelSize() > 8) {
 123             try {
 124                 robot = new Robot();
 125             } catch (AWTException ex) {
 126                 System.err.println("Robot creation failed, continuing.");
 127             }
 128         } else {
 129             System.err.println("No screen rendering checks.");
 130         }
 131 
 132         VolatileImage vi = gc.createCompatibleVolatileImage(512, 512);
 133         vi.validate(gc);
 134 
 135         long timeStarted = System.currentTimeMillis();
 136         while (!done && (System.currentTimeMillis() - timeStarted) < RUN_TIME) {
 137 


 142                     incW = -incW;
 143                 }
 144                 if (h < minH || h > maxH ) {
 145                     incH = -incH;
 146                 }
 147                 frame.setSize(w, h);
 148                 cnt = 0;
 149             }
 150 
 151             // try to put the device into non-default state, for example,
 152             // this operation below will set the transform
 153             vi.validate(gc);
 154             Graphics2D vig = (Graphics2D)vi.getGraphics();
 155             vig.rotate(30.0f, vi.getWidth()/2, vi.getHeight()/2);
 156             vig.drawImage(output, 0, 0,
 157                           vi.getWidth(), vi.getHeight(), null);
 158 
 159             Insets in = frame.getInsets();
 160             frame.getGraphics().drawImage(output, in.left, in.top, null);
 161             if (cnt == 90 && robot != null) {
 162                 robot.waitForIdle();
 163                 // area where we blitted to should be either white or green
 164                 Point p = frame.getLocationOnScreen();
 165                 p.translate(in.left+10, in.top+10);
 166                 BufferedImage bi =
 167                     robot.createScreenCapture(
 168                         new Rectangle(p.x, p.y, IMAGE_W/2, IMAGE_H/2));
 169                 int accepted1[] = { Color.white.getRGB(), Color.green.getRGB()};
 170                 checkBI(bi, accepted1);
 171 
 172                 // the are where we didn't render should stay white
 173                 p = frame.getLocationOnScreen();
 174                 p.translate(in.left, in.top+IMAGE_H+5);
 175                 bi = robot.createScreenCapture(
 176                     new Rectangle(p.x, p.y,
 177                                   frame.getWidth()-in.left-in.right,
 178                                   frame.getHeight()-in.top-in.bottom-5-IMAGE_H));
 179                 int accepted2[] = { Color.white.getRGB() };
 180                 checkBI(bi, accepted2);
 181             }
 182 
 183             Thread.yield();
 184         }
 185         frame.dispose();
 186         System.out.println("Test Passed");
 187     }
 188 
 189     private static void checkBI(BufferedImage bi, int accepted[]) {
 190         for (int x = 0; x < bi.getWidth(); x++) {
 191             for (int y = 0; y < bi.getHeight(); y++) {
 192                 int pix = bi.getRGB(x, y);
 193                 boolean found = false;
 194                 for (int acc : accepted) {
 195                     if (pix == acc) {
 196                         found = true;
 197                         break;
 198                     }
 199                 }
 200                 if (!found) {