Only dirty regions in the MediaOverlay corresponding to its actual media.

Since its dirty regions propagate out to the repaint manager, a big update
there would lead to dirty calls ping-ponging back and forth for a few cycles.



git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@600 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Charlie Groves
2008-08-04 23:38:12 +00:00
parent 78cab07b78
commit 5567dcf2a1
5 changed files with 54 additions and 30 deletions
@@ -382,7 +382,7 @@ public class ActiveRepaintManager extends RepaintManager
// we also need to repaint any components in this layer that are above our freshly // we also need to repaint any components in this layer that are above our freshly
// repainted component // repainted component
fmgr.renderLayers((Graphics2D)g, ocomp, _cbounds, _clipped); fmgr.renderLayers((Graphics2D)g, ocomp, _cbounds, _clipped, drect);
} else if (root != null) { } else if (root != null) {
if (DEBUG) { if (DEBUG) {
@@ -411,8 +411,8 @@ public abstract class FrameManager
} }
// tick all of our frame participants // tick all of our frame participants
for (int ii = 0; ii < _participants.length; ii++) { for (Object _participant : _participants) {
FrameParticipant part = (FrameParticipant)_participants[ii]; FrameParticipant part = (FrameParticipant)_participant;
if (part == null) { if (part == null) {
continue; continue;
} }
@@ -467,8 +467,8 @@ public abstract class FrameManager
{ {
// paint our frame participants (which want to be handled specially) // paint our frame participants (which want to be handled specially)
int painted = 0; int painted = 0;
for (int ii = 0; ii < _participants.length; ii++) { for (Object _participant : _participants) {
FrameParticipant part = (FrameParticipant)_participants[ii]; FrameParticipant part = (FrameParticipant)_participant;
if (part == null) { if (part == null) {
continue; continue;
} }
@@ -513,7 +513,7 @@ public abstract class FrameManager
// render any components in our layered pane that are not in the default layer // render any components in our layered pane that are not in the default layer
_clipped[0] = false; _clipped[0] = false;
renderLayers(gfx, pcomp, _tbounds, _clipped); renderLayers(gfx, pcomp, _tbounds, _clipped, _tbounds);
if (HANG_DEBUG) { if (HANG_DEBUG) {
long delay = (System.currentTimeMillis() - start); long delay = (System.currentTimeMillis() - start);
@@ -551,8 +551,8 @@ public abstract class FrameManager
* Renders all components in all {@link JLayeredPane} layers that intersect the supplied * Renders all components in all {@link JLayeredPane} layers that intersect the supplied
* bounds. * bounds.
*/ */
protected void renderLayers (Graphics2D g, Component pcomp, protected void renderLayers (Graphics2D g, Component pcomp, Rectangle bounds,
Rectangle bounds, boolean[] clipped) boolean[] clipped, Rectangle dirty)
{ {
JLayeredPane lpane = JLayeredPane.getLayeredPaneAbove(pcomp); JLayeredPane lpane = JLayeredPane.getLayeredPaneAbove(pcomp);
if (lpane != null) { if (lpane != null) {
@@ -565,7 +565,7 @@ public abstract class FrameManager
// if we have a MediaOverlay, let it know that any sprites in this region need to be // if we have a MediaOverlay, let it know that any sprites in this region need to be
// repainted as the components beneath them have just been redrawn // repainted as the components beneath them have just been redrawn
if (_overlay != null) { if (_overlay != null) {
_overlay.addDirtyRegion(new Rectangle(bounds)); _overlay.addDirtyRegion(dirty);
} }
} }
@@ -24,6 +24,7 @@ package com.threerings.media;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.util.List; import java.util.List;
import javax.swing.JRootPane; import javax.swing.JRootPane;
import com.threerings.media.animation.Animation; import com.threerings.media.animation.Animation;
@@ -122,12 +123,18 @@ public class MediaOverlay
} }
/** /**
* Adds a dirty region to this overlay. Note: control of the rectangle is granted to our * Adds a dirty region to this overlay.
* underlying {@link RegionManager} which may bend, fold or mutilate it.
*/ */
public void addDirtyRegion (Rectangle rect) public void addDirtyRegion (Rectangle rect)
{ {
_metamgr.getRegionManager().addDirtyRegion(rect); // Only add dirty regions where rect intersects our actual media as the set region will
// propagate out to the repaint manager.
for (AbstractMedia media : _metamgr) {
Rectangle intersection = media.getBounds().intersection(rect);
if (!intersection.isEmpty()) {
_metamgr.getRegionManager().addDirtyRegion(intersection);
}
}
} }
/** /**
@@ -163,10 +170,10 @@ public class MediaOverlay
} }
Rectangle[] dirty = _metamgr.getRegionManager().getDirtyRegions(); Rectangle[] dirty = _metamgr.getRegionManager().getDirtyRegions();
for (int ii = 0; ii < dirty.length; ii++) { for (Rectangle element : dirty) {
gfx.setClip(dirty[ii]); gfx.setClip(element);
_metamgr.paintMedia(gfx, MediaConstants.BACK, dirty[ii]); _metamgr.paintMedia(gfx, MediaConstants.BACK, element);
_metamgr.paintMedia(gfx, MediaConstants.FRONT, dirty[ii]); _metamgr.paintMedia(gfx, MediaConstants.FRONT, element);
} }
return true; return true;
} }
@@ -21,24 +21,28 @@
package com.threerings.media; package com.threerings.media;
import java.util.Arrays; import static com.threerings.media.Log.log;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.util.Arrays;
import java.util.Iterator;
import com.google.common.collect.Iterators;
import com.samskivert.swing.Label;
import com.samskivert.util.IntListUtil; import com.samskivert.util.IntListUtil;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.media.sprite.Sprite; import com.samskivert.swing.Label;
import com.threerings.media.sprite.SpriteManager;
import com.threerings.media.animation.Animation; import com.threerings.media.animation.Animation;
import com.threerings.media.animation.AnimationManager; import com.threerings.media.animation.AnimationManager;
import com.threerings.media.sprite.Sprite;
import static com.threerings.media.Log.log; import com.threerings.media.sprite.SpriteManager;
import com.threerings.media.timer.MediaTimer;
/** /**
* Coordinates interaction between a sprite and animation manager and the media host that hosts and * Coordinates interaction between a sprite and animation manager and the media host that hosts and
@@ -47,7 +51,7 @@ import static com.threerings.media.Log.log;
* functionality, we're constrained by all the extant usages and derivations. * functionality, we're constrained by all the extant usages and derivations.
*/ */
public class MetaMediaManager public class MetaMediaManager
implements MediaConstants implements MediaConstants, Iterable<AbstractMedia>
{ {
public MetaMediaManager (FrameManager framemgr, MediaHost host) public MetaMediaManager (FrameManager framemgr, MediaHost host)
{ {
@@ -332,6 +336,11 @@ public class MetaMediaManager
_spritemgr.viewLocationDidChange(dx, dy); _spritemgr.viewLocationDidChange(dx, dy);
} }
public Iterator<AbstractMedia> iterator ()
{
return Iterators.concat(_spritemgr.enumerateSprites(), _animmgr.iterator());
}
/** The frame manager with whom we register. */ /** The frame manager with whom we register. */
protected FrameManager _framemgr; protected FrameManager _framemgr;
@@ -21,6 +21,8 @@
package com.threerings.media.animation; package com.threerings.media.animation;
import java.util.Iterator;
import com.samskivert.util.SortableArrayList; import com.samskivert.util.SortableArrayList;
import com.threerings.media.AbstractMedia; import com.threerings.media.AbstractMedia;
@@ -31,6 +33,7 @@ import com.threerings.media.AbstractMediaManager;
* generating events when animations finish and suchlike. * generating events when animations finish and suchlike.
*/ */
public class AnimationManager extends AbstractMediaManager public class AnimationManager extends AbstractMediaManager
implements Iterable<Animation>
{ {
/** /**
* Registers the given {@link Animation} with the animation manager for ticking and painting. * Registers the given {@link Animation} with the animation manager for ticking and painting.
@@ -50,6 +53,11 @@ public class AnimationManager extends AbstractMediaManager
removeMedia(anim); removeMedia(anim);
} }
public Iterator<Animation> iterator ()
{
return _anims.iterator();
}
@Override @Override
protected void tickAllMedia (long tickStamp) protected void tickAllMedia (long tickStamp)
{ {