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

You should coalesce PAINT and UPDATE events to make java faster

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • client-libs
    • generic
    • generic



      Name: boT120536 Date: 12/06/2000


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

      You can use the attached demo and try the following:

      1) Make the window bigger
      =========================

      You can see on the console that there has been a
      PaintEvent of type PAINT and a PaintEvent of type
      UPDATE.
      These 2 PaintEvents should be coalesced.

      I think the problem is in the class
      java.awt.EventQueue
      in method
      private void postEvent(AWTEvent theEvent, int priority)

      .
      .
      .
      .
      // For Component source events, traverse the entire list,
      // trying to coalesce events
      if (source instanceof Component) {
          EventQueueItem q = queues[priority].head;

      for (;;) {
          if (q.id == newItem.id && q.event.getSource() == source) {
      .
      .
      .
      .

      You can see that the condition q.id == newItem.id inhibits
      coalescing of a paint followed by an update event even if the
      update area covers completely the paint area. The result is
      that the window is painted, immediately after that the window is
      erased and the window is painted once more.


      2) Make the window smaller
      ==========================

      You can see on the console that there are 2 consecutive
      PaintEvent of type UPDATE.
      These 2 PaintEvents should be coalesced otherwise the
      window is erased painted erased again and painted again.
      This is not only slow but creates also an annoying
      flickering. Unfortunatedly i was'nt able to find the
      source of this behaviour.


      The demo - program
      ====================================================

      import java.awt.*;
      import java.awt.event.*;
      import java.awt.font.*;
      import java.awt.geom.*;
      import javax.swing.*;

      public class PaintCoalescing extends JComponent
      {
      public Dimension getPreferredSize()
      {
      return new Dimension(300, 160);
      }

      public void paintComponent(Graphics g)
      {
      Color origC = g.getColor();
      g.setColor(Color.white);
      g.fillRect(0, 0, getWidth(), getHeight());
      g.setColor(Color.black);
      g.drawString("Hello word", 40, 60);
      g.setColor(origC);
      }

      public static void main(String[] args)
      {
      Toolkit.getDefaultToolkit().addAWTEventListener(
      new AWTEventListener()
      {
      /**
      * Invoked when an event is dispatched in the AWT.
      */
      public void eventDispatched(AWTEvent event)
      {
      System.out.println(event);
      }
      },
      AWTEvent.PAINT_EVENT_MASK
      );
      JFrame fr = new JFrame();
      fr.getContentPane().add(new PaintCoalescing());
      fr.pack();
      fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      fr.setTitle("Paint coalescing");
      fr.setVisible(true);
      }
      }
      (Review ID: 113278)
      ======================================================================

            ehawkessunw Eric Hawkes (Inactive)
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: