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

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp

Issue 2387093002: Reflow comments in canvas-related folders (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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
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
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
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
559 // platforms already
555 // implement the specification's behavior. 560 // implement the specification's behavior.
556 return op == SkXfermode::kSrcIn_Mode || op == SkXfermode::kSrcOut_Mode || 561 return op == SkXfermode::kSrcIn_Mode || op == SkXfermode::kSrcOut_Mode ||
557 op == SkXfermode::kDstIn_Mode || op == SkXfermode::kDstATop_Mode; 562 op == SkXfermode::kDstIn_Mode || op == SkXfermode::kDstATop_Mode;
558 } 563 }
559 564
560 static bool isPathExpensive(const Path& path) { 565 static bool isPathExpensive(const Path& path) {
561 const SkPath& skPath = path.getSkPath(); 566 const SkPath& skPath = path.getSkPath();
562 if (ExpensiveCanvasHeuristicParameters::ConcavePathsAreExpensive && 567 if (ExpensiveCanvasHeuristicParameters::ConcavePathsAreExpensive &&
563 !skPath.isConvex()) 568 !skPath.isConvex())
564 return true; 569 return true;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 851
847 // Compute the src to dst transform 852 // Compute the src to dst transform
848 FloatSize scale(dstRect->size().width() / srcRect->size().width(), 853 FloatSize scale(dstRect->size().width() / srcRect->size().width(),
849 dstRect->size().height() / srcRect->size().height()); 854 dstRect->size().height() / srcRect->size().height());
850 FloatPoint scaledSrcLocation = srcRect->location(); 855 FloatPoint scaledSrcLocation = srcRect->location();
851 scaledSrcLocation.scale(scale.width(), scale.height()); 856 scaledSrcLocation.scale(scale.width(), scale.height());
852 FloatSize offset = dstRect->location() - scaledSrcLocation; 857 FloatSize offset = dstRect->location() - scaledSrcLocation;
853 858
854 srcRect->intersect(imageRect); 859 srcRect->intersect(imageRect);
855 860
856 // To clip the destination rectangle in the same proportion, transform the cli pped src rect 861 // To clip the destination rectangle in the same proportion, transform the
862 // clipped src rect
857 *dstRect = *srcRect; 863 *dstRect = *srcRect;
858 dstRect->scale(scale.width(), scale.height()); 864 dstRect->scale(scale.width(), scale.height());
859 dstRect->move(offset); 865 dstRect->move(offset);
860 } 866 }
861 867
862 static inline CanvasImageSource* toImageSourceInternal( 868 static inline CanvasImageSource* toImageSourceInternal(
863 const CanvasImageSourceUnion& value, 869 const CanvasImageSourceUnion& value,
864 ExceptionState& exceptionState) { 870 ExceptionState& exceptionState) {
865 if (value.isCSSImageValue()) { 871 if (value.isCSSImageValue()) {
866 if (RuntimeEnabledFeatures::cssPaintAPIEnabled()) 872 if (RuntimeEnabledFeatures::cssPaintAPIEnabled())
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 return; 1135 return;
1130 1136
1131 DisableDeferralReason reason = DisableDeferralReasonUnknown; 1137 DisableDeferralReason reason = DisableDeferralReasonUnknown;
1132 if (shouldDisableDeferral(imageSource, &reason)) 1138 if (shouldDisableDeferral(imageSource, &reason))
1133 disableDeferral(reason); 1139 disableDeferral(reason);
1134 else if (image->isTextureBacked()) 1140 else if (image->isTextureBacked())
1135 disableDeferral(DisableDeferralDrawImageWithTextureBackedSourceImage); 1141 disableDeferral(DisableDeferralDrawImageWithTextureBackedSourceImage);
1136 1142
1137 validateStateStack(); 1143 validateStateStack();
1138 1144
1139 // Heuristic for disabling acceleration based on anticipated texture upload ov erhead 1145 // Heuristic for disabling acceleration based on anticipated texture upload
1146 // overhead
1140 // See comments in ExpensiveCanvasHeuristicParameters.h for explanation. 1147 // See comments in ExpensiveCanvasHeuristicParameters.h for explanation.
1141 ImageBuffer* buffer = imageBuffer(); 1148 ImageBuffer* buffer = imageBuffer();
1142 if (buffer && buffer->isAccelerated() && !imageSource->isAccelerated()) { 1149 if (buffer && buffer->isAccelerated() && !imageSource->isAccelerated()) {
1143 float srcArea = srcRect.width() * srcRect.height(); 1150 float srcArea = srcRect.width() * srcRect.height();
1144 if (srcArea > ExpensiveCanvasHeuristicParameters:: 1151 if (srcArea > ExpensiveCanvasHeuristicParameters::
1145 DrawImageTextureUploadHardSizeLimit) { 1152 DrawImageTextureUploadHardSizeLimit) {
1146 buffer->disableAcceleration(); 1153 buffer->disableAcceleration();
1147 } else if (srcArea > ExpensiveCanvasHeuristicParameters:: 1154 } else if (srcArea > ExpensiveCanvasHeuristicParameters::
1148 DrawImageTextureUploadSoftSizeLimit) { 1155 DrawImageTextureUploadSoftSizeLimit) {
1149 SkRect bounds = dstRect; 1156 SkRect bounds = dstRect;
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 if (paint->getLooper() || paint->getImageFilter() || paint->getMaskFilter()) 1716 if (paint->getLooper() || paint->getImageFilter() || paint->getMaskFilter())
1710 return; 1717 return;
1711 1718
1712 SkXfermode* xfermode = paint->getXfermode(); 1719 SkXfermode* xfermode = paint->getXfermode();
1713 if (xfermode) { 1720 if (xfermode) {
1714 SkXfermode::Mode mode; 1721 SkXfermode::Mode mode;
1715 if (xfermode->asMode(&mode)) { 1722 if (xfermode->asMode(&mode)) {
1716 isSourceOver = mode == SkXfermode::kSrcOver_Mode; 1723 isSourceOver = mode == SkXfermode::kSrcOver_Mode;
1717 if (!isSourceOver && mode != SkXfermode::kSrc_Mode && 1724 if (!isSourceOver && mode != SkXfermode::kSrc_Mode &&
1718 mode != SkXfermode::kClear_Mode) 1725 mode != SkXfermode::kClear_Mode)
1719 return; // The code below only knows how to handle Src, SrcOver, and Clear 1726 return; // The code below only knows how to handle Src, SrcOver, and
1727 // Clear
1720 } else { 1728 } else {
1721 // unknown xfermode 1729 // unknown xfermode
1722 ASSERT_NOT_REACHED(); 1730 ASSERT_NOT_REACHED();
1723 return; 1731 return;
1724 } 1732 }
1725 } 1733 }
1726 1734
1727 alpha = paint->getAlpha(); 1735 alpha = paint->getAlpha();
1728 1736
1729 if (isSourceOver && imageType == CanvasRenderingContext2DState::NoImage) { 1737 if (isSourceOver && imageType == CanvasRenderingContext2DState::NoImage) {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * 1990 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] *
1983 m_usageCounters.numBlurredShadows + 1991 m_usageCounters.numBlurredShadows +
1984 ExpensiveCanvasHeuristicParameters:: 1992 ExpensiveCanvasHeuristicParameters::
1985 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * 1993 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] *
1986 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; 1994 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared;
1987 1995
1988 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; 1996 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment;
1989 } 1997 }
1990 1998
1991 } // namespace blink 1999 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698