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

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

Issue 1372463002: Re-land: Make 2D canvas smarter about chosing whether or not to use GPU acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed assert Created 5 years, 2 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 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, 1369 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource,
1370 float sx, float sy, float sw, float sh, 1370 float sx, float sy, float sw, float sh,
1371 float dx, float dy, float dw, float dh, ExceptionState& exceptionState) 1371 float dx, float dy, float dw, float dh, ExceptionState& exceptionState)
1372 { 1372 {
1373 if (!drawingCanvas()) 1373 if (!drawingCanvas())
1374 return; 1374 return;
1375 1375
1376 RefPtr<Image> image; 1376 RefPtr<Image> image;
1377 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus; 1377 SourceImageStatus sourceImageStatus = InvalidSourceImageStatus;
1378 if (!imageSource->isVideoElement()) { 1378 if (!imageSource->isVideoElement()) {
1379 image = imageSource->getSourceImageForCanvas(&sourceImageStatus); 1379 AccelerationHint hint = canvas()->buffer()->isAccelerated() ? PreferAcce leration : PreferNoAcceleration;
1380 image = imageSource->getSourceImageForCanvas(&sourceImageStatus, hint);
1380 if (sourceImageStatus == UndecodableSourceImageStatus) 1381 if (sourceImageStatus == UndecodableSourceImageStatus)
1381 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state."); 1382 exceptionState.throwDOMException(InvalidStateError, "The HTMLImageEl ement provided is in the 'broken' state.");
1382 if (!image || !image->width() || !image->height()) 1383 if (!image || !image->width() || !image->height())
1383 return; 1384 return;
1384 } else { 1385 } else {
1385 if (!static_cast<HTMLVideoElement*>(imageSource)->hasAvailableVideoFrame ()) 1386 if (!static_cast<HTMLVideoElement*>(imageSource)->hasAvailableVideoFrame ())
1386 return; 1387 return;
1387 } 1388 }
1388 1389
1389 if (!std::isfinite(dx) || !std::isfinite(dy) || !std::isfinite(dw) || !std:: isfinite(dh) 1390 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
1477 } 1478 }
1478 1479
1479 CanvasPattern* CanvasRenderingContext2D::createPattern(const CanvasImageSourceUn ion& imageSource, const String& repetitionType, ExceptionState& exceptionState) 1480 CanvasPattern* CanvasRenderingContext2D::createPattern(const CanvasImageSourceUn ion& imageSource, const String& repetitionType, ExceptionState& exceptionState)
1480 { 1481 {
1481 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState); 1482 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti onType, exceptionState);
1482 if (exceptionState.hadException()) 1483 if (exceptionState.hadException())
1483 return nullptr; 1484 return nullptr;
1484 1485
1485 SourceImageStatus status; 1486 SourceImageStatus status;
1486 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); 1487 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource);
1487 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status); 1488 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv as(&status, PreferNoAcceleration);
1488 1489
1489 switch (status) { 1490 switch (status) {
1490 case NormalSourceImageStatus: 1491 case NormalSourceImageStatus:
1491 break; 1492 break;
1492 case ZeroSizeCanvasSourceImageStatus: 1493 case ZeroSizeCanvasSourceImageStatus:
1493 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize().width() ? "height" : "width ")); 1494 exceptionState.throwDOMException(InvalidStateError, String::format("The canvas %s is 0.", imageSourceInternal->elementSize().width() ? "height" : "width "));
1494 return nullptr; 1495 return nullptr;
1495 case UndecodableSourceImageStatus: 1496 case UndecodableSourceImageStatus:
1496 exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state."); 1497 exceptionState.throwDOMException(InvalidStateError, "Source image is in the 'broken' state.");
1497 return nullptr; 1498 return nullptr;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 void CanvasRenderingContext2D::schedulePruneLocalFontCacheIfNeeded() 1768 void CanvasRenderingContext2D::schedulePruneLocalFontCacheIfNeeded()
1768 { 1769 {
1769 if (m_pruneLocalFontCacheScheduled) 1770 if (m_pruneLocalFontCacheScheduled)
1770 return; 1771 return;
1771 m_pruneLocalFontCacheScheduled = true; 1772 m_pruneLocalFontCacheScheduled = true;
1772 Platform::current()->currentThread()->addTaskObserver(this); 1773 Platform::current()->currentThread()->addTaskObserver(this);
1773 } 1774 }
1774 1775
1775 void CanvasRenderingContext2D::didProcessTask() 1776 void CanvasRenderingContext2D::didProcessTask()
1776 { 1777 {
1778 // The rendering surface needs to be prepared now because it will be too lat e
1779 // to create a layer once we are in the paint invalidation phase.
1780 canvas()->prepareSurfaceForPaintingIfNeeded();
1781
1777 pruneLocalFontCache(canvas()->document().canvasFontCache()->maxFonts()); 1782 pruneLocalFontCache(canvas()->document().canvasFontCache()->maxFonts());
1778 m_pruneLocalFontCacheScheduled = false; 1783 m_pruneLocalFontCacheScheduled = false;
1779 Platform::current()->currentThread()->removeTaskObserver(this); 1784 Platform::current()->currentThread()->removeTaskObserver(this);
1780 } 1785 }
1781 1786
1782 void CanvasRenderingContext2D::pruneLocalFontCache(size_t targetSize) 1787 void CanvasRenderingContext2D::pruneLocalFontCache(size_t targetSize)
1783 { 1788 {
1784 if (targetSize == 0) { 1789 if (targetSize == 0) {
1785 // Short cut: LRU does not matter when evicting everything 1790 // Short cut: LRU does not matter when evicting everything
1786 m_fontLRUList.clear(); 1791 m_fontLRUList.clear();
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 case RightTextAlign: 1996 case RightTextAlign:
1992 location.setX(location.x() - width); 1997 location.setX(location.x() - width);
1993 break; 1998 break;
1994 default: 1999 default:
1995 break; 2000 break;
1996 } 2001 }
1997 2002
1998 // The slop built in to this mask rect matches the heuristic used in FontCGW in.cpp for GDI text. 2003 // The slop built in to this mask rect matches the heuristic used in FontCGW in.cpp for GDI text.
1999 TextRunPaintInfo textRunPaintInfo(textRun); 2004 TextRunPaintInfo textRunPaintInfo(textRun);
2000 textRunPaintInfo.bounds = FloatRect(location.x() - fontMetrics.height() / 2, 2005 textRunPaintInfo.bounds = FloatRect(location.x() - fontMetrics.height() / 2,
2001 location.y() - fontMetrics.ascent() - fo ntMetrics.lineGap(), 2006 location.y() - fontMetrics.ascent() - fontMetrics.lineGap(),
2002 width + fontMetrics.height(), 2007 width + fontMetrics.height(),
2003 fontMetrics.lineSpacing()); 2008 fontMetrics.lineSpacing());
2004 if (paintType == CanvasRenderingContext2DState::StrokePaintType) 2009 if (paintType == CanvasRenderingContext2DState::StrokePaintType)
2005 inflateStrokeRect(textRunPaintInfo.bounds); 2010 inflateStrokeRect(textRunPaintInfo.bounds);
2006 2011
2007 CanvasRenderingContext2DAutoRestoreSkCanvas stateRestorer(this); 2012 CanvasRenderingContext2DAutoRestoreSkCanvas stateRestorer(this);
2008 if (useMaxWidth) { 2013 if (useMaxWidth) {
2009 drawingCanvas()->save(); 2014 drawingCanvas()->save();
2010 drawingCanvas()->translate(location.x(), location.y()); 2015 drawingCanvas()->translate(location.x(), location.y());
2011 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" o p) still work. 2016 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" o p) still work.
2012 drawingCanvas()->scale((fontWidth > 0 ? (width / fontWidth) : 0), 1); 2017 drawingCanvas()->scale((fontWidth > 0 ? (width / fontWidth) : 0), 1);
2013 location = FloatPoint(); 2018 location = FloatPoint();
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage) 2324 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage)
2320 return; 2325 return;
2321 if (alpha < 0xFF) 2326 if (alpha < 0xFF)
2322 return; 2327 return;
2323 } 2328 }
2324 2329
2325 canvas()->buffer()->willOverwriteCanvas(); 2330 canvas()->buffer()->willOverwriteCanvas();
2326 } 2331 }
2327 2332
2328 } // namespace blink 2333 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698