sumatrapdf icon indicating copy to clipboard operation
sumatrapdf copied to clipboard

Middle click scrolling is not smooth

Open adamburgess opened this issue 3 years ago • 3 comments

#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

adamburgess avatar Jun 08 '22 05:06 adamburgess

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

GitHubRulesOK avatar Jun 08 '22 10:06 GitHubRulesOK

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

adamburgess avatar Jun 08 '22 11:06 adamburgess

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

GitHubRulesOK avatar Jun 08 '22 11:06 GitHubRulesOK