| 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" |
| 11 #include "core/frame/ImageBitmap.h" | 11 #include "core/frame/ImageBitmap.h" |
| 12 #include "core/html/HTMLCanvasElement.h" | 12 #include "core/html/HTMLCanvasElement.h" |
| 13 #include "core/html/HTMLImageElement.h" | 13 #include "core/html/HTMLImageElement.h" |
| 14 #include "core/html/HTMLVideoElement.h" | 14 #include "core/html/HTMLVideoElement.h" |
| 15 #include "core/html/ImageData.h" | 15 #include "core/html/ImageData.h" |
| 16 #include "modules/canvas2d/CanvasGradient.h" | 16 #include "modules/canvas2d/CanvasGradient.h" |
| 17 #include "modules/canvas2d/CanvasPattern.h" | 17 #include "modules/canvas2d/CanvasPattern.h" |
| 18 #include "modules/canvas2d/CanvasStyle.h" | 18 #include "modules/canvas2d/CanvasStyle.h" |
| 19 #include "modules/canvas2d/Path2D.h" | 19 #include "modules/canvas2d/Path2D.h" |
| 20 #include "platform/Histogram.h" |
| 20 #include "platform/geometry/FloatQuad.h" | 21 #include "platform/geometry/FloatQuad.h" |
| 21 #include "platform/graphics/Color.h" | 22 #include "platform/graphics/Color.h" |
| 22 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 23 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
| 23 #include "platform/graphics/Image.h" | 24 #include "platform/graphics/Image.h" |
| 24 #include "platform/graphics/ImageBuffer.h" | 25 #include "platform/graphics/ImageBuffer.h" |
| 25 #include "platform/graphics/StrokeData.h" | 26 #include "platform/graphics/StrokeData.h" |
| 26 #include "platform/graphics/skia/SkiaUtils.h" | 27 #include "platform/graphics/skia/SkiaUtils.h" |
| 27 #include "third_party/skia/include/core/SkImageFilter.h" | 28 #include "third_party/skia/include/core/SkImageFilter.h" |
| 28 | 29 |
| 29 namespace blink { | 30 namespace blink { |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 return false; | 982 return false; |
| 982 } | 983 } |
| 983 | 984 |
| 984 void BaseRenderingContext2D::drawImage(ExecutionContext* executionContext, Canva
sImageSource* imageSource, | 985 void BaseRenderingContext2D::drawImage(ExecutionContext* executionContext, Canva
sImageSource* imageSource, |
| 985 double sx, double sy, double sw, double sh, | 986 double sx, double sy, double sw, double sh, |
| 986 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) | 987 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) |
| 987 { | 988 { |
| 988 if (!drawingCanvas()) | 989 if (!drawingCanvas()) |
| 989 return; | 990 return; |
| 990 | 991 |
| 992 // TODO(xidachen): After collecting some data, come back and prune off |
| 993 // the ones that is not needed. |
| 994 Optional<ScopedUsHistogramTimer> timer; |
| 995 if (imageBuffer() && imageBuffer()->isAccelerated()) { |
| 996 if (imageSource->isVideoElement()) { |
| 997 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rVideoGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Video.GPU", 0, 10000
000, 50)); |
| 998 timer.emplace(scopedUsCounterVideoGPU); |
| 999 } else if (imageSource->isCanvasElement()) { |
| 1000 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rCanvasGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Canvas.GPU", 0, 100
00000, 50)); |
| 1001 timer.emplace(scopedUsCounterCanvasGPU); |
| 1002 } else if (imageSource->isSVGSource()) { |
| 1003 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rSVGGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.SVG.GPU", 0, 10000000,
50)); |
| 1004 timer.emplace(scopedUsCounterSVGGPU); |
| 1005 } else if (imageSource->isImageBitmap()) { |
| 1006 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rImageBitmapGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.ImageBitmap.GP
U", 0, 10000000, 50)); |
| 1007 timer.emplace(scopedUsCounterImageBitmapGPU); |
| 1008 } else { |
| 1009 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rOthersGPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Others.GPU", 0, 100
00000, 50)); |
| 1010 timer.emplace(scopedUsCounterOthersGPU); |
| 1011 } |
| 1012 } else if (imageBuffer() && imageBuffer()->isRecording()) { |
| 1013 if (imageSource->isVideoElement()) { |
| 1014 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rVideoDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.Video.Displa
yList", 0, 10000000, 50)); |
| 1015 timer.emplace(scopedUsCounterVideoDisplayList); |
| 1016 } else if (imageSource->isCanvasElement()) { |
| 1017 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rCanvasDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.Canvas.Disp
layList", 0, 10000000, 50)); |
| 1018 timer.emplace(scopedUsCounterCanvasDisplayList); |
| 1019 } else if (imageSource->isSVGSource()) { |
| 1020 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rSVGDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.SVG.DisplayLis
t", 0, 10000000, 50)); |
| 1021 timer.emplace(scopedUsCounterSVGDisplayList); |
| 1022 } else if (imageSource->isImageBitmap()) { |
| 1023 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rImageBitmapDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.ImageB
itmap.DisplayList", 0, 10000000, 50)); |
| 1024 timer.emplace(scopedUsCounterImageBitmapDisplayList); |
| 1025 } else { |
| 1026 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rOthersDisplayList, new CustomCountHistogram("Blink.Canvas.DrawImage.Others.Disp
layList", 0, 10000000, 50)); |
| 1027 timer.emplace(scopedUsCounterOthersDisplayList); |
| 1028 } |
| 1029 } else { |
| 1030 if (imageSource->isVideoElement()) { |
| 1031 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rVideoCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Video.CPU", 0, 10000
000, 50)); |
| 1032 timer.emplace(scopedUsCounterVideoCPU); |
| 1033 } else if (imageSource->isCanvasElement()) { |
| 1034 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rCanvasCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Canvas.CPU", 0, 100
00000, 50)); |
| 1035 timer.emplace(scopedUsCounterCanvasCPU); |
| 1036 } else if (imageSource->isSVGSource()) { |
| 1037 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rSVGCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.SVG.CPU", 0, 10000000,
50)); |
| 1038 timer.emplace(scopedUsCounterSVGCPU); |
| 1039 } else if (imageSource->isImageBitmap()) { |
| 1040 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rImageBitmapCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.ImageBitmap.CP
U", 0, 10000000, 50)); |
| 1041 timer.emplace(scopedUsCounterImageBitmapCPU); |
| 1042 } else { |
| 1043 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounte
rOthersCPU, new CustomCountHistogram("Blink.Canvas.DrawImage.Others.CPU", 0, 100
00000, 50)); |
| 1044 timer.emplace(scopedUsCounterOthersCPU); |
| 1045 } |
| 1046 } |
| 1047 |
| 991 RefPtr<Image> image; | 1048 RefPtr<Image> image; |
| 992 FloatSize defaultObjectSize(width(), height()); | 1049 FloatSize defaultObjectSize(width(), height()); |
| 993 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; | 1050 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; |
| 994 if (!imageSource->isVideoElement()) { | 1051 if (!imageSource->isVideoElement()) { |
| 995 AccelerationHint hint = imageBuffer()->isAccelerated() ? PreferAccelerat
ion : PreferNoAcceleration; | 1052 AccelerationHint hint = imageBuffer()->isAccelerated() ? PreferAccelerat
ion : PreferNoAcceleration; |
| 996 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint, S
napshotReasonDrawImage, defaultObjectSize); | 1053 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint, S
napshotReasonDrawImage, defaultObjectSize); |
| 997 if (sourceImageStatus == UndecodableSourceImageStatus) | 1054 if (sourceImageStatus == UndecodableSourceImageStatus) |
| 998 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl
ement provided is in the 'broken' state."); | 1055 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl
ement provided is in the 'broken' state."); |
| 999 if (!image || !image->width() || !image->height()) | 1056 if (!image || !image->width() || !image->height()) |
| 1000 return; | 1057 return; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 size.setHeight(1); | 1240 size.setHeight(1); |
| 1184 | 1241 |
| 1185 ImageData* result = ImageData::create(size); | 1242 ImageData* result = ImageData::create(size); |
| 1186 if (!result) | 1243 if (!result) |
| 1187 exceptionState.throwRangeError("Out of memory at ImageData creation"); | 1244 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
| 1188 return result; | 1245 return result; |
| 1189 } | 1246 } |
| 1190 | 1247 |
| 1191 ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw,
double sh, ExceptionState& exceptionState) const | 1248 ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw,
double sh, ExceptionState& exceptionState) const |
| 1192 { | 1249 { |
| 1250 Optional<ScopedUsHistogramTimer> timer; |
| 1251 if (imageBuffer() && imageBuffer()->isAccelerated()) { |
| 1252 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU
, new CustomCountHistogram("Blink.Canvas.GetImageData.GPU", 0, 10000000, 50)); |
| 1253 timer.emplace(scopedUsCounterGPU); |
| 1254 } else if (imageBuffer() && imageBuffer()->isRecording()) { |
| 1255 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDis
playList, new CustomCountHistogram("Blink.Canvas.GetImageData.DisplayList", 0, 1
0000000, 50)); |
| 1256 timer.emplace(scopedUsCounterDisplayList); |
| 1257 } else { |
| 1258 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCPU
, new CustomCountHistogram("Blink.Canvas.GetImageData.CPU", 0, 10000000, 50)); |
| 1259 timer.emplace(scopedUsCounterCPU); |
| 1260 } |
| 1261 |
| 1193 if (!originClean()) | 1262 if (!originClean()) |
| 1194 exceptionState.throwSecurityError("The canvas has been tainted by cross-
origin data."); | 1263 exceptionState.throwSecurityError("The canvas has been tainted by cross-
origin data."); |
| 1195 else if (!sw || !sh) | 1264 else if (!sw || !sh) |
| 1196 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is 0.", sw ? "height" : "width")); | 1265 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s is 0.", sw ? "height" : "width")); |
| 1197 | 1266 |
| 1198 if (exceptionState.hadException()) | 1267 if (exceptionState.hadException()) |
| 1199 return nullptr; | 1268 return nullptr; |
| 1200 | 1269 |
| 1201 if (sw < 0) { | 1270 if (sw < 0) { |
| 1202 sx += sw; | 1271 sx += sw; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength()))
; | 1305 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength()))
; |
| 1237 } | 1306 } |
| 1238 | 1307 |
| 1239 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy,
ExceptionState& exceptionState) | 1308 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy,
ExceptionState& exceptionState) |
| 1240 { | 1309 { |
| 1241 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta
te); | 1310 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta
te); |
| 1242 } | 1311 } |
| 1243 | 1312 |
| 1244 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy,
double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight, ExceptionS
tate& exceptionState) | 1313 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy,
double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight, ExceptionS
tate& exceptionState) |
| 1245 { | 1314 { |
| 1315 Optional<ScopedUsHistogramTimer> timer; |
| 1316 if (imageBuffer() && imageBuffer()->isAccelerated()) { |
| 1317 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU
, new CustomCountHistogram("Blink.Canvas.PutImageData.GPU", 0, 10000000, 50)); |
| 1318 timer.emplace(scopedUsCounterGPU); |
| 1319 } else if (imageBuffer() && imageBuffer()->isRecording()) { |
| 1320 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDis
playList, new CustomCountHistogram("Blink.Canvas.PutImageData.DisplayList", 0, 1
0000000, 50)); |
| 1321 timer.emplace(scopedUsCounterDisplayList); |
| 1322 } else { |
| 1323 DEFINE_THREAD_SAFE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCPU
, new CustomCountHistogram("Blink.Canvas.PutImageData.CPU", 0, 10000000, 50)); |
| 1324 timer.emplace(scopedUsCounterCPU); |
| 1325 } |
| 1326 |
| 1246 if (data->data()->bufferBase()->isNeutered()) { | 1327 if (data->data()->bufferBase()->isNeutered()) { |
| 1247 exceptionState.throwDOMException(InvalidStateError, "The source data has
been neutered."); | 1328 exceptionState.throwDOMException(InvalidStateError, "The source data has
been neutered."); |
| 1248 return; | 1329 return; |
| 1249 } | 1330 } |
| 1250 ImageBuffer* buffer = imageBuffer(); | 1331 ImageBuffer* buffer = imageBuffer(); |
| 1251 if (!buffer) | 1332 if (!buffer) |
| 1252 return; | 1333 return; |
| 1253 | 1334 |
| 1254 if (dirtyWidth < 0) { | 1335 if (dirtyWidth < 0) { |
| 1255 dirtyX += dirtyWidth; | 1336 dirtyX += dirtyWidth; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 | 1467 |
| 1387 imageBuffer()->willOverwriteCanvas(); | 1468 imageBuffer()->willOverwriteCanvas(); |
| 1388 } | 1469 } |
| 1389 | 1470 |
| 1390 DEFINE_TRACE(BaseRenderingContext2D) | 1471 DEFINE_TRACE(BaseRenderingContext2D) |
| 1391 { | 1472 { |
| 1392 visitor->trace(m_stateStack); | 1473 visitor->trace(m_stateStack); |
| 1393 } | 1474 } |
| 1394 | 1475 |
| 1395 } // namespace blink | 1476 } // namespace blink |
| OLD | NEW |