sumatrapdfreader / sumatrapdf

SumatraPDF reader
http://www.sumatrapdfreader.org
GNU General Public License v3.0
13.76k stars 1.74k forks source link

Middle click scrolling is not smooth #2693

Open adamburgess opened 2 years ago

adamburgess commented 2 years ago

2343 implemented smooth touchpad scrolling, but the other method of scrolling with middle click remains quite janky and low frame rate.

Here's an example. Grabbing with left click is perfectly smooth, but middle click continuous scrolling is very choppy. (120fps video)

https://user-images.githubusercontent.com/7473960/172537804-93f696fe-d117-46df-96fb-248bd124013c.mp4

GitHubRulesOK commented 2 years ago

@adamburgess PDF ePub FB2 and dare I say most other formats that SumatraPDF views are totally opposite in behavior to everyday apps like this browser one.

What I mean is HTML is one single page without breaks thus rolling within a web page is unfettered, it is as fast as hardware can handle, so browser looks smooth but slow on my other device.

Books however are broken into pages, thus need loading pages at a time, but the view does not always show that instantly, they are generally preloaded, either in blocks or the whole book, however its not just as simple as stream the pixels like a video, frame by frame, thus if you change direction or speed there will be a lag for considerable calculations.

The same problem arises even if scrolling slowly in one direction since to preload each line needs decompression and preload with chunks of data in the background. Hence even at a slow rate devices will appear to s t t t utter at different combinations not just as the break becomes visible.

adamburgess commented 2 years ago

I get what you're saying, but it seems odd to me that left-click dragging is done perfectly at my displays full frame rate, so I think the issue is elsewhere?

I had a quick look at the code, and it seems like middle click scrolling is done on a timer with a 20ms delay:

https://github.com/sumatrapdfreader/sumatrapdf/blob/76770e16238847630d5d6b06b166e0bd29f27bb0/src/Selection.h#L5

https://github.com/sumatrapdfreader/sumatrapdf/blob/3aca64ee2614ec9122fc96aa541e85672db56f27/src/Canvas.cpp#L1397-L1398

So, 50fps.

Could the middle click logic be changed to continuously repaint the window and scroll smoothly, instead of doing it on a timer? Or at the very least a much quicker timer...

GitHubRulesOK commented 2 years ago

The code details are beyond my ken , but note the behavior is what I got and get even on high speed kit, thus expect with other similar fast page based apps. The pixels are drawn at one crude resolution then are tweened over a time. (observed as text starts off fuzzy then getting clearer.) There is an option setting recently introduced that you point to SmoothScroll = false but it is only true / false in settings