Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4323072

Graphics2D vector rendering causes 100% cpu for high magnification


    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
    • OS:


      Name: skT88420 Date: 03/18/2000

      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-004, native threads, symcjit)

      Please compile and run the following application. The app displays a simple
      polygon object in a canvas, and has a zoom button. When you click the button,
      you zoom 2 times closer to the object. Each time you zoom, the app displays
      the current zoom factor and the time in milliseconds that it took on the
      console. First few
      times to draw are less than 50 milliseconds on my machine, a pentium III
      laptop. By the time you zoom 128 times, the time is 130 ms, for 256 times it
      is 240 ms, and for 512 times the system hangs, never returns in my
      low-tolerance timeframe, and sends the cpu into 100%.

      Though you may think this frivolous, it is a vast simplification of a very
      realistic process that occurs in mapping - having background objects that are
      frequently shown at all magnification levels. This problem impacts very
      heavily when an end-user chooses to zoom way into a map, perhaps because
      other data only becomes visible at that magnification. Please, please, please
      fix it, or find us a workaround!
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.geom.*;
      import javax.swing.*;

      public class Frame extends JFrame
      private MyCanvas _canvas;

          public static void main(String args[]) {
              new Frame().setVisible(true);

      public Frame()
      addWindowListener(new MyWindowListener());
      getContentPane().setLayout(new BorderLayout());
      _canvas = new MyCanvas();
      getContentPane().add(_canvas, BorderLayout.CENTER);
      getContentPane().add(new MyButton(), BorderLayout.NORTH);

      private class MyWindowListener extends WindowAdapter {
      public void windowClosing(WindowEvent event) {

      private class MyActionListener implements ActionListener {
      public void actionPerformed(ActionEvent event) {

      private class MyButton extends JButton {
      MyButton() {
      addActionListener(new MyActionListener());

          class MyCanvas extends JComponent {
              private AffineTransform transform = new AffineTransform();
              private int xpts[] = { 100, 300, 400, 250, 200, 150, 0, 100 };
              private int ypts[] = { 0, 0, 200, 300, 150, 300, 200, 0 };
              private int npts = 8;
              private Polygon polygon = new Polygon(xpts, ypts, npts);
              private Point2D.Double src = new Point2D.Double();
              private Point2D.Double dst = new Point2D.Double();
              private final double zoomFactor = 2.0;
              private final double centreX = 200.0;
              private final double centreY = 150.0;
              private final double transformX = -centreX *0.5;
              private final double transformY = -centreY *0.5;
              void zoom() {
                  transform.translate(transformX, transformY);
              public void paintComponent(Graphics g) {
                  long t0 = System.currentTimeMillis();
              void showInfo(long time) {
                  System.out.println("zoom="+transform.getScaleX()+" time="+time);
              private void drawPolygon(Graphics2D g2) {
              private void transformPolygon() {
                  polygon = new Polygon();
                  for (int i = 0; i < npts; i++) {
                      src.setLocation((double)xpts[i], (double)ypts[i]);
                      polygon.addPoint((int)dst.x, (int)dst.y);
      (Review ID: 101797)


          Issue Links



              • Assignee:
                flar Jim Graham
                skonchad Sandeep Konchady
              • Votes:
                0 Vote for this issue
                0 Start watching this issue


                • Created: