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

Unified Diff: third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp

Issue 1820733004: Propagate the decoder frame premul info to SkBitmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
index d7e5a06b3d93e845749c12907c03f5ffbb1737c7..a2a7f2a86258311fa3285d76ef920b293a175155 100644
--- a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.cpp
@@ -98,7 +98,8 @@ bool ImageFrame::setSize(int newWidth, int newHeight)
// setSize() should only be called once, it leaks memory otherwise.
ASSERT(!width() && !height());
- m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight));
+ m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight,
+ m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType));
if (!m_bitmap.tryAllocPixels(m_allocator, 0))
return false;
@@ -120,19 +121,14 @@ void ImageFrame::setHasAlpha(bool alpha)
{
m_hasAlpha = alpha;
- // If the frame is not fully loaded, there will be transparent pixels,
- // so we can't tell skia we're opaque, even for image types that logically
- // always are (e.g. jpeg).
- if (m_status != FrameComplete)
- alpha = true;
- m_bitmap.setAlphaType(alpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
+ m_bitmap.setAlphaType(computeAlphaType());
}
void ImageFrame::setStatus(Status status)
{
m_status = status;
if (m_status == FrameComplete) {
- m_bitmap.setAlphaType(m_hasAlpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
+ m_bitmap.setAlphaType(computeAlphaType());
// Send pending pixels changed notifications now, because we can't do this after
// the bitmap has been marked immutable.
notifyBitmapIfPixelsChanged();
@@ -149,4 +145,15 @@ void ImageFrame::zeroFillFrameRect(const IntRect& rect)
setHasAlpha(true);
}
+SkAlphaType ImageFrame::computeAlphaType() const
+{
+ // If the frame is not fully loaded, there will be transparent pixels,
+ // so we can't tell skia we're opaque, even for image types that logically
+ // always are (e.g. jpeg).
+ if (!m_hasAlpha && m_status == FrameComplete)
+ return kOpaque_SkAlphaType;
+
+ return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698