| OLD | NEW |
| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 ~CanvasRenderingContext2DAutoRestoreSkCanvas() | 100 ~CanvasRenderingContext2DAutoRestoreSkCanvas() |
| 101 { | 101 { |
| 102 SkCanvas* c = m_context->drawingCanvas(); | 102 SkCanvas* c = m_context->drawingCanvas(); |
| 103 if (c) | 103 if (c) |
| 104 c->restoreToCount(m_saveCount); | 104 c->restoreToCount(m_saveCount); |
| 105 m_context->validateStateStack(); | 105 m_context->validateStateStack(); |
| 106 } | 106 } |
| 107 private: | 107 private: |
| 108 RawPtrWillBeMember<CanvasRenderingContext2D> m_context; | 108 Member<CanvasRenderingContext2D> m_context; |
| 109 int m_saveCount; | 109 int m_saveCount; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co
nst CanvasContextCreationAttributes& attrs, Document& document) | 112 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co
nst CanvasContextCreationAttributes& attrs, Document& document) |
| 113 : CanvasRenderingContext(canvas) | 113 : CanvasRenderingContext(canvas) |
| 114 , m_hasAlpha(attrs.alpha()) | 114 , m_hasAlpha(attrs.alpha()) |
| 115 , m_contextLostMode(NotLostContext) | 115 , m_contextLostMode(NotLostContext) |
| 116 , m_contextRestorable(true) | 116 , m_contextRestorable(true) |
| 117 , m_tryRestoreContextAttemptCount(0) | 117 , m_tryRestoreContextAttemptCount(0) |
| 118 , m_dispatchContextLostEventTimer(this, &CanvasRenderingContext2D::dispatchC
ontextLostEvent) | 118 , m_dispatchContextLostEventTimer(this, &CanvasRenderingContext2D::dispatchC
ontextLostEvent) |
| 119 , m_dispatchContextRestoredEventTimer(this, &CanvasRenderingContext2D::dispa
tchContextRestoredEvent) | 119 , m_dispatchContextRestoredEventTimer(this, &CanvasRenderingContext2D::dispa
tchContextRestoredEvent) |
| 120 , m_tryRestoreContextEventTimer(this, &CanvasRenderingContext2D::tryRestoreC
ontextEvent) | 120 , m_tryRestoreContextEventTimer(this, &CanvasRenderingContext2D::tryRestoreC
ontextEvent) |
| 121 , m_pruneLocalFontCacheScheduled(false) | 121 , m_pruneLocalFontCacheScheduled(false) |
| 122 { | 122 { |
| 123 if (document.settings() && document.settings()->antialiasedClips2dCanvasEnab
led()) | 123 if (document.settings() && document.settings()->antialiasedClips2dCanvasEnab
led()) |
| 124 m_clipAntialiasing = AntiAliased; | 124 m_clipAntialiasing = AntiAliased; |
| 125 setShouldAntialias(true); | 125 setShouldAntialias(true); |
| 126 #if ENABLE(OILPAN) | 126 #if ENABLE(OILPAN) |
| 127 ThreadState::current()->registerPreFinalizer(this); | 127 ThreadState::current()->registerPreFinalizer(this); |
| 128 #endif | 128 #endif |
| 129 } | 129 } |
| 130 | 130 |
| 131 void CanvasRenderingContext2D::setCanvasGetContextResult(RenderingContext& resul
t) | 131 void CanvasRenderingContext2D::setCanvasGetContextResult(RenderingContext& resul
t) |
| 132 { | 132 { |
| 133 result.setCanvasRenderingContext2D(PassRefPtrWillBeRawPtr<CanvasRenderingCon
text2D>(this)); | 133 result.setCanvasRenderingContext2D(RawPtr<CanvasRenderingContext2D>(this)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void CanvasRenderingContext2D::unwindStateStack() | 136 void CanvasRenderingContext2D::unwindStateStack() |
| 137 { | 137 { |
| 138 if (size_t stackSize = m_stateStack.size()) { | 138 if (size_t stackSize = m_stateStack.size()) { |
| 139 if (SkCanvas* skCanvas = canvas()->existingDrawingCanvas()) { | 139 if (SkCanvas* skCanvas = canvas()->existingDrawingCanvas()) { |
| 140 while (--stackSize) | 140 while (--stackSize) |
| 141 skCanvas->restore(); | 141 skCanvas->restore(); |
| 142 } | 142 } |
| 143 } | 143 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 DEFINE_TRACE(CanvasRenderingContext2D) | 221 DEFINE_TRACE(CanvasRenderingContext2D) |
| 222 { | 222 { |
| 223 visitor->trace(m_hitRegionManager); | 223 visitor->trace(m_hitRegionManager); |
| 224 CanvasRenderingContext::trace(visitor); | 224 CanvasRenderingContext::trace(visitor); |
| 225 BaseRenderingContext2D::trace(visitor); | 225 BaseRenderingContext2D::trace(visitor); |
| 226 } | 226 } |
| 227 | 227 |
| 228 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon
text2D>*) | 228 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon
text2D>*) |
| 229 { | 229 { |
| 230 if (contextLostRestoredEventsEnabled()) { | 230 if (contextLostRestoredEventsEnabled()) { |
| 231 RefPtrWillBeRawPtr<Event> event = Event::createCancelable(EventTypeNames
::contextlost); | 231 RawPtr<Event> event = Event::createCancelable(EventTypeNames::contextlos
t); |
| 232 canvas()->dispatchEvent(event); | 232 canvas()->dispatchEvent(event); |
| 233 if (event->defaultPrevented()) { | 233 if (event->defaultPrevented()) { |
| 234 m_contextRestorable = false; | 234 m_contextRestorable = false; |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 // If RealLostContext, it means the context was not lost due to surface fail
ure | 238 // If RealLostContext, it means the context was not lost due to surface fail
ure |
| 239 // but rather due to a an eviction, which means image buffer exists. | 239 // but rather due to a an eviction, which means image buffer exists. |
| 240 if (m_contextRestorable && m_contextLostMode == RealLostContext) { | 240 if (m_contextRestorable && m_contextLostMode == RealLostContext) { |
| 241 m_tryRestoreContextAttemptCount = 0; | 241 m_tryRestoreContextAttemptCount = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 void CanvasRenderingContext2D::dispatchContextRestoredEvent(Timer<CanvasRenderin
gContext2D>*) | 269 void CanvasRenderingContext2D::dispatchContextRestoredEvent(Timer<CanvasRenderin
gContext2D>*) |
| 270 { | 270 { |
| 271 if (m_contextLostMode == NotLostContext) | 271 if (m_contextLostMode == NotLostContext) |
| 272 return; | 272 return; |
| 273 reset(); | 273 reset(); |
| 274 m_contextLostMode = NotLostContext; | 274 m_contextLostMode = NotLostContext; |
| 275 if (contextLostRestoredEventsEnabled()) { | 275 if (contextLostRestoredEventsEnabled()) { |
| 276 RefPtrWillBeRawPtr<Event> event(Event::create(EventTypeNames::contextres
tored)); | 276 RawPtr<Event> event(Event::create(EventTypeNames::contextrestored)); |
| 277 canvas()->dispatchEvent(event); | 277 canvas()->dispatchEvent(event); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 void CanvasRenderingContext2D::reset() | 281 void CanvasRenderingContext2D::reset() |
| 282 { | 282 { |
| 283 validateStateStack(); | 283 validateStateStack(); |
| 284 unwindStateStack(); | 284 unwindStateStack(); |
| 285 m_stateStack.resize(1); | 285 m_stateStack.resize(1); |
| 286 m_stateStack.first() = CanvasRenderingContext2DState::create(); | 286 m_stateStack.first() = CanvasRenderingContext2DState::create(); |
| 287 m_path.clear(); | 287 m_path.clear(); |
| 288 SkCanvas* c = canvas()->existingDrawingCanvas(); | 288 SkCanvas* c = canvas()->existingDrawingCanvas(); |
| 289 if (c) { | 289 if (c) { |
| 290 c->resetMatrix(); | 290 c->resetMatrix(); |
| 291 c->clipRect(SkRect::MakeWH(canvas()->width(), canvas()->height()), SkReg
ion::kReplace_Op); | 291 c->clipRect(SkRect::MakeWH(canvas()->width(), canvas()->height()), SkReg
ion::kReplace_Op); |
| 292 } | 292 } |
| 293 validateStateStack(); | 293 validateStateStack(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const | 296 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const |
| 297 { | 297 { |
| 298 if (!c) | 298 if (!c) |
| 299 return; | 299 return; |
| 300 WillBeHeapVector<OwnPtrWillBeMember<CanvasRenderingContext2DState>>::const_i
terator currState; | 300 HeapVector<Member<CanvasRenderingContext2DState>>::const_iterator currState; |
| 301 ASSERT(m_stateStack.begin() < m_stateStack.end()); | 301 ASSERT(m_stateStack.begin() < m_stateStack.end()); |
| 302 for (currState = m_stateStack.begin(); currState < m_stateStack.end(); currS
tate++) { | 302 for (currState = m_stateStack.begin(); currState < m_stateStack.end(); currS
tate++) { |
| 303 c->setMatrix(SkMatrix::I()); | 303 c->setMatrix(SkMatrix::I()); |
| 304 currState->get()->playbackClips(c); | 304 currState->get()->playbackClips(c); |
| 305 c->setMatrix(affineTransformToSkMatrix(currState->get()->transform())); | 305 c->setMatrix(affineTransformToSkMatrix(currState->get()->transform())); |
| 306 c->save(); | 306 c->save(); |
| 307 } | 307 } |
| 308 c->restore(); | 308 c->restore(); |
| 309 } | 309 } |
| 310 | 310 |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 hitRegionPath.intersectPath(state().getCurrentClipPath()); | 1004 hitRegionPath.intersectPath(state().getCurrentClipPath()); |
| 1005 if (hitRegionPath.isEmpty()) | 1005 if (hitRegionPath.isEmpty()) |
| 1006 exceptionState.throwDOMException(NotSupportedError, "The specified p
ath has no pixels."); | 1006 exceptionState.throwDOMException(NotSupportedError, "The specified p
ath has no pixels."); |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 if (!m_hitRegionManager) | 1009 if (!m_hitRegionManager) |
| 1010 m_hitRegionManager = HitRegionManager::create(); | 1010 m_hitRegionManager = HitRegionManager::create(); |
| 1011 | 1011 |
| 1012 // Remove previous region (with id or control) | 1012 // Remove previous region (with id or control) |
| 1013 m_hitRegionManager->removeHitRegionById(options.id()); | 1013 m_hitRegionManager->removeHitRegionById(options.id()); |
| 1014 m_hitRegionManager->removeHitRegionByControl(options.control().get()); | 1014 m_hitRegionManager->removeHitRegionByControl(options.control()); |
| 1015 | 1015 |
| 1016 RefPtrWillBeRawPtr<HitRegion> hitRegion = HitRegion::create(hitRegionPath, o
ptions); | 1016 RawPtr<HitRegion> hitRegion = HitRegion::create(hitRegionPath, options); |
| 1017 Element* element = hitRegion->control(); | 1017 Element* element = hitRegion->control(); |
| 1018 if (element && element->isDescendantOf(canvas())) | 1018 if (element && element->isDescendantOf(canvas())) |
| 1019 updateElementAccessibility(hitRegion->path(), hitRegion->control()); | 1019 updateElementAccessibility(hitRegion->path(), hitRegion->control()); |
| 1020 m_hitRegionManager->addHitRegion(hitRegion.release()); | 1020 m_hitRegionManager->addHitRegion(hitRegion.release()); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 void CanvasRenderingContext2D::removeHitRegion(const String& id) | 1023 void CanvasRenderingContext2D::removeHitRegion(const String& id) |
| 1024 { | 1024 { |
| 1025 if (m_hitRegionManager) | 1025 if (m_hitRegionManager) |
| 1026 m_hitRegionManager->removeHitRegionById(id); | 1026 m_hitRegionManager->removeHitRegionById(id); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1042 | 1042 |
| 1043 unsigned CanvasRenderingContext2D::hitRegionsCount() const | 1043 unsigned CanvasRenderingContext2D::hitRegionsCount() const |
| 1044 { | 1044 { |
| 1045 if (m_hitRegionManager) | 1045 if (m_hitRegionManager) |
| 1046 return m_hitRegionManager->getHitRegionsCount(); | 1046 return m_hitRegionManager->getHitRegionsCount(); |
| 1047 | 1047 |
| 1048 return 0; | 1048 return 0; |
| 1049 } | 1049 } |
| 1050 | 1050 |
| 1051 } // namespace blink | 1051 } // namespace blink |
| OLD | NEW |