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

1.2RC1: copyArea is VERY slow in a container

    XMLWordPrintable

Details

    • 2d
    • 1.2.2
    • generic, x86
    • generic, solaris_2.6, windows_95, windows_nt

    Description



      Name: tb29552 Date: 11/11/98


      /*

      copyArea in 1.2RC1 seems to be several orders of magnitude slower in a
      container than it is with 1.1.7 or 1.1.6. This is EXTREMELY important
      to us as we use copyArea to scroll areas of our UI. In 1.1.7, scroll
      speed is fairly good. With 1.2, it is completely unacceptable.

      I've attached a sample program below. On 1.1.7, it can scroll about
      100 times a second. On 1.2, it scrolls about 5 times a second.

      */
      import java.awt.*;
      import java.awt.event.*;

      public class copyAreaTest extends Container implements Runnable {
          int top = 0;
          public copyAreaTest()
          {
              super();
              (new Thread(this)).start();
              Button bt = new Button("Hello");
              bt.setBounds(50, 10, 50, 22);
              bt.setVisible(false);
              add(bt);
          }

          public void update(Graphics g)
          {
              paint(g);
          }

          public void paint(Graphics g)
          {
              synchronized(this) {
                  Rectangle rct = g.getClipBounds();
                  g.setColor(Color.white);
                  g.fillRect(rct.x, rct.y, rct.width, rct.height);
                  g.setFont(getFont());
                  g.setColor(Color.black);

                  Dimension dm = size();
                  for (int y = 0; y <= (dm.height + 10); y += 20) {
                      if (y > rct.y) {
                          int z = y / 20 + top;
                          g.drawString("" + z, 10, y);
                      } /* endif */
                  } // endfor
              }
          }

          public void run()
          {
              while (1 == 1) {
                  Dimension dm = size();
                  if (dm != null && dm.width != 0 && dm.height != 0) {
                      synchronized(this) {
                          top++;
                          Graphics g = getGraphics();
                          g.copyArea(0, 20, dm.width, dm.height - 20, 0, -20);
                          g.setClip(0, dm.height - 20, dm.width, 20);
                          paint(g);
                          g.dispose();
                      }
                  } /* endif */
                  try {
                      Thread.sleep(1);
                  } catch(Exception ex) {
                      ex.printStackTrace();
                  }
              }
          }

          public static void main(String args[]) {
              Frame frm = new Frame("copyAreaTest");
              frm.add(new copyAreaTest());
              frm.addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent ev) {
                      System.exit(0);
                  }
              });
              frm.setSize(500, 500);
              frm.show();
          }
      }

      (Review ID: 42513)
      ======================================================================

      Attachments

        Activity

          People

            tnguyensunw Thanh Nguyen (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: