Chromium Code Reviews| OLD | NEW |
|---|---|
| 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) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 // many callers want to return false after calling this), returns false | 235 // many callers want to return false after calling this), returns false |
| 236 // to enable easy tailcalling. Subclasses may override this to also | 236 // to enable easy tailcalling. Subclasses may override this to also |
| 237 // clean up any local data. | 237 // clean up any local data. |
| 238 virtual bool setFailed() { | 238 virtual bool setFailed() { |
| 239 m_failed = true; | 239 m_failed = true; |
| 240 return false; | 240 return false; |
| 241 } | 241 } |
| 242 | 242 |
| 243 bool failed() const { return m_failed; } | 243 bool failed() const { return m_failed; } |
| 244 | 244 |
| 245 // Clears decoded pixel data from all frames except the provided frame. | 245 // Clears decoded pixel data from all frames except the provided frame. If |
| 246 // subsequent frames depend on this frame's required previous frame, then that | |
| 247 // frame is also kept in cache to prevent re-decoding from the beginning. | |
| 246 // Callers may pass WTF::kNotFound to clear all frames. | 248 // Callers may pass WTF::kNotFound to clear all frames. |
| 247 // Note: If |m_frameBufferCache| contains only one frame, it won't be cleared. | 249 // Note: If |m_frameBufferCache| contains only one frame, it won't be cleared. |
| 248 // Returns the number of bytes of frame data actually cleared. | 250 // Returns the number of bytes of frame data actually cleared. |
| 251 // | |
| 252 // This is a virtual method because MockImageDecoder needs to override it in | |
| 253 // order to run the test ImageFrameGenerator::clearMultiFrameDecode. | |
|
scroggo_chromium
2016/12/01 14:44:07
Instead of making this virtual, how about making M
joostouwerling
2016/12/01 15:05:06
Sgtm but I propose to do that in a different CL. I
scroggo_chromium
2016/12/01 15:08:00
Okay by me, but can you add a TODO? The danger in
joostouwerling
2016/12/01 15:25:21
Done.
| |
| 249 virtual size_t clearCacheExceptFrame(size_t); | 254 virtual size_t clearCacheExceptFrame(size_t); |
| 250 | 255 |
| 251 // If the image has a cursor hot-spot, stores it in the argument | 256 // If the image has a cursor hot-spot, stores it in the argument |
| 252 // and returns true. Otherwise returns false. | 257 // and returns true. Otherwise returns false. |
| 253 virtual bool hotSpot(IntPoint&) const { return false; } | 258 virtual bool hotSpot(IntPoint&) const { return false; } |
| 254 | 259 |
| 255 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) { | 260 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) { |
| 256 // FIXME: this doesn't work for images with multiple frames. | 261 // FIXME: this doesn't work for images with multiple frames. |
| 257 if (m_frameBufferCache.isEmpty()) { | 262 if (m_frameBufferCache.isEmpty()) { |
| 258 m_frameBufferCache.resize(1); | 263 m_frameBufferCache.resize(1); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 // this limit can cause excessive memory use or even crashes on low- | 349 // this limit can cause excessive memory use or even crashes on low- |
| 345 // memory devices. | 350 // memory devices. |
| 346 const size_t m_maxDecodedBytes; | 351 const size_t m_maxDecodedBytes; |
| 347 | 352 |
| 348 // While decoding, we may learn that there are so many animation frames that | 353 // While decoding, we may learn that there are so many animation frames that |
| 349 // we would go beyond our cache budget. | 354 // we would go beyond our cache budget. |
| 350 // If that happens, m_purgeAggressively is set to true. This signals | 355 // If that happens, m_purgeAggressively is set to true. This signals |
| 351 // future decodes to purge old frames as it goes. | 356 // future decodes to purge old frames as it goes. |
| 352 void updateAggressivePurging(size_t index); | 357 void updateAggressivePurging(size_t index); |
| 353 | 358 |
| 359 // The method is only relevant for multi-frame images. | |
| 360 // | |
| 361 // This method indicates whether the provided frame has enough data to decode | |
| 362 // successive frames that depend on it. It is used by clearCacheExceptFrame | |
| 363 // to determine which frame to keep in cache when the indicated frame is not | |
| 364 // yet sufficiently decoded. | |
| 365 // | |
| 366 // The default condition is that the frame status needs to be FramePartial or | |
| 367 // FrameComplete, since the data of previous frames is copied in | |
| 368 // initFrameBuffer() before setting the status to FramePartial. For WebP, | |
| 369 // however, the status needs to be FrameComplete since the complete buffer is | |
| 370 // used to do alpha blending in WEBPImageDecoder::applyPostProcessing(). | |
| 371 // | |
| 372 // Before calling this, verify that frame |index| exists by checking that | |
| 373 // |index| is smaller than |m_frameBufferCache|.size(). | |
| 374 virtual bool frameStatusSufficientForSuccessors(size_t index) { | |
| 375 DCHECK(index < m_frameBufferCache.size()); | |
| 376 return m_frameBufferCache[index].getStatus() != ImageFrame::FrameEmpty; | |
| 377 } | |
| 378 | |
| 354 private: | 379 private: |
| 355 enum class SniffResult { JPEG, PNG, GIF, WEBP, ICO, BMP, Invalid }; | 380 enum class SniffResult { JPEG, PNG, GIF, WEBP, ICO, BMP, Invalid }; |
| 356 | 381 |
| 357 static SniffResult determineImageType(const char* data, size_t length); | 382 static SniffResult determineImageType(const char* data, size_t length); |
| 358 | 383 |
| 359 // Some code paths compute the size of the image as "width * height * 4" | 384 // Some code paths compute the size of the image as "width * height * 4" |
| 360 // and return it as a (signed) int. Avoid overflow. | 385 // and return it as a (signed) int. Avoid overflow. |
| 361 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) { | 386 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) { |
| 362 unsigned long long total_size = static_cast<unsigned long long>(width) * | 387 unsigned long long total_size = static_cast<unsigned long long>(width) * |
| 363 static_cast<unsigned long long>(height); | 388 static_cast<unsigned long long>(height); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 382 | 407 |
| 383 sk_sp<SkColorSpace> m_targetColorSpace = nullptr; | 408 sk_sp<SkColorSpace> m_targetColorSpace = nullptr; |
| 384 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; | 409 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; |
| 385 bool m_sourceToTargetColorTransformNeedsUpdate = false; | 410 bool m_sourceToTargetColorTransformNeedsUpdate = false; |
| 386 std::unique_ptr<SkColorSpaceXform> m_sourceToTargetColorTransform; | 411 std::unique_ptr<SkColorSpaceXform> m_sourceToTargetColorTransform; |
| 387 }; | 412 }; |
| 388 | 413 |
| 389 } // namespace blink | 414 } // namespace blink |
| 390 | 415 |
| 391 #endif | 416 #endif |
| OLD | NEW |