| 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 "platform/graphics/gpu/WebGLImageConversion.h" | 5 #include "platform/graphics/gpu/WebGLImageConversion.h" |
| 6 | 6 |
| 7 #include "platform/CheckedInt.h" | 7 #include "platform/CheckedInt.h" |
| 8 #include "platform/graphics/ImageObserver.h" | 8 #include "platform/graphics/ImageObserver.h" |
| 9 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 9 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
| 10 #include "platform/graphics/cpu/x86/WebGLImageConversionSSE.h" | 10 #include "platform/graphics/cpu/x86/WebGLImageConversionSSE.h" |
| 11 #include "platform/image-decoders/ImageDecoder.h" | 11 #include "platform/image-decoders/ImageDecoder.h" |
| 12 #include "third_party/skia/include/core/SkImage.h" | 12 #include "third_party/skia/include/core/SkImage.h" |
| 13 #include "wtf/OwnPtr.h" | 13 #include "wtf/PtrUtil.h" |
| 14 #include "wtf/PassOwnPtr.h" | 14 #include <memory> |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const float maxInt8Value = INT8_MAX; | 20 const float maxInt8Value = INT8_MAX; |
| 21 const float maxUInt8Value = UINT8_MAX; | 21 const float maxUInt8Value = UINT8_MAX; |
| 22 const float maxInt16Value = INT16_MAX; | 22 const float maxInt16Value = INT16_MAX; |
| 23 const float maxUInt16Value = UINT16_MAX; | 23 const float maxUInt16Value = UINT16_MAX; |
| 24 const double maxInt32Value = INT32_MAX; | 24 const double maxInt32Value = INT32_MAX; |
| (...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 | 1707 |
| 1708 class FormatConverter { | 1708 class FormatConverter { |
| 1709 STACK_ALLOCATED(); | 1709 STACK_ALLOCATED(); |
| 1710 public: | 1710 public: |
| 1711 FormatConverter(unsigned width, unsigned height, | 1711 FormatConverter(unsigned width, unsigned height, |
| 1712 const void* srcStart, void* dstStart, int srcStride, int dstStride) | 1712 const void* srcStart, void* dstStart, int srcStride, int dstStride) |
| 1713 : m_width(width), m_height(height), m_srcStart(srcStart), m_dstStart(dst
Start), m_srcStride(srcStride), m_dstStride(dstStride), m_success(false) | 1713 : m_width(width), m_height(height), m_srcStart(srcStart), m_dstStart(dst
Start), m_srcStride(srcStride), m_dstStride(dstStride), m_success(false) |
| 1714 { | 1714 { |
| 1715 const unsigned MaxNumberOfComponents = 4; | 1715 const unsigned MaxNumberOfComponents = 4; |
| 1716 const unsigned MaxBytesPerComponent = 4; | 1716 const unsigned MaxBytesPerComponent = 4; |
| 1717 m_unpackedIntermediateSrcData = adoptArrayPtr(new uint8_t[m_width * MaxN
umberOfComponents *MaxBytesPerComponent]); | 1717 m_unpackedIntermediateSrcData = wrapArrayUnique(new uint8_t[m_width * Ma
xNumberOfComponents *MaxBytesPerComponent]); |
| 1718 ASSERT(m_unpackedIntermediateSrcData.get()); | 1718 ASSERT(m_unpackedIntermediateSrcData.get()); |
| 1719 } | 1719 } |
| 1720 | 1720 |
| 1721 void convert(WebGLImageConversion::DataFormat srcFormat, WebGLImageConversio
n::DataFormat dstFormat, WebGLImageConversion::AlphaOp); | 1721 void convert(WebGLImageConversion::DataFormat srcFormat, WebGLImageConversio
n::DataFormat dstFormat, WebGLImageConversion::AlphaOp); |
| 1722 bool Success() const { return m_success; } | 1722 bool Success() const { return m_success; } |
| 1723 | 1723 |
| 1724 private: | 1724 private: |
| 1725 template<WebGLImageConversion::DataFormat SrcFormat> | 1725 template<WebGLImageConversion::DataFormat SrcFormat> |
| 1726 void convert(WebGLImageConversion::DataFormat dstFormat, WebGLImageConversio
n::AlphaOp); | 1726 void convert(WebGLImageConversion::DataFormat dstFormat, WebGLImageConversio
n::AlphaOp); |
| 1727 | 1727 |
| 1728 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::D
ataFormat DstFormat> | 1728 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::D
ataFormat DstFormat> |
| 1729 void convert(WebGLImageConversion::AlphaOp); | 1729 void convert(WebGLImageConversion::AlphaOp); |
| 1730 | 1730 |
| 1731 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::D
ataFormat DstFormat, WebGLImageConversion::AlphaOp alphaOp> | 1731 template<WebGLImageConversion::DataFormat SrcFormat, WebGLImageConversion::D
ataFormat DstFormat, WebGLImageConversion::AlphaOp alphaOp> |
| 1732 void convert(); | 1732 void convert(); |
| 1733 | 1733 |
| 1734 const unsigned m_width, m_height; | 1734 const unsigned m_width, m_height; |
| 1735 const void* const m_srcStart; | 1735 const void* const m_srcStart; |
| 1736 void* const m_dstStart; | 1736 void* const m_dstStart; |
| 1737 const int m_srcStride, m_dstStride; | 1737 const int m_srcStride, m_dstStride; |
| 1738 bool m_success; | 1738 bool m_success; |
| 1739 OwnPtr<uint8_t[]> m_unpackedIntermediateSrcData; | 1739 std::unique_ptr<uint8_t[]> m_unpackedIntermediateSrcData; |
| 1740 }; | 1740 }; |
| 1741 | 1741 |
| 1742 void FormatConverter::convert(WebGLImageConversion::DataFormat srcFormat, WebGLI
mageConversion::DataFormat dstFormat, WebGLImageConversion::AlphaOp alphaOp) | 1742 void FormatConverter::convert(WebGLImageConversion::DataFormat srcFormat, WebGLI
mageConversion::DataFormat dstFormat, WebGLImageConversion::AlphaOp alphaOp) |
| 1743 { | 1743 { |
| 1744 #define FORMATCONVERTER_CASE_SRCFORMAT(SrcFormat) \ | 1744 #define FORMATCONVERTER_CASE_SRCFORMAT(SrcFormat) \ |
| 1745 case SrcFormat: \ | 1745 case SrcFormat: \ |
| 1746 return convert<SrcFormat>(dstFormat, alphaOp); | 1746 return convert<SrcFormat>(dstFormat, alphaOp); |
| 1747 | 1747 |
| 1748 switch (srcFormat) { | 1748 switch (srcFormat) { |
| 1749 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA8) | 1749 FORMATCONVERTER_CASE_SRCFORMAT(WebGLImageConversion::DataFormatRA8) |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 | 2133 |
| 2134 RefPtr<SkImage> skiaImage = m_image->imageForCurrentFrame(); | 2134 RefPtr<SkImage> skiaImage = m_image->imageForCurrentFrame(); |
| 2135 SkImageInfo info = skiaImage | 2135 SkImageInfo info = skiaImage |
| 2136 ? SkImageInfo::MakeN32Premul(m_image->width(), m_image->height()) | 2136 ? SkImageInfo::MakeN32Premul(m_image->width(), m_image->height()) |
| 2137 : SkImageInfo::MakeUnknown(); | 2137 : SkImageInfo::MakeUnknown(); |
| 2138 m_alphaOp = AlphaDoNothing; | 2138 m_alphaOp = AlphaDoNothing; |
| 2139 bool hasAlpha = skiaImage ? !skiaImage->isOpaque() : true; | 2139 bool hasAlpha = skiaImage ? !skiaImage->isOpaque() : true; |
| 2140 | 2140 |
| 2141 if ((!skiaImage || ignoreGammaAndColorProfile || (hasAlpha && !premultiplyAl
pha)) && m_image->data()) { | 2141 if ((!skiaImage || ignoreGammaAndColorProfile || (hasAlpha && !premultiplyAl
pha)) && m_image->data()) { |
| 2142 // Attempt to get raw unpremultiplied image data. | 2142 // Attempt to get raw unpremultiplied image data. |
| 2143 OwnPtr<ImageDecoder> decoder(ImageDecoder::create( | 2143 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( |
| 2144 *(m_image->data()), ImageDecoder::AlphaNotPremultiplied, | 2144 *(m_image->data()), ImageDecoder::AlphaNotPremultiplied, |
| 2145 ignoreGammaAndColorProfile ? ImageDecoder::GammaAndColorProfileIgnor
ed : ImageDecoder::GammaAndColorProfileApplied)); | 2145 ignoreGammaAndColorProfile ? ImageDecoder::GammaAndColorProfileIgnor
ed : ImageDecoder::GammaAndColorProfileApplied)); |
| 2146 if (!decoder) | 2146 if (!decoder) |
| 2147 return; | 2147 return; |
| 2148 decoder->setData(m_image->data(), true); | 2148 decoder->setData(m_image->data(), true); |
| 2149 if (!decoder->frameCount()) | 2149 if (!decoder->frameCount()) |
| 2150 return; | 2150 return; |
| 2151 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 2151 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
| 2152 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) | 2152 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) |
| 2153 return; | 2153 return; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2404 } | 2404 } |
| 2405 | 2405 |
| 2406 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); | 2406 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); |
| 2407 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 2407 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
| 2408 if (!converter.Success()) | 2408 if (!converter.Success()) |
| 2409 return false; | 2409 return false; |
| 2410 return true; | 2410 return true; |
| 2411 } | 2411 } |
| 2412 | 2412 |
| 2413 } // namespace blink | 2413 } // namespace blink |
| OLD | NEW |