Microchip Technology AC164127-9 Data Sheet

Page of 34
AN1368
DS01368A-page 30
 2011 Microchip Technology Inc.
APPENDIX B:
DOUBLE-BUFFERING
Manipulating pixels on the screen requires direct writes
to the frame buffer. While these changes are being
executed, the screen is also refreshed. This means that
the changes are displayed immediately as the frame
buffer is being updated. This is not a suitable scheme
when the changes are slow, for example, decoding an
image or having a large number of widgets on a screen.
The display may appear slow in that case and can
cause user dissatisfaction.
One solution to this problem is to use a double-buffering
scheme supported by the Microchip Graphics Library. In
this scheme, the changes are not directly written to the
frame buffer, but instead, they are written to a separate
buffer, called the ‘Draw Buffer’. After all the changes are
made, the draw buffer and frame buffer are exchanged.
Now the draw buffer becomes the frame buffer, and
because of all the changes drawn there, the changes
appear spontaneous to the user. Of course, there will be
a delay, as all the changes have to be written to the draw
buffer before displaying it. This delay is generally more
tolerable than displaying the changes slowly.
After exchanging of the buffers, the latest buffer (which
is now the frame buffer) is copied to the new draw buf-
fer in the background, then the new draw buffer is in
sync with what is being displayed. New changes are
then written to the draw buffer and the cycle continues.
As the double-buffering scheme uses two buffers, the
RAM requirement will double.
In the Microchip Graphics Library, if double-buffering is
enabled, the frame buffer and draw buffer are
exchanged after the changes of all the widgets on a
screen are done (i.e., the new screen appears after the
whole screen is updated and not after updating an
individual widget).
The workflow of double-buffering is as follows:
1.
In the initial stage, the draw buffer and frame buffer
have the same contents, as shown in 
.
FIGURE B-1:
INITIAL STAGE
2.
In the drawing stage, only the draw buffer is
modified, and therefore, the frame buffer is not
visible to the user, as shown in 
.
FIGURE B-2:
DRAWING STAGE
3.
In the swap stage, the draw buffer is swapped
with the frame buffer (by exchange of pointers),
as shown in 
FIGURE B-3:
SWAP STAGE
4.
In the final stage, the frame buffer is copied to
the draw buffer, so the buffers have the same
contents, as shown in 
.
FIGURE B-4:
FINAL STAGE
5.
The workflow cycle continues.
When to Use Double-Buffering?
Use double-buffering when:
• There are large numbers of widgets on a screen
• The decoding and displaying of images are 
required
• The display resolution is larger than the WQVGA, 
even if the above points do not hold true
When Not to Use Double-Buffering?
Do not use double-buffering when:
• The immediate display of changes is required. For 
example, plotting a graph.
• The RAM available for display is limited.
• The display resolution is smaller than the 
WQVGA (this is not a hard rule).
How to Use Double-Buffering?
Double-buffering can be used as follows:
• Enable double-buffering by defining, 
USE_DOUBLE_BUFFERING
 in the 
GraphicsConfig.h
.
• See the section on double-buffering in the 
Microchip Graphics Library Help file for code 
examples.
Draw Buffer
Frame Buffer
Draw Buffer
Frame Buffer
Draw Buffer
Frame Buffer
Exchange
Frame Buffer
Draw Buffer
Copy