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/mips/WebGLImageConversionMSA.h" | 10 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" |
(...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2130 extractImage(premultiplyAlpha, ignoreGammaAndColorProfile); | 2130 extractImage(premultiplyAlpha, ignoreGammaAndColorProfile); |
2131 } | 2131 } |
2132 | 2132 |
2133 void WebGLImageConversion::ImageExtractor::extractImage(bool premultiplyAlpha, b
ool ignoreGammaAndColorProfile) | 2133 void WebGLImageConversion::ImageExtractor::extractImage(bool premultiplyAlpha, b
ool ignoreGammaAndColorProfile) |
2134 { | 2134 { |
2135 ASSERT(!m_imagePixelLocker); | 2135 ASSERT(!m_imagePixelLocker); |
2136 | 2136 |
2137 if (!m_image) | 2137 if (!m_image) |
2138 return; | 2138 return; |
2139 | 2139 |
2140 RefPtr<SkImage> skiaImage = m_image->imageForCurrentFrame(); | 2140 sk_sp<SkImage> skiaImage = m_image->imageForCurrentFrame(); |
2141 SkImageInfo info = skiaImage | 2141 SkImageInfo info = skiaImage |
2142 ? SkImageInfo::MakeN32Premul(m_image->width(), m_image->height()) | 2142 ? SkImageInfo::MakeN32Premul(m_image->width(), m_image->height()) |
2143 : SkImageInfo::MakeUnknown(); | 2143 : SkImageInfo::MakeUnknown(); |
2144 m_alphaOp = AlphaDoNothing; | 2144 m_alphaOp = AlphaDoNothing; |
2145 bool hasAlpha = skiaImage ? !skiaImage->isOpaque() : true; | 2145 bool hasAlpha = skiaImage ? !skiaImage->isOpaque() : true; |
2146 | 2146 |
2147 if ((!skiaImage || ignoreGammaAndColorProfile || (hasAlpha && !premultiplyAl
pha)) && m_image->data()) { | 2147 if ((!skiaImage || ignoreGammaAndColorProfile || (hasAlpha && !premultiplyAl
pha)) && m_image->data()) { |
2148 // Attempt to get raw unpremultiplied image data. | 2148 // Attempt to get raw unpremultiplied image data. |
2149 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( | 2149 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( |
2150 m_image->data(), true, ImageDecoder::AlphaNotPremultiplied, | 2150 m_image->data(), true, ImageDecoder::AlphaNotPremultiplied, |
2151 ignoreGammaAndColorProfile ? ImageDecoder::GammaAndColorProfileIgnor
ed : ImageDecoder::GammaAndColorProfileApplied)); | 2151 ignoreGammaAndColorProfile ? ImageDecoder::GammaAndColorProfileIgnor
ed : ImageDecoder::GammaAndColorProfileApplied)); |
2152 if (!decoder || !decoder->frameCount()) | 2152 if (!decoder || !decoder->frameCount()) |
2153 return; | 2153 return; |
2154 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 2154 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
2155 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) | 2155 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) |
2156 return; | 2156 return; |
2157 hasAlpha = frame->hasAlpha(); | 2157 hasAlpha = frame->hasAlpha(); |
2158 SkBitmap bitmap = frame->bitmap(); | 2158 SkBitmap bitmap = frame->bitmap(); |
2159 if (!frameIsValid(bitmap)) | 2159 if (!frameIsValid(bitmap)) |
2160 return; | 2160 return; |
2161 | 2161 |
2162 // TODO(fmalita): Partial frames are not supported currently: frameIsVal
id ensures that | 2162 // TODO(fmalita): Partial frames are not supported currently: frameIsVal
id ensures that |
2163 // only immutable/fully decoded frames make it through. We could potent
ially relax this | 2163 // only immutable/fully decoded frames make it through. We could potent
ially relax this |
2164 // and allow SkImage::NewFromBitmap to make a copy. | 2164 // and allow SkImage::NewFromBitmap to make a copy. |
2165 ASSERT(bitmap.isImmutable()); | 2165 ASSERT(bitmap.isImmutable()); |
2166 skiaImage = fromSkSp(SkImage::MakeFromBitmap(bitmap)); | 2166 skiaImage = SkImage::MakeFromBitmap(bitmap); |
2167 info = bitmap.info(); | 2167 info = bitmap.info(); |
2168 | 2168 |
2169 if (hasAlpha && premultiplyAlpha) | 2169 if (hasAlpha && premultiplyAlpha) |
2170 m_alphaOp = AlphaDoPremultiply; | 2170 m_alphaOp = AlphaDoPremultiply; |
2171 } else if (!premultiplyAlpha && hasAlpha) { | 2171 } else if (!premultiplyAlpha && hasAlpha) { |
2172 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAl
pha had been applied and the alpha value for each pixel is 0xFF | 2172 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAl
pha had been applied and the alpha value for each pixel is 0xFF |
2173 // which is true at present and may be changed in the future and needs a
djustment accordingly. | 2173 // which is true at present and may be changed in the future and needs a
djustment accordingly. |
2174 // 2. For texImage2D with HTMLCanvasElement input in which Alpha is alre
ady Premultiplied in this port, | 2174 // 2. For texImage2D with HTMLCanvasElement input in which Alpha is alre
ady Premultiplied in this port, |
2175 // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to fals
e. | 2175 // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to fals
e. |
2176 if (m_imageHtmlDomSource != HtmlDomVideo) | 2176 if (m_imageHtmlDomSource != HtmlDomVideo) |
2177 m_alphaOp = AlphaDoUnmultiply; | 2177 m_alphaOp = AlphaDoUnmultiply; |
2178 } | 2178 } |
2179 | 2179 |
2180 if (!skiaImage) | 2180 if (!skiaImage) |
2181 return; | 2181 return; |
2182 | 2182 |
2183 m_imageSourceFormat = SK_B32_SHIFT ? DataFormatRGBA8 : DataFormatBGRA8; | 2183 m_imageSourceFormat = SK_B32_SHIFT ? DataFormatRGBA8 : DataFormatBGRA8; |
2184 m_imageSourceUnpackAlignment = 0; // FIXME: this seems to always be zero - w
hy use at all? | 2184 m_imageSourceUnpackAlignment = 0; // FIXME: this seems to always be zero - w
hy use at all? |
2185 | 2185 |
2186 ASSERT(skiaImage->width() && skiaImage->height()); | 2186 ASSERT(skiaImage->width() && skiaImage->height()); |
2187 m_imageWidth = skiaImage->width(); | 2187 m_imageWidth = skiaImage->width(); |
2188 m_imageHeight = skiaImage->height(); | 2188 m_imageHeight = skiaImage->height(); |
2189 | 2189 |
2190 // Fail if the image was downsampled because of memory limits. | 2190 // Fail if the image was downsampled because of memory limits. |
2191 if (m_imageWidth != (unsigned)m_image->width() || m_imageHeight != (unsigned
)m_image->height()) | 2191 if (m_imageWidth != (unsigned)m_image->width() || m_imageHeight != (unsigned
)m_image->height()) |
2192 return; | 2192 return; |
2193 | 2193 |
2194 m_imagePixelLocker.emplace(skiaImage, info.alphaType(), kN32_SkColorType); | 2194 m_imagePixelLocker.emplace(std::move(skiaImage), info.alphaType(), kN32_SkCo
lorType); |
2195 } | 2195 } |
2196 | 2196 |
2197 unsigned WebGLImageConversion::getChannelBitsByFormat(GLenum format) | 2197 unsigned WebGLImageConversion::getChannelBitsByFormat(GLenum format) |
2198 { | 2198 { |
2199 switch (format) { | 2199 switch (format) { |
2200 case GL_ALPHA: | 2200 case GL_ALPHA: |
2201 return ChannelAlpha; | 2201 return ChannelAlpha; |
2202 case GL_RED: | 2202 case GL_RED: |
2203 case GL_RED_INTEGER: | 2203 case GL_RED_INTEGER: |
2204 case GL_R8: | 2204 case GL_R8: |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2407 } | 2407 } |
2408 | 2408 |
2409 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); | 2409 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); |
2410 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 2410 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
2411 if (!converter.Success()) | 2411 if (!converter.Success()) |
2412 return false; | 2412 return false; |
2413 return true; | 2413 return true; |
2414 } | 2414 } |
2415 | 2415 |
2416 } // namespace blink | 2416 } // namespace blink |
OLD | NEW |