Chromium Code Reviews| 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..f7cc275f84297728558edc9c75acdbe341d01294 100644 |
| --- a/Source/platform/graphics/skia/NativeImageSkia.cpp |
| +++ b/Source/platform/graphics/skia/NativeImageSkia.cpp |
| @@ -332,9 +332,22 @@ 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(); |
| + const SkMatrix totalMatrix = context->getTotalMatrix(); |
| + // Enable anti-aliasing if we're rotated or skewed. |
| + if (!totalMatrix.rectStaysRect()) |
| + return true; |
| + // Check if the dimensions of the destination are "small" (less than one |
| + // destination pixel). To prevent sudden drop-outs. Since we know that |
| + // kRectStaysRect_Mask is set, we can use the kAffine_Mask flag to select |
| + // the relevant components of the matrix to compute the transformed vector. |
|
Justin Novosad
2014/03/25 14:35:07
Reformulate for clarity. Suggestion : Since we kno
|
| + 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 +358,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()) { |