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

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

Issue 1609343004: Add display list fallback reason histograms for 2D canvas (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adding missing histogram Created 4 years, 11 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 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 431 }
432 canvasStyle = CanvasStyle::createFromRGBA(parsedColor.rgb()); 432 canvasStyle = CanvasStyle::createFromRGBA(parsedColor.rgb());
433 } else if (style.isCanvasGradient()) { 433 } else if (style.isCanvasGradient()) {
434 canvasStyle = CanvasStyle::createFromGradient(style.getAsCanvasGradient( )); 434 canvasStyle = CanvasStyle::createFromGradient(style.getAsCanvasGradient( ));
435 } else if (style.isCanvasPattern()) { 435 } else if (style.isCanvasPattern()) {
436 CanvasPattern* canvasPattern = style.getAsCanvasPattern(); 436 CanvasPattern* canvasPattern = style.getAsCanvasPattern();
437 437
438 if (canvas()->originClean() && !canvasPattern->originClean()) 438 if (canvas()->originClean() && !canvasPattern->originClean())
439 canvas()->setOriginTainted(); 439 canvas()->setOriginTainted();
440 if (canvasPattern->pattern()->isTextureBacked()) 440 if (canvasPattern->pattern()->isTextureBacked())
441 canvas()->disableDeferral(); 441 canvas()->disableDeferral(DisableDeferralReasonUsingTextureBackedPat tern);
442 canvasStyle = CanvasStyle::createFromPattern(canvasPattern); 442 canvasStyle = CanvasStyle::createFromPattern(canvasPattern);
443 } 443 }
444 444
445 ASSERT(canvasStyle); 445 ASSERT(canvasStyle);
446 modifiableState().setFillStyle(canvasStyle); 446 modifiableState().setFillStyle(canvasStyle);
447 modifiableState().setUnparsedFillColor(colorString); 447 modifiableState().setUnparsedFillColor(colorString);
448 } 448 }
449 449
450 double CanvasRenderingContext2D::lineWidth() const 450 double CanvasRenderingContext2D::lineWidth() const
451 { 451 {
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 c->translate(dstRect.x(), dstRect.y()); 1334 c->translate(dstRect.x(), dstRect.y());
1335 c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.h eight()); 1335 c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.h eight());
1336 c->translate(-srcRect.x(), -srcRect.y()); 1336 c->translate(-srcRect.x(), -srcRect.y());
1337 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource); 1337 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource);
1338 video->paintCurrentFrame(c, IntRect(IntPoint(), IntSize(video->videoWidt h(), video->videoHeight())), &imagePaint); 1338 video->paintCurrentFrame(c, IntRect(IntPoint(), IntSize(video->videoWidt h(), video->videoHeight())), &imagePaint);
1339 } 1339 }
1340 1340
1341 c->restoreToCount(initialSaveCount); 1341 c->restoreToCount(initialSaveCount);
1342 } 1342 }
1343 1343
1344 bool shouldDisableDeferral(CanvasImageSource* imageSource) 1344 bool shouldDisableDeferral(CanvasImageSource* imageSource, DisableDeferralReason * reason)
1345 { 1345 {
1346 if (imageSource->isVideoElement()) 1346 ASSERT(reason);
1347 ASSERT(*reason == DisableDeferralReasonUnknown);
1348
1349 if (imageSource->isVideoElement()) {
1350 *reason = DisableDeferralReasonDrawImageOfVideo;
1347 return true; 1351 return true;
1352 }
1348 if (imageSource->isCanvasElement()) { 1353 if (imageSource->isCanvasElement()) {
1349 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(imageSource) ; 1354 HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(imageSource) ;
1350 if (canvas->isAnimated2D()) 1355 if (canvas->isAnimated2D()) {
1356 *reason = DisableDeferralReasonDrawImageOfAnimated2dCanvas;
1351 return true; 1357 return true;
1358 }
1352 } 1359 }
1353 return false; 1360 return false;
1354 } 1361 }
1355 1362
1356 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, 1363 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
1357 double sx, double sy, double sw, double sh, 1364 double sx, double sy, double sw, double sh,
1358 double dx, double dy, double dw, double dh, ExceptionState& exceptionState) 1365 double dx, double dy, double dw, double dh, ExceptionState& exceptionState)
1359 { 1366 {
1360 if (!drawingCanvas()) 1367 if (!drawingCanvas())
1361 return; 1368 return;
1362 1369
1363 RefPtr<Image> image; 1370 RefPtr<Image> image;
1364 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; 1371 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus;
1365 if (!imageSource->isVideoElement()) { 1372 if (!imageSource->isVideoElement()) {
1366 AccelerationHint hint = canvas()->buffer()->isAccelerated() ? PreferAcce leration : PreferNoAcceleration; 1373 AccelerationHint hint = canvas()->buffer()->isAccelerated() ? PreferAcce leration : PreferNoAcceleration;
1367 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint); 1374 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint, S napshotReasonDrawImage);
1368 if (sourceImageStatus == UndecodableSourceImageStatus) 1375 if (sourceImageStatus == UndecodableSourceImageStatus)
1369 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state."); 1376 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state.");
1370 if (!image || !image->width() || !image->height()) 1377 if (!image || !image->width() || !image->height())
1371 return; 1378 return;
1372 } else { 1379 } else {
1373 if (!static_cast<HTMLVideoElement*>(imageSource)->hasAvailableVideoFrame ()) 1380 if (!static_cast<HTMLVideoElement*>(imageSource)->hasAvailableVideoFrame ())
1374 return; 1381 return;
1375 } 1382 }
1376 1383
1377 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) || !std:: isfinite(dh) 1384 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) || !std:: isfinite(dh)
1378 || !std::isfinite(sx) || !std::isfinite(sy) || !std::isfinite(sw) || !st d::isfinite(sh) 1385 || !std::isfinite(sx) || !std::isfinite(sy) || !std::isfinite(sw) || !st d::isfinite(sh)
1379 || !dw || !dh || !sw || !sh) 1386 || !dw || !dh || !sw || !sh)
1380 return; 1387 return;
1381 1388
1382 FloatRect srcRect = normalizeRect(FloatRect(sx, sy, sw, sh)); 1389 FloatRect srcRect = normalizeRect(FloatRect(sx, sy, sw, sh));
1383 FloatRect dstRect = normalizeRect(FloatRect(dx, dy, dw, dh)); 1390 FloatRect dstRect = normalizeRect(FloatRect(dx, dy, dw, dh));
1384 1391
1385 clipRectsToImageRect(FloatRect(FloatPoint(), imageSource->elementSize()), &s rcRect, &dstRect); 1392 clipRectsToImageRect(FloatRect(FloatPoint(), imageSource->elementSize()), &s rcRect, &dstRect);
1386 1393
1387 imageSource->adjustDrawRects(&srcRect, &dstRect); 1394 imageSource->adjustDrawRects(&srcRect, &dstRect);
1388 1395
1389 if (srcRect.isEmpty()) 1396 if (srcRect.isEmpty())
1390 return; 1397 return;
1391 1398
1392 if (shouldDisableDeferral(imageSource) || image->isTextureBacked()) 1399 DisableDeferralReason reason = DisableDeferralReasonUnknown;
1393 canvas()->disableDeferral(); 1400 if (shouldDisableDeferral(imageSource, &reason) || image->isTextureBacked())
1401 canvas()->disableDeferral(reason);
1394 1402
1395 validateStateStack(); 1403 validateStateStack();
1396 1404
1397 draw( 1405 draw(
1398 [this, &imageSource, &image, &srcRect, dstRect](SkCanvas* c, const SkPai nt* paint) // draw lambda 1406 [this, &imageSource, &image, &srcRect, dstRect](SkCanvas* c, const SkPai nt* paint) // draw lambda
1399 { 1407 {
1400 drawImageInternal(c, imageSource, image.get(), srcRect, dstRect, pai nt); 1408 drawImageInternal(c, imageSource, image.get(), srcRect, dstRect, pai nt);
1401 }, 1409 },
1402 [this, &dstRect](const SkIRect& clipBounds) // overdraw test lambda 1410 [this, &dstRect](const SkIRect& clipBounds) // overdraw test lambda
1403 { 1411 {
(...skipping 13 matching lines...) Expand all
1417 1425
1418 if (isExpensive) { 1426 if (isExpensive) {
1419 ImageBuffer* buffer = canvas()->buffer(); 1427 ImageBuffer* buffer = canvas()->buffer();
1420 if (buffer) 1428 if (buffer)
1421 buffer->setHasExpensiveOp(); 1429 buffer->setHasExpensiveOp();
1422 } 1430 }
1423 1431
1424 if (imageSource->isCanvasElement() && static_cast<HTMLCanvasElement*>(imageS ource)->is3D()) { 1432 if (imageSource->isCanvasElement() && static_cast<HTMLCanvasElement*>(imageS ource)->is3D()) {
1425 // WebGL to 2D canvas: must flush graphics context to prevent a race 1433 // WebGL to 2D canvas: must flush graphics context to prevent a race
1426 // FIXME: crbug.com/516331 Fix the underlying synchronization issue so t his flush can be eliminated. 1434 // FIXME: crbug.com/516331 Fix the underlying synchronization issue so t his flush can be eliminated.
1427 canvas()->buffer()->flushGpu(); 1435 canvas()->buffer()->flushGpu(FlushReasonDrawImageOfWebGL);
1428 } 1436 }
1429 1437
1430 if (canvas()->originClean() && wouldTaintOrigin(imageSource)) 1438 if (canvas()->originClean() && wouldTaintOrigin(imageSource))
1431 canvas()->setOriginTainted(); 1439 canvas()->setOriginTainted();
1432 } 1440 }
1433 1441
1434 void CanvasRenderingContext2D::clearCanvas() 1442 void CanvasRenderingContext2D::clearCanvas()
1435 { 1443 {
1436 FloatRect canvasRect(0, 0, canvas()->width(), canvas()->height()); 1444 FloatRect canvasRect(0, 0, canvas()->width(), canvas()->height());
1437 checkOverdraw(canvasRect, 0, CanvasRenderingContext2DState::NoImage, ClipFil l); 1445 checkOverdraw(canvasRect, 0, CanvasRenderingContext2DState::NoImage, ClipFil l);
(...skipping 27 matching lines...) Expand all
1465 } 1473 }
1466 1474
1467 CanvasPattern* CanvasRenderingContext2D::createPattern(const CanvasImageSourceUn ion& imageSource, const String& repetitionType, ExceptionState& exceptionState) 1475 CanvasPattern* CanvasRenderingContext2D::createPattern(const CanvasImageSourceUn ion& imageSource, const String& repetitionType, ExceptionState& exceptionState)
1468 { 1476 {
1469 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState); 1477 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState);
1470 if (exceptionState.hadException()) 1478 if (exceptionState.hadException())
1471 return nullptr; 1479 return nullptr;
1472 1480
1473 SourceImageStatus status; 1481 SourceImageStatus status;
1474 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 1482 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
1475 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status, PreferNoAcceleration); 1483 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status, PreferNoAcceleration, SnapshotReasonCreatePattern);
1476 1484
1477 switch (status) { 1485 switch (status) {
1478 case NormalSourceImageStatus: 1486 case NormalSourceImageStatus:
1479 break; 1487 break;
1480 case ZeroSizeCanvasSourceImageStatus: 1488 case ZeroSizeCanvasSourceImageStatus:
1481 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize().width() ? "height" : "width ")); 1489 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize().width() ? "height" : "width "));
1482 return nullptr; 1490 return nullptr;
1483 case UndecodableSourceImageStatus: 1491 case UndecodableSourceImageStatus:
1484 exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state."); 1492 exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state.");
1485 return nullptr; 1493 return nullptr;
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage) 2336 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage)
2329 return; 2337 return;
2330 if (alpha < 0xFF) 2338 if (alpha < 0xFF)
2331 return; 2339 return;
2332 } 2340 }
2333 2341
2334 canvas()->buffer()->willOverwriteCanvas(); 2342 canvas()->buffer()->willOverwriteCanvas();
2335 } 2343 }
2336 2344
2337 } // namespace blink 2345 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698