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