| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 virtual bool decodeToYUV() { return false; } | 272 virtual bool decodeToYUV() { return false; } |
| 273 virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) {} | 273 virtual void setImagePlanes(std::unique_ptr<ImagePlanes>) {} |
| 274 | 274 |
| 275 protected: | 275 protected: |
| 276 ImageDecoder(AlphaOption alphaOption, | 276 ImageDecoder(AlphaOption alphaOption, |
| 277 GammaAndColorProfileOption colorOptions, | 277 GammaAndColorProfileOption colorOptions, |
| 278 size_t maxDecodedBytes) | 278 size_t maxDecodedBytes) |
| 279 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied), | 279 : m_premultiplyAlpha(alphaOption == AlphaPremultiplied), |
| 280 m_ignoreGammaAndColorProfile(colorOptions == | 280 m_ignoreGammaAndColorProfile(colorOptions == |
| 281 GammaAndColorProfileIgnored), | 281 GammaAndColorProfileIgnored), |
| 282 m_maxDecodedBytes(maxDecodedBytes) {} | 282 m_maxDecodedBytes(maxDecodedBytes), |
| 283 m_purgeAggressively(false) {} |
| 283 | 284 |
| 284 // Calculates the most recent frame whose image data may be needed in | 285 // Calculates the most recent frame whose image data may be needed in |
| 285 // order to decode frame |frameIndex|, based on frame disposal methods | 286 // order to decode frame |frameIndex|, based on frame disposal methods |
| 286 // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether | 287 // and |frameRectIsOpaque|, where |frameRectIsOpaque| signifies whether |
| 287 // the rectangle of frame at |frameIndex| is known to be opaque. | 288 // the rectangle of frame at |frameIndex| is known to be opaque. |
| 288 // If no previous frame's data is required, returns WTF::kNotFound. | 289 // If no previous frame's data is required, returns WTF::kNotFound. |
| 289 // | 290 // |
| 290 // This function requires that the previous frame's | 291 // This function requires that the previous frame's |
| 291 // |m_requiredPreviousFrameIndex| member has been set correctly. The | 292 // |m_requiredPreviousFrameIndex| member has been set correctly. The |
| 292 // easiest way to ensure this is for subclasses to call this method and | 293 // easiest way to ensure this is for subclasses to call this method and |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 const bool m_ignoreGammaAndColorProfile; | 326 const bool m_ignoreGammaAndColorProfile; |
| 326 ImageOrientation m_orientation; | 327 ImageOrientation m_orientation; |
| 327 | 328 |
| 328 // The maximum amount of memory a decoded image should require. Ideally, | 329 // The maximum amount of memory a decoded image should require. Ideally, |
| 329 // image decoders should downsample large images to fit under this limit | 330 // image decoders should downsample large images to fit under this limit |
| 330 // (and then return the downsampled size from decodedSize()). Ignoring | 331 // (and then return the downsampled size from decodedSize()). Ignoring |
| 331 // this limit can cause excessive memory use or even crashes on low- | 332 // this limit can cause excessive memory use or even crashes on low- |
| 332 // memory devices. | 333 // memory devices. |
| 333 const size_t m_maxDecodedBytes; | 334 const size_t m_maxDecodedBytes; |
| 334 | 335 |
| 336 // While decoding, we may learn that there are so many animation frames that |
| 337 // we would go beyond our cache budget. |
| 338 // If that happens, m_purgeAggressively is set to true. This signals |
| 339 // future decodes to purge old frames as it goes. |
| 340 void updateAggressivePurging(size_t index); |
| 341 bool m_purgeAggressively; |
| 342 |
| 335 private: | 343 private: |
| 336 enum class SniffResult { JPEG, PNG, GIF, WEBP, ICO, BMP, Invalid }; | 344 enum class SniffResult { JPEG, PNG, GIF, WEBP, ICO, BMP, Invalid }; |
| 337 | 345 |
| 338 static SniffResult determineImageType(const char* data, size_t length); | 346 static SniffResult determineImageType(const char* data, size_t length); |
| 339 | 347 |
| 340 // Some code paths compute the size of the image as "width * height * 4" | 348 // Some code paths compute the size of the image as "width * height * 4" |
| 341 // and return it as a (signed) int. Avoid overflow. | 349 // and return it as a (signed) int. Avoid overflow. |
| 342 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) { | 350 static bool sizeCalculationMayOverflow(unsigned width, unsigned height) { |
| 343 unsigned long long total_size = static_cast<unsigned long long>(width) * | 351 unsigned long long total_size = static_cast<unsigned long long>(width) * |
| 344 static_cast<unsigned long long>(height); | 352 static_cast<unsigned long long>(height); |
| 345 return total_size > ((1 << 29) - 1); | 353 return total_size > ((1 << 29) - 1); |
| 346 } | 354 } |
| 347 | 355 |
| 348 IntSize m_size; | 356 IntSize m_size; |
| 349 bool m_sizeAvailable = false; | 357 bool m_sizeAvailable = false; |
| 350 bool m_isAllDataReceived = false; | 358 bool m_isAllDataReceived = false; |
| 351 bool m_failed = false; | 359 bool m_failed = false; |
| 352 | 360 |
| 353 bool m_hasColorProfile = false; | 361 bool m_hasColorProfile = false; |
| 354 ImageFrame::ICCProfile m_colorProfile; | 362 ImageFrame::ICCProfile m_colorProfile; |
| 355 | 363 |
| 356 #if USE(QCMSLIB) | 364 #if USE(QCMSLIB) |
| 357 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; | 365 QCMSTransformUniquePtr m_sourceToOutputDeviceColorTransform; |
| 358 #endif | 366 #endif |
| 359 }; | 367 }; |
| 360 | 368 |
| 361 } // namespace blink | 369 } // namespace blink |
| 362 | 370 |
| 363 #endif | 371 #endif |
| OLD | NEW |