Bug 1555511 Part 2: Remove a float division in MVM::ScaleZoomWithDisplayWidth. r=botond

This is a drive-by fix to turn a division into a multiplication. It also
is more correct in that the existing code attempts a divide-by-zero if
aNewViewport.width is zero. The updated code will instead return a zoom
of zero in such a case.

Differential Revision: https://phabricator.services.mozilla.com/D32909

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brad Werth 2019-05-31 22:10:59 +00:00
parent 8c5b5937fe
commit 2c084a33fd

View File

@ -184,13 +184,13 @@ CSSToScreenScale MobileViewportManager::ClampZoom(
CSSToScreenScale MobileViewportManager::ScaleZoomWithDisplayWidth(
const CSSToScreenScale& aZoom, const float& aDisplayWidthChangeRatio,
const CSSSize& aNewViewport, const CSSSize& aOldViewport) {
float cssViewportChangeRatio = (aOldViewport.width == 0)
? 1.0f
: aNewViewport.width / aOldViewport.width;
CSSToScreenScale newZoom(aZoom.scale * aDisplayWidthChangeRatio /
cssViewportChangeRatio);
MVM_LOG("%p: Old zoom was %f, changed by %f/%f to %f\n", this, aZoom.scale,
aDisplayWidthChangeRatio, cssViewportChangeRatio, newZoom.scale);
float inverseCssWidthChangeRatio =
(aNewViewport.width == 0) ? 1.0f
: aOldViewport.width / aNewViewport.width;
CSSToScreenScale newZoom(aZoom.scale * aDisplayWidthChangeRatio *
inverseCssWidthChangeRatio);
MVM_LOG("%p: Old zoom was %f, changed by %f * %f to %f\n", this, aZoom.scale,
aDisplayWidthChangeRatio, inverseCssWidthChangeRatio, newZoom.scale);
return newZoom;
}