| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 m_tryRestoreContextAttemptCount(0), | 120 m_tryRestoreContextAttemptCount(0), |
| 121 m_dispatchContextLostEventTimer( | 121 m_dispatchContextLostEventTimer( |
| 122 this, | 122 this, |
| 123 &CanvasRenderingContext2D::dispatchContextLostEvent), | 123 &CanvasRenderingContext2D::dispatchContextLostEvent), |
| 124 m_dispatchContextRestoredEventTimer( | 124 m_dispatchContextRestoredEventTimer( |
| 125 this, | 125 this, |
| 126 &CanvasRenderingContext2D::dispatchContextRestoredEvent), | 126 &CanvasRenderingContext2D::dispatchContextRestoredEvent), |
| 127 m_tryRestoreContextEventTimer( | 127 m_tryRestoreContextEventTimer( |
| 128 this, | 128 this, |
| 129 &CanvasRenderingContext2D::tryRestoreContextEvent), | 129 &CanvasRenderingContext2D::tryRestoreContextEvent), |
| 130 m_pruneLocalFontCacheScheduled(false) { | 130 m_shouldPruneLocalFontCache(false) { |
| 131 if (document.settings() && | 131 if (document.settings() && |
| 132 document.settings()->getAntialiasedClips2dCanvasEnabled()) | 132 document.settings()->getAntialiasedClips2dCanvasEnabled()) |
| 133 m_clipAntialiasing = AntiAliased; | 133 m_clipAntialiasing = AntiAliased; |
| 134 setShouldAntialias(true); | 134 setShouldAntialias(true); |
| 135 validateStateStack(); | 135 validateStateStack(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void CanvasRenderingContext2D::setCanvasGetContextResult( | 138 void CanvasRenderingContext2D::setCanvasGetContextResult( |
| 139 RenderingContext& result) { | 139 RenderingContext& result) { |
| 140 result.setCanvasRenderingContext2D(this); | 140 result.setCanvasRenderingContext2D(this); |
| 141 } | 141 } |
| 142 | 142 |
| 143 CanvasRenderingContext2D::~CanvasRenderingContext2D() {} | 143 CanvasRenderingContext2D::~CanvasRenderingContext2D() {} |
| 144 | 144 |
| 145 void CanvasRenderingContext2D::dispose() { | |
| 146 if (m_pruneLocalFontCacheScheduled) | |
| 147 Platform::current()->currentThread()->removeTaskObserver(this); | |
| 148 } | |
| 149 | |
| 150 void CanvasRenderingContext2D::validateStateStack() const { | 145 void CanvasRenderingContext2D::validateStateStack() const { |
| 151 #if DCHECK_IS_ON() | 146 #if DCHECK_IS_ON() |
| 152 if (PaintCanvas* skCanvas = canvas()->existingDrawingCanvas()) { | 147 if (PaintCanvas* skCanvas = canvas()->existingDrawingCanvas()) { |
| 153 // The canvas should always have an initial save frame, to support | 148 // The canvas should always have an initial save frame, to support |
| 154 // resetting the top level matrix and clip. | 149 // resetting the top level matrix and clip. |
| 155 DCHECK_GT(skCanvas->getSaveCount(), 1); | 150 DCHECK_GT(skCanvas->getSaveCount(), 1); |
| 156 | 151 |
| 157 if (m_contextLostMode == NotLostContext) { | 152 if (m_contextLostMode == NotLostContext) { |
| 158 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), | 153 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), |
| 159 m_stateStack.size() + 1); | 154 m_stateStack.size() + 1); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 if (dirtyRect.isEmpty()) | 343 if (dirtyRect.isEmpty()) |
| 349 return; | 344 return; |
| 350 | 345 |
| 351 if (ExpensiveCanvasHeuristicParameters::BlurredShadowsAreExpensive && | 346 if (ExpensiveCanvasHeuristicParameters::BlurredShadowsAreExpensive && |
| 352 state().shouldDrawShadows() && state().shadowBlur() > 0) { | 347 state().shouldDrawShadows() && state().shadowBlur() > 0) { |
| 353 ImageBuffer* buffer = canvas()->buffer(); | 348 ImageBuffer* buffer = canvas()->buffer(); |
| 354 if (buffer) | 349 if (buffer) |
| 355 buffer->setHasExpensiveOp(); | 350 buffer->setHasExpensiveOp(); |
| 356 } | 351 } |
| 357 | 352 |
| 358 canvas()->didDraw(SkRect::Make(dirtyRect)); | 353 CanvasRenderingContext::didDraw(dirtyRect); |
| 359 } | 354 } |
| 360 | 355 |
| 361 bool CanvasRenderingContext2D::stateHasFilter() { | 356 bool CanvasRenderingContext2D::stateHasFilter() { |
| 362 return state().hasFilter(canvas(), canvas()->size(), this); | 357 return state().hasFilter(canvas(), canvas()->size(), this); |
| 363 } | 358 } |
| 364 | 359 |
| 365 sk_sp<SkImageFilter> CanvasRenderingContext2D::stateGetFilter() { | 360 sk_sp<SkImageFilter> CanvasRenderingContext2D::stateGetFilter() { |
| 366 return state().getFilter(canvas(), canvas()->size(), this); | 361 return state().getFilter(canvas(), canvas()->size(), this); |
| 367 } | 362 } |
| 368 | 363 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 elementFontDescription.setComputedSize( | 471 elementFontDescription.setComputedSize( |
| 477 elementFontDescription.specifiedSize()); | 472 elementFontDescription.specifiedSize()); |
| 478 fontStyle->setFontDescription(elementFontDescription); | 473 fontStyle->setFontDescription(elementFontDescription); |
| 479 fontStyle->font().update(fontStyle->font().getFontSelector()); | 474 fontStyle->font().update(fontStyle->font().getFontSelector()); |
| 480 canvas()->document().ensureStyleResolver().computeFont(fontStyle.get(), | 475 canvas()->document().ensureStyleResolver().computeFont(fontStyle.get(), |
| 481 *parsedStyle); | 476 *parsedStyle); |
| 482 m_fontsResolvedUsingCurrentStyle.add(newFont, fontStyle->font()); | 477 m_fontsResolvedUsingCurrentStyle.add(newFont, fontStyle->font()); |
| 483 DCHECK(!m_fontLRUList.contains(newFont)); | 478 DCHECK(!m_fontLRUList.contains(newFont)); |
| 484 m_fontLRUList.add(newFont); | 479 m_fontLRUList.add(newFont); |
| 485 pruneLocalFontCache(canvasFontCache->hardMaxFonts()); // hard limit | 480 pruneLocalFontCache(canvasFontCache->hardMaxFonts()); // hard limit |
| 486 schedulePruneLocalFontCacheIfNeeded(); // soft limit | 481 m_shouldPruneLocalFontCache = true; // apply soft limit |
| 487 modifiableState().setFont( | 482 modifiableState().setFont( |
| 488 fontStyle->font(), canvas()->document().styleEngine().fontSelector()); | 483 fontStyle->font(), canvas()->document().styleEngine().fontSelector()); |
| 489 } | 484 } |
| 490 } else { | 485 } else { |
| 491 Font resolvedFont; | 486 Font resolvedFont; |
| 492 if (!canvasFontCache->getFontUsingDefaultStyle(newFont, resolvedFont)) | 487 if (!canvasFontCache->getFontUsingDefaultStyle(newFont, resolvedFont)) |
| 493 return; | 488 return; |
| 494 modifiableState().setFont( | 489 modifiableState().setFont( |
| 495 resolvedFont, canvas()->document().styleEngine().fontSelector()); | 490 resolvedFont, canvas()->document().styleEngine().fontSelector()); |
| 496 } | 491 } |
| 497 | 492 |
| 498 // The parse succeeded. | 493 // The parse succeeded. |
| 499 String newFontSafeCopy(newFont); // Create a string copy since newFont can be | 494 String newFontSafeCopy(newFont); // Create a string copy since newFont can be |
| 500 // deleted inside realizeSaves. | 495 // deleted inside realizeSaves. |
| 501 modifiableState().setUnparsedFont(newFontSafeCopy); | 496 modifiableState().setUnparsedFont(newFontSafeCopy); |
| 502 } | 497 } |
| 503 | 498 |
| 504 void CanvasRenderingContext2D::schedulePruneLocalFontCacheIfNeeded() { | |
| 505 if (m_pruneLocalFontCacheScheduled) | |
| 506 return; | |
| 507 m_pruneLocalFontCacheScheduled = true; | |
| 508 Platform::current()->currentThread()->addTaskObserver(this); | |
| 509 } | |
| 510 | |
| 511 void CanvasRenderingContext2D::didProcessTask() { | 499 void CanvasRenderingContext2D::didProcessTask() { |
| 512 Platform::current()->currentThread()->removeTaskObserver(this); | 500 CanvasRenderingContext::didProcessTask(); |
| 513 | |
| 514 // This should be the only place where canvas() needs to be checked for | 501 // This should be the only place where canvas() needs to be checked for |
| 515 // nullness because the circular refence with HTMLCanvasElement mean the | 502 // nullness because the circular refence with HTMLCanvasElement means the |
| 516 // canvas and the context keep each other alive as long as the pair is | 503 // canvas and the context keep each other alive. As long as the pair is |
| 517 // referenced the task observer is the only persisten refernce to this object | 504 // referenced, the task observer is the only persistent refernce to this |
| 518 // that is not traced, so didProcessTask() may be call at a time when the | 505 // object |
| 506 // that is not traced, so didProcessTask() may be called at a time when the |
| 519 // canvas has been garbage collected but not the context. | 507 // canvas has been garbage collected but not the context. |
| 520 if (!canvas()) | 508 if (m_shouldPruneLocalFontCache && canvas()) { |
| 521 return; | 509 m_shouldPruneLocalFontCache = false; |
| 522 | 510 pruneLocalFontCache(canvas()->document().canvasFontCache()->maxFonts()); |
| 523 // The rendering surface needs to be prepared now because it will be too late | 511 } |
| 524 // to create a layer once we are in the paint invalidation phase. | |
| 525 canvas()->prepareSurfaceForPaintingIfNeeded(); | |
| 526 | |
| 527 pruneLocalFontCache(canvas()->document().canvasFontCache()->maxFonts()); | |
| 528 m_pruneLocalFontCacheScheduled = false; | |
| 529 } | 512 } |
| 530 | 513 |
| 531 void CanvasRenderingContext2D::pruneLocalFontCache(size_t targetSize) { | 514 void CanvasRenderingContext2D::pruneLocalFontCache(size_t targetSize) { |
| 532 if (targetSize == 0) { | 515 if (targetSize == 0) { |
| 533 // Short cut: LRU does not matter when evicting everything | 516 // Short cut: LRU does not matter when evicting everything |
| 534 m_fontLRUList.clear(); | 517 m_fontLRUList.clear(); |
| 535 m_fontsResolvedUsingCurrentStyle.clear(); | 518 m_fontsResolvedUsingCurrentStyle.clear(); |
| 536 return; | 519 return; |
| 537 } | 520 } |
| 538 while (m_fontLRUList.size() > targetSize) { | 521 while (m_fontLRUList.size() > targetSize) { |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 } | 1150 } |
| 1168 return true; | 1151 return true; |
| 1169 } | 1152 } |
| 1170 | 1153 |
| 1171 void CanvasRenderingContext2D::resetUsageTracking() { | 1154 void CanvasRenderingContext2D::resetUsageTracking() { |
| 1172 UsageCounters newCounters; | 1155 UsageCounters newCounters; |
| 1173 m_usageCounters = newCounters; | 1156 m_usageCounters = newCounters; |
| 1174 } | 1157 } |
| 1175 | 1158 |
| 1176 } // namespace blink | 1159 } // namespace blink |
| OLD | NEW |