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

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

Issue 1460523002: GIF decoding to Index8, unit tests and misusing unit test as benchmark (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return; 218 return;
219 219
220 m_size = m_actualDecoder->size(); 220 m_size = m_actualDecoder->size();
221 m_filenameExtension = m_actualDecoder->filenameExtension(); 221 m_filenameExtension = m_actualDecoder->filenameExtension();
222 // JPEG images support YUV decoding: other decoders do not, WEBP could in fu ture. 222 // JPEG images support YUV decoding: other decoders do not, WEBP could in fu ture.
223 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && (m_filename Extension == "jpg"); 223 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && (m_filename Extension == "jpg");
224 m_hasColorProfile = m_actualDecoder->hasColorProfile(); 224 m_hasColorProfile = m_actualDecoder->hasColorProfile();
225 225
226 const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationN one || (m_allDataReceived && m_actualDecoder->frameCount() == 1u); 226 const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationN one || (m_allDataReceived && m_actualDecoder->frameCount() == 1u);
227 m_frameGenerator = ImageFrameGenerator::create(SkISize::Make(m_actualDecoder ->decodedSize().width(), m_actualDecoder->decodedSize().height()), m_data, m_all DataReceived, !isSingleFrame); 227 m_frameGenerator = ImageFrameGenerator::create(SkISize::Make(m_actualDecoder ->decodedSize().width(), m_actualDecoder->decodedSize().height()), m_data, m_all DataReceived, !isSingleFrame);
228 // GIF images support Index8 decoding: other decoders do not.
229 m_frameGenerator->setDecoderCanDecodeToIndex8(m_filenameExtension == "gif");
228 } 230 }
229 231
230 void DeferredImageDecoder::prepareLazyDecodedFrames() 232 void DeferredImageDecoder::prepareLazyDecodedFrames()
231 { 233 {
232 if (!s_enabled 234 if (!s_enabled
233 || !m_actualDecoder 235 || !m_actualDecoder
234 || !m_actualDecoder->isSizeAvailable() 236 || !m_actualDecoder->isSizeAvailable()
235 || m_actualDecoder->filenameExtension() == "ico") 237 || m_actualDecoder->filenameExtension() == "ico")
236 return; 238 return;
237 239
(...skipping 20 matching lines...) Expand all
258 m_frameData[lastFrame].m_isComplete = m_actualDecoder->frameIsCompleteAt Index(lastFrame); 260 m_frameData[lastFrame].m_isComplete = m_actualDecoder->frameIsCompleteAt Index(lastFrame);
259 } 261 }
260 262
261 if (m_allDataReceived) { 263 if (m_allDataReceived) {
262 m_repetitionCount = m_actualDecoder->repetitionCount(); 264 m_repetitionCount = m_actualDecoder->repetitionCount();
263 m_actualDecoder.clear(); 265 m_actualDecoder.clear();
264 m_data = nullptr; 266 m_data = nullptr;
265 } 267 }
266 } 268 }
267 269
268 inline SkImageInfo imageInfoFrom(const SkISize& decodedSize, bool knownToBeOpaqu e) 270 static inline SkImageInfo imageInfoFrom(const SkISize& decodedSize, bool knownTo BeOpaque)
269 { 271 {
270 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 272 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
271 } 273 }
272 274
273 PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index, bool knownToBeOpaque) const 275 PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index, bool knownToBeOpaque) const
274 { 276 {
275 const SkISize& decodedSize = m_frameGenerator->getFullSize(); 277 const SkISize& decodedSize = m_frameGenerator->getFullSize();
276 ASSERT(decodedSize.width() > 0); 278 ASSERT(decodedSize.width() > 0);
277 ASSERT(decodedSize.height() > 0); 279 ASSERT(decodedSize.height() > 0);
278 280
279 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera tor, imageInfoFrom(decodedSize, knownToBeOpaque), index); 281 const SkImageInfo info = m_frameGenerator->canDecodeTo(index, kIndex_8_SkCol orType)
280 RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator)); // S kImage takes ownership of the generator. 282 ? SkImageInfo::Make(decodedSize.width(), decodedSize.height(), kIndex_8_ SkColorType,
283 knownToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType)
284 : imageInfoFrom(decodedSize, knownToBeOpaque);
285
286 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera tor, info, index);
287 RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator));
281 if (!image) 288 if (!image)
282 return nullptr; 289 return nullptr;
283 290
284 generator->setGenerationId(image->uniqueID()); 291 generator->setGenerationId(image->uniqueID());
285 generator->setCanYUVDecode(m_canYUVDecode); 292 generator->setCanYUVDecode(m_canYUVDecode);
286 293
287 return image.release(); 294 return image.release();
288 } 295 }
289 296
290 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const 297 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const
291 { 298 {
292 // TODO: Implement. 299 // TODO: Implement.
293 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; 300 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false;
294 } 301 }
295 302
296 } // namespace blink 303 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698