Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/BaseRenderingContext2D.cpp

Issue 2771933002: Update createImageData/getImageData/putImageData from float to long (Closed)
Patch Set: Reset tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 ImageData* BaseRenderingContext2D::createImageData( 1499 ImageData* BaseRenderingContext2D::createImageData(
1500 ImageData* imageData, 1500 ImageData* imageData,
1501 ExceptionState& exceptionState) const { 1501 ExceptionState& exceptionState) const {
1502 ImageData* result = ImageData::create(imageData->size()); 1502 ImageData* result = ImageData::create(imageData->size());
1503 if (!result) 1503 if (!result)
1504 exceptionState.throwRangeError("Out of memory at ImageData creation"); 1504 exceptionState.throwRangeError("Out of memory at ImageData creation");
1505 return result; 1505 return result;
1506 } 1506 }
1507 1507
1508 ImageData* BaseRenderingContext2D::createImageData( 1508 ImageData* BaseRenderingContext2D::createImageData(
1509 double sw, 1509 int sw,
1510 double sh, 1510 int sh,
1511 ExceptionState& exceptionState) const { 1511 ExceptionState& exceptionState) const {
1512 if (!sw || !sh) { 1512 if (!sw || !sh) {
1513 exceptionState.throwDOMException( 1513 exceptionState.throwDOMException(
1514 IndexSizeError, 1514 IndexSizeError,
1515 String::format("The source %s is 0.", sw ? "height" : "width")); 1515 String::format("The source %s is 0.", sw ? "height" : "width"));
1516 return nullptr; 1516 return nullptr;
1517 } 1517 }
1518 1518
1519 FloatSize logicalSize(fabs(sw), fabs(sh)); 1519 IntSize size(abs(sw), abs(sh));
1520 if (!logicalSize.isExpressibleAsIntSize())
1521 return nullptr;
1522
1523 IntSize size = expandedIntSize(logicalSize);
1524 if (size.width() < 1)
1525 size.setWidth(1);
1526 if (size.height() < 1)
1527 size.setHeight(1);
1528 1520
1529 ImageData* result = ImageData::create(size); 1521 ImageData* result = ImageData::create(size);
1530 if (!result) 1522 if (!result)
1531 exceptionState.throwRangeError("Out of memory at ImageData creation"); 1523 exceptionState.throwRangeError("Out of memory at ImageData creation");
1532 return result; 1524 return result;
1533 } 1525 }
1534 1526
1535 ImageData* BaseRenderingContext2D::getImageData( 1527 ImageData* BaseRenderingContext2D::getImageData(
1536 double sx, 1528 int sx,
1537 double sy, 1529 int sy,
1538 double sw, 1530 int sw,
1539 double sh, 1531 int sh,
1540 ExceptionState& exceptionState) const { 1532 ExceptionState& exceptionState) const {
1541 m_usageCounters.numGetImageDataCalls++; 1533 m_usageCounters.numGetImageDataCalls++;
1542 m_usageCounters.areaGetImageDataCalls += sw * sh; 1534 m_usageCounters.areaGetImageDataCalls += sw * sh;
1543 if (!originClean()) 1535 if (!originClean())
1544 exceptionState.throwSecurityError( 1536 exceptionState.throwSecurityError(
1545 "The canvas has been tainted by cross-origin data."); 1537 "The canvas has been tainted by cross-origin data.");
1546 else if (!sw || !sh) 1538 else if (!sw || !sh)
1547 exceptionState.throwDOMException( 1539 exceptionState.throwDOMException(
1548 IndexSizeError, 1540 IndexSizeError,
1549 String::format("The source %s is 0.", sw ? "height" : "width")); 1541 String::format("The source %s is 0.", sw ? "height" : "width"));
1550 1542
1551 if (exceptionState.hadException()) 1543 if (exceptionState.hadException())
1552 return nullptr; 1544 return nullptr;
1553 1545
1554 if (sw < 0) { 1546 if (sw < 0) {
1555 sx += sw; 1547 sx += sw;
1556 sw = -sw; 1548 sw = -sw;
1557 } 1549 }
1558 if (sh < 0) { 1550 if (sh < 0) {
1559 sy += sh; 1551 sy += sh;
1560 sh = -sh; 1552 sh = -sh;
1561 } 1553 }
1562 1554
1563 FloatRect logicalRect(sx, sy, sw, sh);
1564 if (logicalRect.width() < 1)
1565 logicalRect.setWidth(1);
1566 if (logicalRect.height() < 1)
1567 logicalRect.setHeight(1);
1568 if (!logicalRect.isExpressibleAsIntRect())
1569 return nullptr;
1570
1571 Optional<ScopedUsHistogramTimer> timer; 1555 Optional<ScopedUsHistogramTimer> timer;
1572 if (imageBuffer() && imageBuffer()->isAccelerated()) { 1556 if (imageBuffer() && imageBuffer()->isAccelerated()) {
1573 DEFINE_THREAD_SAFE_STATIC_LOCAL( 1557 DEFINE_THREAD_SAFE_STATIC_LOCAL(
1574 CustomCountHistogram, scopedUsCounterGPU, 1558 CustomCountHistogram, scopedUsCounterGPU,
1575 new CustomCountHistogram("Blink.Canvas.GetImageData.GPU", 0, 10000000, 1559 new CustomCountHistogram("Blink.Canvas.GetImageData.GPU", 0, 10000000,
1576 50)); 1560 50));
1577 timer.emplace(scopedUsCounterGPU); 1561 timer.emplace(scopedUsCounterGPU);
1578 } else if (imageBuffer() && imageBuffer()->isRecording()) { 1562 } else if (imageBuffer() && imageBuffer()->isRecording()) {
1579 DEFINE_THREAD_SAFE_STATIC_LOCAL( 1563 DEFINE_THREAD_SAFE_STATIC_LOCAL(
1580 CustomCountHistogram, scopedUsCounterDisplayList, 1564 CustomCountHistogram, scopedUsCounterDisplayList,
1581 new CustomCountHistogram("Blink.Canvas.GetImageData.DisplayList", 0, 1565 new CustomCountHistogram("Blink.Canvas.GetImageData.DisplayList", 0,
1582 10000000, 50)); 1566 10000000, 50));
1583 timer.emplace(scopedUsCounterDisplayList); 1567 timer.emplace(scopedUsCounterDisplayList);
1584 } else { 1568 } else {
1585 DEFINE_THREAD_SAFE_STATIC_LOCAL( 1569 DEFINE_THREAD_SAFE_STATIC_LOCAL(
1586 CustomCountHistogram, scopedUsCounterCPU, 1570 CustomCountHistogram, scopedUsCounterCPU,
1587 new CustomCountHistogram("Blink.Canvas.GetImageData.CPU", 0, 10000000, 1571 new CustomCountHistogram("Blink.Canvas.GetImageData.CPU", 0, 10000000,
1588 50)); 1572 50));
1589 timer.emplace(scopedUsCounterCPU); 1573 timer.emplace(scopedUsCounterCPU);
1590 } 1574 }
1591 1575
1592 IntRect imageDataRect = enclosingIntRect(logicalRect); 1576 IntRect imageDataRect(sx, sy, sw, sh);
1577 DVLOG(1) << sx << ", " << sy << ", " << sw << ", " << sh;
1593 ImageBuffer* buffer = imageBuffer(); 1578 ImageBuffer* buffer = imageBuffer();
1594 if (!buffer || isContextLost()) { 1579 if (!buffer || isContextLost()) {
1595 ImageData* result = ImageData::create(imageDataRect.size()); 1580 ImageData* result = ImageData::create(imageDataRect.size());
1596 if (!result) 1581 if (!result)
1597 exceptionState.throwRangeError("Out of memory at ImageData creation"); 1582 exceptionState.throwRangeError("Out of memory at ImageData creation");
1598 return result; 1583 return result;
1599 } 1584 }
1600 1585
1601 WTF::ArrayBufferContents contents; 1586 WTF::ArrayBufferContents contents;
1602 if (!buffer->getImageData(Unmultiplied, imageDataRect, contents)) { 1587 if (!buffer->getImageData(Unmultiplied, imageDataRect, contents)) {
1603 exceptionState.throwRangeError("Out of memory at ImageData creation"); 1588 exceptionState.throwRangeError("Out of memory at ImageData creation");
1604 return nullptr; 1589 return nullptr;
1605 } 1590 }
1606 1591
1607 DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(contents); 1592 DOMArrayBuffer* arrayBuffer = DOMArrayBuffer::create(contents);
1608 return ImageData::create( 1593 return ImageData::create(
1609 imageDataRect.size(), 1594 imageDataRect.size(),
1610 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength())); 1595 DOMUint8ClampedArray::create(arrayBuffer, 0, arrayBuffer->byteLength()));
1611 } 1596 }
1612 1597
1613 void BaseRenderingContext2D::putImageData(ImageData* data, 1598 void BaseRenderingContext2D::putImageData(ImageData* data,
1614 double dx, 1599 int dx,
1615 double dy, 1600 int dy,
1616 ExceptionState& exceptionState) { 1601 ExceptionState& exceptionState) {
1617 putImageData(data, dx, dy, 0, 0, data->width(), data->height(), 1602 putImageData(data, dx, dy, 0, 0, data->width(), data->height(),
1618 exceptionState); 1603 exceptionState);
1619 } 1604 }
1620 1605
1621 void BaseRenderingContext2D::putImageData(ImageData* data, 1606 void BaseRenderingContext2D::putImageData(ImageData* data,
1622 double dx, 1607 int dx,
1623 double dy, 1608 int dy,
1624 double dirtyX, 1609 int dirtyX,
1625 double dirtyY, 1610 int dirtyY,
1626 double dirtyWidth, 1611 int dirtyWidth,
1627 double dirtyHeight, 1612 int dirtyHeight,
1628 ExceptionState& exceptionState) { 1613 ExceptionState& exceptionState) {
1629 m_usageCounters.numPutImageDataCalls++; 1614 m_usageCounters.numPutImageDataCalls++;
1630 m_usageCounters.areaPutImageDataCalls += dirtyWidth * dirtyHeight; 1615 m_usageCounters.areaPutImageDataCalls += dirtyWidth * dirtyHeight;
1631 if (data->data()->bufferBase()->isNeutered()) { 1616 if (data->data()->bufferBase()->isNeutered()) {
1632 exceptionState.throwDOMException(InvalidStateError, 1617 exceptionState.throwDOMException(InvalidStateError,
1633 "The source data has been neutered."); 1618 "The source data has been neutered.");
1634 return; 1619 return;
1635 } 1620 }
1636 ImageBuffer* buffer = imageBuffer(); 1621 ImageBuffer* buffer = imageBuffer();
1637 if (!buffer) 1622 if (!buffer)
1638 return; 1623 return;
1639 1624
1640 if (dirtyWidth < 0) { 1625 if (dirtyWidth < 0) {
1641 dirtyX += dirtyWidth; 1626 dirtyX += dirtyWidth;
1642 dirtyWidth = -dirtyWidth; 1627 dirtyWidth = -dirtyWidth;
1643 } 1628 }
1644 1629
1645 if (dirtyHeight < 0) { 1630 if (dirtyHeight < 0) {
1646 dirtyY += dirtyHeight; 1631 dirtyY += dirtyHeight;
1647 dirtyHeight = -dirtyHeight; 1632 dirtyHeight = -dirtyHeight;
1648 } 1633 }
1649 1634
1650 FloatRect clipRect(dirtyX, dirtyY, dirtyWidth, dirtyHeight); 1635 IntRect destRect(dirtyX, dirtyY, dirtyWidth, dirtyHeight);
1651 clipRect.intersect(IntRect(0, 0, data->width(), data->height())); 1636 destRect.intersect(IntRect(0, 0, data->width(), data->height()));
1652 IntSize destOffset(static_cast<int>(dx), static_cast<int>(dy)); 1637 IntSize destOffset(static_cast<int>(dx), static_cast<int>(dy));
1653 IntRect destRect = enclosingIntRect(clipRect);
1654 destRect.move(destOffset); 1638 destRect.move(destOffset);
1655 destRect.intersect(IntRect(IntPoint(), buffer->size())); 1639 destRect.intersect(IntRect(IntPoint(), buffer->size()));
1656 if (destRect.isEmpty()) 1640 if (destRect.isEmpty())
1657 return; 1641 return;
1658 1642
1659 Optional<ScopedUsHistogramTimer> timer; 1643 Optional<ScopedUsHistogramTimer> timer;
1660 if (imageBuffer() && imageBuffer()->isAccelerated()) { 1644 if (imageBuffer() && imageBuffer()->isAccelerated()) {
1661 DEFINE_THREAD_SAFE_STATIC_LOCAL( 1645 DEFINE_THREAD_SAFE_STATIC_LOCAL(
1662 CustomCountHistogram, scopedUsCounterGPU, 1646 CustomCountHistogram, scopedUsCounterGPU,
1663 new CustomCountHistogram("Blink.Canvas.PutImageData.GPU", 0, 10000000, 1647 new CustomCountHistogram("Blink.Canvas.PutImageData.GPU", 0, 10000000,
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] * 2014 ExpensiveCanvasHeuristicParameters::ShadowFixedCost[index] *
2031 m_usageCounters.numBlurredShadows + 2015 m_usageCounters.numBlurredShadows +
2032 ExpensiveCanvasHeuristicParameters:: 2016 ExpensiveCanvasHeuristicParameters::
2033 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] * 2017 ShadowVariableCostPerAreaTimesShadowBlurSquared[index] *
2034 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared; 2018 m_usageCounters.boundingBoxAreaTimesShadowBlurSquared;
2035 2019
2036 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment; 2020 return basicCostOfDrawCalls + fillTypeAdjustment + shadowAdjustment;
2037 } 2021 }
2038 2022
2039 } // namespace blink 2023 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698