Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(901)

Unified Diff: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp

Issue 2157953002: Change filter quality when scaling-down in drawImage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: account for rotation and update layout test Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/canvas-imageSmoothingQuality-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
diff --git a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
index 2029de6d7d7f812aa189ca4529e5031003f1e253..edebc44d401d88710cace0a853989b5b072d6eaa 100644
--- a/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp
@@ -941,6 +941,11 @@ bool BaseRenderingContext2D::shouldDrawImageAntialiased(const FloatRect& destRec
return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fabs(heightExpansion) < 1;
}
+static bool isDrawScalingDown(const FloatRect& srcRect, const FloatRect& dstRect, double xScale, double yScale)
+{
+ return dstRect.width() * xScale < srcRect.width() && dstRect.height() * yScale < srcRect.height();
Justin Novosad 2016/07/20 19:43:56 I had an idea: you can optimize out the expensive
xidachen 2016/07/20 20:31:33 Done.
+}
+
void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* imageSource, Image* image, const FloatRect& srcRect, const FloatRect& dstRect, const SkPaint* paint)
{
trackDrawCall(DrawImage);
@@ -972,6 +977,9 @@ void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* i
imagePaint.setImageFilter(nullptr);
}
+ if (!imageSmoothingEnabled() && isDrawScalingDown(srcRect, dstRect, state().transform().xScale(), state().transform().yScale()))
+ imagePaint.setFilterQuality(kLow_SkFilterQuality);
+
if (!imageSource->isVideoElement()) {
imagePaint.setAntiAlias(shouldDrawImageAntialiased(dstRect));
image->draw(c, imagePaint, dstRect, srcRect, DoNotRespectImageOrientation, Image::DoNotClampImageToSourceRect);
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/canvas/canvas-imageSmoothingQuality-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698