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

Unified Diff: Source/platform/graphics/skia/NativeImageSkia.cpp

Issue 210043004: Draw thin slices of an image w/ anti-aliasing for 2D <canvas> (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Clarifications. Created 6 years, 9 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 | « Source/platform/graphics/GraphicsContext.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/skia/NativeImageSkia.cpp
diff --git a/Source/platform/graphics/skia/NativeImageSkia.cpp b/Source/platform/graphics/skia/NativeImageSkia.cpp
index f7e70af0ad4d05d15b9903954a24f59e89866f85..f9ed9b6beb100e1c1dbb5323251aac4327af9e69 100644
--- a/Source/platform/graphics/skia/NativeImageSkia.cpp
+++ b/Source/platform/graphics/skia/NativeImageSkia.cpp
@@ -332,9 +332,33 @@ SkBitmap NativeImageSkia::resizedBitmap(const SkISize& scaledImageSize, const Sk
return resizedSubset;
}
-static bool hasNon90rotation(GraphicsContext* context)
+static bool shouldDrawAntiAliased(GraphicsContext* context, const SkRect& destRect)
{
- return !context->getTotalMatrix().rectStaysRect();
+ if (!context->shouldAntialias())
+ return false;
+ const SkMatrix totalMatrix = context->getTotalMatrix();
+ // Don't disable anti-aliasing if we're rotated or skewed.
+ if (!totalMatrix.rectStaysRect())
+ return true;
+ // Disable anti-aliasing for scales or n*90 degree rotations.
+ // Allow to opt out of the optimization though for "hairline" geometry
+ // images - using the shouldAntialiasHairlineImages() GraphicsContext flag.
+ if (!context->shouldAntialiasHairlineImages())
+ return false;
+ // Check if the dimensions of the destination are "small" (less than one
+ // device pixel). To prevent sudden drop-outs. Since we know that
+ // kRectStaysRect_Mask is set, the matrix either has scale and no skew or
+ // vice versa. We can query the kAffine_Mask flag to determine which case
+ // it is.
+ // FIXME: This queries the CTM while drawing, which is generally
+ // discouraged. Always drawing with AA can negatively impact performance
+ // though - that's why it's not always on.
+ SkScalar widthExpansion, heightExpansion;
+ if (totalMatrix.getType() & SkMatrix::kAffine_Mask)
+ widthExpansion = totalMatrix[SkMatrix::kMSkewY], heightExpansion = totalMatrix[SkMatrix::kMSkewX];
+ else
+ widthExpansion = totalMatrix[SkMatrix::kMScaleX], heightExpansion = totalMatrix[SkMatrix::kMScaleY];
+ return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fabs(heightExpansion) < 1;
}
void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, const SkRect& destRect, PassRefPtr<SkXfermode> compOp) const
@@ -345,8 +369,7 @@ void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons
paint.setColorFilter(context->colorFilter());
paint.setAlpha(context->getNormalizedAlpha());
paint.setLooper(context->drawLooper());
- // only antialias if we're rotated or skewed
- paint.setAntiAlias(hasNon90rotation(context));
+ paint.setAntiAlias(shouldDrawAntiAliased(context, destRect));
ResamplingMode resampling;
if (context->isAccelerated()) {
« no previous file with comments | « Source/platform/graphics/GraphicsContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698