Write flickering free code

From AbiWiki

(Difference between revisions)
Jump to: navigation, search
 
Line 3: Line 3:
To enable double buffering for a certain section, you will first create a FV_ViewDoubleBuffering object (eg. dblBuffObj) and then enclose the code between dblBuffObj.beginDoubleBuffering() and dblBuffObj.endDoubleBuffering(). Now, let's take a look at those 3 parameters passed to the constructor:
To enable double buffering for a certain section, you will first create a FV_ViewDoubleBuffering object (eg. dblBuffObj) and then enclose the code between dblBuffObj.beginDoubleBuffering() and dblBuffObj.endDoubleBuffering(). Now, let's take a look at those 3 parameters passed to the constructor:
-
1. FV_View *pView
+
#FV_View *pView<br />This is a reference to the current view. It is used to determine the GR_Graphics object used for drawing and to record any FV_View::_draw calls that take place.
-
This is a reference to the current view. It is used to determine the GR_Graphics object used for drawing and to record any FV_View::_draw calls that take place.
+
#bool suspendDirectDrawing<br />This tells the object to discard any drawing that takes place between beginDoubleBuffering() and endDoubleBuffering() calls. Yes, I said discard. There are many functions (like insertSpan, for example) which have "drawing side effects": insertSpan() inserts a span and then draws something on the screen. When this is followed by a updateScreen(false), it is really useless.
-
 
+
#bool callDrawOnlyAtTheEnd<br />This tells the object to record FV_View::_draw calls between beginDoubleBuffering() and endDoubleBuffering() and call _draw only once, inside endDoubleBuffering() with the cumulative effect of all previous calls.
-
2. bool suspendDirectDrawing
+
-
This tells the object to discard any drawing that takes place between beginDoubleBuffering() and endDoubleBuffering() calls. Yes, I said discard. There are many functions (like insertSpan, for example) which have "drawing side effects": insertSpan() inserts a span and then draws something on the screen. When this is followed by a updateScreen(false), it is really useless.
+
-
 
+
-
3. bool callDrawOnlyAtTheEnd
+
-
This tells the object to record FV_View::_draw calls between beginDoubleBuffering() and endDoubleBuffering() and call _draw only once, inside endDoubleBuffering() with the cumulative effect of all previous calls.
+
For most functions, the following code works well enough:
For most functions, the following code works well enough:
-
<code>
+
<tt>
-
FV_ViewDoubleBuffering dblBuffObj(?, true, true);
+
FV_ViewDoubleBuffering dblBuffObj(?, true, true);<br />
dblBuffObj.beginDoubleBuffering();
dblBuffObj.beginDoubleBuffering();
-
</code>
+
</tt>
-
On the other side, sometimes, you will need to call dblBuffObj.endDoubleBuffering(); before the function returns and / or set suspendDirectDrawing / callDrawOnlyAtTheEnd to false. However, the combination "FV_ViewDoubleBuffering dblBuffObj(?, true, false);" is wrong, because it has no effect at all: it discards the _draw calls as well, resulting in no drawing (if you don't draw, what do you want to double buffer?).
+
On the other side, sometimes, you will need to call dblBuffObj.endDoubleBuffering(); before the function returns and / or set suspendDirectDrawing / callDrawOnlyAtTheEnd to false. However, the combination <tt>FV_ViewDoubleBuffering dblBuffObj(?, true, false);</tt> is wrong, because it has no effect at all: it discards the _draw calls as well, resulting in no drawing (if you don't draw, what do you want to double buffer?).

Current revision as of 16:44, 19 July 2011

The double buffering in AbiWord is meant to be managed by a FV_ViewDoubleBuffering object. One may find ways to avoid using FV_ViewDoubleBuffering and directly call the double buffering code in GR_Graphics / GR_Painter, but this isn't recommended.

To enable double buffering for a certain section, you will first create a FV_ViewDoubleBuffering object (eg. dblBuffObj) and then enclose the code between dblBuffObj.beginDoubleBuffering() and dblBuffObj.endDoubleBuffering(). Now, let's take a look at those 3 parameters passed to the constructor:

  1. FV_View *pView
    This is a reference to the current view. It is used to determine the GR_Graphics object used for drawing and to record any FV_View::_draw calls that take place.
  2. bool suspendDirectDrawing
    This tells the object to discard any drawing that takes place between beginDoubleBuffering() and endDoubleBuffering() calls. Yes, I said discard. There are many functions (like insertSpan, for example) which have "drawing side effects": insertSpan() inserts a span and then draws something on the screen. When this is followed by a updateScreen(false), it is really useless.
  3. bool callDrawOnlyAtTheEnd
    This tells the object to record FV_View::_draw calls between beginDoubleBuffering() and endDoubleBuffering() and call _draw only once, inside endDoubleBuffering() with the cumulative effect of all previous calls.

For most functions, the following code works well enough:

FV_ViewDoubleBuffering dblBuffObj(?, true, true);
dblBuffObj.beginDoubleBuffering();

On the other side, sometimes, you will need to call dblBuffObj.endDoubleBuffering(); before the function returns and / or set suspendDirectDrawing / callDrawOnlyAtTheEnd to false. However, the combination FV_ViewDoubleBuffering dblBuffObj(?, true, false); is wrong, because it has no effect at all: it discards the _draw calls as well, resulting in no drawing (if you don't draw, what do you want to double buffer?).

Personal tools