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 , double xScale, double yScale) | |
945 { | |
946 return dstRect.width() * xScale < srcRect.width() && dstRect.height() * ySca le < 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.
| |
947 } | |
948 | |
944 void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* i mageSource, Image* image, const FloatRect& srcRect, const FloatRect& dstRect, co nst SkPaint* paint) | 949 void BaseRenderingContext2D::drawImageInternal(SkCanvas* c, CanvasImageSource* i mageSource, Image* image, const FloatRect& srcRect, const FloatRect& dstRect, co nst SkPaint* paint) |
945 { | 950 { |
946 trackDrawCall(DrawImage); | 951 trackDrawCall(DrawImage); |
947 | 952 |
948 int initialSaveCount = c->getSaveCount(); | 953 int initialSaveCount = c->getSaveCount(); |
949 SkPaint imagePaint = *paint; | 954 SkPaint imagePaint = *paint; |
950 | 955 |
951 if (paint->getImageFilter()) { | 956 if (paint->getImageFilter()) { |
952 SkMatrix ctm = c->getTotalMatrix(); | 957 SkMatrix ctm = c->getTotalMatrix(); |
953 SkMatrix invCtm; | 958 SkMatrix invCtm; |
(...skipping 11 matching lines...) Expand all Loading... | |
965 SkPaint layerPaint; | 970 SkPaint layerPaint; |
966 layerPaint.setXfermode(sk_ref_sp(paint->getXfermode())); | 971 layerPaint.setXfermode(sk_ref_sp(paint->getXfermode())); |
967 layerPaint.setImageFilter(paint->getImageFilter()); | 972 layerPaint.setImageFilter(paint->getImageFilter()); |
968 | 973 |
969 c->saveLayer(&bounds, &layerPaint); | 974 c->saveLayer(&bounds, &layerPaint); |
970 c->concat(ctm); | 975 c->concat(ctm); |
971 imagePaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 976 imagePaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
972 imagePaint.setImageFilter(nullptr); | 977 imagePaint.setImageFilter(nullptr); |
973 } | 978 } |
974 | 979 |
980 if (!imageSmoothingEnabled() && isDrawScalingDown(srcRect, dstRect, state(). transform().xScale(), state().transform().yScale())) | |
981 imagePaint.setFilterQuality(kLow_SkFilterQuality); | |
982 | |
975 if (!imageSource->isVideoElement()) { | 983 if (!imageSource->isVideoElement()) { |
976 imagePaint.setAntiAlias(shouldDrawImageAntialiased(dstRect)); | 984 imagePaint.setAntiAlias(shouldDrawImageAntialiased(dstRect)); |
977 image->draw(c, imagePaint, dstRect, srcRect, DoNotRespectImageOrientatio n, Image::DoNotClampImageToSourceRect); | 985 image->draw(c, imagePaint, dstRect, srcRect, DoNotRespectImageOrientatio n, Image::DoNotClampImageToSourceRect); |
978 } else { | 986 } else { |
979 c->save(); | 987 c->save(); |
980 c->clipRect(dstRect); | 988 c->clipRect(dstRect); |
981 c->translate(dstRect.x(), dstRect.y()); | 989 c->translate(dstRect.x(), dstRect.y()); |
982 c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.h eight()); | 990 c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.h eight()); |
983 c->translate(-srcRect.x(), -srcRect.y()); | 991 c->translate(-srcRect.x(), -srcRect.y()); |
984 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource); | 992 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource); |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 numPatterns(0), | 1587 numPatterns(0), |
1580 numDrawWithComplexClips(0), | 1588 numDrawWithComplexClips(0), |
1581 numBlurredShadows(0), | 1589 numBlurredShadows(0), |
1582 numFilters(0), | 1590 numFilters(0), |
1583 numGetImageDataCalls(0), | 1591 numGetImageDataCalls(0), |
1584 numPutImageDataCalls(0), | 1592 numPutImageDataCalls(0), |
1585 numClearRectCalls(0), | 1593 numClearRectCalls(0), |
1586 numDrawFocusCalls(0) {} | 1594 numDrawFocusCalls(0) {} |
1587 | 1595 |
1588 } // namespace blink | 1596 } // namespace blink |
OLD | NEW |