classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Swing painting reworked


From: Roman Kennke
Subject: [cp-patches] FYI: Swing painting reworked
Date: Fri, 14 Oct 2005 22:07:26 +0000

Hi,

I decided to commit my painting work. I tested this with various apps and
had no problems so far. And we have CVS and a bunch of good developers,
peer review and all that. Somebody is going to scream anyway ;-)

So here is what has changed:
- The RepaintManager now uses HashMaps and ArrayLists instead of
Hashtables and Vectors. This avoids some unnecessary synchronizing.
- When the work request is actually done, we switch the data structures
with work datastructures, so that the eventthread can work with these
structures, while application threads can call repaint() and repaint()
unblocked. Otherwise the application threads would possibly be blocked
when the RepaintWorker is active. This is significant on some slow
hardware, where painting actually takes time (we have a graphics card
here that needs 700ms alone to map a backbuffer to the screen!)
- The RepaintManager now simply calls paintImmediatly for each dirty
region. The optimization here happens in JComponent: Each time a paint()
method exits, it sets the component completelyClean, so it is not
painted again within the same work request.
- paintImmediatly now searches its paint root more sensibly, using the
opaque and optimizedDrawingEnabled properties. So we don't always go up
to the JRootPane but instead only paint what is really needed, taking
the opaqueness and potentially overlapping components into account
- the paint requests are performed in an ordered fashion, components that
are higher in the containment hierarchy are painted first, the lower
level components last. This way, it is quite likely that the lower level
components are marked clean during painting the higher level components.

I think that's all.

2005-10-14  Roman Kennke  <address@hidden>

        * javax/swing/JComponent.java
        (paintLock): Removed unneeded field.
        (isCompletelyDirty): New field.
        (setBorder): Don't get active if actual value didn't change.
        Otherwise trigger a repaint.
        (paint): Mark this component as clean after painting when the clip
        covered the whole component.
        (paintImmediately): Find more sensible paint root via new helper
        methods.
        (paintDoubleBuffered): Don't synchronize here.
        (setFont): Don't get active if actual value didn't change.
        Otherwise trigger a repaint and revalidate.
        (setBackground): Don't get active if actual value didn't change.
        Otherwise trigger a repaint.
        (setForeground): Don't get active if actual value didn't change.
        Otherwise trigger a repaint.
        (setUI): Trigger a repaint.
        (findPaintRoot): New helper method.
        (findOverlapFreeParent): New helper method.
        (findOpaqueParent): New helper method.
        * javax/swing/RepaintManager.java
        (ComponentComparator): New inner class. Used to sort components
        according to their depth in the containment hierarchy.
        (dirtyComponents): Use HashMap instead of Hashtable.
        (workDirtyComponents): New field.
        (repaintOrder): New field.
        (workRepaintOrder): New field.
        (comparator): New field.
        (invalidComponents): Use ArrayList instead of Vector.
        (workInvalidComponents): New field.
        (RepaintManager): Initialize new fields.
        (removeInvalidComponent): Adjusted for ArrayList.
        (addDirtyRegion): Return if component in question is not showing.
        Insert the new component in the repaintOrder list.
        (insertRepaintOrder): New method. Maintains a sorted list of
        components.
        (getDirtyRegion): Return empty Rectangle instead of null when
        component is not dirty, as specified.
        (markCompletelyDirty): Set flag in JComponent.
        (markCompletelyClean): Synchronize access to fields.
        (isCompletelyDirty): Use flag in JComponent to determine this
        property.
        (validateInvalidComponents): Use workInvalidComponents when
        revalidating. This avoids blocking of application threads
        in revalidate() calls.
        (paintDirtyRegion): Use work* fields when
        repainting. This avoids blocking of application threads
        in repaint() calls. Simplify actual work, now we simply call
        paintImmediatly() on the dirty components.

/Roman

Attachment: Swing-Painting.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]