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/cssom/CSSURLImageValue.h" | 10 #include "core/css/cssom/CSSURLImageValue.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 void BaseRenderingContext2D::realizeSaves() { | 46 void BaseRenderingContext2D::realizeSaves() { |
47 validateStateStack(); | 47 validateStateStack(); |
48 if (state().hasUnrealizedSaves()) { | 48 if (state().hasUnrealizedSaves()) { |
49 ASSERT(m_stateStack.size() >= 1); | 49 ASSERT(m_stateStack.size() >= 1); |
50 // Reduce the current state's unrealized count by one now, | 50 // Reduce the current state's unrealized count by one now, |
51 // to reflect the fact we are saving one state. | 51 // to reflect the fact we are saving one state. |
52 m_stateStack.last()->restore(); | 52 m_stateStack.last()->restore(); |
53 m_stateStack.append(CanvasRenderingContext2DState::create( | 53 m_stateStack.append(CanvasRenderingContext2DState::create( |
54 state(), CanvasRenderingContext2DState::DontCopyClipList)); | 54 state(), CanvasRenderingContext2DState::DontCopyClipList)); |
55 // Set the new state's unrealized count to 0, because it has no outstanding
saves. | 55 // Set the new state's unrealized count to 0, because it has no outstanding |
56 // We need to do this explicitly because the copy constructor and operator=
used | 56 // saves. |
57 // by the Vector operations copy the unrealized count from the previous stat
e (in | 57 // We need to do this explicitly because the copy constructor and operator= |
58 // turn necessary to support correct resizing and unwinding of the stack). | 58 // used by the Vector operations copy the unrealized count from the previous |
| 59 // state (in turn necessary to support correct resizing and unwinding of the |
| 60 // stack). |
59 m_stateStack.last()->resetUnrealizedSaveCount(); | 61 m_stateStack.last()->resetUnrealizedSaveCount(); |
60 SkCanvas* canvas = drawingCanvas(); | 62 SkCanvas* canvas = drawingCanvas(); |
61 if (canvas) | 63 if (canvas) |
62 canvas->save(); | 64 canvas->save(); |
63 validateStateStack(); | 65 validateStateStack(); |
64 } | 66 } |
65 } | 67 } |
66 | 68 |
67 void BaseRenderingContext2D::save() { | 69 void BaseRenderingContext2D::save() { |
68 m_stateStack.last()->save(); | 70 m_stateStack.last()->save(); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 // When CTM becomes non-invertible, realizeSaves() can make CTM identity. | 494 // When CTM becomes non-invertible, realizeSaves() can make CTM identity. |
493 if (ctm.isIdentity() && invertibleCTM) | 495 if (ctm.isIdentity() && invertibleCTM) |
494 return; | 496 return; |
495 | 497 |
496 // resetTransform() resolves the non-invertible CTM state. | 498 // resetTransform() resolves the non-invertible CTM state. |
497 modifiableState().resetTransform(); | 499 modifiableState().resetTransform(); |
498 c->setMatrix(affineTransformToSkMatrix(baseTransform())); | 500 c->setMatrix(affineTransformToSkMatrix(baseTransform())); |
499 | 501 |
500 if (invertibleCTM) | 502 if (invertibleCTM) |
501 m_path.transform(ctm); | 503 m_path.transform(ctm); |
502 // When else, do nothing because all transform methods didn't update m_path wh
en CTM became non-invertible. | 504 // When else, do nothing because all transform methods didn't update m_path |
503 // It means that resetTransform() restores m_path just before CTM became non-i
nvertible. | 505 // when CTM became non-invertible. |
| 506 // It means that resetTransform() restores m_path just before CTM became |
| 507 // non-invertible. |
504 } | 508 } |
505 | 509 |
506 void BaseRenderingContext2D::setTransform(double m11, | 510 void BaseRenderingContext2D::setTransform(double m11, |
507 double m12, | 511 double m12, |
508 double m21, | 512 double m21, |
509 double m22, | 513 double m22, |
510 double dx, | 514 double dx, |
511 double dy) { | 515 double dy) { |
512 SkCanvas* c = drawingCanvas(); | 516 SkCanvas* c = drawingCanvas(); |
513 if (!c) | 517 if (!c) |
(...skipping 30 matching lines...) Expand all Loading... |
544 if (height < 0) { | 548 if (height < 0) { |
545 height = -height; | 549 height = -height; |
546 y -= height; | 550 y -= height; |
547 } | 551 } |
548 | 552 |
549 return true; | 553 return true; |
550 } | 554 } |
551 | 555 |
552 bool BaseRenderingContext2D::isFullCanvasCompositeMode(SkXfermode::Mode op) { | 556 bool BaseRenderingContext2D::isFullCanvasCompositeMode(SkXfermode::Mode op) { |
553 // See 4.8.11.1.3 Compositing | 557 // See 4.8.11.1.3 Compositing |
554 // CompositeSourceAtop and CompositeDestinationOut are not listed here as the
platforms already | 558 // CompositeSourceAtop and CompositeDestinationOut are not listed here as the |
555 // implement the specification's behavior. | 559 // platforms already implement the specification's behavior. |
556 return op == SkXfermode::kSrcIn_Mode || op == SkXfermode::kSrcOut_Mode || | 560 return op == SkXfermode::kSrcIn_Mode || op == SkXfermode::kSrcOut_Mode || |
557 op == SkXfermode::kDstIn_Mode || op == SkXfermode::kDstATop_Mode; | 561 op == SkXfermode::kDstIn_Mode || op == SkXfermode::kDstATop_Mode; |
558 } | 562 } |
559 | 563 |
560 static bool isPathExpensive(const Path& path) { | 564 static bool isPathExpensive(const Path& path) { |
561 const SkPath& skPath = path.getSkPath(); | 565 const SkPath& skPath = path.getSkPath(); |
562 if (ExpensiveCanvasHeuristicParameters::ConcavePathsAreExpensive && | 566 if (ExpensiveCanvasHeuristicParameters::ConcavePathsAreExpensive && |
563 !skPath.isConvex()) | 567 !skPath.isConvex()) |
564 return true; | 568 return true; |
565 | 569 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 | 850 |
847 // Compute the src to dst transform | 851 // Compute the src to dst transform |
848 FloatSize scale(dstRect->size().width() / srcRect->size().width(), | 852 FloatSize scale(dstRect->size().width() / srcRect->size().width(), |
849 dstRect->size().height() / srcRect->size().height()); | 853 dstRect->size().height() / srcRect->size().height()); |
850 FloatPoint scaledSrcLocation = srcRect->location(); | 854 FloatPoint scaledSrcLocation = srcRect->location(); |
851 scaledSrcLocation.scale(scale.width(), scale.height()); | 855 scaledSrcLocation.scale(scale.width(), scale.height()); |
852 FloatSize offset = dstRect->location() - scaledSrcLocation; | 856 FloatSize offset = dstRect->location() - scaledSrcLocation; |
853 | 857 |
854 srcRect->intersect(imageRect); | 858 srcRect->intersect(imageRect); |
855 | 859 |
856 // To clip the destination rectangle in the same proportion, transform the cli
pped src rect | 860 // To clip the destination rectangle in the same proportion, transform the |
| 861 // clipped src rect |
857 *dstRect = *srcRect; | 862 *dstRect = *srcRect; |
858 dstRect->scale(scale.width(), scale.height()); | 863 dstRect->scale(scale.width(), scale.height()); |
859 dstRect->move(offset); | 864 dstRect->move(offset); |
860 } | 865 } |
861 | 866 |
862 static inline CanvasImageSource* toImageSourceInternal( | 867 static inline CanvasImageSource* toImageSourceInternal( |
863 const CanvasImageSourceUnion& value, | 868 const CanvasImageSourceUnion& value, |
864 ExceptionState& exceptionState) { | 869 ExceptionState& exceptionState) { |
865 if (value.isCSSImageValue()) { | 870 if (value.isCSSImageValue()) { |
866 if (RuntimeEnabledFeatures::cssPaintAPIEnabled()) | 871 if (RuntimeEnabledFeatures::cssPaintAPIEnabled()) |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 return; | 1134 return; |
1130 | 1135 |
1131 DisableDeferralReason reason = DisableDeferralReasonUnknown; | 1136 DisableDeferralReason reason = DisableDeferralReasonUnknown; |
1132 if (shouldDisableDeferral(imageSource, &reason)) | 1137 if (shouldDisableDeferral(imageSource, &reason)) |
1133 disableDeferral(reason); | 1138 disableDeferral(reason); |
1134 else if (image->isTextureBacked()) | 1139 else if (image->isTextureBacked()) |
1135 disableDeferral(DisableDeferralDrawImageWithTextureBackedSourceImage); | 1140 disableDeferral(DisableDeferralDrawImageWithTextureBackedSourceImage); |
1136 | 1141 |
1137 validateStateStack(); | 1142 validateStateStack(); |
1138 | 1143 |
1139 // Heuristic for disabling acceleration based on anticipated texture upload ov
erhead | 1144 // Heuristic for disabling acceleration based on anticipated texture upload |
| 1145 // overhead. |
1140 // See comments in ExpensiveCanvasHeuristicParameters.h for explanation. | 1146 // See comments in ExpensiveCanvasHeuristicParameters.h for explanation. |
1141 ImageBuffer* buffer = imageBuffer(); | 1147 ImageBuffer* buffer = imageBuffer(); |
1142 if (buffer && buffer->isAccelerated() && !imageSource->isAccelerated()) { | 1148 if (buffer && buffer->isAccelerated() && !imageSource->isAccelerated()) { |
1143 float srcArea = srcRect.width() * srcRect.height(); | 1149 float srcArea = srcRect.width() * srcRect.height(); |
1144 if (srcArea > ExpensiveCanvasHeuristicParameters:: | 1150 if (srcArea > ExpensiveCanvasHeuristicParameters:: |
1145 DrawImageTextureUploadHardSizeLimit) { | 1151 DrawImageTextureUploadHardSizeLimit) { |
1146 buffer->disableAcceleration(); | 1152 buffer->disableAcceleration(); |
1147 } else if (srcArea > ExpensiveCanvasHeuristicParameters:: | 1153 } else if (srcArea > ExpensiveCanvasHeuristicParameters:: |
1148 DrawImageTextureUploadSoftSizeLimit) { | 1154 DrawImageTextureUploadSoftSizeLimit) { |
1149 SkRect bounds = dstRect; | 1155 SkRect bounds = dstRect; |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 if (paint->getLooper() || paint->getImageFilter() || paint->getMaskFilter()) | 1715 if (paint->getLooper() || paint->getImageFilter() || paint->getMaskFilter()) |
1710 return; | 1716 return; |
1711 | 1717 |
1712 SkXfermode* xfermode = paint->getXfermode(); | 1718 SkXfermode* xfermode = paint->getXfermode(); |
1713 if (xfermode) { | 1719 if (xfermode) { |
1714 SkXfermode::Mode mode; | 1720 SkXfermode::Mode mode; |
1715 if (xfermode->asMode(&mode)) { | 1721 if (xfermode->asMode(&mode)) { |
1716 isSourceOver = mode == SkXfermode::kSrcOver_Mode; | 1722 isSourceOver = mode == SkXfermode::kSrcOver_Mode; |
1717 if (!isSourceOver && mode != SkXfermode::kSrc_Mode && | 1723 if (!isSourceOver && mode != SkXfermode::kSrc_Mode && |
1718 mode != SkXfermode::kClear_Mode) | 1724 mode != SkXfermode::kClear_Mode) |
1719 return; // The code below only knows how to handle Src, SrcOver, and
Clear | 1725 return; // The code below only knows how to handle Src, SrcOver, and |
| 1726 // Clear |
1720 } else { | 1727 } else { |
1721 // unknown xfermode | 1728 // unknown xfermode |
1722 ASSERT_NOT_REACHED(); | 1729 ASSERT_NOT_REACHED(); |
1723 return; | 1730 return; |
1724 } | 1731 } |
1725 } | 1732 } |
1726 | 1733 |
1727 alpha = paint->getAlpha(); | 1734 alpha = paint->getAlpha(); |
1728 | 1735 |
1729 if (isSourceOver && imageType == CanvasRenderingContext2DState::NoImage) { | 1736 if (isSourceOver && imageType == CanvasRenderingContext2DState::NoImage) { |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * | 1989 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * |
1983 m_usageCounters.numBlurredShadows + | 1990 m_usageCounters.numBlurredShadows + |
1984 ExpensiveCanvasHeuristicParameters:: | 1991 ExpensiveCanvasHeuristicParameters:: |
1985 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * | 1992 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * |
1986 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; | 1993 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; |
1987 | 1994 |
1988 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; | 1995 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; |
1989 } | 1996 } |
1990 | 1997 |
1991 } // namespace blink | 1998 } // namespace blink |
OLD | NEW |