Certain applications can use layers to
display a static background on top of which “live” graphic objects
will be drawn and manipulated by the user.
In this type of application, the graphic
objects taking part in the background are static and are not
modified by the user or the application. Thus, it is possible to
draw just once for all of the layers constituting the graphic
background. This increases the drawing speed of the application.
The process is called triple
buffering. This term is used because the layers will be drawn in
an additional off screen image. Thereafter, when the view needs to
be redrawn, this image is used instead of redrawing the graphic
objects.
Note
Unlike double buffering, triple buffering is not
engaged to remove flickering but to increase the drawing speed.
Double and triple buffering can be used together.
For an instance of
IlvManagerView
, it is possible to indicate that a certain number of layers will
be part of the triple buffering.
This is done using the following method of
IlvManagerView
:
void setTripleBufferedLayerCount(int n)
When this method is called, layers with
indices between 0 and n-1 (the nth background layers) will be
triple buffered.
Once the method is called and the view has
been painted once, further modifications to graphic objects will
not be rendered on the screen, since only the triple buffer image
will be displayed.
Note that the triple buffer will be updated
only when:
- The transformer of the view changes (you are zooming or panning the view).
- You add or remove layers.
- You change the number of triple-buffered layers.
- The triple-buffered layer visibility changes.
- You add graphic objects to or remove them from the triple-buffered layers.
- You call applyToObject to make changes to the triple-buffered graphic objects on the triple-buffered layers.NoteSome interactors, such as the reshape interactor, call this function. Therefore, when you reshape a graphic object on a triple-buffered layer with the mouse, the triple buffer is invalidated.
- You change the visibility of the graphic objects on the triple-buffered layers.
- You change the triple-buffered layer on which the graphic objects are positioned.
If for any reason you need to update the
triple buffer, you can use these methods:
void invalidateTripleBuffer(boolean repaint) void invalidateTripleBuffer(IlvRect rect, boolean repaint)
To summarize, an application will use triple
buffering when the contents of background layers are static, and
when the application does not require the user to zoom and pan
frequently.