| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 ~CanvasRenderingContext2DAutoRestoreSkCanvas() | 107 ~CanvasRenderingContext2DAutoRestoreSkCanvas() |
| 108 { | 108 { |
| 109 SkCanvas* c = m_context->drawingCanvas(); | 109 SkCanvas* c = m_context->drawingCanvas(); |
| 110 if (c) | 110 if (c) |
| 111 c->restoreToCount(m_saveCount); | 111 c->restoreToCount(m_saveCount); |
| 112 m_context->validateStateStack(); | 112 m_context->validateStateStack(); |
| 113 } | 113 } |
| 114 private: | 114 private: |
| 115 RawPtrWillBeMember<CanvasRenderingContext2D> m_context; | 115 Member<CanvasRenderingContext2D> m_context; |
| 116 int m_saveCount; | 116 int m_saveCount; |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co
nst CanvasContextCreationAttributes& attrs, Document& document) | 119 CanvasRenderingContext2D::CanvasRenderingContext2D(HTMLCanvasElement* canvas, co
nst CanvasContextCreationAttributes& attrs, Document& document) |
| 120 : CanvasRenderingContext(canvas) | 120 : CanvasRenderingContext(canvas) |
| 121 , m_clipAntialiasing(NotAntiAliased) | 121 , m_clipAntialiasing(NotAntiAliased) |
| 122 , m_hasAlpha(attrs.alpha()) | 122 , m_hasAlpha(attrs.alpha()) |
| 123 , m_contextLostMode(NotLostContext) | 123 , m_contextLostMode(NotLostContext) |
| 124 , m_contextRestorable(true) | 124 , m_contextRestorable(true) |
| 125 , m_tryRestoreContextAttemptCount(0) | 125 , m_tryRestoreContextAttemptCount(0) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 DEFINE_TRACE(CanvasRenderingContext2D) | 220 DEFINE_TRACE(CanvasRenderingContext2D) |
| 221 { | 221 { |
| 222 visitor->trace(m_stateStack); | 222 visitor->trace(m_stateStack); |
| 223 visitor->trace(m_hitRegionManager); | 223 visitor->trace(m_hitRegionManager); |
| 224 CanvasRenderingContext::trace(visitor); | 224 CanvasRenderingContext::trace(visitor); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon
text2D>*) | 227 void CanvasRenderingContext2D::dispatchContextLostEvent(Timer<CanvasRenderingCon
text2D>*) |
| 228 { | 228 { |
| 229 if (contextLostRestoredEventsEnabled()) { | 229 if (contextLostRestoredEventsEnabled()) { |
| 230 RefPtrWillBeRawPtr<Event> event = Event::createCancelable(EventTypeNames
::contextlost); | 230 RawPtr<Event> event = Event::createCancelable(EventTypeNames::contextlos
t); |
| 231 canvas()->dispatchEvent(event); | 231 canvas()->dispatchEvent(event); |
| 232 if (event->defaultPrevented()) { | 232 if (event->defaultPrevented()) { |
| 233 m_contextRestorable = false; | 233 m_contextRestorable = false; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 // If RealLostContext, it means the context was not lost due to surface fail
ure | 237 // If RealLostContext, it means the context was not lost due to surface fail
ure |
| 238 // but rather due to a an eviction, which means image buffer exists. | 238 // but rather due to a an eviction, which means image buffer exists. |
| 239 if (m_contextRestorable && m_contextLostMode == RealLostContext) { | 239 if (m_contextRestorable && m_contextLostMode == RealLostContext) { |
| 240 m_tryRestoreContextAttemptCount = 0; | 240 m_tryRestoreContextAttemptCount = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 void CanvasRenderingContext2D::dispatchContextRestoredEvent(Timer<CanvasRenderin
gContext2D>*) | 268 void CanvasRenderingContext2D::dispatchContextRestoredEvent(Timer<CanvasRenderin
gContext2D>*) |
| 269 { | 269 { |
| 270 if (m_contextLostMode == NotLostContext) | 270 if (m_contextLostMode == NotLostContext) |
| 271 return; | 271 return; |
| 272 reset(); | 272 reset(); |
| 273 m_contextLostMode = NotLostContext; | 273 m_contextLostMode = NotLostContext; |
| 274 if (contextLostRestoredEventsEnabled()) { | 274 if (contextLostRestoredEventsEnabled()) { |
| 275 RefPtrWillBeRawPtr<Event> event(Event::create(EventTypeNames::contextres
tored)); | 275 RawPtr<Event> event(Event::create(EventTypeNames::contextrestored)); |
| 276 canvas()->dispatchEvent(event); | 276 canvas()->dispatchEvent(event); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 void CanvasRenderingContext2D::reset() | 280 void CanvasRenderingContext2D::reset() |
| 281 { | 281 { |
| 282 validateStateStack(); | 282 validateStateStack(); |
| 283 unwindStateStack(); | 283 unwindStateStack(); |
| 284 m_stateStack.resize(1); | 284 m_stateStack.resize(1); |
| 285 m_stateStack.first() = CanvasRenderingContext2DState::create(); | 285 m_stateStack.first() = CanvasRenderingContext2DState::create(); |
| 286 m_path.clear(); | 286 m_path.clear(); |
| 287 SkCanvas* c = canvas()->existingDrawingCanvas(); | 287 SkCanvas* c = canvas()->existingDrawingCanvas(); |
| 288 if (c) { | 288 if (c) { |
| 289 c->resetMatrix(); | 289 c->resetMatrix(); |
| 290 c->clipRect(SkRect::MakeWH(canvas()->width(), canvas()->height()), SkReg
ion::kReplace_Op); | 290 c->clipRect(SkRect::MakeWH(canvas()->width(), canvas()->height()), SkReg
ion::kReplace_Op); |
| 291 } | 291 } |
| 292 validateStateStack(); | 292 validateStateStack(); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const | 295 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const |
| 296 { | 296 { |
| 297 if (!c) | 297 if (!c) |
| 298 return; | 298 return; |
| 299 WillBeHeapVector<OwnPtrWillBeMember<CanvasRenderingContext2DState>>::const_i
terator currState; | 299 HeapVector<Member<CanvasRenderingContext2DState>>::const_iterator currState; |
| 300 ASSERT(m_stateStack.begin() < m_stateStack.end()); | 300 ASSERT(m_stateStack.begin() < m_stateStack.end()); |
| 301 for (currState = m_stateStack.begin(); currState < m_stateStack.end(); currS
tate++) { | 301 for (currState = m_stateStack.begin(); currState < m_stateStack.end(); currS
tate++) { |
| 302 c->setMatrix(SkMatrix::I()); | 302 c->setMatrix(SkMatrix::I()); |
| 303 currState->get()->playbackClips(c); | 303 currState->get()->playbackClips(c); |
| 304 c->setMatrix(affineTransformToSkMatrix(currState->get()->transform())); | 304 c->setMatrix(affineTransformToSkMatrix(currState->get()->transform())); |
| 305 c->save(); | 305 c->save(); |
| 306 } | 306 } |
| 307 c->restore(); | 307 c->restore(); |
| 308 } | 308 } |
| 309 | 309 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 String CanvasRenderingContext2D::filter() const | 639 String CanvasRenderingContext2D::filter() const |
| 640 { | 640 { |
| 641 return state().unparsedFilter(); | 641 return state().unparsedFilter(); |
| 642 } | 642 } |
| 643 | 643 |
| 644 void CanvasRenderingContext2D::setFilter(const String& filterString) | 644 void CanvasRenderingContext2D::setFilter(const String& filterString) |
| 645 { | 645 { |
| 646 if (filterString == state().unparsedFilter()) | 646 if (filterString == state().unparsedFilter()) |
| 647 return; | 647 return; |
| 648 | 648 |
| 649 RefPtrWillBeRawPtr<CSSValue> filterValue = CSSParser::parseSingleValue(CSSPr
opertyWebkitFilter, filterString, CSSParserContext(HTMLStandardMode, 0)); | 649 RawPtr<CSSValue> filterValue = CSSParser::parseSingleValue(CSSPropertyWebkit
Filter, filterString, CSSParserContext(HTMLStandardMode, 0)); |
| 650 | 650 |
| 651 if (!filterValue || filterValue->isInitialValue() || filterValue->isInherite
dValue()) | 651 if (!filterValue || filterValue->isInitialValue() || filterValue->isInherite
dValue()) |
| 652 return; | 652 return; |
| 653 | 653 |
| 654 modifiableState().setUnparsedFilter(filterString); | 654 modifiableState().setUnparsedFilter(filterString); |
| 655 modifiableState().setFilter(filterValue.release()); | 655 modifiableState().setFilter(filterValue.release()); |
| 656 } | 656 } |
| 657 | 657 |
| 658 PassRefPtrWillBeRawPtr<SVGMatrixTearOff> CanvasRenderingContext2D::currentTransf
orm() const | 658 RawPtr<SVGMatrixTearOff> CanvasRenderingContext2D::currentTransform() const |
| 659 { | 659 { |
| 660 return SVGMatrixTearOff::create(state().transform()); | 660 return SVGMatrixTearOff::create(state().transform()); |
| 661 } | 661 } |
| 662 | 662 |
| 663 void CanvasRenderingContext2D::setCurrentTransform(PassRefPtrWillBeRawPtr<SVGMat
rixTearOff> passMatrixTearOff) | 663 void CanvasRenderingContext2D::setCurrentTransform(RawPtr<SVGMatrixTearOff> pass
MatrixTearOff) |
| 664 { | 664 { |
| 665 RefPtrWillBeRawPtr<SVGMatrixTearOff> matrixTearOff = passMatrixTearOff; | 665 RawPtr<SVGMatrixTearOff> matrixTearOff = passMatrixTearOff; |
| 666 const AffineTransform& transform = matrixTearOff->value(); | 666 const AffineTransform& transform = matrixTearOff->value(); |
| 667 setTransform(transform.a(), transform.b(), transform.c(), transform.d(), tra
nsform.e(), transform.f()); | 667 setTransform(transform.a(), transform.b(), transform.c(), transform.d(), tra
nsform.e(), transform.f()); |
| 668 } | 668 } |
| 669 | 669 |
| 670 void CanvasRenderingContext2D::scale(double sx, double sy) | 670 void CanvasRenderingContext2D::scale(double sx, double sy) |
| 671 { | 671 { |
| 672 SkCanvas* c = drawingCanvas(); | 672 SkCanvas* c = drawingCanvas(); |
| 673 if (!c) | 673 if (!c) |
| 674 return; | 674 return; |
| 675 | 675 |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 | 1232 |
| 1233 // To clip the destination rectangle in the same proportion, transform the c
lipped src rect | 1233 // To clip the destination rectangle in the same proportion, transform the c
lipped src rect |
| 1234 *dstRect = *srcRect; | 1234 *dstRect = *srcRect; |
| 1235 dstRect->scale(scale.width(), scale.height()); | 1235 dstRect->scale(scale.width(), scale.height()); |
| 1236 dstRect->move(offset); | 1236 dstRect->move(offset); |
| 1237 } | 1237 } |
| 1238 | 1238 |
| 1239 static inline CanvasImageSource* toImageSourceInternal(const CanvasImageSourceUn
ion& value) | 1239 static inline CanvasImageSource* toImageSourceInternal(const CanvasImageSourceUn
ion& value) |
| 1240 { | 1240 { |
| 1241 if (value.isHTMLImageElement()) | 1241 if (value.isHTMLImageElement()) |
| 1242 return value.getAsHTMLImageElement().get(); | 1242 return value.getAsHTMLImageElement(); |
| 1243 if (value.isHTMLVideoElement()) | 1243 if (value.isHTMLVideoElement()) |
| 1244 return value.getAsHTMLVideoElement().get(); | 1244 return value.getAsHTMLVideoElement(); |
| 1245 if (value.isHTMLCanvasElement()) | 1245 if (value.isHTMLCanvasElement()) |
| 1246 return value.getAsHTMLCanvasElement().get(); | 1246 return value.getAsHTMLCanvasElement(); |
| 1247 if (value.isImageBitmap()) | 1247 if (value.isImageBitmap()) |
| 1248 return value.getAsImageBitmap().get(); | 1248 return value.getAsImageBitmap(); |
| 1249 ASSERT_NOT_REACHED(); | 1249 ASSERT_NOT_REACHED(); |
| 1250 return nullptr; | 1250 return nullptr; |
| 1251 } | 1251 } |
| 1252 | 1252 |
| 1253 void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSour
ce, double x, double y, ExceptionState& exceptionState) | 1253 void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSour
ce, double x, double y, ExceptionState& exceptionState) |
| 1254 { | 1254 { |
| 1255 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); | 1255 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); |
| 1256 FloatSize sourceRectSize = imageSourceInternal->elementSize(); | 1256 FloatSize sourceRectSize = imageSourceInternal->elementSize(); |
| 1257 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(); | 1257 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(); |
| 1258 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.
height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState); | 1258 drawImage(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceRectSize.
height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState); |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2236 hitRegionPath = state().intersectPathWithClip(hitRegionPath.skPath()); | 2236 hitRegionPath = state().intersectPathWithClip(hitRegionPath.skPath()); |
| 2237 if (hitRegionPath.isEmpty()) | 2237 if (hitRegionPath.isEmpty()) |
| 2238 exceptionState.throwDOMException(NotSupportedError, "The specified p
ath has no pixels."); | 2238 exceptionState.throwDOMException(NotSupportedError, "The specified p
ath has no pixels."); |
| 2239 } | 2239 } |
| 2240 | 2240 |
| 2241 if (!m_hitRegionManager) | 2241 if (!m_hitRegionManager) |
| 2242 m_hitRegionManager = HitRegionManager::create(); | 2242 m_hitRegionManager = HitRegionManager::create(); |
| 2243 | 2243 |
| 2244 // Remove previous region (with id or control) | 2244 // Remove previous region (with id or control) |
| 2245 m_hitRegionManager->removeHitRegionById(options.id()); | 2245 m_hitRegionManager->removeHitRegionById(options.id()); |
| 2246 m_hitRegionManager->removeHitRegionByControl(options.control().get()); | 2246 m_hitRegionManager->removeHitRegionByControl(options.control()); |
| 2247 | 2247 |
| 2248 RefPtrWillBeRawPtr<HitRegion> hitRegion = HitRegion::create(hitRegionPath, o
ptions); | 2248 RawPtr<HitRegion> hitRegion = HitRegion::create(hitRegionPath, options); |
| 2249 Element* element = hitRegion->control(); | 2249 Element* element = hitRegion->control(); |
| 2250 if (element && element->isDescendantOf(canvas())) | 2250 if (element && element->isDescendantOf(canvas())) |
| 2251 updateElementAccessibility(hitRegion->path(), hitRegion->control()); | 2251 updateElementAccessibility(hitRegion->path(), hitRegion->control()); |
| 2252 m_hitRegionManager->addHitRegion(hitRegion.release()); | 2252 m_hitRegionManager->addHitRegion(hitRegion.release()); |
| 2253 } | 2253 } |
| 2254 | 2254 |
| 2255 void CanvasRenderingContext2D::removeHitRegion(const String& id) | 2255 void CanvasRenderingContext2D::removeHitRegion(const String& id) |
| 2256 { | 2256 { |
| 2257 if (m_hitRegionManager) | 2257 if (m_hitRegionManager) |
| 2258 m_hitRegionManager->removeHitRegionById(id); | 2258 m_hitRegionManager->removeHitRegionById(id); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2341 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage) | 2341 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage) |
| 2342 return; | 2342 return; |
| 2343 if (alpha < 0xFF) | 2343 if (alpha < 0xFF) |
| 2344 return; | 2344 return; |
| 2345 } | 2345 } |
| 2346 | 2346 |
| 2347 canvas()->buffer()->willOverwriteCanvas(); | 2347 canvas()->buffer()->willOverwriteCanvas(); |
| 2348 } | 2348 } |
| 2349 | 2349 |
| 2350 } // namespace blink | 2350 } // namespace blink |
| OLD | NEW |