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

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

Issue 2054643003: Remove duplication of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (rebase) Created 4 years, 5 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 Samuel Weinig (sam.weinig@gmail.com) 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 void BitmapImage::destroyDecodedData() 112 void BitmapImage::destroyDecodedData()
113 { 113 {
114 m_cachedFrame.clear(); 114 m_cachedFrame.clear();
115 for (size_t i = 0; i < m_frames.size(); ++i) 115 for (size_t i = 0; i < m_frames.size(); ++i)
116 m_frames[i].clear(true); 116 m_frames[i].clear(true);
117 m_source.clearCacheExceptFrame(kNotFound); 117 m_source.clearCacheExceptFrame(kNotFound);
118 notifyMemoryChanged(); 118 notifyMemoryChanged();
119 } 119 }
120 120
121 PassRefPtr<SharedBuffer> BitmapImage::data()
122 {
123 return m_source.data();
124 }
125
121 void BitmapImage::notifyMemoryChanged() 126 void BitmapImage::notifyMemoryChanged()
122 { 127 {
123 if (getImageObserver()) 128 if (getImageObserver())
124 getImageObserver()->decodedSizeChangedTo(this, totalFrameBytes()); 129 getImageObserver()->decodedSizeChangedTo(this, totalFrameBytes());
125 } 130 }
126 131
127 size_t BitmapImage::totalFrameBytes() 132 size_t BitmapImage::totalFrameBytes()
128 { 133 {
129 const size_t numFrames = frameCount(); 134 const size_t numFrames = frameCount();
130 size_t totalBytes = 0; 135 size_t totalBytes = 0;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 { 182 {
178 updateSize(); 183 updateSize();
179 return m_sizeRespectingOrientation; 184 return m_sizeRespectingOrientation;
180 } 185 }
181 186
182 bool BitmapImage::getHotSpot(IntPoint& hotSpot) const 187 bool BitmapImage::getHotSpot(IntPoint& hotSpot) const
183 { 188 {
184 return m_source.getHotSpot(hotSpot); 189 return m_source.getHotSpot(hotSpot);
185 } 190 }
186 191
192 bool BitmapImage::setData(PassRefPtr<SharedBuffer> data, bool allDataReceived)
193 {
194 if (!data.get())
195 return true;
196
197 int length = data->size();
198 if (!length)
199 return true;
200
201 m_source.setData(*data, allDataReceived);
202
203 return dataChanged(allDataReceived);
204 }
205
187 bool BitmapImage::dataChanged(bool allDataReceived) 206 bool BitmapImage::dataChanged(bool allDataReceived)
188 { 207 {
189 TRACE_EVENT0("blink", "BitmapImage::dataChanged"); 208 TRACE_EVENT0("blink", "BitmapImage::dataChanged");
190 209
191 // Clear all partially-decoded frames. For most image formats, there is only 210 // Clear all partially-decoded frames. For most image formats, there is only
192 // one frame, but at least GIF and ICO can have more. With GIFs, the frames 211 // one frame, but at least GIF and ICO can have more. With GIFs, the frames
193 // come in order and we ask to decode them in order, waiting to request a 212 // come in order and we ask to decode them in order, waiting to request a
194 // subsequent frame until the prior one is complete. Given that we clear 213 // subsequent frame until the prior one is complete. Given that we clear
195 // incomplete frames here, this means there is at most one incomplete frame 214 // incomplete frames here, this means there is at most one incomplete frame
196 // (even if we use destroyDecodedData() -- since it doesn't reset the 215 // (even if we use destroyDecodedData() -- since it doesn't reset the
(...skipping 14 matching lines...) Expand all
211 // cleared-on-a-previous-pass) frames! 230 // cleared-on-a-previous-pass) frames!
212 if (m_frames[i].m_haveMetadata && !m_frames[i].m_isComplete) { 231 if (m_frames[i].m_haveMetadata && !m_frames[i].m_isComplete) {
213 m_frames[i].clear(true); 232 m_frames[i].clear(true);
214 if (i == m_cachedFrameIndex) 233 if (i == m_cachedFrameIndex)
215 m_cachedFrame.clear(); 234 m_cachedFrame.clear();
216 } 235 }
217 } 236 }
218 237
219 // Feed all the data we've seen so far to the image decoder. 238 // Feed all the data we've seen so far to the image decoder.
220 m_allDataReceived = allDataReceived; 239 m_allDataReceived = allDataReceived;
221 ASSERT(data());
222 m_source.setData(*data(), allDataReceived);
223 240
224 m_haveFrameCount = false; 241 m_haveFrameCount = false;
225 return isSizeAvailable(); 242 return isSizeAvailable();
226 } 243 }
227 244
228 bool BitmapImage::hasColorProfile() const 245 bool BitmapImage::hasColorProfile() const
229 { 246 {
230 return m_source.hasColorProfile(); 247 return m_source.hasColorProfile();
231 } 248 }
232 249
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 607
591 // We need to draw this frame if we advanced to it while not skipping, or if 608 // We need to draw this frame if we advanced to it while not skipping, or if
592 // while trying to skip frames we hit the last frame and thus had to stop. 609 // while trying to skip frames we hit the last frame and thus had to stop.
593 if (skippingFrames != advancedAnimation) 610 if (skippingFrames != advancedAnimation)
594 getImageObserver()->animationAdvanced(this); 611 getImageObserver()->animationAdvanced(this);
595 612
596 return advancedAnimation; 613 return advancedAnimation;
597 } 614 }
598 615
599 } // namespace blink 616 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698