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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google, Inc. 3 * Copyright (C) 2008, 2009 Google, Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 m_hasAlpha = other.m_hasAlpha; 91 m_hasAlpha = other.m_hasAlpha;
92 m_bitmap.reset(); 92 m_bitmap.reset();
93 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); 93 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType());
94 } 94 }
95 95
96 bool ImageFrame::setSize(int newWidth, int newHeight) 96 bool ImageFrame::setSize(int newWidth, int newHeight)
97 { 97 {
98 // setSize() should only be called once, it leaks memory otherwise. 98 // setSize() should only be called once, it leaks memory otherwise.
99 ASSERT(!width() && !height()); 99 ASSERT(!width() && !height());
100 100
101 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); 101 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, computeAlphaType( )));
102 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) 102 if (!m_bitmap.tryAllocPixels(m_allocator, 0))
Noel Gordon 2016/03/21 22:37:16 Maybe don't call computeAlphaType() here? Instead
f(malita) 2016/03/21 22:46:24 Done.
103 return false; 103 return false;
104 104
105 zeroFillPixelData(); 105 zeroFillPixelData();
106 return true; 106 return true;
107 } 107 }
108 108
109 const SkBitmap& ImageFrame::bitmap() const 109 const SkBitmap& ImageFrame::bitmap() const
110 { 110 {
111 return m_bitmap; 111 return m_bitmap;
112 } 112 }
113 113
114 bool ImageFrame::hasAlpha() const 114 bool ImageFrame::hasAlpha() const
115 { 115 {
116 return m_hasAlpha; 116 return m_hasAlpha;
117 } 117 }
118 118
119 void ImageFrame::setHasAlpha(bool alpha) 119 void ImageFrame::setHasAlpha(bool alpha)
120 { 120 {
121 m_hasAlpha = alpha; 121 m_hasAlpha = alpha;
122 122
123 // If the frame is not fully loaded, there will be transparent pixels, 123 m_bitmap.setAlphaType(computeAlphaType());
124 // so we can't tell skia we're opaque, even for image types that logically
125 // always are (e.g. jpeg).
126 if (m_status != FrameComplete)
127 alpha = true;
128 m_bitmap.setAlphaType(alpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
129 } 124 }
130 125
131 void ImageFrame::setStatus(Status status) 126 void ImageFrame::setStatus(Status status)
132 { 127 {
133 m_status = status; 128 m_status = status;
134 if (m_status == FrameComplete) { 129 if (m_status == FrameComplete) {
135 m_bitmap.setAlphaType(m_hasAlpha ? kPremul_SkAlphaType : kOpaque_SkAlpha Type); 130 m_bitmap.setAlphaType(computeAlphaType());
136 // Send pending pixels changed notifications now, because we can't do th is after 131 // Send pending pixels changed notifications now, because we can't do th is after
137 // the bitmap has been marked immutable. 132 // the bitmap has been marked immutable.
138 notifyBitmapIfPixelsChanged(); 133 notifyBitmapIfPixelsChanged();
139 m_bitmap.setImmutable(); // Tell the bitmap it's done. 134 m_bitmap.setImmutable(); // Tell the bitmap it's done.
140 } 135 }
141 } 136 }
142 137
143 void ImageFrame::zeroFillFrameRect(const IntRect& rect) 138 void ImageFrame::zeroFillFrameRect(const IntRect& rect)
144 { 139 {
145 if (rect.isEmpty()) 140 if (rect.isEmpty())
146 return; 141 return;
147 142
148 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); 143 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0));
149 setHasAlpha(true); 144 setHasAlpha(true);
150 } 145 }
151 146
147 SkAlphaType ImageFrame::computeAlphaType() const
148 {
149 // If the frame is not fully loaded, there will be transparent pixels,
150 // so we can't tell skia we're opaque, even for image types that logically
151 // always are (e.g. jpeg).
152 if (!m_hasAlpha && m_status == FrameComplete)
153 return kOpaque_SkAlphaType;
154
155 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
156 }
157
152 } // namespace blink 158 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698