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

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: 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 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 return true; 979 return true;
979 } 980 }
980 } 981 }
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 {
989 Optional<ScopedUsHistogramTimer> timer;
990 if (imageBuffer() && imageBuffer()->isAccelerated()) {
991 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU, ("Blink.Ca nvas.DrawImage.GPU", 0, 10000000, 50));
Justin Novosad 2016/05/19 15:36:55 Should also classify by type of image source.
xidachen 2016/05/20 12:36:54 Done.
992 timer.emplace(scopedUsCounterGPU);
993 } else if (imageBuffer() && imageBuffer()->isRecording()) {
994 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDL, ("Blink.Can vas.DrawImage.DL", 0, 10000000, 50));
995 timer.emplace(scopedUsCounterDL);
996 } else {
997 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSW, ("Blink.Can vas.DrawImage.SW", 0, 10000000, 50));
998 timer.emplace(scopedUsCounterSW);
999 }
1000
988 if (!drawingCanvas()) 1001 if (!drawingCanvas())
989 return; 1002 return;
990 1003
991 RefPtr<Image> image; 1004 RefPtr<Image> image;
992 FloatSize defaultObjectSize(width(), height()); 1005 FloatSize defaultObjectSize(width(), height());
993 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; 1006 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus;
994 if (!imageSource->isVideoElement()) { 1007 if (!imageSource->isVideoElement()) {
995 AccelerationHint hint = imageBuffer()->isAccelerated() ? PreferAccelerat ion : PreferNoAcceleration; 1008 AccelerationHint hint = imageBuffer()->isAccelerated() ? PreferAccelerat ion : PreferNoAcceleration;
996 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint, S napshotReasonDrawImage, defaultObjectSize); 1009 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint, S napshotReasonDrawImage, defaultObjectSize);
997 if (sourceImageStatus == UndecodableSourceImageStatus) 1010 if (sourceImageStatus == UndecodableSourceImageStatus)
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 ImageData* BaseRenderingContext2D::createImageData(ImageData* imageData, Excepti onState &exceptionState) const 1173 ImageData* BaseRenderingContext2D::createImageData(ImageData* imageData, Excepti onState &exceptionState) const
1161 { 1174 {
1162 ImageData* result = ImageData::create(imageData->size()); 1175 ImageData* result = ImageData::create(imageData->size());
1163 if (!result) 1176 if (!result)
1164 exceptionState.throwRangeError("Out of memory at ImageData creation"); 1177 exceptionState.throwRangeError("Out of memory at ImageData creation");
1165 return result; 1178 return result;
1166 } 1179 }
1167 1180
1168 ImageData* BaseRenderingContext2D::createImageData(double sw, double sh, Excepti onState& exceptionState) const 1181 ImageData* BaseRenderingContext2D::createImageData(double sw, double sh, Excepti onState& exceptionState) const
1169 { 1182 {
1183 Optional<ScopedUsHistogramTimer> timer;
1184 if (imageBuffer() && imageBuffer()->isAccelerated()) {
1185 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU, ("Blink.Ca nvas.CreateImageData.GPU", 0, 10000000, 50));
Justin Novosad 2016/05/19 15:36:55 I don think we need to measure this one. It's over
xidachen 2016/05/20 12:36:54 Done.
1186 timer.emplace(scopedUsCounterGPU);
1187 } else if (imageBuffer() && imageBuffer()->isRecording()) {
1188 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDL, ("Blink.Can vas.CreateImageData.DL", 0, 10000000, 50));
1189 timer.emplace(scopedUsCounterDL);
1190 } else {
1191 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSW, ("Blink.Can vas.CreateImageData.SW", 0, 10000000, 50));
1192 timer.emplace(scopedUsCounterSW);
1193 }
1194
1170 if (!sw || !sh) { 1195 if (!sw || !sh) {
1171 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is 0.", sw ? "height" : "width")); 1196 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is 0.", sw ? "height" : "width"));
1172 return nullptr; 1197 return nullptr;
1173 } 1198 }
1174 1199
1175 FloatSize logicalSize(fabs(sw), fabs(sh)); 1200 FloatSize logicalSize(fabs(sw), fabs(sh));
1176 if (!logicalSize.isExpressibleAsIntSize()) 1201 if (!logicalSize.isExpressibleAsIntSize())
1177 return nullptr; 1202 return nullptr;
1178 1203
1179 IntSize size = expandedIntSize(logicalSize); 1204 IntSize size = expandedIntSize(logicalSize);
1180 if (size.width() < 1) 1205 if (size.width() < 1)
1181 size.setWidth(1); 1206 size.setWidth(1);
1182 if (size.height() < 1) 1207 if (size.height() < 1)
1183 size.setHeight(1); 1208 size.setHeight(1);
1184 1209
1185 ImageData* result = ImageData::create(size); 1210 ImageData* result = ImageData::create(size);
1186 if (!result) 1211 if (!result)
1187 exceptionState.throwRangeError("Out of memory at ImageData creation"); 1212 exceptionState.throwRangeError("Out of memory at ImageData creation");
1188 return result; 1213 return result;
1189 } 1214 }
1190 1215
1191 ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw, double sh, ExceptionState& exceptionState) const 1216 ImageData* BaseRenderingContext2D::getImageData(double sx, double sy, double sw, double sh, ExceptionState& exceptionState) const
1192 { 1217 {
1218 Optional<ScopedUsHistogramTimer> timer;
1219 if (imageBuffer() && imageBuffer()->isAccelerated()) {
1220 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU, ("Blink.Ca nvas.GetImageData.GPU", 0, 10000000, 50));
1221 timer.emplace(scopedUsCounterGPU);
1222 } else if (imageBuffer() && imageBuffer()->isRecording()) {
1223 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDL, ("Blink.Can vas.GetImageData.DL", 0, 10000000, 50));
1224 timer.emplace(scopedUsCounterDL);
1225 } else {
1226 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSW, ("Blink.Can vas.GetImageData.SW", 0, 10000000, 50));
1227 timer.emplace(scopedUsCounterSW);
1228 }
1229
1193 if (!originClean()) 1230 if (!originClean())
1194 exceptionState.throwSecurityError("The canvas has been tainted by cross- origin data."); 1231 exceptionState.throwSecurityError("The canvas has been tainted by cross- origin data.");
1195 else if (!sw || !sh) 1232 else if (!sw || !sh)
1196 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is 0.", sw ? "height" : "width")); 1233 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s is 0.", sw ? "height" : "width"));
1197 1234
1198 if (exceptionState.hadException()) 1235 if (exceptionState.hadException())
1199 return nullptr; 1236 return nullptr;
1200 1237
1201 if (sw < 0) { 1238 if (sw < 0) {
1202 sx += sw; 1239 sx += sw;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength())) ; 1273 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength())) ;
1237 } 1274 }
1238 1275
1239 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, ExceptionState& exceptionState) 1276 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, ExceptionState& exceptionState)
1240 { 1277 {
1241 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta te); 1278 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), exceptionSta te);
1242 } 1279 }
1243 1280
1244 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight, ExceptionS tate& exceptionState) 1281 void BaseRenderingContext2D::putImageData(ImageData* data, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight, ExceptionS tate& exceptionState)
1245 { 1282 {
1283 Optional<ScopedUsHistogramTimer> timer;
1284 if (imageBuffer() && imageBuffer()->isAccelerated()) {
1285 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterGPU, ("Blink.Ca nvas.PutImageData.GPU", 0, 10000000, 50));
1286 timer.emplace(scopedUsCounterGPU);
1287 } else if (imageBuffer() && imageBuffer()->isRecording()) {
1288 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterDL, ("Blink.Can vas.PutImageData.DL", 0, 10000000, 50));
1289 timer.emplace(scopedUsCounterDL);
1290 } else {
1291 DEFINE_STATIC_LOCAL(CustomCountHistogram, scopedUsCounterSW, ("Blink.Can vas.PutImageData.SW", 0, 10000000, 50));
1292 timer.emplace(scopedUsCounterSW);
1293 }
1294
1246 if (data->data()->bufferBase()->isNeutered()) { 1295 if (data->data()->bufferBase()->isNeutered()) {
1247 exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered."); 1296 exceptionState.throwDOMException(InvalidStateError, "The source data has been neutered.");
1248 return; 1297 return;
1249 } 1298 }
1250 ImageBuffer* buffer = imageBuffer(); 1299 ImageBuffer* buffer = imageBuffer();
1251 if (!buffer) 1300 if (!buffer)
1252 return; 1301 return;
1253 1302
1254 if (dirtyWidth < 0) { 1303 if (dirtyWidth < 0) {
1255 dirtyX += dirtyWidth; 1304 dirtyX += dirtyWidth;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 1435
1387 imageBuffer()->willOverwriteCanvas(); 1436 imageBuffer()->willOverwriteCanvas();
1388 } 1437 }
1389 1438
1390 DEFINE_TRACE(BaseRenderingContext2D) 1439 DEFINE_TRACE(BaseRenderingContext2D)
1391 { 1440 {
1392 visitor->trace(m_stateStack); 1441 visitor->trace(m_stateStack);
1393 } 1442 }
1394 1443
1395 } // namespace blink 1444 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698