-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api-minor] Render high-res partial page views when falling back to CSS zoom (bug 1492303) #19128
base: master
Are you sure you want to change the base?
Conversation
2f715cb
to
5ad7743
Compare
4d80dcc
to
074c515
Compare
After discussing this patch with @calixteman, I updated it to prioritize rendering the full css-zoomed canvas rather than the high-resolution one. This means that, when zooming in, you'll first see the css-zoomed canvas, and then it will be replaced by the high-res one once it's ready. It's a slightly worse experience, however it guarantees that we do not regress in cases where the user starts moving around before that we are done rendering the background canvas (because if only the high-res canvas is there, they'll see just white until when the new high-res canvas is rendered). I also changed the logic that decides when to re-render the high-res canvas to not only do it once the user scrolls past its edges, but when the user is close to scrolling past the edges. |
074c515
to
b711cf5
Compare
69a98fc
to
3408061
Compare
Unfortunately this approach has a problem right now: since the various SVG paths for drawings are inserted inside the |
3408061
to
9c13462
Compare
Fixing the drawing problem required changing the new canvas to be in the existing |
9c13462
to
feea3e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a few more comments, mostly for the first patch since I've only begun looking at the Render high-res partial page views when falling back to CSS zoom
commit (and that one requires careful checking).
Also, is this new functionality anything that we could "easily" test with e.g. integration-tests?
feea3e4
to
ad7f77d
Compare
I'm working on adding some meaningful tests. |
db51d7f
to
9479f88
Compare
/botio integrationtest |
From: Bot.io (Linux m4)ReceivedCommand cmd_integrationtest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.241.84.105:8877/026343628fae9c8/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_integrationtest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.193.163.58:8877/7a79d253a24948d/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/026343628fae9c8/output.txt Total script time: 11.39 mins
|
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/7a79d253a24948d/output.txt Total script time: 26.77 mins
|
The windows-only failure for "PDF viewer CSS-only zoom triggers when going bigger than maxCanvasPixels triggers CSS-only zoom above maxCanvasPixels" could be related, I'm taking a look |
9479f88
to
e1bba12
Compare
/botio integrationtest |
From: Bot.io (Linux m4)ReceivedCommand cmd_integrationtest from @nicolo-ribaudo received. Current queue size: 0 Live output at: http://54.241.84.105:8877/436dc9e45979302/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_integrationtest from @nicolo-ribaudo received. Current queue size: 0 Live output at: http://54.193.163.58:8877/cc74bcfef9fd08a/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/436dc9e45979302/output.txt Total script time: 11.71 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/cc74bcfef9fd08a/output.txt Total script time: 26.34 mins
|
Once @calixteman is OK with this, I'll look through the PR one final time. Another small, but probably pointless, optimization would be the following: diff --git a/web/app.js b/web/app.js
index 5dfdbbd0b..08df46093 100644
--- a/web/app.js
+++ b/web/app.js
@@ -2310,7 +2310,7 @@ function onPageRender({ pageNumber }) {
}
}
-function onPageRendered({ pageNumber, error }) {
+function onPageRendered({ pageNumber, isDetailView, error }) {
// If the page is still visible when it has finished rendering,
// ensure that the page number input loading indicator is hidden.
if (pageNumber === this.page) {
@@ -2318,7 +2318,7 @@ function onPageRendered({ pageNumber, error }) {
}
// Use the rendered page to set the corresponding thumbnail image.
- if (this.pdfSidebar?.visibleView === SidebarView.THUMBS) {
+ if (!isDetailView && this.pdfSidebar?.visibleView === SidebarView.THUMBS) {
const pageView = this.pdfViewer.getPageView(/* index = */ pageNumber - 1);
const thumbnailView = this.pdfThumbnailViewer?.getThumbnail(
/* index = */ pageNumber - 1 |
e1bba12
to
5e27b06
Compare
This base class contains the generic logic for: - Creating a canvas and showing when appropriate - Rendering in the canvas - Keeping track of the rendering state
…SS zoom (bug 1492303) When rendering big PDF pages at high zoom levels, we currently fall back to CSS zoom to avoid rendering canvases with too many pixels. This causes zoomed in PDF to look blurry, and the text to be potentially unreadable. This commit adds support for rendering _part_ of a page (called `PDFPageDetailView` in the code), so that we can render portion of a page in a smaller canvas without hiting the maximun canvas size limit. Specifically, we render an area of that page that is slightly larger than the area that is visible on the screen (100% larger in each direction, unless we have to limit it due to the maximum canvas size). As the user scrolls around the page, we re-render a new area centered around what is currently visible.
When scrolling quickly, the constant re-rendering of the detail view significantly affects rendering performance, causing Firefox to not render even the _background canvas_, which is just a static canvas not being re-drawn by JavaScript. This commit changes the viewer to only render the detail view while scrolling if its rendering hasn't just been cancelled. This means that: - when the user is scrolling slowly, we have enough time to render the detail view before that we need to change its area, so the user always sees the full screen as high resolution. - when the user is scrolling quickly, as soon as we have to cancel a rendering we just give up, and the user will see the lower resolution canvas. When then the user stops scrolling, we render the detail view for the new visible area.
5e27b06
to
9aedbf9
Compare
Rebased to solve conflicts with the autolinking PR. |
/botio integrationtest |
From: Bot.io (Linux m4)ReceivedCommand cmd_integrationtest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.241.84.105:8877/93a86c1affda7c9/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_integrationtest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.193.163.58:8877/196968bc509de42/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/93a86c1affda7c9/output.txt Total script time: 11.39 mins
|
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/196968bc509de42/output.txt Total script time: 27.90 mins
|
/botio-linux preview |
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.241.84.105:8877/e2205635278fd08/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/e2205635278fd08/output.txt Total script time: 0.86 mins Published |
Commit:
To play around with this patch, you need to use a large PDF (the one I'm using is https://www.gtt.to.it/cms/risorse/urbana/mappa/mapparete.pdf) and zoom in: in the current release the text becomes blurry, while with this patch it remains sharp. Also, if you set
maxCanvasPixels
to a smaller value (for example, 8M) you'll more clearly see the effects also at lower zoom levels. Note however that ifmaxCanvasPixels
is set to less than 9 time the number of pixels visible in your window you'll get more frequent re-renders as you scroll.The
PDFPageDetailView
class still process every single operation of the PDF, even if many of them will actually be outside of the canvas and thus not be actually rendered. This is acceptable because we are only rendering one "detail view" per page at a time, and we are not splitting the page in multiple tiles that might appear at the same time on the screen. In the future however #19043 could improve the performance of this patch, and it would enable (for example) tiling a page into multiple detail views when printing it.There are some very minor TODOs that I left in the code, for some areas I need review feedback for. Also, I still need to find the best way to write tests.
Fixes #14147
Before:
![image](https://private-user-images.githubusercontent.com/7000710/391137091-3e0b45df-00d5-4e83-b30f-1b9571a65f09.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTc3MzYsIm5iZiI6MTczOTAxNzQzNiwicGF0aCI6Ii83MDAwNzEwLzM5MTEzNzA5MS0zZTBiNDVkZi0wMGQ1LTRlODMtYjMwZi0xYjk1NzFhNjVmMDkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTIyMzU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDBlMmY0NzgzMTVlMGEwNWU2OTA2MTI1Y2I1NjFlNTAxYTljMjdhMzk4ZDc0MTAzMzMyNWYyNzMzNDJiNTMyNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.e2lj5PsoOiyDsfPxhZvC02LRDY4Trp6RjKhI9mqFuJI)
After:
![image](https://private-user-images.githubusercontent.com/7000710/391137183-4d4e30f5-9fb8-4967-a0c8-21501c7cdc36.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTc3MzYsIm5iZiI6MTczOTAxNzQzNiwicGF0aCI6Ii83MDAwNzEwLzM5MTEzNzE4My00ZDRlMzBmNS05ZmI4LTQ5NjctYTBjOC0yMTUwMWM3Y2RjMzYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTIyMzU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OGU0MTE3MjFkZmIzODZlZTFmODA1ZTAwZTViNGIyM2RmZmE5NTk4OTVhMzFmZDBlZTFiNTlhYjkzYTY4MGZlOSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.Irz-GvnXamdtFrbqsHk57HNLL_OmZte3Qt4rO8hsGN8)
https://www.gtt.to.it/cms/risorse/urbana/mappa/mapparete.pdf at 400% zoom
Before:
![image](https://private-user-images.githubusercontent.com/7000710/391137669-61825ba3-e40a-43b2-8bff-1fd344658226.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTc3MzYsIm5iZiI6MTczOTAxNzQzNiwicGF0aCI6Ii83MDAwNzEwLzM5MTEzNzY2OS02MTgyNWJhMy1lNDBhLTQzYjItOGJmZi0xZmQzNDQ2NTgyMjYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTIyMzU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzgzZWIxZWVkY2QwZmVlOWJmNjdjMGY0Yjk2ZTMxYTllN2E2MTI0ODljZjU0MGQxZGExNGFiZWFiYzVjYjg3OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.mo8KfX3ifKYA3F2hkvttb-gXnr4UdJtRm_0y3ewtrIs)
After:
![image](https://private-user-images.githubusercontent.com/7000710/391138050-6b501b52-2621-4b37-b76e-80f583cc3aae.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTc3MzYsIm5iZiI6MTczOTAxNzQzNiwicGF0aCI6Ii83MDAwNzEwLzM5MTEzODA1MC02YjUwMWI1Mi0yNjIxLTRiMzctYjc2ZS04MGY1ODNjYzNhYWUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMTIyMzU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NGZkMTNiZmFjODM5OGQyYWJiNTVlZDFiMTM1NjBjZjFmZjk2NGViYmMxZDMwMWQzNDAzMWI4MjRlMzk3Y2UwYiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.la_06aymzqWiSkwsu8OGoV4qvkP8Icj3hGI-lknZ4Tg)
Fixes #14193