From f83cf1506cd4cc828cf7ceae2b015739486e90e1 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 18 Jul 2017 13:13:44 +0200 Subject: [PATCH] Bug 1360415 - Enable smoothing in canvas.drawImage when down-scaling, even with imageSmoothingEnabled=false. r=bzbarsky --- dom/canvas/CanvasRenderingContext2D.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index b5c85625c139..1992ef5004ad 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -5361,10 +5361,18 @@ CanvasRenderingContext2D::DrawImage(const CanvasImageSource& aImage, return; } + // Per spec, the smoothing setting applies only to scaling up a bitmap image. + // When down-scaling the user agent is free to choose whether or not to smooth + // the image. Nearest sampling when down-scaling is rarely desirable and + // smoothing when down-scaling matches chromium's behavior. + // If any dimension is up-scaled, we consider the image as being up-scaled. + auto scale = mTarget->GetTransform().ScaleFactors(true); + bool isDownScale = aDw * Abs(scale.width) < aSw && aDh * Abs(scale.height) < aSh; + SamplingFilter samplingFilter; AntialiasMode antialiasMode; - if (CurrentState().imageSmoothingEnabled) { + if (CurrentState().imageSmoothingEnabled || isDownScale) { samplingFilter = gfx::SamplingFilter::LINEAR; antialiasMode = AntialiasMode::DEFAULT; } else {