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

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

Issue 1992253002: Adding performance tracking for canvas API calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo Created 4 years, 7 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/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
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 Optional<ScopedUsHistogramTimer> timer;
993 if (imageBuffer() && imageBuffer()->isAccelerated()) {
994 if (imageSource->isVideoElement()) {
995 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterVideoGPU, ( "Blink.Canvas.DrawImage.VideoGPU", 0, 10000000, 50));
996 timer.emplace(scopedUsCounterVideoGPU);
997 } else if (imageSource->isCanvasElement()) {
998 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCanvasGPU, ("Blink.Canvas.DrawImage.CanvasGPU", 0, 10000000, 50));
999 timer.emplace(scopedUsCounterCanvasGPU);
1000 } else if (imageSource->isSVGSource()) {
1001 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSVGGPU, ("B link.Canvas.DrawImage.SVGGPU", 0, 10000000, 50));
1002 timer.emplace(scopedUsCounterSVGGPU);
1003 } else if (imageSource->isImageBitmap()) {
1004 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterImageBitmap GPU, ("Blink.Canvas.DrawImage.ImageBitmapGPU", 0, 10000000, 50));
1005 timer.emplace(scopedUsCounterImageBitmapGPU);
1006 } else {
1007 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterOthersGPU, ("Blink.Canvas.DrawImage.OthersGPU", 0, 10000000, 50));
1008 timer.emplace(scopedUsCounterOthersGPU);
1009 }
1010 } else if (imageBuffer() && imageBuffer()->isRecording()) {
1011 if (imageSource->isVideoElement()) {
1012 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterVideoDispla yList, ("Blink.Canvas.DrawImage.VideoDisplayList", 0, 10000000, 50));
1013 timer.emplace(scopedUsCounterVideoDisplayList);
1014 } else if (imageSource->isCanvasElement()) {
1015 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCanvasDispl ayList, ("Blink.Canvas.DrawImage.CanvasDisplayList", 0, 10000000, 50));
1016 timer.emplace(scopedUsCounterCanvasDisplayList);
1017 } else if (imageSource->isSVGSource()) {
1018 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSVGDisplayL ist, ("Blink.Canvas.DrawImage.SVGDisplayList", 0, 10000000, 50));
1019 timer.emplace(scopedUsCounterSVGDisplayList);
1020 } else if (imageSource->isImageBitmap()) {
1021 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterImageBitmap DisplayList, ("Blink.Canvas.DrawImage.ImageBitmapDisplayList", 0, 10000000, 50)) ;
1022 timer.emplace(scopedUsCounterImageBitmapDisplayList);
1023 } else {
1024 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterOthersDispl ayList, ("Blink.Canvas.DrawImage.OthersDisplayList", 0, 10000000, 50));
1025 timer.emplace(scopedUsCounterOthersDisplayList);
1026 }
1027 } else {
1028 if (imageSource->isVideoElement()) {
1029 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterVideoCPU, ( "Blink.Canvas.DrawImage.VideoCPU", 0, 10000000, 50));
1030 timer.emplace(scopedUsCounterVideoCPU);
1031 } else if (imageSource->isCanvasElement()) {
1032 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCanvasCPU, ("Blink.Canvas.DrawImage.CanvasCPU", 0, 10000000, 50));
1033 timer.emplace(scopedUsCounterCanvasCPU);
1034 } else if (imageSource->isSVGSource()) {
1035 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSVGCPU, ("B link.Canvas.DrawImage.SVGCPU", 0, 10000000, 50));
1036 timer.emplace(scopedUsCounterSVGCPU);
1037 } else if (imageSource->isImageBitmap()) {
1038 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterImageBitmap CPU, ("Blink.Canvas.DrawImage.ImageBitmapCPU", 0, 10000000, 50));
1039 timer.emplace(scopedUsCounterImageBitmapCPU);
1040 } else {
1041 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterOthersCPU, ("Blink.Canvas.DrawImage.OthersCPU", 0, 10000000, 50));
1042 timer.emplace(scopedUsCounterOthersCPU);
1043 }
1044 }
1045
991 RefPtr<Image> image; 1046 RefPtr<Image> image;
992 FloatSize defaultObjectSize(width(), height()); 1047 FloatSize defaultObjectSize(width(), height());
993 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; 1048 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus;
994 if (!imageSource->isVideoElement()) { 1049 if (!imageSource->isVideoElement()) {
995 AccelerationHint hint = imageBuffer()->isAccelerated() ? PreferAccelerat ion : PreferNoAcceleration; 1050 AccelerationHint hint = imageBuffer()->isAccelerated() ? PreferAccelerat ion : PreferNoAcceleration;
996 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint, S napshotReasonDrawImage, defaultObjectSize); 1051 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint, S napshotReasonDrawImage, defaultObjectSize);
997 if (sourceImageStatus == UndecodableSourceImageStatus) 1052 if (sourceImageStatus == UndecodableSourceImageStatus)
998 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state."); 1053 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state.");
999 if (!image || !image->width() || !image->height()) 1054 if (!image || !image->width() || !image->height())
1000 return; 1055 return;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 size.setHeight(1); 1238 size.setHeight(1);
1184 1239
1185 ImageData* result = ImageData::create(size); 1240 ImageData* result = ImageData::create(size);
1186 if (!result) 1241 if (!result)
1187 exceptionState.throwRangeError("Out of memory at ImageData creation"); 1242 exceptionState.throwRangeError("Out of memory at ImageData creation");
1188 return result; 1243 return result;
1189 } 1244 }
1190 1245
1191 ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw, double sh, ExceptionState& exceptionState) const 1246 ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw, double sh, ExceptionState& exceptionState) const
1192 { 1247 {
1248 Optional<ScopedUsHistogramTimer> timer;
1249 if (imageBuffer() && imageBuffer()->isAccelerated()) {
1250 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU, ("Blink.Ca nvas.GetImageData.GPU", 0, 10000000, 50));
1251 timer.emplace(scopedUsCounterGPU);
1252 } else if (imageBuffer() && imageBuffer()->isRecording()) {
1253 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDisplayList, (" Blink.Canvas.GetImageData.DisplayList", 0, 10000000, 50));
1254 timer.emplace(scopedUsCounterDisplayList);
1255 } else {
1256 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCPU, ("Blink.Ca nvas.GetImageData.CPU", 0, 10000000, 50));
1257 timer.emplace(scopedUsCounterCPU);
1258 }
1259
1193 if (!originClean()) 1260 if (!originClean())
1194 exceptionState.throwSecurityError("The canvas has been tainted by cross- origin data."); 1261 exceptionState.throwSecurityError("The canvas has been tainted by cross- origin data.");
1195 else if (!sw || !sh) 1262 else if (!sw || !sh)
1196 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is 0.", sw ? "height" : "width")); 1263 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is 0.", sw ? "height" : "width"));
1197 1264
1198 if (exceptionState.hadException()) 1265 if (exceptionState.hadException())
1199 return nullptr; 1266 return nullptr;
1200 1267
1201 if (sw < 0) { 1268 if (sw < 0) {
1202 sx += sw; 1269 sx += sw;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength())) ; 1303 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength())) ;
1237 } 1304 }
1238 1305
1239 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, ExceptionState& exceptionState) 1306 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, ExceptionState& exceptionState)
1240 { 1307 {
1241 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta te); 1308 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta te);
1242 } 1309 }
1243 1310
1244 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight, ExceptionS tate& exceptionState) 1311 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight, ExceptionS tate& exceptionState)
1245 { 1312 {
1313 Optional<ScopedUsHistogramTimer> timer;
1314 if (imageBuffer() && imageBuffer()->isAccelerated()) {
1315 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU, ("Blink.Ca nvas.PutImageData.GPU", 0, 10000000, 50));
1316 timer.emplace(scopedUsCounterGPU);
1317 } else if (imageBuffer() && imageBuffer()->isRecording()) {
1318 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDisplayList, (" Blink.Canvas.PutImageData.DisplayList", 0, 10000000, 50));
1319 timer.emplace(scopedUsCounterDisplayList);
1320 } else {
1321 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterCPU, ("Blink.Ca nvas.PutImageData.CPU", 0, 10000000, 50));
1322 timer.emplace(scopedUsCounterCPU);
1323 }
1324
1246 if (data->data()->bufferBase()->isNeutered()) { 1325 if (data->data()->bufferBase()->isNeutered()) {
1247 exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered."); 1326 exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered.");
1248 return; 1327 return;
1249 } 1328 }
1250 ImageBuffer* buffer = imageBuffer(); 1329 ImageBuffer* buffer = imageBuffer();
1251 if (!buffer) 1330 if (!buffer)
1252 return; 1331 return;
1253 1332
1254 if (dirtyWidth < 0) { 1333 if (dirtyWidth < 0) {
1255 dirtyX += dirtyWidth; 1334 dirtyX += dirtyWidth;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 1465
1387 imageBuffer()->willOverwriteCanvas(); 1466 imageBuffer()->willOverwriteCanvas();
1388 } 1467 }
1389 1468
1390 DEFINE_TRACE(BaseRenderingContext2D) 1469 DEFINE_TRACE(BaseRenderingContext2D)
1391 { 1470 {
1392 visitor->trace(m_stateStack); 1471 visitor->trace(m_stateStack);
1393 } 1472 }
1394 1473
1395 } // namespace blink 1474 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698