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

SLOW Graphics performance in 1.2beta2

XMLWordPrintable

    • 2d
    • 1.2fcs
    • x86, sparc
    • solaris_2.6, windows_95
    • Not verified



      Name: rm29839 Date: 01/21/98


      BUG ONE: g.drawImage() is an order of magnatude slower in
      JDK 1.2beta2 compared to 1.1.4.

      BUG TWO: In JDK 1.2beta2, double buffering slows g.drawChars()
      by TWO orders of magnatude and "mucks up" the characters.
      Note: Double buffering uses a new BufferedImageGraphics2D class
      which appears to be unintentionally scaling the characters!




      import java.awt.*;
      import java.awt.event.*;
      import java.awt.image.*;

      /**
        * This class demonstrates slow Graphics class performance in
        * JDK 1.2beta2. <br>
        *
        * BUG ONE: g.drawImage() is an order of magnatude slower in
        * JDK 1.2beta2 compared to 1.1.4. <br>
        *
        * BUG TWO: In JDK 1.2beta2, double buffering slows g.drawChars()
        * by TWO orders of magnatude and "mucks up" the characters.
        * Note: Double buffering uses a new BufferedImageGraphics2D class
        * which appears to be unintentionally scaling the characters! <br>
        *
        * A mouse press toggles double buffering and calls repaint(). <br>
        *
        * Typical times on my Sparc 20 (Sol 2.6) running JDK 1.2beta2 (no JIT) are:
        *
        <pre>

      20 msec painting 200 chars with a sun.awt.motif.X11Graphics
      354 msec painting 200 8x8 images with a sun.awt.motif.X11Graphics
      379 in single buffered update()

      3109 msec painting 200 chars with a sun.awt.image.BufferedImageGraphics2D
      146 msec painting 200 8x8 images with a sun.awt.image.BufferedImageGraphics2D
      3261 in double buffered update()

        </pre>
        *
        * Typical times on my Sparc 20 (Sol 2.6) running JDK 1.1.4 are:
        *
        <pre>

      15 msec painting 200 chars with a sun.awt.motif.X11Graphics
      33 msec painting 200 8x8 images with a sun.awt.motif.X11Graphics
      51 in single buffered update()

      15 msec painting 200 chars with a sun.awt.motif.X11Graphics
      32 msec painting 200 8x8 images with a sun.awt.motif.X11Graphics
      51 in double buffered update()

        </pre>
        *
        * @author ###@###.###
        */
      class SlowGraphics extends Canvas
      {
              char ch[] = { 'A' };
              Image arrow;

              public SlowGraphics()
              {
                      // create a simple 8x8 image
                      //
                      int ARROW_WIDTH = 8, ARROW_HEIGHT = 8;

                      byte[] arrowOutline = { 0,0,0,1,1,0,0,0,
                                                      0,0,0,1,1,0,0,0,
                                                      0,0,0,1,1,0,0,0,
                                                      0,0,0,1,1,0,0,0,
                                                      1,1,1,1,1,1,1,1,
                                                      0,1,1,1,1,1,1,0,
                                                      0,0,1,1,1,1,0,0,
                                                      0,0,0,1,1,0,0,0 };

                      // red AARRGGBB
                      int tmp[] = new int[ARROW_HEIGHT * ARROW_WIDTH];
                      for (int i = 0 ; i < arrowOutline.length ; i++)
                              tmp[i] = ((arrowOutline[i] == 1) ? 0xffff0000
                                                              : 0x00ffffff);

                      ImageProducer redArrowSource;
                      redArrowSource = new MemoryImageSource(ARROW_WIDTH,
                                              ARROW_HEIGHT, tmp, 0, ARROW_WIDTH);
                      arrow = createImage(redArrowSource);


                      enableEvents(AWTEvent.MOUSE_EVENT_MASK);
              }

              Image im = null;
              boolean doubleBuffer = false;
              public void update(Graphics g)
              {
                      long start = System.currentTimeMillis();
                      if (doubleBuffer)
                      {
                              Dimension sz = getSize();
                              if (im == null)
                                      im = createImage(sz.width, sz.height);
                              Graphics og = im.getGraphics();

                              super.update(og);

                              g.drawImage(im, 0, 0, this);
                              og.dispose();
                      }
                      else
                      {
                              super.update(g);
                      }
                      long time = System.currentTimeMillis() - start;
                      System.err.println(time + " in "
                                      + (doubleBuffer ? "double" : "single")
                                      + " buffered update()\n");
              }

              public void paint(Graphics g)
              {
                      // call drawChars() 200 times, report time elapsed
                      //
                      long start = System.currentTimeMillis();
                      for (int i = 0; i < 200; i++)
                              g.drawChars(ch, 0, 1, 30, 20);
                      long time = System.currentTimeMillis() - start;
                      System.err.println(time + " msec painting 200 chars with a "
                                              + g.getClass().getName());

                      // call drawImage() 200 times, report time elapsed
                      //
                      start = System.currentTimeMillis();
                      for (int i = 0; i < 200; i++)
                              g.drawImage(arrow, 10, 10, this);
                      time = System.currentTimeMillis() - start;
                      System.err.println(time +" msec painting 200 8x8 images with a "+ g.getClass().getName());
              }

              public Dimension getPreferredSize() { return getSize(); }
              public Dimension getMinimumSize() { return getSize(); }

              protected void processMouseEvent(MouseEvent e)
              {
                      switch(e.getID())
                      {
                              // toggle double buffering
                              case MouseEvent.MOUSE_PRESSED:
                                      doubleBuffer = !doubleBuffer;
                                      repaint();
                              break;
                      }
                      super.processMouseEvent(e);
              }

              public static void main(String args[])
              {
                      Frame frame = new Frame();

                      Component c = new SlowGraphics();
                      c.setSize(100, 50);
                      frame.add(c);

                      frame.pack();
                      frame.show();
              }
      }
      (Review ID: 23390)
      ======================================================================

            jehung Jeannette Hung (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: