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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 1962563002: Fix ImageDecoder::frameIsCompleteAtIndex - fully received instead of decoded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Deferred decoding for ICO Created 4 years, 6 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) Research In Motion Limited 2009-2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOp tion alphaOption, GammaAndColorProfileOption colorOptions) 108 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOp tion alphaOption, GammaAndColorProfileOption colorOptions)
109 { 109 {
110 const char* contents; 110 const char* contents;
111 const size_t length = data.getSomeData(contents, 0); 111 const size_t length = data.getSomeData(contents, 0);
112 return create(contents, length, alphaOption, colorOptions); 112 return create(contents, length, alphaOption, colorOptions);
113 } 113 }
114 114
115 size_t ImageDecoder::frameCount() 115 size_t ImageDecoder::frameCount()
116 { 116 {
117 if (m_haveUpdatedFrameCount)
118 return m_frameBufferCache.size();
119
117 const size_t oldSize = m_frameBufferCache.size(); 120 const size_t oldSize = m_frameBufferCache.size();
118 const size_t newSize = decodeFrameCount(); 121 const size_t newSize = decodeFrameCount();
119 if (oldSize != newSize) { 122 if (oldSize != newSize) {
120 m_frameBufferCache.resize(newSize); 123 m_frameBufferCache.resize(newSize);
121 for (size_t i = oldSize; i < newSize; ++i) { 124 for (size_t i = oldSize; i < newSize; ++i) {
122 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); 125 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha);
123 initializeNewFrame(i); 126 initializeNewFrame(i);
124 } 127 }
125 } 128 }
129 m_haveUpdatedFrameCount = true;
126 return newSize; 130 return newSize;
127 } 131 }
128 132
129 ImageFrame* ImageDecoder::frameBufferAtIndex(size_t index) 133 ImageFrame* ImageDecoder::frameBufferAtIndex(size_t index)
130 { 134 {
131 if (index >= frameCount()) 135 if (index >= frameCount())
132 return 0; 136 return 0;
133 137
134 ImageFrame* frame = &m_frameBufferCache[index]; 138 ImageFrame* frame = &m_frameBufferCache[index];
135 if (frame->getStatus() != ImageFrame::FrameComplete) { 139 if (frame->getStatus() != ImageFrame::FrameComplete) {
136 PlatformInstrumentation::willDecodeImage(filenameExtension()); 140 PlatformInstrumentation::willDecodeImage(filenameExtension());
137 decode(index); 141 decode(index);
138 PlatformInstrumentation::didDecodeImage(); 142 PlatformInstrumentation::didDecodeImage();
139 } 143 }
140 144
141 frame->notifyBitmapIfPixelsChanged(); 145 frame->notifyBitmapIfPixelsChanged();
142 return frame; 146 return frame;
143 } 147 }
144 148
145 bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const 149 bool ImageDecoder::frameIsFullyReceivedAtIndex(size_t index) const
146 { 150 {
147 return !frameIsCompleteAtIndex(index) || m_frameBufferCache[index].hasAlpha( ); 151 ASSERT(m_haveUpdatedFrameCount);
148 } 152 return (index < m_frameBufferCache.size())
149 153 && (m_isAllDataReceived || failed() || m_frameBufferCache[index].getStat us() == ImageFrame::FrameComplete);
150 bool ImageDecoder::frameIsCompleteAtIndex(size_t index) const
151 {
152 return (index < m_frameBufferCache.size()) &&
153 (m_frameBufferCache[index].getStatus() == ImageFrame::FrameComplete);
154 } 154 }
155 155
156 size_t ImageDecoder::frameBytesAtIndex(size_t index) const 156 size_t ImageDecoder::frameBytesAtIndex(size_t index) const
157 { 157 {
158 if (index >= m_frameBufferCache.size() || m_frameBufferCache[index].getStatu s() == ImageFrame::FrameEmpty) 158 if (index >= m_frameBufferCache.size() || m_frameBufferCache[index].getStatu s() == ImageFrame::FrameEmpty)
159 return 0; 159 return 0;
160 160
161 struct ImageSize { 161 struct ImageSize {
162 162
163 explicit ImageSize(IntSize size) 163 explicit ImageSize(IntSize size)
164 { 164 {
165 area = static_cast<uint64_t>(size.width()) * size.height(); 165 area = static_cast<uint64_t>(size.width()) * size.height();
166 } 166 }
167 167
168 uint64_t area; 168 uint64_t area;
169 }; 169 };
170 170
171 return ImageSize(frameSizeAtIndex(index)).area * sizeof(ImageFrame::PixelDat a); 171 return ImageSize(frameSizeAtIndex(index)).area * sizeof(ImageFrame::PixelDat a);
172 } 172 }
173 173
174 bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const
175 {
176 ASSERT(m_haveUpdatedFrameCount);
177 if (m_frameBufferCache.size() == 1)
178 return !frameIsCompleteAtIndex(index) || m_frameBufferCache[index].hasAl pha();
179 return !frameIsFullyReceivedAtIndex(index) || m_frameBufferCache[index].hasA lpha();
180 }
181
174 bool ImageDecoder::deferredImageDecodingEnabled() 182 bool ImageDecoder::deferredImageDecodingEnabled()
175 { 183 {
176 return DeferredImageDecoder::enabled(); 184 return DeferredImageDecoder::enabled();
177 } 185 }
178 186
179 size_t ImageDecoder::clearCacheExceptFrame(size_t clearExceptFrame) 187 size_t ImageDecoder::clearCacheExceptFrame(size_t clearExceptFrame)
180 { 188 {
181 // Don't clear if there are no frames or only one frame. 189 // Don't clear if there are no frames or only one frame.
182 if (m_frameBufferCache.size() <= 1) 190 if (m_frameBufferCache.size() <= 1)
183 return 0; 191 return 0;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 364
357 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; 365 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8;
358 366
359 // FIXME: Don't force perceptual intent if the image profile contains an int ent. 367 // FIXME: Don't force perceptual intent if the image profile contains an int ent.
360 m_sourceToOutputDeviceColorTransform = adoptPtr(qcms_transform_create(inputP rofile.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PE RCEPTUAL)); 368 m_sourceToOutputDeviceColorTransform = adoptPtr(qcms_transform_create(inputP rofile.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PE RCEPTUAL));
361 } 369 }
362 370
363 #endif // USE(QCMSLIB) 371 #endif // USE(QCMSLIB)
364 372
365 } // namespace blink 373 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698