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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/gpu/WebGLImageConversion.cpp

Issue 2155973002: Save a bitmap copy when advancing to dependent GIF and WebP animation frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: finalizePixelsAndGetImage. Created 4 years, 3 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 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"
(...skipping 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 unpack<SrcFormat>(srcRowStart, reinterpret_cast<IntermType*>(m_unpac kedIntermediateSrcData.get()), m_width); 1917 unpack<SrcFormat>(srcRowStart, reinterpret_cast<IntermType*>(m_unpac kedIntermediateSrcData.get()), m_width);
1918 pack<DstFormat, alphaOp>(reinterpret_cast<IntermType*>(m_unpackedInt ermediateSrcData.get()), dstRowStart, m_width); 1918 pack<DstFormat, alphaOp>(reinterpret_cast<IntermType*>(m_unpackedInt ermediateSrcData.get()), dstRowStart, m_width);
1919 srcRowStart += srcStrideInElements; 1919 srcRowStart += srcStrideInElements;
1920 dstRowStart += dstStrideInElements; 1920 dstRowStart += dstStrideInElements;
1921 } 1921 }
1922 } 1922 }
1923 m_success = true; 1923 m_success = true;
1924 return; 1924 return;
1925 } 1925 }
1926 1926
1927 bool frameIsValid(const SkBitmap& frameBitmap)
1928 {
1929 return !frameBitmap.isNull()
1930 && !frameBitmap.empty()
1931 && frameBitmap.isImmutable()
1932 && frameBitmap.colorType() == kN32_SkColorType;
1933 }
1934
1935 } // anonymous namespace 1927 } // anonymous namespace
1936 1928
1937 WebGLImageConversion::PixelStoreParams::PixelStoreParams() 1929 WebGLImageConversion::PixelStoreParams::PixelStoreParams()
1938 : alignment(4) 1930 : alignment(4)
1939 , rowLength(0) 1931 , rowLength(0)
1940 , imageHeight(0) 1932 , imageHeight(0)
1941 , skipPixels(0) 1933 , skipPixels(0)
1942 , skipRows(0) 1934 , skipRows(0)
1943 , skipImages(0) 1935 , skipImages(0)
1944 { 1936 {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 // Attempt to get raw unpremultiplied image data. 2135 // Attempt to get raw unpremultiplied image data.
2144 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create( 2136 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(
2145 ImageDecoder::determineImageType(*(m_image->data())), ImageDecoder:: AlphaNotPremultiplied, 2137 ImageDecoder::determineImageType(*(m_image->data())), ImageDecoder:: AlphaNotPremultiplied,
2146 ignoreGammaAndColorProfile ? ImageDecoder::GammaAndColorProfileIgnor ed : ImageDecoder::GammaAndColorProfileApplied)); 2138 ignoreGammaAndColorProfile ? ImageDecoder::GammaAndColorProfileIgnor ed : ImageDecoder::GammaAndColorProfileApplied));
2147 if (!decoder) 2139 if (!decoder)
2148 return; 2140 return;
2149 decoder->setData(m_image->data(), true); 2141 decoder->setData(m_image->data(), true);
2150 if (!decoder->frameCount()) 2142 if (!decoder->frameCount())
2151 return; 2143 return;
2152 ImageFrame* frame = decoder->frameBufferAtIndex(0); 2144 ImageFrame* frame = decoder->frameBufferAtIndex(0);
2145
2146 // TODO(fmalita): Partial frames are not supported currently: only fully
2147 // decoded frames make it through. We could potentially relax this and
2148 // allow ImageFrame::finalizePixelsAndGetImage to make a copy.
Peter Kasting 2016/08/30 06:59:40 Isn't it already allowed to make a copy? Does thi
aleksandar.stojiljkovic 2016/09/21 20:56:57 By early return if "frame->getStatus() != ImageFra
2153 if (!frame || frame->getStatus() != ImageFrame::FrameComplete) 2149 if (!frame || frame->getStatus() != ImageFrame::FrameComplete)
2154 return; 2150 return;
2155 hasAlpha = frame->hasAlpha(); 2151 hasAlpha = frame->hasAlpha();
2156 SkBitmap bitmap = frame->bitmap(); 2152 SkBitmap bitmap = frame->bitmap();
2157 if (!frameIsValid(bitmap))
2158 return;
2159 2153
2160 // TODO(fmalita): Partial frames are not supported currently: frameIsVal id ensures that 2154 DCHECK_EQ(bitmap.colorType(), kN32_SkColorType);
Peter Kasting 2016/08/30 06:59:40 Same comment as in ImageBitmap.cpp.
aleksandar.stojiljkovic 2016/09/21 20:56:57 Done.
2161 // only immutable/fully decoded frames make it through. We could potent ially relax this 2155 skiaImage = frame->finalizePixelsAndGetImage();
2162 // and allow SkImage::NewFromBitmap to make a copy.
2163 ASSERT(bitmap.isImmutable());
2164 skiaImage = fromSkSp(SkImage::MakeFromBitmap(bitmap));
2165 info = bitmap.info(); 2156 info = bitmap.info();
2166 2157
2167 if (hasAlpha && premultiplyAlpha) 2158 if (hasAlpha && premultiplyAlpha)
2168 m_alphaOp = AlphaDoPremultiply; 2159 m_alphaOp = AlphaDoPremultiply;
2169 } else if (!premultiplyAlpha && hasAlpha) { 2160 } else if (!premultiplyAlpha && hasAlpha) {
2170 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAl pha had been applied and the alpha value for each pixel is 0xFF 2161 // 1. For texImage2D with HTMLVideoElment input, assume no PremultiplyAl pha had been applied and the alpha value for each pixel is 0xFF
2171 // which is true at present and may be changed in the future and needs a djustment accordingly. 2162 // which is true at present and may be changed in the future and needs a djustment accordingly.
2172 // 2. For texImage2D with HTMLCanvasElement input in which Alpha is alre ady Premultiplied in this port, 2163 // 2. For texImage2D with HTMLCanvasElement input in which Alpha is alre ady Premultiplied in this port,
2173 // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to fals e. 2164 // do AlphaDoUnmultiply if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to fals e.
2174 if (m_imageHtmlDomSource != HtmlDomVideo) 2165 if (m_imageHtmlDomSource != HtmlDomVideo)
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 } 2396 }
2406 2397
2407 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride); 2398 FormatConverter converter(width, height, sourceData, destinationData, srcStr ide, dstStride);
2408 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); 2399 converter.convert(sourceDataFormat, dstDataFormat, alphaOp);
2409 if (!converter.Success()) 2400 if (!converter.Success())
2410 return false; 2401 return false;
2411 return true; 2402 return true;
2412 } 2403 }
2413 2404
2414 } // namespace blink 2405 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698