| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/canvas2d/BaseRenderingContext2D.h" | 5 #include "modules/canvas2d/BaseRenderingContext2D.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 9 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 10 #include "core/css/parser/CSSParser.h" | 10 #include "core/css/parser/CSSParser.h" |
| (...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 // discouraged. Always drawing with AA can negatively impact performance | 934 // discouraged. Always drawing with AA can negatively impact performance |
| 935 // though - that's why it's not always on. | 935 // though - that's why it's not always on. |
| 936 SkScalar widthExpansion, heightExpansion; | 936 SkScalar widthExpansion, heightExpansion; |
| 937 if (ctm.getType() & SkMatrix::kAffine_Mask) | 937 if (ctm.getType() & SkMatrix::kAffine_Mask) |
| 938 widthExpansion = ctm[SkMatrix::kMSkewY], heightExpansion = ctm[SkMatrix:
:kMSkewX]; | 938 widthExpansion = ctm[SkMatrix::kMSkewY], heightExpansion = ctm[SkMatrix:
:kMSkewX]; |
| 939 else | 939 else |
| 940 widthExpansion = ctm[SkMatrix::kMScaleX], heightExpansion = ctm[SkMatrix
::kMScaleY]; | 940 widthExpansion = ctm[SkMatrix::kMScaleX], heightExpansion = ctm[SkMatrix
::kMScaleY]; |
| 941 return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fa
bs(heightExpansion) < 1; | 941 return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fa
bs(heightExpansion) < 1; |
| 942 } | 942 } |
| 943 | 943 |
| 944 static bool isDrawScalingDown(const FloatRect& srcRect, const FloatRect& dstRect
, float xScaleSquared, float yScaleSquared) |
| 945 { |
| 946 return dstRect.width() * dstRect.width() * xScaleSquared < srcRect.width() *
srcRect.width() |
| 947 && dstRect.height() * dstRect.height() * yScaleSquared < srcRect.height(
) * srcRect.height(); |
| 948 } |
| 949 |
| 944 void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* i
mageSource, Image* image, const FloatRect& srcRect, const FloatRect& dstRect, co
nst SkPaint* paint) | 950 void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* i
mageSource, Image* image, const FloatRect& srcRect, const FloatRect& dstRect, co
nst SkPaint* paint) |
| 945 { | 951 { |
| 946 trackDrawCall(DrawImage); | 952 trackDrawCall(DrawImage); |
| 947 | 953 |
| 948 int initialSaveCount = c->getSaveCount(); | 954 int initialSaveCount = c->getSaveCount(); |
| 949 SkPaint imagePaint = *paint; | 955 SkPaint imagePaint = *paint; |
| 950 | 956 |
| 951 if (paint->getImageFilter()) { | 957 if (paint->getImageFilter()) { |
| 952 SkMatrix ctm = c->getTotalMatrix(); | 958 SkMatrix ctm = c->getTotalMatrix(); |
| 953 SkMatrix invCtm; | 959 SkMatrix invCtm; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 965 SkPaint layerPaint; | 971 SkPaint layerPaint; |
| 966 layerPaint.setXfermode(sk_ref_sp(paint->getXfermode())); | 972 layerPaint.setXfermode(sk_ref_sp(paint->getXfermode())); |
| 967 layerPaint.setImageFilter(paint->getImageFilter()); | 973 layerPaint.setImageFilter(paint->getImageFilter()); |
| 968 | 974 |
| 969 c->saveLayer(&bounds, &layerPaint); | 975 c->saveLayer(&bounds, &layerPaint); |
| 970 c->concat(ctm); | 976 c->concat(ctm); |
| 971 imagePaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 977 imagePaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 972 imagePaint.setImageFilter(nullptr); | 978 imagePaint.setImageFilter(nullptr); |
| 973 } | 979 } |
| 974 | 980 |
| 981 if (!imageSmoothingEnabled() && isDrawScalingDown(srcRect, dstRect, state().
transform().xScaleSquared(), state().transform().yScaleSquared())) |
| 982 imagePaint.setFilterQuality(kLow_SkFilterQuality); |
| 983 |
| 975 if (!imageSource->isVideoElement()) { | 984 if (!imageSource->isVideoElement()) { |
| 976 imagePaint.setAntiAlias(shouldDrawImageAntialiased(dstRect)); | 985 imagePaint.setAntiAlias(shouldDrawImageAntialiased(dstRect)); |
| 977 image->draw(c, imagePaint, dstRect, srcRect, DoNotRespectImageOrientatio
n, Image::DoNotClampImageToSourceRect); | 986 image->draw(c, imagePaint, dstRect, srcRect, DoNotRespectImageOrientatio
n, Image::DoNotClampImageToSourceRect); |
| 978 } else { | 987 } else { |
| 979 c->save(); | 988 c->save(); |
| 980 c->clipRect(dstRect); | 989 c->clipRect(dstRect); |
| 981 c->translate(dstRect.x(), dstRect.y()); | 990 c->translate(dstRect.x(), dstRect.y()); |
| 982 c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.h
eight()); | 991 c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.h
eight()); |
| 983 c->translate(-srcRect.x(), -srcRect.y()); | 992 c->translate(-srcRect.x(), -srcRect.y()); |
| 984 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource); | 993 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource); |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 numPatterns(0), | 1588 numPatterns(0), |
| 1580 numDrawWithComplexClips(0), | 1589 numDrawWithComplexClips(0), |
| 1581 numBlurredShadows(0), | 1590 numBlurredShadows(0), |
| 1582 numFilters(0), | 1591 numFilters(0), |
| 1583 numGetImageDataCalls(0), | 1592 numGetImageDataCalls(0), |
| 1584 numPutImageDataCalls(0), | 1593 numPutImageDataCalls(0), |
| 1585 numClearRectCalls(0), | 1594 numClearRectCalls(0), |
| 1586 numDrawFocusCalls(0) {} | 1595 numDrawFocusCalls(0) {} |
| 1587 | 1596 |
| 1588 } // namespace blink | 1597 } // namespace blink |
| OLD | NEW |