| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // many callers want to return false after calling this), returns false | 233 // many callers want to return false after calling this), returns false |
| 234 // to enable easy tailcalling. Subclasses may override this to also | 234 // to enable easy tailcalling. Subclasses may override this to also |
| 235 // clean up any local data. | 235 // clean up any local data. |
| 236 virtual bool setFailed() { | 236 virtual bool setFailed() { |
| 237 m_failed = true; | 237 m_failed = true; |
| 238 return false; | 238 return false; |
| 239 } | 239 } |
| 240 | 240 |
| 241 bool failed() const { return m_failed; } | 241 bool failed() const { return m_failed; } |
| 242 | 242 |
| 243 // Clears decoded pixel data from all frames except the provided frame. | 243 // Clears decoded pixel data from all frames except the provided frame. If |
| 244 // subsequent frames depend on this frame's required previous frame, then that |
| 245 // frame is also kept in cache to prevent re-decoding from the beginning. |
| 244 // Callers may pass WTF::kNotFound to clear all frames. | 246 // Callers may pass WTF::kNotFound to clear all frames. |
| 245 // Note: If |m_frameBufferCache| contains only one frame, it won't be cleared. | 247 // Note: If |m_frameBufferCache| contains only one frame, it won't be cleared. |
| 246 // Returns the number of bytes of frame data actually cleared. | 248 // Returns the number of bytes of frame data actually cleared. |
| 247 virtual size_t clearCacheExceptFrame(size_t); | 249 size_t clearCacheExceptFrame(size_t); |
| 248 | 250 |
| 249 // If the image has a cursor hot-spot, stores it in the argument | 251 // If the image has a cursor hot-spot, stores it in the argument |
| 250 // and returns true. Otherwise returns false. | 252 // and returns true. Otherwise returns false. |
| 251 virtual bool hotSpot(IntPoint&) const { return false; } | 253 virtual bool hotSpot(IntPoint&) const { return false; } |
| 252 | 254 |
| 253 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) { | 255 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) { |
| 254 // FIXME: this doesn't work for images with multiple frames. | 256 // FIXME: this doesn't work for images with multiple frames. |
| 255 if (m_frameBufferCache.isEmpty()) { | 257 if (m_frameBufferCache.isEmpty()) { |
| 256 m_frameBufferCache.resize(1); | 258 m_frameBufferCache.resize(1); |
| 257 m_frameBufferCache[0].setRequiredPreviousFrameIndex( | 259 m_frameBufferCache[0].setRequiredPreviousFrameIndex( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // this limit can cause excessive memory use or even crashes on low- | 338 // this limit can cause excessive memory use or even crashes on low- |
| 337 // memory devices. | 339 // memory devices. |
| 338 const size_t m_maxDecodedBytes; | 340 const size_t m_maxDecodedBytes; |
| 339 | 341 |
| 340 // While decoding, we may learn that there are so many animation frames that | 342 // While decoding, we may learn that there are so many animation frames that |
| 341 // we would go beyond our cache budget. | 343 // we would go beyond our cache budget. |
| 342 // If that happens, m_purgeAggressively is set to true. This signals | 344 // If that happens, m_purgeAggressively is set to true. This signals |
| 343 // future decodes to purge old frames as it goes. | 345 // future decodes to purge old frames as it goes. |
| 344 void updateAggressivePurging(size_t index); | 346 void updateAggressivePurging(size_t index); |
| 345 | 347 |
| 348 // The method is only relevant for multi-frame images. |
| 349 // |
| 350 // This method indicates whether the provided frame has enough data to decode |
| 351 // successive frames that depend on it. It is used by clearCacheExceptFrame |
| 352 // to determine which frame to keep in cache when the indicated frame is not |
| 353 // yet sufficiently decoded. |
| 354 // |
| 355 // The default condition is that the frame status needs to be FramePartial or |
| 356 // FrameComplete, since the data of previous frames is copied in |
| 357 // initFrameBuffer() before setting the status to FramePartial. For WebP, |
| 358 // however, the status needs to be FrameComplete since the complete buffer is |
| 359 // used to do alpha blending in WEBPImageDecoder::applyPostProcessing(). |
| 360 // |
| 361 // Before calling this, verify that frame |index| exists by checking that |
| 362 // |index| is smaller than |m_frameBufferCache|.size(). |
| 363 virtual bool frameStatusSufficientForSuccessors(size_t index) { |
| 364 DCHECK(index < m_frameBufferCache.size()); |
| 365 return m_frameBufferCache[index].getStatus() != ImageFrame::FrameEmpty; |
| 366 } |
| 367 |
| 346 private: | 368 private: |
| 347 enum class SniffResult { JPEG, PNG, GIF, WEBP, ICO, BMP, Invalid }; | 369 enum class SniffResult { JPEG, PNG, GIF, WEBP, ICO, BMP, Invalid }; |
| 348 | 370 |
| 349 static SniffResult determineImageType(const char* data, size_t length); | 371 static SniffResult determineImageType(const char* data, size_t length); |
| 350 | 372 |
| 351 // Some code paths compute the size of the image as "width * height * 4" | 373 // Some code paths compute the size of the image as "width * height * 4" |
| 352 // and return it as a (signed) int. Avoid overflow. | 374 // and return it as a (signed) int. Avoid overflow. |
| 353 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) { | 375 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) { |
| 354 unsigned long long total_size = static_cast<unsigned long long>(width) * | 376 unsigned long long total_size = static_cast<unsigned long long>(width) * |
| 355 static_cast<unsigned long long>(height); | 377 static_cast<unsigned long long>(height); |
| 356 return total_size > ((1 << 29) - 1); | 378 return total_size > ((1 << 29) - 1); |
| 357 } | 379 } |
| 358 | 380 |
| 359 bool m_purgeAggressively; | 381 bool m_purgeAggressively; |
| 360 | 382 |
| 361 IntSize m_size; | 383 IntSize m_size; |
| 362 bool m_sizeAvailable = false; | 384 bool m_sizeAvailable = false; |
| 363 bool m_isAllDataReceived = false; | 385 bool m_isAllDataReceived = false; |
| 364 bool m_failed = false; | 386 bool m_failed = false; |
| 365 bool m_hasHistogrammedColorSpace = false; | 387 bool m_hasHistogrammedColorSpace = false; |
| 366 | 388 |
| 367 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; | 389 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; |
| 368 std::unique_ptr<SkColorSpaceXform> m_sourceToOutputDeviceColorTransform; | 390 std::unique_ptr<SkColorSpaceXform> m_sourceToOutputDeviceColorTransform; |
| 369 }; | 391 }; |
| 370 | 392 |
| 371 } // namespace blink | 393 } // namespace blink |
| 372 | 394 |
| 373 #endif | 395 #endif |
| OLD | NEW |