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