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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // Drawing methods need to use this instead of SkAutoCanvasRestore in case | 83 // Drawing methods need to use this instead of SkAutoCanvasRestore in case |
84 // overdraw detection substitutes the recording canvas (to discard overdrawn | 84 // overdraw detection substitutes the recording canvas (to discard overdrawn |
85 // draw calls). | 85 // draw calls). |
86 class CanvasRenderingContext2DAutoRestoreSkCanvas { | 86 class CanvasRenderingContext2DAutoRestoreSkCanvas { |
87 STACK_ALLOCATED(); | 87 STACK_ALLOCATED(); |
88 | 88 |
89 public: | 89 public: |
90 explicit CanvasRenderingContext2DAutoRestoreSkCanvas( | 90 explicit CanvasRenderingContext2DAutoRestoreSkCanvas( |
91 CanvasRenderingContext2D* context) | 91 CanvasRenderingContext2D* context) |
92 : m_context(context), m_saveCount(0) { | 92 : m_context(context), m_saveCount(0) { |
93 ASSERT(m_context); | 93 DCHECK(m_context); |
94 SkCanvas* c = m_context->drawingCanvas(); | 94 SkCanvas* c = m_context->drawingCanvas(); |
95 if (c) { | 95 if (c) { |
96 m_saveCount = c->getSaveCount(); | 96 m_saveCount = c->getSaveCount(); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 ~CanvasRenderingContext2DAutoRestoreSkCanvas() { | 100 ~CanvasRenderingContext2DAutoRestoreSkCanvas() { |
101 SkCanvas* c = m_context->drawingCanvas(); | 101 SkCanvas* c = m_context->drawingCanvas(); |
102 if (c) | 102 if (c) |
103 c->restoreToCount(m_saveCount); | 103 c->restoreToCount(m_saveCount); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 canvas()->discardImageBuffer(); | 188 canvas()->discardImageBuffer(); |
189 } | 189 } |
190 m_dispatchContextLostEventTimer.startOneShot(0, BLINK_FROM_HERE); | 190 m_dispatchContextLostEventTimer.startOneShot(0, BLINK_FROM_HERE); |
191 } | 191 } |
192 | 192 |
193 void CanvasRenderingContext2D::didSetSurfaceSize() { | 193 void CanvasRenderingContext2D::didSetSurfaceSize() { |
194 if (!m_contextRestorable) | 194 if (!m_contextRestorable) |
195 return; | 195 return; |
196 // This code path is for restoring from an eviction | 196 // This code path is for restoring from an eviction |
197 // Restoring from surface failure is handled internally | 197 // Restoring from surface failure is handled internally |
198 ASSERT(m_contextLostMode != NotLostContext && !canvas()->hasImageBuffer()); | 198 DCHECK(m_contextLostMode != NotLostContext && !canvas()->hasImageBuffer()); |
199 | 199 |
200 if (canvas()->buffer()) { | 200 if (canvas()->buffer()) { |
201 if (contextLostRestoredEventsEnabled()) { | 201 if (contextLostRestoredEventsEnabled()) { |
202 m_dispatchContextRestoredEventTimer.startOneShot(0, BLINK_FROM_HERE); | 202 m_dispatchContextRestoredEventTimer.startOneShot(0, BLINK_FROM_HERE); |
203 } else { | 203 } else { |
204 // legacy synchronous context restoration. | 204 // legacy synchronous context restoration. |
205 reset(); | 205 reset(); |
206 m_contextLostMode = NotLostContext; | 206 m_contextLostMode = NotLostContext; |
207 } | 207 } |
208 } | 208 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 if (m_contextLostMode == NotLostContext) | 261 if (m_contextLostMode == NotLostContext) |
262 return; | 262 return; |
263 reset(); | 263 reset(); |
264 m_contextLostMode = NotLostContext; | 264 m_contextLostMode = NotLostContext; |
265 if (contextLostRestoredEventsEnabled()) { | 265 if (contextLostRestoredEventsEnabled()) { |
266 Event* event(Event::create(EventTypeNames::contextrestored)); | 266 Event* event(Event::create(EventTypeNames::contextrestored)); |
267 canvas()->dispatchEvent(event); | 267 canvas()->dispatchEvent(event); |
268 } | 268 } |
269 } | 269 } |
270 | 270 |
| 271 void CanvasRenderingContext2D::willDrawImage(CanvasImageSource* source) const { |
| 272 canvas()->willDrawImageTo2DContext(source); |
| 273 } |
| 274 |
271 ColorBehavior CanvasRenderingContext2D::drawImageColorBehavior() const { | 275 ColorBehavior CanvasRenderingContext2D::drawImageColorBehavior() const { |
272 return CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas(); | 276 return CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas(); |
273 } | 277 } |
274 | 278 |
275 void CanvasRenderingContext2D::reset() { | 279 void CanvasRenderingContext2D::reset() { |
276 // This is a multiple inherritance bootstrap | 280 // This is a multiple inherritance bootstrap |
277 BaseRenderingContext2D::reset(); | 281 BaseRenderingContext2D::reset(); |
278 } | 282 } |
279 | 283 |
280 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const { | 284 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 CanvasFontCache* canvasFontCache = canvas()->document().canvasFontCache(); | 449 CanvasFontCache* canvasFontCache = canvas()->document().canvasFontCache(); |
446 | 450 |
447 // Map the <canvas> font into the text style. If the font uses keywords like | 451 // Map the <canvas> font into the text style. If the font uses keywords like |
448 // larger/smaller, these will work relative to the canvas. | 452 // larger/smaller, these will work relative to the canvas. |
449 RefPtr<ComputedStyle> fontStyle; | 453 RefPtr<ComputedStyle> fontStyle; |
450 const ComputedStyle* computedStyle = canvas()->ensureComputedStyle(); | 454 const ComputedStyle* computedStyle = canvas()->ensureComputedStyle(); |
451 if (computedStyle) { | 455 if (computedStyle) { |
452 HashMap<String, Font>::iterator i = | 456 HashMap<String, Font>::iterator i = |
453 m_fontsResolvedUsingCurrentStyle.find(newFont); | 457 m_fontsResolvedUsingCurrentStyle.find(newFont); |
454 if (i != m_fontsResolvedUsingCurrentStyle.end()) { | 458 if (i != m_fontsResolvedUsingCurrentStyle.end()) { |
455 ASSERT(m_fontLRUList.contains(newFont)); | 459 DCHECK(m_fontLRUList.contains(newFont)); |
456 m_fontLRUList.remove(newFont); | 460 m_fontLRUList.remove(newFont); |
457 m_fontLRUList.add(newFont); | 461 m_fontLRUList.add(newFont); |
458 modifiableState().setFont( | 462 modifiableState().setFont( |
459 i->value, canvas()->document().styleEngine().fontSelector()); | 463 i->value, canvas()->document().styleEngine().fontSelector()); |
460 } else { | 464 } else { |
461 MutableStylePropertySet* parsedStyle = | 465 MutableStylePropertySet* parsedStyle = |
462 canvasFontCache->parseFont(newFont); | 466 canvasFontCache->parseFont(newFont); |
463 if (!parsedStyle) | 467 if (!parsedStyle) |
464 return; | 468 return; |
465 fontStyle = ComputedStyle::create(); | 469 fontStyle = ComputedStyle::create(); |
466 FontDescription elementFontDescription( | 470 FontDescription elementFontDescription( |
467 computedStyle->getFontDescription()); | 471 computedStyle->getFontDescription()); |
468 // Reset the computed size to avoid inheriting the zoom factor from the | 472 // Reset the computed size to avoid inheriting the zoom factor from the |
469 // <canvas> element. | 473 // <canvas> element. |
470 elementFontDescription.setComputedSize( | 474 elementFontDescription.setComputedSize( |
471 elementFontDescription.specifiedSize()); | 475 elementFontDescription.specifiedSize()); |
472 fontStyle->setFontDescription(elementFontDescription); | 476 fontStyle->setFontDescription(elementFontDescription); |
473 fontStyle->font().update(fontStyle->font().getFontSelector()); | 477 fontStyle->font().update(fontStyle->font().getFontSelector()); |
474 canvas()->document().ensureStyleResolver().computeFont(fontStyle.get(), | 478 canvas()->document().ensureStyleResolver().computeFont(fontStyle.get(), |
475 *parsedStyle); | 479 *parsedStyle); |
476 m_fontsResolvedUsingCurrentStyle.add(newFont, fontStyle->font()); | 480 m_fontsResolvedUsingCurrentStyle.add(newFont, fontStyle->font()); |
477 ASSERT(!m_fontLRUList.contains(newFont)); | 481 DCHECK(!m_fontLRUList.contains(newFont)); |
478 m_fontLRUList.add(newFont); | 482 m_fontLRUList.add(newFont); |
479 pruneLocalFontCache(canvasFontCache->hardMaxFonts()); // hard limit | 483 pruneLocalFontCache(canvasFontCache->hardMaxFonts()); // hard limit |
480 schedulePruneLocalFontCacheIfNeeded(); // soft limit | 484 schedulePruneLocalFontCacheIfNeeded(); // soft limit |
481 modifiableState().setFont( | 485 modifiableState().setFont( |
482 fontStyle->font(), canvas()->document().styleEngine().fontSelector()); | 486 fontStyle->font(), canvas()->document().styleEngine().fontSelector()); |
483 } | 487 } |
484 } else { | 488 } else { |
485 Font resolvedFont; | 489 Font resolvedFont; |
486 if (!canvasFontCache->getFontUsingDefaultStyle(newFont, resolvedFont)) | 490 if (!canvasFontCache->getFontUsingDefaultStyle(newFont, resolvedFont)) |
487 return; | 491 return; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 if (computedStyle) | 679 if (computedStyle) |
676 *computedStyle = style; | 680 *computedStyle = style; |
677 switch (direction) { | 681 switch (direction) { |
678 case CanvasRenderingContext2DState::DirectionInherit: | 682 case CanvasRenderingContext2DState::DirectionInherit: |
679 return style ? style->direction() : TextDirection::kLtr; | 683 return style ? style->direction() : TextDirection::kLtr; |
680 case CanvasRenderingContext2DState::DirectionRTL: | 684 case CanvasRenderingContext2DState::DirectionRTL: |
681 return TextDirection::kRtl; | 685 return TextDirection::kRtl; |
682 case CanvasRenderingContext2DState::DirectionLTR: | 686 case CanvasRenderingContext2DState::DirectionLTR: |
683 return TextDirection::kLtr; | 687 return TextDirection::kLtr; |
684 } | 688 } |
685 ASSERT_NOT_REACHED(); | 689 NOTREACHED(); |
686 return TextDirection::kLtr; | 690 return TextDirection::kLtr; |
687 } | 691 } |
688 | 692 |
689 String CanvasRenderingContext2D::direction() const { | 693 String CanvasRenderingContext2D::direction() const { |
690 if (state().getDirection() == CanvasRenderingContext2DState::DirectionInherit) | 694 if (state().getDirection() == CanvasRenderingContext2DState::DirectionInherit) |
691 canvas()->document().updateStyleAndLayoutTreeForNode(canvas()); | 695 canvas()->document().updateStyleAndLayoutTreeForNode(canvas()); |
692 return toTextDirection(state().getDirection(), canvas()) == | 696 return toTextDirection(state().getDirection(), canvas()) == |
693 TextDirection::kRtl | 697 TextDirection::kRtl |
694 ? rtlDirectionString | 698 ? rtlDirectionString |
695 : ltrDirectionString; | 699 : ltrDirectionString; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 | 826 |
823 if (!std::isfinite(x) || !std::isfinite(y)) | 827 if (!std::isfinite(x) || !std::isfinite(y)) |
824 return; | 828 return; |
825 if (maxWidth && (!std::isfinite(*maxWidth) || *maxWidth <= 0)) | 829 if (maxWidth && (!std::isfinite(*maxWidth) || *maxWidth <= 0)) |
826 return; | 830 return; |
827 | 831 |
828 // Currently, SkPictureImageFilter does not support subpixel text | 832 // Currently, SkPictureImageFilter does not support subpixel text |
829 // anti-aliasing, which is expected when !creationAttributes().alpha(), so we | 833 // anti-aliasing, which is expected when !creationAttributes().alpha(), so we |
830 // need to fall out of display list mode when drawing text to an opaque | 834 // need to fall out of display list mode when drawing text to an opaque |
831 // canvas. crbug.com/583809 | 835 // canvas. crbug.com/583809 |
832 if (!creationAttributes().alpha() && !isAccelerated()) | 836 if (!creationAttributes().alpha() && !isAccelerated()) { |
833 canvas()->disableDeferral( | 837 canvas()->disableDeferral( |
834 DisableDeferralReasonSubPixelTextAntiAliasingSupport); | 838 DisableDeferralReasonSubPixelTextAntiAliasingSupport); |
| 839 } |
835 | 840 |
836 const Font& font = accessFont(); | 841 const Font& font = accessFont(); |
837 font.getFontDescription().setSubpixelAscentDescent(true); | 842 font.getFontDescription().setSubpixelAscentDescent(true); |
838 const SimpleFontData* fontData = font.primaryFont(); | 843 const SimpleFontData* fontData = font.primaryFont(); |
839 DCHECK(fontData); | 844 DCHECK(fontData); |
840 if (!fontData) | 845 if (!fontData) |
841 return; | 846 return; |
842 const FontMetrics& fontMetrics = fontData->getFontMetrics(); | 847 const FontMetrics& fontMetrics = fontData->getFontMetrics(); |
843 | 848 |
844 // FIXME: Need to turn off font smoothing. | 849 // FIXME: Need to turn off font smoothing. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 scrollPathIntoViewInternal(path); | 1001 scrollPathIntoViewInternal(path); |
997 drawFocusRing(path); | 1002 drawFocusRing(path); |
998 } | 1003 } |
999 | 1004 |
1000 // Update its accessible bounds whether it's focused or not. | 1005 // Update its accessible bounds whether it's focused or not. |
1001 updateElementAccessibility(path, element); | 1006 updateElementAccessibility(path, element); |
1002 } | 1007 } |
1003 | 1008 |
1004 bool CanvasRenderingContext2D::focusRingCallIsValid(const Path& path, | 1009 bool CanvasRenderingContext2D::focusRingCallIsValid(const Path& path, |
1005 Element* element) { | 1010 Element* element) { |
1006 ASSERT(element); | 1011 DCHECK(element); |
1007 if (!state().isTransformInvertible()) | 1012 if (!state().isTransformInvertible()) |
1008 return false; | 1013 return false; |
1009 if (path.isEmpty()) | 1014 if (path.isEmpty()) |
1010 return false; | 1015 return false; |
1011 if (!element->isDescendantOf(canvas())) | 1016 if (!element->isDescendantOf(canvas())) |
1012 return false; | 1017 return false; |
1013 | 1018 |
1014 return true; | 1019 return true; |
1015 } | 1020 } |
1016 | 1021 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 !c->getClipDeviceBounds(0)) { | 1088 !c->getClipDeviceBounds(0)) { |
1084 exceptionState.throwDOMException(NotSupportedError, | 1089 exceptionState.throwDOMException(NotSupportedError, |
1085 "The specified path has no pixels."); | 1090 "The specified path has no pixels."); |
1086 return; | 1091 return; |
1087 } | 1092 } |
1088 | 1093 |
1089 hitRegionPath.transform(state().transform()); | 1094 hitRegionPath.transform(state().transform()); |
1090 | 1095 |
1091 if (state().hasClip()) { | 1096 if (state().hasClip()) { |
1092 hitRegionPath.intersectPath(state().getCurrentClipPath()); | 1097 hitRegionPath.intersectPath(state().getCurrentClipPath()); |
1093 if (hitRegionPath.isEmpty()) | 1098 if (hitRegionPath.isEmpty()) { |
1094 exceptionState.throwDOMException(NotSupportedError, | 1099 exceptionState.throwDOMException(NotSupportedError, |
1095 "The specified path has no pixels."); | 1100 "The specified path has no pixels."); |
| 1101 } |
1096 } | 1102 } |
1097 | 1103 |
1098 if (!m_hitRegionManager) | 1104 if (!m_hitRegionManager) |
1099 m_hitRegionManager = HitRegionManager::create(); | 1105 m_hitRegionManager = HitRegionManager::create(); |
1100 | 1106 |
1101 // Remove previous region (with id or control) | 1107 // Remove previous region (with id or control) |
1102 m_hitRegionManager->removeHitRegionById(options.id()); | 1108 m_hitRegionManager->removeHitRegionById(options.id()); |
1103 m_hitRegionManager->removeHitRegionByControl(options.control()); | 1109 m_hitRegionManager->removeHitRegionByControl(options.control()); |
1104 | 1110 |
1105 HitRegion* hitRegion = HitRegion::create(hitRegionPath, options); | 1111 HitRegion* hitRegion = HitRegion::create(hitRegionPath, options); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 } | 1165 } |
1160 return true; | 1166 return true; |
1161 } | 1167 } |
1162 | 1168 |
1163 void CanvasRenderingContext2D::resetUsageTracking() { | 1169 void CanvasRenderingContext2D::resetUsageTracking() { |
1164 UsageCounters newCounters; | 1170 UsageCounters newCounters; |
1165 m_usageCounters = newCounters; | 1171 m_usageCounters = newCounters; |
1166 } | 1172 } |
1167 | 1173 |
1168 } // namespace blink | 1174 } // namespace blink |
OLD | NEW |