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 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 if (static_cast<ImageBitmap*>(value.getAsImageBitmap())->isNeutered()) { | 851 if (static_cast<ImageBitmap*>(value.getAsImageBitmap())->isNeutered()) { |
852 exceptionState.throwDOMException(InvalidStateError, String::format("
The image source is detached")); | 852 exceptionState.throwDOMException(InvalidStateError, String::format("
The image source is detached")); |
853 return nullptr; | 853 return nullptr; |
854 } | 854 } |
855 return value.getAsImageBitmap(); | 855 return value.getAsImageBitmap(); |
856 } | 856 } |
857 ASSERT_NOT_REACHED(); | 857 ASSERT_NOT_REACHED(); |
858 return nullptr; | 858 return nullptr; |
859 } | 859 } |
860 | 860 |
861 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource
, double x, double y, ExceptionState& exceptionState) | 861 void BaseRenderingContext2D::drawImage(ExecutionContext* executionContext, const
CanvasImageSourceUnion& imageSource, double x, double y, ExceptionState& except
ionState) |
862 { | 862 { |
863 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource,
exceptionState); | 863 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource,
exceptionState); |
864 if (!imageSourceInternal) | 864 if (!imageSourceInternal) |
865 return; | 865 return; |
866 FloatSize defaultObjectSize(width(), height()); | 866 FloatSize defaultObjectSize(width(), height()); |
867 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz
e); | 867 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz
e); |
868 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(default
ObjectSize); | 868 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(default
ObjectSize); |
869 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.
height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState); | 869 drawImage(executionContext, imageSourceInternal, 0, 0, sourceRectSize.width(
), sourceRectSize.height(), x, y, destRectSize.width(), destRectSize.height(), e
xceptionState); |
870 } | 870 } |
871 | 871 |
872 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource
, | 872 void BaseRenderingContext2D::drawImage(ExecutionContext* executionContext, const
CanvasImageSourceUnion& imageSource, |
873 double x, double y, double width, double height, ExceptionState& exceptionSt
ate) | 873 double x, double y, double width, double height, ExceptionState& exceptionSt
ate) |
874 { | 874 { |
875 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource,
exceptionState); | 875 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource,
exceptionState); |
876 if (!imageSourceInternal) | 876 if (!imageSourceInternal) |
877 return; | 877 return; |
878 FloatSize defaultObjectSize(this->width(), this->height()); | 878 FloatSize defaultObjectSize(this->width(), this->height()); |
879 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz
e); | 879 FloatSize sourceRectSize = imageSourceInternal->elementSize(defaultObjectSiz
e); |
880 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.
height(), x, y, width, height, exceptionState); | 880 drawImage(executionContext, imageSourceInternal, 0, 0, sourceRectSize.width(
), sourceRectSize.height(), x, y, width, height, exceptionState); |
881 } | 881 } |
882 | 882 |
883 void BaseRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSource
, | 883 void BaseRenderingContext2D::drawImage(ExecutionContext* executionContext, const
CanvasImageSourceUnion& imageSource, |
884 double sx, double sy, double sw, double sh, | 884 double sx, double sy, double sw, double sh, |
885 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) | 885 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) |
886 { | 886 { |
887 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource,
exceptionState); | 887 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource,
exceptionState); |
888 if (!imageSourceInternal) | 888 if (!imageSourceInternal) |
889 return; | 889 return; |
890 drawImage(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat
e); | 890 drawImage(executionContext, imageSourceInternal, sx, sy, sw, sh, dx, dy, dw,
dh, exceptionState); |
891 } | 891 } |
892 | 892 |
893 bool BaseRenderingContext2D::shouldDrawImageAntialiased(const FloatRect& destRec
t) const | 893 bool BaseRenderingContext2D::shouldDrawImageAntialiased(const FloatRect& destRec
t) const |
894 { | 894 { |
895 if (!state().shouldAntialias()) | 895 if (!state().shouldAntialias()) |
896 return false; | 896 return false; |
897 SkCanvas* c = drawingCanvas(); | 897 SkCanvas* c = drawingCanvas(); |
898 ASSERT(c); | 898 ASSERT(c); |
899 | 899 |
900 const SkMatrix &ctm = c->getTotalMatrix(); | 900 const SkMatrix &ctm = c->getTotalMatrix(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 if (imageSource->isCanvasElement()) { | 974 if (imageSource->isCanvasElement()) { |
975 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(imageSource)
; | 975 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(imageSource)
; |
976 if (canvas->isAnimated2D()) { | 976 if (canvas->isAnimated2D()) { |
977 *reason = DisableDeferralReasonDrawImageOfAnimated2dCanvas; | 977 *reason = DisableDeferralReasonDrawImageOfAnimated2dCanvas; |
978 return true; | 978 return true; |
979 } | 979 } |
980 } | 980 } |
981 return false; | 981 return false; |
982 } | 982 } |
983 | 983 |
984 void BaseRenderingContext2D::drawImage(CanvasImageSource* imageSource, | 984 void BaseRenderingContext2D::drawImage(ExecutionContext* executionContext, Canva
sImageSource* imageSource, |
985 double sx, double sy, double sw, double sh, | 985 double sx, double sy, double sw, double sh, |
986 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) | 986 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) |
987 { | 987 { |
988 if (!drawingCanvas()) | 988 if (!drawingCanvas()) |
989 return; | 989 return; |
990 | 990 |
991 RefPtr<Image> image; | 991 RefPtr<Image> image; |
992 FloatSize defaultObjectSize(width(), height()); | 992 FloatSize defaultObjectSize(width(), height()); |
993 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; | 993 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; |
994 if (!imageSource->isVideoElement()) { | 994 if (!imageSource->isVideoElement()) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 | 1045 |
1046 if (imageSize.width() * imageSize.height() > width() * height() * ExpensiveC
anvasHeuristicParameters::ExpensiveImageSizeRatio) | 1046 if (imageSize.width() * imageSize.height() > width() * height() * ExpensiveC
anvasHeuristicParameters::ExpensiveImageSizeRatio) |
1047 isExpensive = true; | 1047 isExpensive = true; |
1048 | 1048 |
1049 if (isExpensive) { | 1049 if (isExpensive) { |
1050 ImageBuffer* buffer = imageBuffer(); | 1050 ImageBuffer* buffer = imageBuffer(); |
1051 if (buffer) | 1051 if (buffer) |
1052 buffer->setHasExpensiveOp(); | 1052 buffer->setHasExpensiveOp(); |
1053 } | 1053 } |
1054 | 1054 |
1055 if (originClean() && wouldTaintOrigin(imageSource, nullptr)) | 1055 if (originClean() && wouldTaintOrigin(imageSource, executionContext)) |
1056 setOriginTainted(); | 1056 setOriginTainted(); |
1057 } | 1057 } |
1058 | 1058 |
1059 void BaseRenderingContext2D::clearCanvas() | 1059 void BaseRenderingContext2D::clearCanvas() |
1060 { | 1060 { |
1061 FloatRect canvasRect(0, 0, width(), height()); | 1061 FloatRect canvasRect(0, 0, width(), height()); |
1062 checkOverdraw(canvasRect, 0, CanvasRenderingContext2DState::NoImage, ClipFil
l); | 1062 checkOverdraw(canvasRect, 0, CanvasRenderingContext2DState::NoImage, ClipFil
l); |
1063 SkCanvas* c = drawingCanvas(); | 1063 SkCanvas* c = drawingCanvas(); |
1064 if (c) | 1064 if (c) |
1065 c->clear(hasAlpha() ? SK_ColorTRANSPARENT : SK_ColorBLACK); | 1065 c->clear(hasAlpha() ? SK_ColorTRANSPARENT : SK_ColorBLACK); |
(...skipping 16 matching lines...) Expand all Loading... |
1082 { | 1082 { |
1083 if (r0 < 0 || r1 < 0) { | 1083 if (r0 < 0 || r1 < 0) { |
1084 exceptionState.throwDOMException(IndexSizeError, String::format("The %s
provided is less than 0.", r0 < 0 ? "r0" : "r1")); | 1084 exceptionState.throwDOMException(IndexSizeError, String::format("The %s
provided is less than 0.", r0 < 0 ? "r0" : "r1")); |
1085 return nullptr; | 1085 return nullptr; |
1086 } | 1086 } |
1087 | 1087 |
1088 CanvasGradient* gradient = CanvasGradient::create(FloatPoint(x0, y0), r0, Fl
oatPoint(x1, y1), r1); | 1088 CanvasGradient* gradient = CanvasGradient::create(FloatPoint(x0, y0), r0, Fl
oatPoint(x1, y1), r1); |
1089 return gradient; | 1089 return gradient; |
1090 } | 1090 } |
1091 | 1091 |
1092 CanvasPattern* BaseRenderingContext2D::createPattern(ScriptState* scriptState, c
onst CanvasImageSourceUnion& imageSource, const String& repetitionType, Exceptio
nState& exceptionState) | 1092 CanvasPattern* BaseRenderingContext2D::createPattern(ExecutionContext* execution
Context, const CanvasImageSourceUnion& imageSource, const String& repetitionType
, ExceptionState& exceptionState) |
1093 { | 1093 { |
1094 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti
onType, exceptionState); | 1094 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti
onType, exceptionState); |
1095 if (exceptionState.hadException()) | 1095 if (exceptionState.hadException()) |
1096 return nullptr; | 1096 return nullptr; |
1097 | 1097 |
1098 SourceImageStatus status; | 1098 SourceImageStatus status; |
1099 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource,
exceptionState); | 1099 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource,
exceptionState); |
1100 if (!imageSourceInternal) | 1100 if (!imageSourceInternal) |
1101 return nullptr; | 1101 return nullptr; |
1102 FloatSize defaultObjectSize(width(), height()); | 1102 FloatSize defaultObjectSize(width(), height()); |
(...skipping 12 matching lines...) Expand all Loading... |
1115 imageForRendering = Image::nullImage(); | 1115 imageForRendering = Image::nullImage(); |
1116 break; | 1116 break; |
1117 case IncompleteSourceImageStatus: | 1117 case IncompleteSourceImageStatus: |
1118 return nullptr; | 1118 return nullptr; |
1119 default: | 1119 default: |
1120 ASSERT_NOT_REACHED(); | 1120 ASSERT_NOT_REACHED(); |
1121 return nullptr; | 1121 return nullptr; |
1122 } | 1122 } |
1123 ASSERT(imageForRendering); | 1123 ASSERT(imageForRendering); |
1124 | 1124 |
1125 bool originClean = !wouldTaintOrigin(imageSourceInternal, scriptState); | 1125 bool originClean = !wouldTaintOrigin(imageSourceInternal, executionContext); |
1126 | 1126 |
1127 return CanvasPattern::create(imageForRendering.release(), repeatMode, origin
Clean); | 1127 return CanvasPattern::create(imageForRendering.release(), repeatMode, origin
Clean); |
1128 } | 1128 } |
1129 | 1129 |
1130 bool BaseRenderingContext2D::computeDirtyRect(const FloatRect& localRect, SkIRec
t* dirtyRect) | 1130 bool BaseRenderingContext2D::computeDirtyRect(const FloatRect& localRect, SkIRec
t* dirtyRect) |
1131 { | 1131 { |
1132 SkIRect clipBounds; | 1132 SkIRect clipBounds; |
1133 if (!drawingCanvas()->getClipDeviceBounds(&clipBounds)) | 1133 if (!drawingCanvas()->getClipDeviceBounds(&clipBounds)) |
1134 return false; | 1134 return false; |
1135 return computeDirtyRect(localRect, clipBounds, dirtyRect); | 1135 return computeDirtyRect(localRect, clipBounds, dirtyRect); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 | 1386 |
1387 imageBuffer()->willOverwriteCanvas(); | 1387 imageBuffer()->willOverwriteCanvas(); |
1388 } | 1388 } |
1389 | 1389 |
1390 DEFINE_TRACE(BaseRenderingContext2D) | 1390 DEFINE_TRACE(BaseRenderingContext2D) |
1391 { | 1391 { |
1392 visitor->trace(m_stateStack); | 1392 visitor->trace(m_stateStack); |
1393 } | 1393 } |
1394 | 1394 |
1395 } // namespace blink | 1395 } // namespace blink |
OLD | NEW |