Mind the devicePixelRatio when drawing on-screen in presentation mode
ClosedPublic

Authored by sander on Jun 15 2019, 9:54 PM.

Details

Summary

Previously, when using a screen scaling factor larger than 1, the drawings by mouse or stylus in presentation mode were slightly blocky. The underlying cause was:

  • a few integer types used for coordinates that were non-integer
  • the intermediate use of a QPixmap without the correct devicePixelRatio.

Before:

After:

BUG: 384143

Test Plan
  1. Set QT_SCREEN_SCALE_FACTORS to something larger than 1, e.g., 1.5.
  2. Open a pdf file
  3. Switch to presentation mode
  4. Choose a color in the toolbar near the top of the screen
  5. Draw something with the mouse
  6. Without the patch the drawing is slightly blocky, with the patch it isn't.

Diff Detail

Repository
R223 Okular
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
sander created this revision.Jun 15 2019, 9:54 PM
Restricted Application added a project: Okular. · View Herald TranscriptJun 15 2019, 9:54 PM
Restricted Application added a subscriber: okular-devel. · View Herald Transcript
sander requested review of this revision.Jun 15 2019, 9:54 PM
sander edited the summary of this revision. (Show Details)

Path quality gets even better (slightly) if I replace the sequence of lines drawn by SmoothPathEngine with a QPainterPath. Do you prefer this change right here or in a separate patch on top?

ui/presentationwidget.cpp
900

Maybe use a scoped

const QSizeF pmSize { geom.width() * dpr, geom.height() * dpr };

instead of repeatedly recalculating width and height?

1329

Is this change necessary? Conversion to double was already there. screenPos() would change semantic from "relative to widget" to "relative to screen". Doesn't matter because widget is probably always full screen. But otoh the whole thing is called PresentationWidget, so keeping "relative to widget" seems reasonable.

Ping?

Nice patch. Maybe someone with a real HiDPI setup (I can only fake it) should have a look at it too.

I don't have one, sorry. LGTM as-is though.

sander marked an inline comment as done.Jun 20 2019, 4:29 PM
sander added inline comments.
ui/presentationwidget.cpp
900

Okay!

1329

You cannot use x() and y() because they return integer coordinates, while with fractional screen scaling the coordinates really are fractional, too. But I agree that keeping with "relative to widget" positions is better, so I changed screenPos to localPos.

sander updated this revision to Diff 60149.Jun 20 2019, 4:30 PM
sander marked an inline comment as done.
  • Use localPos instead of screenPos
  • Factor out intermediate Pixmap size computations
  • Use QPainterPath for smoother paths
This revision is now accepted and ready to land.Jun 21 2019, 8:12 PM
This revision was automatically updated to reflect the committed changes.