| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/gpu/WebGLImageConversion.h" | 6 #include "platform/graphics/gpu/WebGLImageConversion.h" |
| 7 | 7 |
| 8 #include "platform/CheckedInt.h" | 8 #include "platform/CheckedInt.h" |
| 9 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
| 10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
| (...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 | 1532 |
| 1533 WebGLImageConversion::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomS
ource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile
) | 1533 WebGLImageConversion::ImageExtractor::ImageExtractor(Image* image, ImageHtmlDomS
ource imageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile
) |
| 1534 { | 1534 { |
| 1535 m_image = image; | 1535 m_image = image; |
| 1536 m_imageHtmlDomSource = imageHtmlDomSource; | 1536 m_imageHtmlDomSource = imageHtmlDomSource; |
| 1537 m_extractSucceeded = extractImage(premultiplyAlpha, ignoreGammaAndColorProfi
le); | 1537 m_extractSucceeded = extractImage(premultiplyAlpha, ignoreGammaAndColorProfi
le); |
| 1538 } | 1538 } |
| 1539 | 1539 |
| 1540 WebGLImageConversion::ImageExtractor::~ImageExtractor() | 1540 WebGLImageConversion::ImageExtractor::~ImageExtractor() |
| 1541 { | 1541 { |
| 1542 if (m_skiaImage) | 1542 if (!m_skiaBitmap.isNull()) |
| 1543 m_skiaImage->bitmap().unlockPixels(); | 1543 m_skiaBitmap.unlockPixels(); |
| 1544 } | 1544 } |
| 1545 | 1545 |
| 1546 bool WebGLImageConversion::ImageExtractor::extractImage(bool premultiplyAlpha, b
ool ignoreGammaAndColorProfile) | 1546 bool WebGLImageConversion::ImageExtractor::extractImage(bool premultiplyAlpha, b
ool ignoreGammaAndColorProfile) |
| 1547 { | 1547 { |
| 1548 if (!m_image) | 1548 if (!m_image) |
| 1549 return false; | 1549 return false; |
| 1550 m_skiaImage = m_image->nativeImageForCurrentFrame(); | 1550 m_skiaBitmap = m_image->bitmapForCurrentFrame(); |
| 1551 m_alphaOp = AlphaDoNothing; | 1551 m_alphaOp = AlphaDoNothing; |
| 1552 bool hasAlpha = m_skiaImage ? !m_skiaImage->bitmap().isOpaque() : true; | 1552 bool hasAlpha = m_skiaBitmap.isNull() || !m_skiaBitmap.isOpaque(); |
| 1553 if ((!m_skiaImage || ignoreGammaAndColorProfile || (hasAlpha && !premultiply
Alpha)) && m_image->data()) { | 1553 if ((m_skiaBitmap.isNull() || ignoreGammaAndColorProfile || (hasAlpha && !pr
emultiplyAlpha)) && m_image->data()) { |
| 1554 // Attempt to get raw unpremultiplied image data. | 1554 // Attempt to get raw unpremultiplied image data. |
| 1555 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( | 1555 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( |
| 1556 *(m_image->data()), ImageSource::AlphaNotPremultiplied, | 1556 *(m_image->data()), ImageSource::AlphaNotPremultiplied, |
| 1557 ignoreGammaAndColorProfile ? ImageSource::GammaAndColorProfileIgnore
d : ImageSource::GammaAndColorProfileApplied)); | 1557 ignoreGammaAndColorProfile ? ImageSource::GammaAndColorProfileIgnore
d : ImageSource::GammaAndColorProfileApplied)); |
| 1558 if (!decoder) | 1558 if (!decoder) |
| 1559 return false; | 1559 return false; |
| 1560 decoder->setData(m_image->data(), true); | 1560 decoder->setData(m_image->data(), true); |
| 1561 if (!decoder->frameCount()) | 1561 if (!decoder->frameCount()) |
| 1562 return false; | 1562 return false; |
| 1563 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 1563 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
| 1564 if (!frame || frame->status() != ImageFrame::FrameComplete) | 1564 if (!frame || frame->status() != ImageFrame::FrameComplete) |
| 1565 return false; | 1565 return false; |
| 1566 hasAlpha = frame->hasAlpha(); | 1566 hasAlpha = frame->hasAlpha(); |
| 1567 m_nativeImage = frame->asNewNativeImage(); | 1567 m_bitmap = frame->bitmap(); |
| 1568 if (!m_nativeImage.get() || !m_nativeImage->isDataComplete() || !m_nativ
eImage->bitmap().width() || !m_nativeImage->bitmap().height()) | 1568 if (m_bitmap.isNull() || !m_bitmap.isImmutable() || !m_bitmap.width() ||
!m_bitmap.height()) |
| 1569 return false; | 1569 return false; |
| 1570 if (m_nativeImage->bitmap().colorType() != kN32_SkColorType) | 1570 if (m_bitmap.colorType() != kN32_SkColorType) |
| 1571 return false; | 1571 return false; |
| 1572 m_skiaImage = m_nativeImage.get(); | 1572 m_skiaBitmap = m_bitmap; |
| 1573 if (hasAlpha && premultiplyAlpha) | 1573 if (hasAlpha && premultiplyAlpha) |
| 1574 m_alphaOp = AlphaDoPremultiply; | 1574 m_alphaOp = AlphaDoPremultiply; |
| 1575 } else if (!premultiplyAlpha && hasAlpha) { | 1575 } else if (!premultiplyAlpha && hasAlpha) { |
| 1576 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAl
pha had been applied and the alpha value for each pixel is 0xFF | 1576 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAl
pha had been applied and the alpha value for each pixel is 0xFF |
| 1577 // which is true at present and may be changed in the future and needs a
djustment accordingly. | 1577 // which is true at present and may be changed in the future and needs a
djustment accordingly. |
| 1578 // 2. For texImage2D with HTMLCanvasElement input in which Alpha is alre
ady Premultiplied in this port, | 1578 // 2. For texImage2D with HTMLCanvasElement input in which Alpha is alre
ady Premultiplied in this port, |
| 1579 // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to fals
e. | 1579 // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to fals
e. |
| 1580 if (m_imageHtmlDomSource != HtmlDomVideo) | 1580 if (m_imageHtmlDomSource != HtmlDomVideo) |
| 1581 m_alphaOp = AlphaDoUnmultiply; | 1581 m_alphaOp = AlphaDoUnmultiply; |
| 1582 } | 1582 } |
| 1583 if (!m_skiaImage) | 1583 if (m_skiaBitmap.isNull()) |
| 1584 return false; | 1584 return false; |
| 1585 | 1585 |
| 1586 m_imageSourceFormat = SK_B32_SHIFT ? DataFormatRGBA8 : DataFormatBGRA8; | 1586 m_imageSourceFormat = SK_B32_SHIFT ? DataFormatRGBA8 : DataFormatBGRA8; |
| 1587 m_imageWidth = m_skiaImage->bitmap().width(); | 1587 m_imageWidth = m_skiaBitmap.width(); |
| 1588 m_imageHeight = m_skiaImage->bitmap().height(); | 1588 m_imageHeight = m_skiaBitmap.height(); |
| 1589 if (!m_imageWidth || !m_imageHeight) { | 1589 if (!m_imageWidth || !m_imageHeight) { |
| 1590 m_skiaImage.clear(); | 1590 m_skiaBitmap.reset(); |
| 1591 return false; | 1591 return false; |
| 1592 } | 1592 } |
| 1593 // Fail if the image was downsampled because of memory limits. | 1593 // Fail if the image was downsampled because of memory limits. |
| 1594 if (m_imageWidth != (unsigned)m_image->size().width() || m_imageHeight != (u
nsigned)m_image->size().height()) { | 1594 if (m_imageWidth != (unsigned)m_image->size().width() || m_imageHeight != (u
nsigned)m_image->size().height()) { |
| 1595 m_skiaImage.clear(); | 1595 m_skiaBitmap.reset(); |
| 1596 return false; | 1596 return false; |
| 1597 } | 1597 } |
| 1598 m_imageSourceUnpackAlignment = 0; | 1598 m_imageSourceUnpackAlignment = 0; |
| 1599 m_skiaImage->bitmap().lockPixels(); | 1599 m_skiaBitmap.lockPixels(); |
| 1600 m_imagePixelData = m_skiaImage->bitmap().getPixels(); | 1600 m_imagePixelData = m_skiaBitmap.getPixels(); |
| 1601 return true; | 1601 return true; |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 unsigned WebGLImageConversion::getClearBitsByFormat(GLenum format) | 1604 unsigned WebGLImageConversion::getClearBitsByFormat(GLenum format) |
| 1605 { | 1605 { |
| 1606 switch (format) { | 1606 switch (format) { |
| 1607 case GL_ALPHA: | 1607 case GL_ALPHA: |
| 1608 case GL_LUMINANCE: | 1608 case GL_LUMINANCE: |
| 1609 case GL_LUMINANCE_ALPHA: | 1609 case GL_LUMINANCE_ALPHA: |
| 1610 case GL_RGB: | 1610 case GL_RGB: |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 } | 1776 } |
| 1777 | 1777 |
| 1778 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); | 1778 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); |
| 1779 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 1779 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
| 1780 if (!converter.Success()) | 1780 if (!converter.Success()) |
| 1781 return false; | 1781 return false; |
| 1782 return true; | 1782 return true; |
| 1783 } | 1783 } |
| 1784 | 1784 |
| 1785 } // namespace blink | 1785 } // namespace blink |
| OLD | NEW |