com.hdcookbook.grin.animator
Class RenderContext

java.lang.Object
  extended by com.hdcookbook.grin.animator.RenderContext

public abstract class RenderContext
extends java.lang.Object

This class represents a context for tracking the updates that will be needed to render the next frame of animation. It tracks areas that will need to be displayed, and areas that will need to be erased and then displayed. The animation framework collapses these areas into an optimized set.

Internally, two sets of "render area" targets are maintained, one set for erasing, and one set for drawing. Each target computes its bounding rectangle. Before erasing and before painting, the animation framework attempts to collapse these targets.


Constructor Summary
RenderContext()
           
 
Method Summary
abstract  void addArea(DrawRecord r)
          Add the given area to this render area, so that the animation manager knows about it.
abstract  void guaranteeAreaFilled(DrawRecord r)
          Guarantee that the given area will have all of its pixels filled (e.g.
abstract  int setTarget(int newTarget)
          Set the render area target for this context to direct its calls for adding areas.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RenderContext

public RenderContext()
Method Detail

addArea

public abstract void addArea(DrawRecord r)
Add the given area to this render area, so that the animation manager knows about it. The framework will erase any part of the area that needs it in this frame, cause drawing to any part of the area that needs it in this frame, and arrange to erase any part of the area that needs it in the next frame.

A given DrawRecord instance can't be added to a RenderContext more than once.


guaranteeAreaFilled

public abstract void guaranteeAreaFilled(DrawRecord r)
Guarantee that the given area will have all of its pixels filled (e.g. by Src mode drawing, or by drawing with fully opaque pixels). This information can be used to help optimize the areas that need to be erased - the current RenderArea to be erased can have this area removed from it.

If the fill-guarantee area doesn't result in the rectangular bounds of the erase area being reduced, it probably won't help. At least in the first implementation, only removal of a complete slice of the bounding rectangle of a RenderArea is effective.

It's OK to call this method for an area that hasn't changed since the last frame of drawing. The area in question will only be drawn to if requested by a call to one of the other methods.

A given DrawRecord instance can't be added to a RenderContext more than once. It also can't be used for both addArea() and guaranteeAreaFilled().


setTarget

public abstract int setTarget(int newTarget)
Set the render area target for this context to direct its calls for adding areas. Callers of this method should restore the target to the old value when done, to put the RenderContext back in a consistent state.

A typical scene should usually have a small number of targets, like between one and maybe four. See the discussion in AnimationClient.addDisplayAreas(RenderContext) for a more in-depth discussion of this.

Parameters:
newTarget - The draw target number, obtained from mapDrawTargets
Returns:
the old target number
See Also:
AnimationClient.addDisplayAreas(RenderContext), AnimationClient.mapDrawTargets(java.util.Hashtable)