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 13 matching lines...) Expand all Loading... |
24 #include "platform/RuntimeEnabledFeatures.h" | 24 #include "platform/RuntimeEnabledFeatures.h" |
25 #include "platform/geometry/FloatQuad.h" | 25 #include "platform/geometry/FloatQuad.h" |
26 #include "platform/graphics/Color.h" | 26 #include "platform/graphics/Color.h" |
27 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 27 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
28 #include "platform/graphics/Image.h" | 28 #include "platform/graphics/Image.h" |
29 #include "platform/graphics/ImageBuffer.h" | 29 #include "platform/graphics/ImageBuffer.h" |
30 #include "platform/graphics/StrokeData.h" | 30 #include "platform/graphics/StrokeData.h" |
31 #include "platform/graphics/paint/PaintCanvas.h" | 31 #include "platform/graphics/paint/PaintCanvas.h" |
32 #include "platform/graphics/paint/PaintFlags.h" | 32 #include "platform/graphics/paint/PaintFlags.h" |
33 #include "platform/graphics/skia/SkiaUtils.h" | 33 #include "platform/graphics/skia/SkiaUtils.h" |
| 34 #include "platform/wtf/CheckedNumeric.h" |
34 | 35 |
35 namespace blink { | 36 namespace blink { |
36 | 37 |
37 BaseRenderingContext2D::BaseRenderingContext2D() | 38 BaseRenderingContext2D::BaseRenderingContext2D() |
38 : m_clipAntialiasing(NotAntiAliased) { | 39 : m_clipAntialiasing(NotAntiAliased) { |
39 m_stateStack.push_back(CanvasRenderingContext2DState::create()); | 40 m_stateStack.push_back(CanvasRenderingContext2DState::create()); |
40 } | 41 } |
41 | 42 |
42 BaseRenderingContext2D::~BaseRenderingContext2D() {} | 43 BaseRenderingContext2D::~BaseRenderingContext2D() {} |
43 | 44 |
(...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 exceptionState.throwRangeError("Out of memory at ImageData creation"); | 1524 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
1524 return result; | 1525 return result; |
1525 } | 1526 } |
1526 | 1527 |
1527 ImageData* BaseRenderingContext2D::getImageData( | 1528 ImageData* BaseRenderingContext2D::getImageData( |
1528 int sx, | 1529 int sx, |
1529 int sy, | 1530 int sy, |
1530 int sw, | 1531 int sw, |
1531 int sh, | 1532 int sh, |
1532 ExceptionState& exceptionState) const { | 1533 ExceptionState& exceptionState) const { |
| 1534 if (!WTF::CheckMul(sw, sh).IsValid<int>()) { |
| 1535 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
| 1536 return nullptr; |
| 1537 } |
| 1538 |
1533 m_usageCounters.numGetImageDataCalls++; | 1539 m_usageCounters.numGetImageDataCalls++; |
1534 m_usageCounters.areaGetImageDataCalls += sw * sh; | 1540 m_usageCounters.areaGetImageDataCalls += sw * sh; |
1535 if (!originClean()) | 1541 if (!originClean()) |
1536 exceptionState.throwSecurityError( | 1542 exceptionState.throwSecurityError( |
1537 "The canvas has been tainted by cross-origin data."); | 1543 "The canvas has been tainted by cross-origin data."); |
1538 else if (!sw || !sh) | 1544 else if (!sw || !sh) |
1539 exceptionState.throwDOMException( | 1545 exceptionState.throwDOMException( |
1540 IndexSizeError, | 1546 IndexSizeError, |
1541 String::format("The source %s is 0.", sw ? "height" : "width")); | 1547 String::format("The source %s is 0.", sw ? "height" : "width")); |
1542 | 1548 |
1543 if (exceptionState.hadException()) | 1549 if (exceptionState.hadException()) |
1544 return nullptr; | 1550 return nullptr; |
1545 | 1551 |
1546 if (sw < 0) { | 1552 if (sw < 0) { |
1547 sx += sw; | 1553 sx += sw; |
1548 sw = -sw; | 1554 sw = -sw; |
1549 } | 1555 } |
1550 if (sh < 0) { | 1556 if (sh < 0) { |
1551 sy += sh; | 1557 sy += sh; |
1552 sh = -sh; | 1558 sh = -sh; |
1553 } | 1559 } |
1554 | 1560 |
| 1561 if (!WTF::CheckAdd(sx, sw).IsValid<int>() || |
| 1562 !WTF::CheckAdd(sy, sh).IsValid<int>()) { |
| 1563 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
| 1564 return nullptr; |
| 1565 } |
| 1566 |
1555 Optional<ScopedUsHistogramTimer> timer; | 1567 Optional<ScopedUsHistogramTimer> timer; |
1556 if (imageBuffer() && imageBuffer()->isAccelerated()) { | 1568 if (imageBuffer() && imageBuffer()->isAccelerated()) { |
1557 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 1569 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
1558 CustomCountHistogram, scopedUsCounterGPU, | 1570 CustomCountHistogram, scopedUsCounterGPU, |
1559 new CustomCountHistogram("Blink.Canvas.GetImageData.GPU", 0, 10000000, | 1571 new CustomCountHistogram("Blink.Canvas.GetImageData.GPU", 0, 10000000, |
1560 50)); | 1572 50)); |
1561 timer.emplace(scopedUsCounterGPU); | 1573 timer.emplace(scopedUsCounterGPU); |
1562 } else if (imageBuffer() && imageBuffer()->isRecording()) { | 1574 } else if (imageBuffer() && imageBuffer()->isRecording()) { |
1563 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 1575 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
1564 CustomCountHistogram, scopedUsCounterDisplayList, | 1576 CustomCountHistogram, scopedUsCounterDisplayList, |
1565 new CustomCountHistogram("Blink.Canvas.GetImageData.DisplayList", 0, | 1577 new CustomCountHistogram("Blink.Canvas.GetImageData.DisplayList", 0, |
1566 10000000, 50)); | 1578 10000000, 50)); |
1567 timer.emplace(scopedUsCounterDisplayList); | 1579 timer.emplace(scopedUsCounterDisplayList); |
1568 } else { | 1580 } else { |
1569 DEFINE_THREAD_SAFE_STATIC_LOCAL( | 1581 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
1570 CustomCountHistogram, scopedUsCounterCPU, | 1582 CustomCountHistogram, scopedUsCounterCPU, |
1571 new CustomCountHistogram("Blink.Canvas.GetImageData.CPU", 0, 10000000, | 1583 new CustomCountHistogram("Blink.Canvas.GetImageData.CPU", 0, 10000000, |
1572 50)); | 1584 50)); |
1573 timer.emplace(scopedUsCounterCPU); | 1585 timer.emplace(scopedUsCounterCPU); |
1574 } | 1586 } |
1575 | 1587 |
1576 IntRect imageDataRect(sx, sy, sw, sh); | 1588 IntRect imageDataRect(sx, sy, sw, sh); |
1577 DVLOG(1) << sx << ", " << sy << ", " << sw << ", " << sh; | |
1578 ImageBuffer* buffer = imageBuffer(); | 1589 ImageBuffer* buffer = imageBuffer(); |
1579 if (!buffer || isContextLost()) { | 1590 if (!buffer || isContextLost()) { |
1580 ImageData* result = ImageData::create(imageDataRect.size()); | 1591 ImageData* result = ImageData::create(imageDataRect.size()); |
1581 if (!result) | 1592 if (!result) |
1582 exceptionState.throwRangeError("Out of memory at ImageData creation"); | 1593 exceptionState.throwRangeError("Out of memory at ImageData creation"); |
1583 return result; | 1594 return result; |
1584 } | 1595 } |
1585 | 1596 |
1586 WTF::ArrayBufferContents contents; | 1597 WTF::ArrayBufferContents contents; |
1587 if (!buffer->getImageData(Unmultiplied, imageDataRect, contents)) { | 1598 if (!buffer->getImageData(Unmultiplied, imageDataRect, contents)) { |
(...skipping 16 matching lines...) Expand all Loading... |
1604 } | 1615 } |
1605 | 1616 |
1606 void BaseRenderingContext2D::putImageData(ImageData* data, | 1617 void BaseRenderingContext2D::putImageData(ImageData* data, |
1607 int dx, | 1618 int dx, |
1608 int dy, | 1619 int dy, |
1609 int dirtyX, | 1620 int dirtyX, |
1610 int dirtyY, | 1621 int dirtyY, |
1611 int dirtyWidth, | 1622 int dirtyWidth, |
1612 int dirtyHeight, | 1623 int dirtyHeight, |
1613 ExceptionState& exceptionState) { | 1624 ExceptionState& exceptionState) { |
| 1625 if (!WTF::CheckMul(dirtyWidth, dirtyHeight).IsValid<int>()) { |
| 1626 return; |
| 1627 } |
| 1628 |
1614 m_usageCounters.numPutImageDataCalls++; | 1629 m_usageCounters.numPutImageDataCalls++; |
1615 m_usageCounters.areaPutImageDataCalls += dirtyWidth * dirtyHeight; | 1630 m_usageCounters.areaPutImageDataCalls += dirtyWidth * dirtyHeight; |
1616 if (data->data()->bufferBase()->isNeutered()) { | 1631 if (data->data()->bufferBase()->isNeutered()) { |
1617 exceptionState.throwDOMException(InvalidStateError, | 1632 exceptionState.throwDOMException(InvalidStateError, |
1618 "The source data has been neutered."); | 1633 "The source data has been neutered."); |
1619 return; | 1634 return; |
1620 } | 1635 } |
1621 ImageBuffer* buffer = imageBuffer(); | 1636 ImageBuffer* buffer = imageBuffer(); |
1622 if (!buffer) | 1637 if (!buffer) |
1623 return; | 1638 return; |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * | 2029 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * |
2015 m_usageCounters.numBlurredShadows + | 2030 m_usageCounters.numBlurredShadows + |
2016 ExpensiveCanvasHeuristicParameters:: | 2031 ExpensiveCanvasHeuristicParameters:: |
2017 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * | 2032 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * |
2018 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; | 2033 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; |
2019 | 2034 |
2020 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; | 2035 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; |
2021 } | 2036 } |
2022 | 2037 |
2023 } // namespace blink | 2038 } // namespace blink |
OLD | NEW |