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>
This commit is contained in:
parent
9fc9b87540
commit
f9a0f1a9be
@ -321,6 +321,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
|
||||
, 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 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
|
||||
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 @@ void Viewer::setCurrentSlide(int slide) {
|
||||
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 Viewer::computePreTouchMatrix() {
|
||||
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::onPaint(SkSurface* surface) {
|
||||
|
||||
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 @@ void Viewer::drawImGui() {
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -168,6 +168,7 @@ private:
|
||||
skcms_TransferFunction fColorSpaceTransferFn;
|
||||
|
||||
// transform data
|
||||
bool fApplyBackingScale;
|
||||
SkScalar fZoomLevel;
|
||||
SkScalar fRotation;
|
||||
SkVector fOffset;
|
||||
|
Loading…
Reference in New Issue
Block a user