News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Flicker reduction drawing strategy

Started by Biterider, May 25, 2021, 04:02:46 AM

Previous topic - Next topic

LiaoMi

Hi jj2007,

when scrolling the text has at least 3 additional frames, the text is displayed with a soapy effect. The top border causes flickering at the bottom region of the window when resized. With general resizing, there is a green flicker in the background of the program  :rolleyes:

LiaoMi


We can visually see the flicker, if we use the program screentogif, in this program, you can change the recording rate and view the rendering by frame. By combining this data with the obtained measurements, then we can draw conclusions about the performance.
https://www.screentogif.com/
https://github.com/NickeManarin/ScreenToGif/releases/download/2.30/ScreenToGif.2.30.Portable.zip

@jj2007
Flickering of the text while scrolling could not be confirmed. This is probably an optical illusion - https://en.wikipedia.org/wiki/Optical_illusion
The rest of the flickering was confirmed, you can look at the picture.

LiaoMi


LiaoMi

If you compare both results, you can see that there are the same patterns. The sequence of drawing is visible, areas that were processed separately are visible. The new concept shows black artifacts and more shifts in the transform window. In the regular form, this effect appears less often and the transformation of the window is more often limited to one drawing, if we consider this event to be atomic. Visually, I did not see any difference with my own eyes.

The only technique that can remove flicker is double buffering  :tongue:

jj2007

Quote from: LiaoMi on May 25, 2021, 08:58:56 PMhttps://github.com/NickeManarin/ScreenToGif/releases/download/2.30/ScreenToGif.2.30.Portable.zip
That one asks for dotnot 4.8 :sad:

QuoteFlickering of the text while scrolling could not be confirmed. This is probably an optical illusion - https://en.wikipedia.org/wiki/Optical_illusion
The rest of the flickering was confirmed, you can look at the picture.

I didn't say the text flickers. The RichEdit control is quite good at that, actually. The embedded simple edit control does flicker a bit, and this is normal for edit controls.

daydreamer

Quote from: LiaoMi on May 25, 2021, 10:37:48 PM
If you compare both results, you can see that there are the same patterns. The sequence of drawing is visible, areas that were processed separately are visible. The new concept shows black artifacts and more shifts in the transform window. In the regular form, this effect appears less often and the transformation of the window is more often limited to one drawing, if we consider this event to be atomic. Visually, I did not see any difference with my own eyes.

The only technique that can remove flicker is double buffering  :tongue:
there are some more advanced api's that let you wait for vertical retrace,disadvantage to draw in order opposite direction than screen output to monitor
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

HSE

Quote from: jj2007 on May 25, 2021, 10:08:28 AM
Tested, no effect. I bet that SetWindowPos uses MoveWindow under the hood :cool:
SetWindowPos allow a lot of flags, but apparently nothing for this problem.

Quote from: jj2007 on May 25, 2021, 07:39:20 PM
If I take away the vertical scrollbar by omitting WS_VSCROLL from the style during CreateWindowEx, and then enable it afterwards with SetWindowLong
:thumbsup:
Equations in Assembly: SmplMath

HSE

Perhaps is for here?:
QuoteThe DeferWindowPos function updates the specified multiple-window - position structure for the specified window. The function then returns the handle to the updated structure. The EndDeferWindowPos function uses the information in this structure to change the position and size of a number of windows simultaneously. The BeginDeferWindowPos function creates the structure.
Equations in Assembly: SmplMath

Biterider

Hi HSE
Dynamic layouts use DeferWindowPos to reposition all controls at once.

Biterider

LiaoMi

Quote from: HSE on May 26, 2021, 01:25:20 AM
Perhaps is for here?:
QuoteThe DeferWindowPos function updates the specified multiple-window - position structure for the specified window. The function then returns the handle to the updated structure. The EndDeferWindowPos function uses the information in this structure to change the position and size of a number of windows simultaneously. The BeginDeferWindowPos function creates the structure.

