| 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 ImageFrameGeneratorTest::clearMultiFrameDecode. |
| 254 // |
| 255 // @TODO Let MockImageDecoder override ImageFrame::clearFrameBuffer instead, |
| 256 // so this method can be made non-virtual. It is used in the test |
| 257 // ImageFrameGeneratorTest::clearMultiFrameDecode. The test needs to |
| 258 // be modified since two frames may be kept in cache, instead of |
| 259 // always just one, with this clearCacheExceptFrame implementation. |
| 249 virtual size_t clearCacheExceptFrame(size_t); | 260 virtual size_t clearCacheExceptFrame(size_t); |
| 250 | 261 |
| 251 // If the image has a cursor hot-spot, stores it in the argument | 262 // If the image has a cursor hot-spot, stores it in the argument |
| 252 // and returns true. Otherwise returns false. | 263 // and returns true. Otherwise returns false. |
| 253 virtual bool hotSpot(IntPoint&) const { return false; } | 264 virtual bool hotSpot(IntPoint&) const { return false; } |
| 254 | 265 |
| 255 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) { | 266 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) { |
| 256 // FIXME: this doesn't work for images with multiple frames. | 267 // FIXME: this doesn't work for images with multiple frames. |
| 257 if (m_frameBufferCache.isEmpty()) { | 268 if (m_frameBufferCache.isEmpty()) { |
| 258 m_frameBufferCache.resize(1); | 269 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- | 355 // this limit can cause excessive memory use or even crashes on low- |
| 345 // memory devices. | 356 // memory devices. |
| 346 const size_t m_maxDecodedBytes; | 357 const size_t m_maxDecodedBytes; |
| 347 | 358 |
| 348 // While decoding, we may learn that there are so many animation frames that | 359 // While decoding, we may learn that there are so many animation frames that |
| 349 // we would go beyond our cache budget. | 360 // we would go beyond our cache budget. |
| 350 // If that happens, m_purgeAggressively is set to true. This signals | 361 // If that happens, m_purgeAggressively is set to true. This signals |
| 351 // future decodes to purge old frames as it goes. | 362 // future decodes to purge old frames as it goes. |
| 352 void updateAggressivePurging(size_t index); | 363 void updateAggressivePurging(size_t index); |
| 353 | 364 |
| 365 // The method is only relevant for multi-frame images. |
| 366 // |
| 367 // This method indicates whether the provided frame has enough data to decode |
| 368 // successive frames that depend on it. It is used by clearCacheExceptFrame |
| 369 // to determine which frame to keep in cache when the indicated frame is not |
| 370 // yet sufficiently decoded. |
| 371 // |
| 372 // The default condition is that the frame status needs to be FramePartial or |
| 373 // FrameComplete, since the data of previous frames is copied in |
| 374 // initFrameBuffer() before setting the status to FramePartial. For WebP, |
| 375 // however, the status needs to be FrameComplete since the complete buffer is |
| 376 // used to do alpha blending in WEBPImageDecoder::applyPostProcessing(). |
| 377 // |
| 378 // Before calling this, verify that frame |index| exists by checking that |
| 379 // |index| is smaller than |m_frameBufferCache|.size(). |
| 380 virtual bool frameStatusSufficientForSuccessors(size_t index) { |
| 381 DCHECK(index < m_frameBufferCache.size()); |
| 382 return m_frameBufferCache[index].getStatus() != ImageFrame::FrameEmpty; |
| 383 } |
| 384 |
| 354 private: | 385 private: |
| 355 enum class SniffResult { JPEG, PNG, GIF, WEBP, ICO, BMP, Invalid }; | 386 enum class SniffResult { JPEG, PNG, GIF, WEBP, ICO, BMP, Invalid }; |
| 356 | 387 |
| 357 static SniffResult determineImageType(const char* data, size_t length); | 388 static SniffResult determineImageType(const char* data, size_t length); |
| 358 | 389 |
| 359 // Some code paths compute the size of the image as "width * height * 4" | 390 // Some code paths compute the size of the image as "width * height * 4" |
| 360 // and return it as a (signed) int. Avoid overflow. | 391 // and return it as a (signed) int. Avoid overflow. |
| 361 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) { | 392 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) { |
| 362 unsigned long long total_size = static_cast<unsigned long long>(width) * | 393 unsigned long long total_size = static_cast<unsigned long long>(width) * |
| 363 static_cast<unsigned long long>(height); | 394 static_cast<unsigned long long>(height); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 382 | 413 |
| 383 sk_sp<SkColorSpace> m_targetColorSpace = nullptr; | 414 sk_sp<SkColorSpace> m_targetColorSpace = nullptr; |
| 384 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; | 415 sk_sp<SkColorSpace> m_embeddedColorSpace = nullptr; |
| 385 bool m_sourceToTargetColorTransformNeedsUpdate = false; | 416 bool m_sourceToTargetColorTransformNeedsUpdate = false; |
| 386 std::unique_ptr<SkColorSpaceXform> m_sourceToTargetColorTransform; | 417 std::unique_ptr<SkColorSpaceXform> m_sourceToTargetColorTransform; |
| 387 }; | 418 }; |
| 388 | 419 |
| 389 } // namespace blink | 420 } // namespace blink |
| 390 | 421 |
| 391 #endif | 422 #endif |
| OLD | NEW |