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

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

Issue 1307143005: Make 2D canvas smarter about chosing whether or not to use GPU acceleration (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 5 years, 3 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 | Annotate | Revision Log
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 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, 1370 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
1371 float sx, float sy, float sw, float sh, 1371 float sx, float sy, float sw, float sh,
1372 float dx, float dy, float dw, float dh, ExceptionState& exceptionState) 1372 float dx, float dy, float dw, float dh, ExceptionState& exceptionState)
1373 { 1373 {
1374 if (!drawingCanvas()) 1374 if (!drawingCanvas())
1375 return; 1375 return;
1376 1376
1377 RefPtr<Image> image; 1377 RefPtr<Image> image;
1378 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; 1378 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus;
1379 if (!imageSource->isVideoElement()) { 1379 if (!imageSource->isVideoElement()) {
1380 image = imageSource->getSourceImageForCanvas(&sourceImageStatus); 1380 AccelerationHint hint = canvas()->buffer()->isAccelerated() ? PreferAcce leration : PreferNoAcceleration;
1381 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint);
1381 if (sourceImageStatus == UndecodableSourceImageStatus) 1382 if (sourceImageStatus == UndecodableSourceImageStatus)
1382 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state."); 1383 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state.");
1383 if (!image || !image->width() || !image->height()) 1384 if (!image || !image->width() || !image->height())
1384 return; 1385 return;
1385 } else { 1386 } else {
1386 if (!static_cast<HTMLVideoElement*>(imageSource)->hasAvailableVideoFrame ()) 1387 if (!static_cast<HTMLVideoElement*>(imageSource)->hasAvailableVideoFrame ())
1387 return; 1388 return;
1388 } 1389 }
1389 1390
1390 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) || !std:: isfinite(dh) 1391 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) || !std:: isfinite(dh)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 } 1479 }
1479 1480
1480 CanvasPattern* CanvasRenderingContext2D::createPattern(const CanvasImageSourceUn ion& imageSource, const String& repetitionType, ExceptionState& exceptionState) 1481 CanvasPattern* CanvasRenderingContext2D::createPattern(const CanvasImageSourceUn ion& imageSource, const String& repetitionType, ExceptionState& exceptionState)
1481 { 1482 {
1482 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState); 1483 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState);
1483 if (exceptionState.hadException()) 1484 if (exceptionState.hadException())
1484 return nullptr; 1485 return nullptr;
1485 1486
1486 SourceImageStatus status; 1487 SourceImageStatus status;
1487 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 1488 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
1488 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status); 1489 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status, PreferNoAcceleration);
1489 1490
1490 switch (status) { 1491 switch (status) {
1491 case NormalSourceImageStatus: 1492 case NormalSourceImageStatus:
1492 break; 1493 break;
1493 case ZeroSizeCanvasSourceImageStatus: 1494 case ZeroSizeCanvasSourceImageStatus:
1494 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize().width() ? "height" : "width ")); 1495 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize().width() ? "height" : "width "));
1495 return nullptr; 1496 return nullptr;
1496 case UndecodableSourceImageStatus: 1497 case UndecodableSourceImageStatus:
1497 exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state."); 1498 exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state.");
1498 return nullptr; 1499 return nullptr;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 void CanvasRenderingContext2D::schedulePruneLocalFontCacheIfNeeded() 1769 void CanvasRenderingContext2D::schedulePruneLocalFontCacheIfNeeded()
1769 { 1770 {
1770 if (m_pruneLocalFontCacheScheduled) 1771 if (m_pruneLocalFontCacheScheduled)
1771 return; 1772 return;
1772 m_pruneLocalFontCacheScheduled = true; 1773 m_pruneLocalFontCacheScheduled = true;
1773 Platform::current()->currentThread()->addTaskObserver(this); 1774 Platform::current()->currentThread()->addTaskObserver(this);
1774 } 1775 }
1775 1776
1776 void CanvasRenderingContext2D::didProcessTask() 1777 void CanvasRenderingContext2D::didProcessTask()
1777 { 1778 {
1779 // The rendering surface needs to be prepared now because it will be too lat e
1780 // to create a layer once we are in the paint invalidation phase.
1781 canvas()->prepareSurfaceForPaintingIfNeeded();
1782
1778 pruneLocalFontCache(canvas()->document().canvasFontCache()->maxFonts()); 1783 pruneLocalFontCache(canvas()->document().canvasFontCache()->maxFonts());
1779 m_pruneLocalFontCacheScheduled = false; 1784 m_pruneLocalFontCacheScheduled = false;
1780 Platform::current()->currentThread()->removeTaskObserver(this); 1785 Platform::current()->currentThread()->removeTaskObserver(this);
1781 } 1786 }
1782 1787
1783 void CanvasRenderingContext2D::pruneLocalFontCache(size_t targetSize) 1788 void CanvasRenderingContext2D::pruneLocalFontCache(size_t targetSize)
1784 { 1789 {
1785 if (targetSize == 0) { 1790 if (targetSize == 0) {
1786 // Short cut: LRU does not matter when evicting everything 1791 // Short cut: LRU does not matter when evicting everything
1787 m_fontLRUList.clear(); 1792 m_fontLRUList.clear();
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage) 2325 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage)
2321 return; 2326 return;
2322 if (alpha < 0xFF) 2327 if (alpha < 0xFF)
2323 return; 2328 return;
2324 } 2329 }
2325 2330
2326 canvas()->buffer()->willOverwriteCanvas(); 2331 canvas()->buffer()->willOverwriteCanvas();
2327 } 2332 }
2328 2333
2329 } // namespace blink 2334 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698