Hi HSE,

Wm_size Edit flicker - http://masm32.com/board/index.php?topic=7668.msg83761#msg83761 and http://masm32.com/board/index.php?topic=7668.msg83780#msg83780

case WM_ENTERSIZEMOVE:
SendMessage(hEdit, WM_SETREDRAW, 0, 0);
return TRUE;
case WM_EXITSIZEMOVE: {
SendMessage(hEdit, WM_SETREDRAW, 1, 0);
RedrawWindow(hwndDlg, NULL, NULL, RDW_INVALIDATE | RDW_ERASE);
}
return TRUE;

HSE

Quote from: Biterider on May 26, 2021, 01:52:13 AM
Dynamic layouts use DeferWindowPos to reposition all controls at once.
Ok. Then that don't solve very much.

Quote from: LiaoMi on May 26, 2021, 01:56:31 AM
Wm_size Edit flicker
That could be usefull  :thumbsup:, just I don't know how  :cool:
Equations in Assembly: SmplMath

jj2007

Quote from: Biterider on May 26, 2021, 01:52:13 AM
Dynamic layouts use DeferWindowPos to reposition all controls at once.

That's an interesting option. I use MoveWindow, ..., 1 to reposition all controls in a loop. Perhaps DeferWindowPos is faster or less flickery, I'll have to look into that - thanks for the hint :thup:

Attached a debug version of my demo, demonstrating why the richedit's vertical scrollbar is jumping up and down - btw only for horizontal sizing. The cause is found (it's a bug in the control) but so far no therapy in sight :sad:

Btw invoke SendMessage, hMyEdit, WM_SETREDRAW, 0, 0 is not a valid option, it just looks ugly :sad:

Event Message
  .if uMsg_==WM_ENTERSIZEMOVE
invoke GetScrollInfo, hMyEdit, SB_VERT, addr sinf
fdeb 4, "start sizing", sinf.nMin, sinf.nMax, sinf.nPage, sinf.nPos, sinf.nTrackPos
  .elseif uMsg_==WM_SIZING
invoke GetScrollInfo, hMyEdit, SB_VERT, addr sinf
fdeb 4, "GetScrollInfo", sinf.nMax
  .elseif uMsg_==WM_EXITSIZEMOVE
invoke GetScrollInfo, hMyEdit, SB_VERT, addr sinf
fdeb 4, "end sizing", sinf.nMin, sinf.nMax, sinf.nPage, sinf.nPos, sinf.nTrackPos
  .endif

hutch--

There is a magic rule, do not layer windows that independently update their client area. A bare window with the background colour set in the WNDCLASSEX does not flicker. If you put another window over it, then set the base window to 0 or a transparent background. If you need to have multiple windows, ensure that what is under them has the update turned off. It makes the layout a bit more complicated but done right, you will have no flicker at all.

jj2007

Hutch,

That is all correct, but the WS_CLIPCHILDREN style should take care of that. My experience is that certain controls behave worse than others. The RichEdit control, for example, remains pretty smooth, except that there is that jumping vertical scrollbar. Edit and static controls, otoh, do flicker when you resize them. Not much, but it's clearly visible.

GuiParas equ xr0, y0, w880, h-1, b Red ; right-aligned, on top, 88% width, red background
GuiMenu equ @File, &Open, &Save, -, E&xit, @Edit, Undo, Copy, Paste
include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyEdit, "richedit", FileRead$(98), bcol LiteBlueGreen, x100, w800, y50, h250, wrap
  GuiControl MyRich, "edit", FileRead$(99), bcol White, x100, w800, y350, h250
  GuiControl MyStatic, "static", FileRead$(99), bcol LiteYellow, x100, w800, y650, h250
GuiEnd


The attached executables are built once with the WS_CLIPCHILDREN style, once without. The difference is obvious. Still, even with WS_CLIPCHILDREN set, the ordinary edit and static controls do flicker a little bit, only the RichEdit control stays smooth.