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 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 FloatSize offset = dstRect->location() - scaledSrcLocation; | 1476 FloatSize offset = dstRect->location() - scaledSrcLocation; |
1477 | 1477 |
1478 srcRect->intersect(imageRect); | 1478 srcRect->intersect(imageRect); |
1479 | 1479 |
1480 // To clip the destination rectangle in the same proportion, transform the c
lipped src rect | 1480 // To clip the destination rectangle in the same proportion, transform the c
lipped src rect |
1481 *dstRect = *srcRect; | 1481 *dstRect = *srcRect; |
1482 dstRect->scale(scale.width(), scale.height()); | 1482 dstRect->scale(scale.width(), scale.height()); |
1483 dstRect->move(offset); | 1483 dstRect->move(offset); |
1484 } | 1484 } |
1485 | 1485 |
1486 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, float x
, float y, ExceptionState& exceptionState) | 1486 static inline CanvasImageSource* toImageSourceInternal(const CanvasImageSourceUn
ion& value) |
1487 { | 1487 { |
1488 FloatSize sourceRectSize = imageSource->sourceSize(); | 1488 if (value.isHTMLImageElement()) |
1489 FloatSize destRectSize = imageSource->defaultDestinationSize(); | 1489 return value.getAsHTMLImageElement().get(); |
1490 drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.
height(), x, y, destRectSize.width(), destRectSize.height(), exceptionState); | 1490 if (value.isHTMLVideoElement()) |
| 1491 return value.getAsHTMLVideoElement().get(); |
| 1492 if (value.isHTMLCanvasElement()) |
| 1493 return value.getAsHTMLCanvasElement().get(); |
| 1494 if (value.isImageBitmap()) |
| 1495 return value.getAsImageBitmap().get(); |
| 1496 ASSERT_NOT_REACHED(); |
| 1497 return nullptr; |
1491 } | 1498 } |
1492 | 1499 |
1493 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, | 1500 void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSour
ce, float x, float y, ExceptionState& exceptionState) |
| 1501 { |
| 1502 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); |
| 1503 FloatSize sourceRectSize = imageSourceInternal->sourceSize(); |
| 1504 FloatSize destRectSize = imageSourceInternal->defaultDestinationSize(); |
| 1505 drawImageInternal(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceR
ectSize.height(), x, y, destRectSize.width(), destRectSize.height(), exceptionSt
ate); |
| 1506 } |
| 1507 |
| 1508 void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSour
ce, |
1494 float x, float y, float width, float height, ExceptionState& exceptionState) | 1509 float x, float y, float width, float height, ExceptionState& exceptionState) |
1495 { | 1510 { |
1496 FloatSize sourceRectSize = imageSource->sourceSize(); | 1511 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); |
1497 drawImageInternal(imageSource, 0, 0, sourceRectSize.width(), sourceRectSize.
height(), x, y, width, height, exceptionState); | 1512 FloatSize sourceRectSize = imageSourceInternal->sourceSize(); |
| 1513 drawImageInternal(imageSourceInternal, 0, 0, sourceRectSize.width(), sourceR
ectSize.height(), x, y, width, height, exceptionState); |
1498 } | 1514 } |
1499 | 1515 |
1500 void CanvasRenderingContext2D::drawImage(CanvasImageSource* imageSource, | 1516 void CanvasRenderingContext2D::drawImage(const CanvasImageSourceUnion& imageSour
ce, |
1501 float sx, float sy, float sw, float sh, | 1517 float sx, float sy, float sw, float sh, |
1502 float dx, float dy, float dw, float dh, ExceptionState& exceptionState) | 1518 float dx, float dy, float dw, float dh, ExceptionState& exceptionState) |
1503 { | 1519 { |
1504 drawImageInternal(imageSource, sx, sy, sw, sh, dx, dy, dw, dh, exceptionStat
e); | 1520 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); |
| 1521 drawImageInternal(imageSourceInternal, sx, sy, sw, sh, dx, dy, dw, dh, excep
tionState); |
1505 } | 1522 } |
1506 | 1523 |
1507 static void drawVideo(GraphicsContext* c, CanvasImageSource* imageSource, FloatR
ect srcRect, FloatRect dstRect) | 1524 static void drawVideo(GraphicsContext* c, CanvasImageSource* imageSource, FloatR
ect srcRect, FloatRect dstRect) |
1508 { | 1525 { |
1509 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource); | 1526 HTMLVideoElement* video = static_cast<HTMLVideoElement*>(imageSource); |
1510 GraphicsContextStateSaver stateSaver(*c); | 1527 GraphicsContextStateSaver stateSaver(*c); |
1511 c->clip(dstRect); | 1528 c->clip(dstRect); |
1512 c->translate(dstRect.x(), dstRect.y()); | 1529 c->translate(dstRect.x(), dstRect.y()); |
1513 c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.heigh
t()); | 1530 c->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.heigh
t()); |
1514 c->translate(-srcRect.x(), -srcRect.y()); | 1531 c->translate(-srcRect.x(), -srcRect.y()); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 { | 1693 { |
1677 if (r0 < 0 || r1 < 0) { | 1694 if (r0 < 0 || r1 < 0) { |
1678 exceptionState.throwDOMException(IndexSizeError, String::format("The %s
provided is less than 0.", r0 < 0 ? "r0" : "r1")); | 1695 exceptionState.throwDOMException(IndexSizeError, String::format("The %s
provided is less than 0.", r0 < 0 ? "r0" : "r1")); |
1679 return nullptr; | 1696 return nullptr; |
1680 } | 1697 } |
1681 | 1698 |
1682 RefPtrWillBeRawPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPo
int(x0, y0), r0, FloatPoint(x1, y1), r1); | 1699 RefPtrWillBeRawPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPo
int(x0, y0), r0, FloatPoint(x1, y1), r1); |
1683 return gradient.release(); | 1700 return gradient.release(); |
1684 } | 1701 } |
1685 | 1702 |
1686 PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca
nvasImageSource* imageSource, | 1703 PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(co
nst CanvasImageSourceUnion& imageSource, |
1687 const String& repetitionType, ExceptionState& exceptionState) | 1704 const String& repetitionType, ExceptionState& exceptionState) |
1688 { | 1705 { |
1689 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti
onType, exceptionState); | 1706 Pattern::RepeatMode repeatMode = CanvasPattern::parseRepetitionType(repetiti
onType, exceptionState); |
1690 if (exceptionState.hadException()) | 1707 if (exceptionState.hadException()) |
1691 return nullptr; | 1708 return nullptr; |
1692 | 1709 |
1693 SourceImageStatus status; | 1710 SourceImageStatus status; |
1694 RefPtr<Image> imageForRendering = imageSource->getSourceImageForCanvas(CopyS
ourceImageIfVolatile, &status); | 1711 CanvasImageSource* imageSourceInternal = toImageSourceInternal(imageSource); |
| 1712 RefPtr<Image> imageForRendering = imageSourceInternal->getSourceImageForCanv
as(CopySourceImageIfVolatile, &status); |
1695 | 1713 |
1696 switch (status) { | 1714 switch (status) { |
1697 case NormalSourceImageStatus: | 1715 case NormalSourceImageStatus: |
1698 break; | 1716 break; |
1699 case ZeroSizeCanvasSourceImageStatus: | 1717 case ZeroSizeCanvasSourceImageStatus: |
1700 exceptionState.throwDOMException(InvalidStateError, String::format("The
canvas %s is 0.", imageSource->sourceSize().width() ? "height" : "width")); | 1718 exceptionState.throwDOMException(InvalidStateError, String::format("The
canvas %s is 0.", imageSourceInternal->sourceSize().width() ? "height" : "width"
)); |
1701 return nullptr; | 1719 return nullptr; |
1702 case UndecodableSourceImageStatus: | 1720 case UndecodableSourceImageStatus: |
1703 exceptionState.throwDOMException(InvalidStateError, "Source image is in
the 'broken' state."); | 1721 exceptionState.throwDOMException(InvalidStateError, "Source image is in
the 'broken' state."); |
1704 return nullptr; | 1722 return nullptr; |
1705 case InvalidSourceImageStatus: | 1723 case InvalidSourceImageStatus: |
1706 imageForRendering = Image::nullImage(); | 1724 imageForRendering = Image::nullImage(); |
1707 break; | 1725 break; |
1708 case IncompleteSourceImageStatus: | 1726 case IncompleteSourceImageStatus: |
1709 return nullptr; | 1727 return nullptr; |
1710 default: | 1728 default: |
1711 case ExternalSourceImageStatus: // should not happen when mode is CopySource
ImageIfVolatile | 1729 case ExternalSourceImageStatus: // should not happen when mode is CopySource
ImageIfVolatile |
1712 ASSERT_NOT_REACHED(); | 1730 ASSERT_NOT_REACHED(); |
1713 return nullptr; | 1731 return nullptr; |
1714 } | 1732 } |
1715 ASSERT(imageForRendering); | 1733 ASSERT(imageForRendering); |
1716 | 1734 |
1717 bool originClean = !wouldTaintOrigin(imageSource); | 1735 bool originClean = !wouldTaintOrigin(imageSourceInternal); |
1718 | 1736 |
1719 return CanvasPattern::create(imageForRendering.release(), repeatMode, origin
Clean); | 1737 return CanvasPattern::create(imageForRendering.release(), repeatMode, origin
Clean); |
1720 } | 1738 } |
1721 | 1739 |
1722 bool CanvasRenderingContext2D::computeDirtyRect(const FloatRect& localRect, Floa
tRect* dirtyRect) | 1740 bool CanvasRenderingContext2D::computeDirtyRect(const FloatRect& localRect, Floa
tRect* dirtyRect) |
1723 { | 1741 { |
1724 FloatRect clipBounds; | 1742 FloatRect clipBounds; |
1725 if (!drawingContext()->getTransformedClipBounds(&clipBounds)) | 1743 if (!drawingContext()->getTransformedClipBounds(&clipBounds)) |
1726 return false; | 1744 return false; |
1727 return computeDirtyRect(localRect, clipBounds, dirtyRect); | 1745 return computeDirtyRect(localRect, clipBounds, dirtyRect); |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2448 | 2466 |
2449 unsigned CanvasRenderingContext2D::hitRegionsCount() const | 2467 unsigned CanvasRenderingContext2D::hitRegionsCount() const |
2450 { | 2468 { |
2451 if (m_hitRegionManager) | 2469 if (m_hitRegionManager) |
2452 return m_hitRegionManager->getHitRegionsCount(); | 2470 return m_hitRegionManager->getHitRegionsCount(); |
2453 | 2471 |
2454 return 0; | 2472 return 0; |
2455 } | 2473 } |
2456 | 2474 |
2457 } // namespace blink | 2475 } // namespace blink |
OLD | NEW |