Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
| 7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
| 8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
| 10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 m_tryRestoreContextAttemptCount(0), | 119 m_tryRestoreContextAttemptCount(0), |
| 120 m_dispatchContextLostEventTimer( | 120 m_dispatchContextLostEventTimer( |
| 121 this, | 121 this, |
| 122 &CanvasRenderingContext2D::dispatchContextLostEvent), | 122 &CanvasRenderingContext2D::dispatchContextLostEvent), |
| 123 m_dispatchContextRestoredEventTimer( | 123 m_dispatchContextRestoredEventTimer( |
| 124 this, | 124 this, |
| 125 &CanvasRenderingContext2D::dispatchContextRestoredEvent), | 125 &CanvasRenderingContext2D::dispatchContextRestoredEvent), |
| 126 m_tryRestoreContextEventTimer( | 126 m_tryRestoreContextEventTimer( |
| 127 this, | 127 this, |
| 128 &CanvasRenderingContext2D::tryRestoreContextEvent), | 128 &CanvasRenderingContext2D::tryRestoreContextEvent), |
| 129 m_pruneLocalFontCacheScheduled(false) { | 129 m_shouldPruneLocalFontCache(false) { |
| 130 if (document.settings() && | 130 if (document.settings() && |
| 131 document.settings()->getAntialiasedClips2dCanvasEnabled()) | 131 document.settings()->getAntialiasedClips2dCanvasEnabled()) |
| 132 m_clipAntialiasing = AntiAliased; | 132 m_clipAntialiasing = AntiAliased; |
| 133 setShouldAntialias(true); | 133 setShouldAntialias(true); |
| 134 validateStateStack(); | 134 validateStateStack(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void CanvasRenderingContext2D::setCanvasGetContextResult( | 137 void CanvasRenderingContext2D::setCanvasGetContextResult( |
| 138 RenderingContext& result) { | 138 RenderingContext& result) { |
| 139 result.setCanvasRenderingContext2D(this); | 139 result.setCanvasRenderingContext2D(this); |
| 140 } | 140 } |
| 141 | 141 |
| 142 CanvasRenderingContext2D::~CanvasRenderingContext2D() {} | 142 CanvasRenderingContext2D::~CanvasRenderingContext2D() {} |
| 143 | 143 |
| 144 void CanvasRenderingContext2D::dispose() { | |
| 145 if (m_pruneLocalFontCacheScheduled) | |
| 146 Platform::current()->currentThread()->removeTaskObserver(this); | |
| 147 } | |
| 148 | |
| 149 void CanvasRenderingContext2D::validateStateStack() const { | 144 void CanvasRenderingContext2D::validateStateStack() const { |
| 150 #if DCHECK_IS_ON() | 145 #if DCHECK_IS_ON() |
| 151 if (SkCanvas* skCanvas = canvas()->existingDrawingCanvas()) { | 146 if (SkCanvas* skCanvas = canvas()->existingDrawingCanvas()) { |
| 152 // The canvas should always have an initial save frame, to support | 147 // The canvas should always have an initial save frame, to support |
| 153 // resetting the top level matrix and clip. | 148 // resetting the top level matrix and clip. |
| 154 DCHECK_GT(skCanvas->getSaveCount(), 1); | 149 DCHECK_GT(skCanvas->getSaveCount(), 1); |
| 155 | 150 |
| 156 if (m_contextLostMode == NotLostContext) { | 151 if (m_contextLostMode == NotLostContext) { |
| 157 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), | 152 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), |
| 158 m_stateStack.size() + 1); | 153 m_stateStack.size() + 1); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 if (dirtyRect.isEmpty()) | 341 if (dirtyRect.isEmpty()) |
| 347 return; | 342 return; |
| 348 | 343 |
| 349 if (ExpensiveCanvasHeuristicParameters::BlurredShadowsAreExpensive && | 344 if (ExpensiveCanvasHeuristicParameters::BlurredShadowsAreExpensive && |
| 350 state().shouldDrawShadows() && state().shadowBlur() > 0) { | 345 state().shouldDrawShadows() && state().shadowBlur() > 0) { |
| 351 ImageBuffer* buffer = canvas()->buffer(); | 346 ImageBuffer* buffer = canvas()->buffer(); |
| 352 if (buffer) | 347 if (buffer) |
| 353 buffer->setHasExpensiveOp(); | 348 buffer->setHasExpensiveOp(); |
| 354 } | 349 } |
| 355 | 350 |
| 356 canvas()->didDraw(SkRect::Make(dirtyRect)); | 351 CanvasRenderingContext::didDraw(dirtyRect); |
| 357 } | 352 } |
| 358 | 353 |
| 359 bool CanvasRenderingContext2D::stateHasFilter() { | 354 bool CanvasRenderingContext2D::stateHasFilter() { |
| 360 return state().hasFilter(canvas(), canvas()->size(), this); | 355 return state().hasFilter(canvas(), canvas()->size(), this); |
| 361 } | 356 } |
| 362 | 357 |
| 363 sk_sp<SkImageFilter> CanvasRenderingContext2D::stateGetFilter() { | 358 sk_sp<SkImageFilter> CanvasRenderingContext2D::stateGetFilter() { |
| 364 return state().getFilter(canvas(), canvas()->size(), this); | 359 return state().getFilter(canvas(), canvas()->size(), this); |
| 365 } | 360 } |
| 366 | 361 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 elementFontDescription.setComputedSize( | 469 elementFontDescription.setComputedSize( |
| 475 elementFontDescription.specifiedSize()); | 470 elementFontDescription.specifiedSize()); |
| 476 fontStyle->setFontDescription(elementFontDescription); | 471 fontStyle->setFontDescription(elementFontDescription); |
| 477 fontStyle->font().update(fontStyle->font().getFontSelector()); | 472 fontStyle->font().update(fontStyle->font().getFontSelector()); |
| 478 canvas()->document().ensureStyleResolver().computeFont(fontStyle.get(), | 473 canvas()->document().ensureStyleResolver().computeFont(fontStyle.get(), |
| 479 *parsedStyle); | 474 *parsedStyle); |
| 480 m_fontsResolvedUsingCurrentStyle.add(newFont, fontStyle->font()); | 475 m_fontsResolvedUsingCurrentStyle.add(newFont, fontStyle->font()); |
| 481 DCHECK(!m_fontLRUList.contains(newFont)); | 476 DCHECK(!m_fontLRUList.contains(newFont)); |
| 482 m_fontLRUList.add(newFont); | 477 m_fontLRUList.add(newFont); |
| 483 pruneLocalFontCache(canvasFontCache->hardMaxFonts()); // hard limit | 478 pruneLocalFontCache(canvasFontCache->hardMaxFonts()); // hard limit |
| 484 schedulePruneLocalFontCacheIfNeeded(); // soft limit | 479 m_shouldPruneLocalFontCache = true; // apply soft limit |
| 485 modifiableState().setFont( | 480 modifiableState().setFont( |
| 486 fontStyle->font(), canvas()->document().styleEngine().fontSelector()); | 481 fontStyle->font(), canvas()->document().styleEngine().fontSelector()); |
| 487 } | 482 } |
| 488 } else { | 483 } else { |
| 489 Font resolvedFont; | 484 Font resolvedFont; |
| 490 if (!canvasFontCache->getFontUsingDefaultStyle(newFont, resolvedFont)) | 485 if (!canvasFontCache->getFontUsingDefaultStyle(newFont, resolvedFont)) |
| 491 return; | 486 return; |
| 492 modifiableState().setFont( | 487 modifiableState().setFont( |
| 493 resolvedFont, canvas()->document().styleEngine().fontSelector()); | 488 resolvedFont, canvas()->document().styleEngine().fontSelector()); |
| 494 } | 489 } |
| 495 | 490 |
| 496 // The parse succeeded. | 491 // The parse succeeded. |
| 497 String newFontSafeCopy(newFont); // Create a string copy since newFont can be | 492 String newFontSafeCopy(newFont); // Create a string copy since newFont can be |
| 498 // deleted inside realizeSaves. | 493 // deleted inside realizeSaves. |
| 499 modifiableState().setUnparsedFont(newFontSafeCopy); | 494 modifiableState().setUnparsedFont(newFontSafeCopy); |
| 500 } | 495 } |
| 501 | 496 |
| 502 void CanvasRenderingContext2D::schedulePruneLocalFontCacheIfNeeded() { | |
| 503 if (m_pruneLocalFontCacheScheduled) | |
| 504 return; | |
| 505 m_pruneLocalFontCacheScheduled = true; | |
| 506 Platform::current()->currentThread()->addTaskObserver(this); | |
| 507 } | |
| 508 | |
| 509 void CanvasRenderingContext2D::didProcessTask() { | 497 void CanvasRenderingContext2D::didProcessTask() { |
| 510 Platform::current()->currentThread()->removeTaskObserver(this); | 498 CanvasRenderingContext::didProcessTask(); |
| 511 | |
| 512 // This should be the only place where canvas() needs to be checked for | 499 // This should be the only place where canvas() needs to be checked for |
| 513 // nullness because the circular refence with HTMLCanvasElement mean the | 500 // nullness because the circular refence with HTMLCanvasElement means the |
| 514 // canvas and the context keep each other alive as long as the pair is | 501 // canvas and the context keep each other alive. As long as the pair is |
| 515 // referenced the task observer is the only persisten refernce to this object | 502 // referenced, the task observer is the only persistent refernce to this |
| 516 // that is not traced, so didProcessTask() may be call at a time when the | 503 // object |
| 504 // that is not traced, so didProcessTask() may be called at a time when the | |
| 517 // canvas has been garbage collected but not the context. | 505 // canvas has been garbage collected but not the context. |
| 518 if (!canvas()) | 506 if (m_shouldPruneLocalFontCache && canvas()) { |
| 519 return; | 507 m_shouldPruneLocalFontCache = false; |
| 520 | 508 pruneLocalFontCache(canvas()->document().canvasFontCache()->maxFonts()); |
| 521 // The rendering surface needs to be prepared now because it will be too late | 509 } |
| 522 // to create a layer once we are in the paint invalidation phase. | |
| 523 canvas()->prepareSurfaceForPaintingIfNeeded(); | |
|
xlai (Olivia)
2017/01/27 22:23:25
Is there any specific reason why you move this cre
Justin Novosad
2017/02/07 21:52:29
There is no change in functionality. Just a drive-
| |
| 524 | |
| 525 pruneLocalFontCache(canvas()->document().canvasFontCache()->maxFonts()); | |
| 526 m_pruneLocalFontCacheScheduled = false; | |
| 527 } | 510 } |
| 528 | 511 |
| 529 void CanvasRenderingContext2D::pruneLocalFontCache(size_t targetSize) { | 512 void CanvasRenderingContext2D::pruneLocalFontCache(size_t targetSize) { |
| 530 if (targetSize == 0) { | 513 if (targetSize == 0) { |
| 531 // Short cut: LRU does not matter when evicting everything | 514 // Short cut: LRU does not matter when evicting everything |
| 532 m_fontLRUList.clear(); | 515 m_fontLRUList.clear(); |
| 533 m_fontsResolvedUsingCurrentStyle.clear(); | 516 m_fontsResolvedUsingCurrentStyle.clear(); |
| 534 return; | 517 return; |
| 535 } | 518 } |
| 536 while (m_fontLRUList.size() > targetSize) { | 519 while (m_fontLRUList.size() > targetSize) { |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1165 } | 1148 } |
| 1166 return true; | 1149 return true; |
| 1167 } | 1150 } |
| 1168 | 1151 |
| 1169 void CanvasRenderingContext2D::resetUsageTracking() { | 1152 void CanvasRenderingContext2D::resetUsageTracking() { |
| 1170 UsageCounters newCounters; | 1153 UsageCounters newCounters; |
| 1171 m_usageCounters = newCounters; | 1154 m_usageCounters = newCounters; |
| 1172 } | 1155 } |
| 1173 | 1156 |
| 1174 } // namespace blink | 1157 } // namespace blink |
| OLD | NEW |