Viewer scale factor improvement.
This change treats all slides as being in units of points (not pixels).
Window dimensions are communicated to slides in terms of points. This
allows slides which use the window dimensions for scaling to remain in
the same unit space as the gms. Allowing thh slides to also know the
actual pixel dimensions is left for later (this may be wanted when
testing proper selection of bitmap resources).
This also splits the backing scale from the zoom factor. The backing
scale is allowed to be toggled by the user. This allows for easy
reproduction at nominal size. When the backing scale is turned off the
points and the pixels are the same size. Slides which use the window
dimensions for scaling have the backing scale moved from the Viewer
transform to the window dimensions which are reported in pixels
(which are equal to points) when the backing scale is turned off.
Change-Id: Id288c4d8664a0a0972f1171a6159101c2b4ae90f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/364018
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 81746e8..9c2e6e6 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -321,6 +321,7 @@
, fColorSpacePrimaries(gSrgbPrimaries)
// Our UI can only tweak gamma (currently), so start out gamma-only
, fColorSpaceTransferFn(SkNamedTransferFn::k2Dot2)
+ , fApplyBackingScale(true)
, fZoomLevel(0.0f)
, fRotation(0.0f)
, fOffset{0.5f, 0.5f}
@@ -376,10 +377,7 @@
fDisplay = fWindow->getRequestedDisplayParams();
fRefresh = FLAGS_redraw;
- // computePreTouchMatrix uses exp(fZoomLevel) to compute the scale.
- float scaleFactor = fWindow->scaleFactor();
- fZoomLevel = log(scaleFactor);
- fImGuiLayer.setScaleFactor(scaleFactor);
+ fImGuiLayer.setScaleFactor(fWindow->scaleFactor());
// Configure timers
fStatsLayer.setActive(FLAGS_stats);
@@ -1104,8 +1102,12 @@
fSlides[fCurrentSlide]->unload();
}
- fSlides[slide]->load(SkIntToScalar(fWindow->width()),
- SkIntToScalar(fWindow->height()));
+ SkScalar scaleFactor = 1.0;
+ if (fApplyBackingScale) {
+ scaleFactor = fWindow->scaleFactor();
+ }
+ fSlides[slide]->load(SkIntToScalar(fWindow->width()) / scaleFactor,
+ SkIntToScalar(fWindow->height()) / scaleFactor);
fCurrentSlide = slide;
this->setupCurrentSlide();
}
@@ -1175,6 +1177,9 @@
SkMatrix m = fDefaultMatrix;
SkScalar zoomScale = exp(fZoomLevel);
+ if (fApplyBackingScale) {
+ zoomScale *= fWindow->scaleFactor();
+ }
m.preTranslate((fOffset.x() - 0.5f) * 2.0f, (fOffset.y() - 0.5f) * 2.0f);
m.preScale(zoomScale, zoomScale);
@@ -1540,7 +1545,11 @@
void Viewer::onResize(int width, int height) {
if (fCurrentSlide >= 0) {
- fSlides[fCurrentSlide]->resize(width, height);
+ SkScalar scaleFactor = 1.0;
+ if (fApplyBackingScale) {
+ scaleFactor = fWindow->scaleFactor();
+ }
+ fSlides[fCurrentSlide]->resize(width / scaleFactor, height / scaleFactor);
}
}
@@ -1905,6 +1914,12 @@
}
if (ImGui::CollapsingHeader("Transform")) {
+ if (ImGui::Checkbox("Apply Backing Scale", &fApplyBackingScale)) {
+ this->preTouchMatrixChanged();
+ this->onResize(fWindow->width(), fWindow->height());
+ paramsChanged = true;
+ }
+
float zoom = fZoomLevel;
if (ImGui::SliderFloat("Zoom", &zoom, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL)) {
fZoomLevel = zoom;