Author Topic: Flicker reduction drawing strategy  (Read 1872 times)

LiaoMi

  • Member
  • ****
  • Posts: 922
Re: Flicker reduction drawing strategy
« Reply #15 on: May 25, 2021, 08:08:37 PM »
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

  • Member
  • ****
  • Posts: 922
Re: Flicker reduction drawing strategy
« Reply #16 on: May 25, 2021, 08:58:56 PM »

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

  • Member
  • ****
  • Posts: 922
Re: Flicker reduction drawing strategy
« Reply #17 on: May 25, 2021, 10:17:47 PM »
Hi Biterider,

here is the test ...

LiaoMi

  • Member
  • ****
  • Posts: 922
Re: Flicker reduction drawing strategy
« Reply #18 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:

jj2007

  • Member
  • *****
  • Posts: 11552
  • Assembler is fun ;-)
    • MasmBasic
Re: Flicker reduction drawing strategy
« Reply #19 on: May 25, 2021, 10:47:13 PM »
https://github.com/NickeManarin/ScreenToGif/releases/download/2.30/ScreenToGif.2.30.Portable.zip
That one asks for dotnot 4.8 :sad:

Quote
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.

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

  • Member
  • *****
  • Posts: 1721
  • building nextdoor
Re: Flicker reduction drawing strategy
« Reply #20 on: May 25, 2021, 11:29:02 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
 
SIMD fan and macro fan
why assembly is fastest is because its switch has no (brakes) breaks
:P
only in 16bit assembly you can get away with "Only words" :P

HSE

  • Member
  • *****
  • Posts: 1745
  • <AMD>< 7-32>
Re: Flicker reduction drawing strategy
« Reply #21 on: May 25, 2021, 11:47:41 PM »
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.

If I take away the vertical scrollbar by omitting WS_VSCROLL from the style during CreateWindowEx, and then enable it afterwards with SetWindowLong
:thumbsup:

HSE

  • Member
  • *****
  • Posts: 1745
  • <AMD>< 7-32>
Re: Flicker reduction drawing strategy
« Reply #22 on: May 26, 2021, 01:25:20 AM »
Perhaps is for here?:
Quote
The 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.

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 729
  • ObjAsm Developer
    • ObjAsm
Re: Flicker reduction drawing strategy
« Reply #23 on: May 26, 2021, 01:52:13 AM »
Hi HSE
Dynamic layouts use DeferWindowPos to reposition all controls at once.

Biterider

LiaoMi

  • Member
  • ****
  • Posts: 922
Re: Flicker reduction drawing strategy
« Reply #24 on: May 26, 2021, 01:56:31 AM »
Perhaps is for here?:
Quote
The 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

Code: [Select]
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

  • Member
  • *****
  • Posts: 1745
  • <AMD>< 7-32>
Re: Flicker reduction drawing strategy
« Reply #25 on: May 26, 2021, 06:07:25 AM »
Dynamic layouts use DeferWindowPos to reposition all controls at once.
Ok. Then that don't solve very much.

Wm_size Edit flicker
That could be usefull  :thumbsup:, just I don't know how  :cool:

jj2007

  • Member
  • *****
  • Posts: 11552
  • Assembler is fun ;-)
    • MasmBasic
Re: Flicker reduction drawing strategy
« Reply #26 on: May 26, 2021, 07:48:50 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:

Code: [Select]
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--

  • Administrator
  • Member
  • ******
  • Posts: 8498
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Flicker reduction drawing strategy
« Reply #27 on: May 26, 2021, 12:02:26 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 11552
  • Assembler is fun ;-)
    • MasmBasic
Re: Flicker reduction drawing strategy
« Reply #28 on: May 26, 2021, 08:04:49 PM »
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.

Code: [Select]
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.