OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/canvas2d/BaseRenderingContext2D.h" | 5 #include "modules/canvas2d/BaseRenderingContext2D.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "core/css/cssom/CSSURLImageValue.h" | 10 #include "core/css/cssom/CSSURLImageValue.h" |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1519 FloatSize logicalSize(fabs(sw), fabs(sh)); | 1519 FloatSize logicalSize(fabs(sw), fabs(sh)); |
1520 if (!logicalSize.isExpressibleAsIntSize()) | 1520 if (!logicalSize.isExpressibleAsIntSize()) |
1521 return nullptr; | 1521 return nullptr; |
1522 | 1522 |
1523 IntSize size = expandedIntSize(logicalSize); | 1523 IntSize size = expandedIntSize(logicalSize); |
1524 if (size.width() < 1) | 1524 if (size.width() < 1) |
1525 size.setWidth(1); | 1525 size.setWidth(1); |
1526 if (size.height() < 1) | 1526 if (size.height() < 1) |
1527 size.setHeight(1); | 1527 size.setHeight(1); |
1528 | 1528 |
1529 ImageData* result = ImageData::create(size); | 1529 ImageData* result = nullptr; |
1530 if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() && | |
1531 RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { | |
1532 ImageDataColorSettings colorSettings; | |
1533 colorSettings.setColorSpace(renderingContext()->colorSpaceAsString()); | |
Justin Novosad
2017/03/27 19:43:48
Hmmm... so createImageData inherits the setting fr
zakerinasab
2017/03/30 17:56:11
I'll do.
| |
1534 switch (renderingContext()->pixelFormat()) { | |
1535 case kRGBA8CanvasPixelFormat: | |
1536 colorSettings.setStorageFormat(kUint8ClampedArrayStorageFormatName); | |
1537 break; | |
1538 case kF16CanvasPixelFormat: | |
1539 colorSettings.setStorageFormat(kFloat32ArrayStorageFormatName); | |
1540 break; | |
1541 case kRGB10A2CanvasPixelFormat: | |
1542 case kRGBA12CanvasPixelFormat: | |
1543 default: | |
1544 NOTREACHED(); | |
1545 } | |
1546 LOG(ERROR) << "In createImageData: " << colorSettings.colorSpace() << ", " | |
1547 << colorSettings.storageFormat(); | |
1548 result = ImageData::create(size, &colorSettings); | |
1549 } else { | |
1550 result = ImageData::create(size); | |
1551 } | |
1530 if (!result) | 1552 if (!result) |
1531 exceptionState.throwRangeError("Out of memory at ImageData creation"); | 1553 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
1532 return result; | 1554 return result; |
1533 } | 1555 } |
1534 | 1556 |
1535 ImageData* BaseRenderingContext2D::getImageData( | 1557 ImageData* BaseRenderingContext2D::getImageData( |
1536 double sx, | 1558 double sx, |
1537 double sy, | 1559 double sy, |
1538 double sw, | 1560 double sw, |
1539 double sh, | 1561 double sh, |
1540 ExceptionState& exceptionState) const { | 1562 ExceptionState& exceptionState) const { |
1563 LOG(ERROR) << renderingContext()->colorSpaceAsString(); | |
1564 LOG(ERROR) << renderingContext()->pixelFormatAsString(); | |
Justin Novosad
2017/03/27 19:43:48
I See a lot of error logging in this file that loo
zakerinasab
2017/03/30 17:56:11
This was a work in progress. Removed now.
| |
1541 m_usageCounters.numGetImageDataCalls++; | 1565 m_usageCounters.numGetImageDataCalls++; |
1542 m_usageCounters.areaGetImageDataCalls += sw * sh; | 1566 m_usageCounters.areaGetImageDataCalls += sw * sh; |
1543 if (!originClean()) | 1567 if (!originClean()) |
1544 exceptionState.throwSecurityError( | 1568 exceptionState.throwSecurityError( |
1545 "The canvas has been tainted by cross-origin data."); | 1569 "The canvas has been tainted by cross-origin data."); |
1546 else if (!sw || !sh) | 1570 else if (!sw || !sh) |
1547 exceptionState.throwDOMException( | 1571 exceptionState.throwDOMException( |
1548 IndexSizeError, | 1572 IndexSizeError, |
1549 String::format("The source %s is 0.", sw ? "height" : "width")); | 1573 String::format("The source %s is 0.", sw ? "height" : "width")); |
1550 | 1574 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1582 10000000, 50)); | 1606 10000000, 50)); |
1583 timer.emplace(scopedUsCounterDisplayList); | 1607 timer.emplace(scopedUsCounterDisplayList); |
1584 } else { | 1608 } else { |
1585 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 1609 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
1586 CustomCountHistogram, scopedUsCounterCPU, | 1610 CustomCountHistogram, scopedUsCounterCPU, |
1587 new CustomCountHistogram("Blink.Canvas.GetImageData.CPU", 0, 10000000, | 1611 new CustomCountHistogram("Blink.Canvas.GetImageData.CPU", 0, 10000000, |
1588 50)); | 1612 50)); |
1589 timer.emplace(scopedUsCounterCPU); | 1613 timer.emplace(scopedUsCounterCPU); |
1590 } | 1614 } |
1591 | 1615 |
1616 ImageDataColorSettings colorSettings; | |
1617 LOG(ERROR) << "Default: " << colorSettings.colorSpace() << ", " | |
1618 << colorSettings.storageFormat(); | |
1619 bool canvasIsColorManaged = | |
1620 RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() && | |
1621 RuntimeEnabledFeatures::colorCorrectRenderingEnabled(); | |
1622 if (canvasIsColorManaged) { | |
1623 colorSettings.setColorSpace(renderingContext()->colorSpaceAsString()); | |
1624 switch (renderingContext()->pixelFormat()) { | |
1625 case kRGBA8CanvasPixelFormat: | |
1626 colorSettings.setStorageFormat(kUint8ClampedArrayStorageFormatName); | |
1627 break; | |
1628 case kF16CanvasPixelFormat: | |
1629 colorSettings.setStorageFormat(kFloat32ArrayStorageFormatName); | |
1630 break; | |
1631 case kRGB10A2CanvasPixelFormat: | |
1632 case kRGBA12CanvasPixelFormat: | |
1633 default: | |
1634 NOTREACHED(); | |
1635 } | |
1636 LOG(ERROR) << "Set: " << colorSettings.colorSpace() << ", " | |
1637 << colorSettings.storageFormat(); | |
1638 } | |
1639 | |
1592 IntRect imageDataRect = enclosingIntRect(logicalRect); | 1640 IntRect imageDataRect = enclosingIntRect(logicalRect); |
1593 ImageBuffer* buffer = imageBuffer(); | 1641 ImageBuffer* buffer = imageBuffer(); |
1594 if (!buffer || isContextLost()) { | 1642 if (!buffer || isContextLost()) { |
1595 ImageData* result = ImageData::create(imageDataRect.size()); | 1643 ImageData* result = nullptr; |
1644 if (canvasIsColorManaged) | |
1645 result = ImageData::create(imageDataRect.size(), &colorSettings); | |
1646 else | |
1647 result = ImageData::create(imageDataRect.size()); | |
1596 if (!result) | 1648 if (!result) |
1597 exceptionState.throwRangeError("Out of memory at ImageData creation"); | 1649 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
1598 return result; | 1650 return result; |
1599 } | 1651 } |
1600 | 1652 |
1601 WTF::ArrayBufferContents contents; | 1653 WTF::ArrayBufferContents contents; |
1602 if (!buffer->getImageData(Unmultiplied, imageDataRect, contents)) { | 1654 if (!buffer->getImageData(Unmultiplied, imageDataRect, contents)) { |
1603 exceptionState.throwRangeError("Out of memory at ImageData creation"); | 1655 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
1604 return nullptr; | 1656 return nullptr; |
1605 } | 1657 } |
1606 | 1658 |
1607 DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(contents); | 1659 DOMArrayBuffer* arrayBuffer = nullptr; |
1660 DOMArrayBufferView* arrayBufferView = nullptr; | |
1661 DOMFloat32Array* dataArray = nullptr; | |
1662 | |
1663 LOG(ERROR) << "HERE"; | |
1664 if (canvasIsColorManaged) { | |
1665 LOG(ERROR) << "Canvas is color managed"; | |
1666 ImageDataStorageFormat storageFormat = | |
1667 ImageData::getImageDataStorageFormat(colorSettings.storageFormat()); | |
1668 switch (storageFormat) { | |
1669 case kUint8ClampedArrayStorageFormat: | |
1670 arrayBuffer = DOMArrayBuffer::create(contents); | |
1671 return ImageData::create( | |
1672 imageDataRect.size(), | |
1673 DOMUint8ClampedArray::create(arrayBuffer, 0, | |
1674 arrayBuffer->byteLength())); | |
1675 break; | |
1676 case kUint16ArrayStorageFormat: | |
1677 NOTREACHED(); | |
1678 break; | |
1679 case kFloat32ArrayStorageFormat: | |
1680 LOG(ERROR) << "kFloat32ArrayStorageFormat"; | |
1681 arrayBufferView = ImageData:: | |
1682 convertPixelsFromCanvasPixelFormatToImageDataStorageFormat( | |
1683 contents, renderingContext()->pixelFormat(), storageFormat); | |
1684 LOG(ERROR) << (void*)(arrayBufferView); | |
1685 LOG(ERROR) << arrayBufferView->byteLength(); | |
1686 LOG(ERROR) << arrayBufferView->typeSize(); | |
1687 dataArray = const_cast<DOMFloat32Array*>( | |
1688 static_cast<const DOMFloat32Array*>(arrayBufferView)); | |
1689 return ImageData::create(imageDataRect.size(), arrayBufferView, | |
1690 &colorSettings); | |
1691 default: | |
1692 NOTREACHED(); | |
1693 } | |
1694 return nullptr; | |
1695 } | |
1696 LOG(ERROR) << "NOT color managed canvas"; | |
1697 | |
1698 arrayBuffer = DOMArrayBuffer::create(contents); | |
1608 return ImageData::create( | 1699 return ImageData::create( |
1609 imageDataRect.size(), | 1700 imageDataRect.size(), |
1610 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength())); | 1701 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength())); |
1611 } | 1702 } |
1612 | 1703 |
1613 void BaseRenderingContext2D::putImageData(ImageData* data, | 1704 void BaseRenderingContext2D::putImageData(ImageData* data, |
1614 double dx, | 1705 double dx, |
1615 double dy, | 1706 double dy, |
1616 ExceptionState& exceptionState) { | 1707 ExceptionState& exceptionState) { |
1617 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), | 1708 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1676 50)); | 1767 50)); |
1677 timer.emplace(scopedUsCounterCPU); | 1768 timer.emplace(scopedUsCounterCPU); |
1678 } | 1769 } |
1679 | 1770 |
1680 IntRect sourceRect(destRect); | 1771 IntRect sourceRect(destRect); |
1681 sourceRect.move(-destOffset); | 1772 sourceRect.move(-destOffset); |
1682 | 1773 |
1683 checkOverdraw(destRect, 0, CanvasRenderingContext2DState::NoImage, | 1774 checkOverdraw(destRect, 0, CanvasRenderingContext2DState::NoImage, |
1684 UntransformedUnclippedFill); | 1775 UntransformedUnclippedFill); |
1685 | 1776 |
1686 buffer->putByteArray(Unmultiplied, data->data()->data(), | 1777 unsigned char* source = data->data()->data(); |
1687 IntSize(data->width(), data->height()), sourceRect, | 1778 if (RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled() && |
1688 IntPoint(destOffset)); | 1779 RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) { |
1689 | 1780 source = data->getImageDataInCanvasColorSettings( |
1781 renderingContext()->colorSpace(), renderingContext()->pixelFormat()); | |
1782 } else { | |
1783 buffer->putByteArray(Unmultiplied, source, | |
1784 IntSize(data->width(), data->height()), sourceRect, | |
1785 IntPoint(destOffset)); | |
1786 } | |
1690 didDraw(destRect); | 1787 didDraw(destRect); |
1691 } | 1788 } |
1692 | 1789 |
1693 void BaseRenderingContext2D::inflateStrokeRect(FloatRect& rect) const { | 1790 void BaseRenderingContext2D::inflateStrokeRect(FloatRect& rect) const { |
1694 // Fast approximation of the stroke's bounding rect. | 1791 // Fast approximation of the stroke's bounding rect. |
1695 // This yields a slightly oversized rect but is very fast | 1792 // This yields a slightly oversized rect but is very fast |
1696 // compared to Path::strokeBoundingRect(). | 1793 // compared to Path::strokeBoundingRect(). |
1697 static const double root2 = sqrtf(2); | 1794 static const double root2 = sqrtf(2); |
1698 double delta = state().lineWidth() / 2; | 1795 double delta = state().lineWidth() / 2; |
1699 if (state().getLineJoin() == MiterJoin) | 1796 if (state().getLineJoin() == MiterJoin) |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2025 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * | 2122 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * |
2026 m_usageCounters.numBlurredShadows + | 2123 m_usageCounters.numBlurredShadows + |
2027 ExpensiveCanvasHeuristicParameters:: | 2124 ExpensiveCanvasHeuristicParameters:: |
2028 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * | 2125 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * |
2029 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; | 2126 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; |
2030 | 2127 |
2031 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; | 2128 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; |
2032 } | 2129 } |
2033 | 2130 |
2034 } // namespace blink | 2131 } // namespace blink |
OLD | NEW |