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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 // FrameData::clear()). | 108 // FrameData::clear()). |
109 PassNativeImagePtr asNewNativeImage() const; | 109 PassNativeImagePtr asNewNativeImage() const; |
110 | 110 |
111 bool hasAlpha() const; | 111 bool hasAlpha() const; |
112 const IntRect& originalFrameRect() const { return m_originalFrameRect; } | 112 const IntRect& originalFrameRect() const { return m_originalFrameRect; } |
113 FrameStatus status() const { return m_status; } | 113 FrameStatus status() const { return m_status; } |
114 unsigned duration() const { return m_duration; } | 114 unsigned duration() const { return m_duration; } |
115 FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } | 115 FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } |
116 bool premultiplyAlpha() const { return m_premultiplyAlpha; } | 116 bool premultiplyAlpha() const { return m_premultiplyAlpha; } |
117 void reportMemoryUsage(MemoryObjectInfo*) const; | 117 void reportMemoryUsage(MemoryObjectInfo*) const; |
118 size_t requiredPreviousFrameIndex() const | |
119 { | |
120 ASSERT(m_requiredPreviousFrameIndexValid); | |
121 return m_requiredPreviousFrameIndex; | |
122 } | |
123 #if !ASSERT_DISABLED | |
124 bool requiredPreviousFrameIndexValid() const { return m_requiredPrevious FrameIndexValid; } | |
125 #endif | |
118 | 126 |
119 void setHasAlpha(bool alpha); | 127 void setHasAlpha(bool alpha); |
120 void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } | 128 void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } |
121 void setStatus(FrameStatus status); | 129 void setStatus(FrameStatus status); |
122 void setDuration(unsigned duration) { m_duration = duration; } | 130 void setDuration(unsigned duration) { m_duration = duration; } |
123 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } | 131 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
124 void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = p remultiplyAlpha; } | 132 void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = p remultiplyAlpha; } |
133 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) | |
134 { | |
135 m_requiredPreviousFrameIndex = previousFrameIndex; | |
136 #if !ASSERT_DISABLED | |
137 m_requiredPreviousFrameIndexValid = true; | |
138 #endif | |
139 } | |
125 | 140 |
126 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, un signed a) | 141 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, un signed a) |
127 { | 142 { |
128 setRGBA(getAddr(x, y), r, g, b, a); | 143 setRGBA(getAddr(x, y), r, g, b, a); |
129 } | 144 } |
130 | 145 |
131 inline PixelData* getAddr(int x, int y) | 146 inline PixelData* getAddr(int x, int y) |
132 { | 147 { |
133 return m_bitmap->bitmap().getAddr32(x, y); | 148 return m_bitmap->bitmap().getAddr32(x, y); |
134 } | 149 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 SkBitmap::Allocator* m_allocator; | 208 SkBitmap::Allocator* m_allocator; |
194 bool m_hasAlpha; | 209 bool m_hasAlpha; |
195 IntRect m_originalFrameRect; // This will always just be the entire | 210 IntRect m_originalFrameRect; // This will always just be the entire |
196 // buffer except for GIF frames whose | 211 // buffer except for GIF frames whose |
197 // original rect was smaller than the | 212 // original rect was smaller than the |
198 // overall image size. | 213 // overall image size. |
199 FrameStatus m_status; | 214 FrameStatus m_status; |
200 unsigned m_duration; | 215 unsigned m_duration; |
201 FrameDisposalMethod m_disposalMethod; | 216 FrameDisposalMethod m_disposalMethod; |
202 bool m_premultiplyAlpha; | 217 bool m_premultiplyAlpha; |
218 | |
219 // The frame that must be decoded before this frame can be decoded. | |
220 // WTF::notFound if this frame doesn't require any previous frame. | |
221 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never | |
222 // be read for image formats that do not have multiple frames. | |
223 size_t m_requiredPreviousFrameIndex; | |
224 #if !ASSERT_DISABLED | |
225 bool m_requiredPreviousFrameIndexValid; | |
226 #endif | |
203 }; | 227 }; |
204 | 228 |
205 // ImageDecoder is a base for all format-specific decoders | 229 // ImageDecoder is a base for all format-specific decoders |
206 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache. | 230 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache. |
207 class ImageDecoder { | 231 class ImageDecoder { |
208 WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED; | 232 WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED; |
209 public: | 233 public: |
210 ImageDecoder(ImageSource::AlphaOption alphaOption, ImageSource::GammaAnd ColorProfileOption gammaAndColorProfileOption) | 234 ImageDecoder(ImageSource::AlphaOption alphaOption, ImageSource::GammaAnd ColorProfileOption gammaAndColorProfileOption) |
211 : m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied) | 235 : m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied) |
212 , m_ignoreGammaAndColorProfile(gammaAndColorProfileOption == ImageSo urce::GammaAndColorProfileIgnored) | 236 , m_ignoreGammaAndColorProfile(gammaAndColorProfileOption == ImageSo urce::GammaAndColorProfileIgnored) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 // to enable easy tailcalling. Subclasses may override this to also | 375 // to enable easy tailcalling. Subclasses may override this to also |
352 // clean up any local data. | 376 // clean up any local data. |
353 virtual bool setFailed() | 377 virtual bool setFailed() |
354 { | 378 { |
355 m_failed = true; | 379 m_failed = true; |
356 return false; | 380 return false; |
357 } | 381 } |
358 | 382 |
359 bool failed() const { return m_failed; } | 383 bool failed() const { return m_failed; } |
360 | 384 |
361 // Clears decoded pixel data from before the provided frame unless that | 385 // Clears decoded pixel data from all frames except the provided frame, |
362 // data may be needed to decode future frames (e.g. due to GIF frame | 386 // unless that frame has status FrameEmpty, in which case we instead |
363 // compositing). | 387 // preserve the most recent frame whose data is required in order to |
364 virtual void clearFrameBufferCache(size_t) { } | 388 // decode this frame. Callers may pass WTF::notFound to clear all frames . |
389 // | |
390 // Returns the number of bytes of frame data actually cleared. | |
391 size_t clearCacheExceptFrame(size_t); | |
365 | 392 |
366 // If the image has a cursor hot-spot, stores it in the argument | 393 // If the image has a cursor hot-spot, stores it in the argument |
367 // and returns true. Otherwise returns false. | 394 // and returns true. Otherwise returns false. |
368 virtual bool hotSpot(IntPoint&) const { return false; } | 395 virtual bool hotSpot(IntPoint&) const { return false; } |
369 | 396 |
370 virtual void reportMemoryUsage(MemoryObjectInfo*) const; | 397 virtual void reportMemoryUsage(MemoryObjectInfo*) const; |
371 | 398 |
372 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) | 399 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) |
373 { | 400 { |
374 // FIXME: this doesn't work for images with multiple frames. | 401 // FIXME: this doesn't work for images with multiple frames. |
375 if (m_frameBufferCache.isEmpty()) | 402 if (m_frameBufferCache.isEmpty()) |
376 m_frameBufferCache.resize(1); | 403 m_frameBufferCache.resize(1); |
377 m_frameBufferCache[0].setMemoryAllocator(allocator); | 404 m_frameBufferCache[0].setMemoryAllocator(allocator); |
378 } | 405 } |
379 | 406 |
380 protected: | 407 protected: |
408 // Calculates the most recent frame whose image data may be needed in | |
409 // order to decode frame |frameIndex|, based on frame disposal methods. | |
410 // If no previous frame's data is required, returns WTF::notFound. | |
411 // | |
412 // This function requires that the previous frame's |m_requiredPreviousF rameIndex| | |
Peter Kasting
2013/05/29 21:03:19
Nit: It seems like you're trying to wrap comments
| |
413 // member has been set correctly. The easiest way to ensure this is for | |
414 // subclasses to call this method and store the result on the frame via | |
415 // setRequiredPreviousFrameIndex() as soon as the frame has been created | |
416 // and parsed sufficiently to determine the disposal method; assuming | |
417 // this happens for all frames in order, the required invariant will hol d. | |
418 // | |
419 // Image formats which do not use more than one frame do not need to | |
420 // worry about this; see comments on ImageFrame::m_requiredPreviousFrame Index. | |
421 size_t findRequiredPreviousFrame(size_t frameIndex); | |
422 | |
423 virtual void clearFrameBuffer(size_t frameIndex); | |
424 | |
381 RefPtr<SharedBuffer> m_data; // The encoded data. | 425 RefPtr<SharedBuffer> m_data; // The encoded data. |
382 Vector<ImageFrame, 1> m_frameBufferCache; | 426 Vector<ImageFrame, 1> m_frameBufferCache; |
383 bool m_premultiplyAlpha; | 427 bool m_premultiplyAlpha; |
384 bool m_ignoreGammaAndColorProfile; | 428 bool m_ignoreGammaAndColorProfile; |
385 ImageOrientation m_orientation; | 429 ImageOrientation m_orientation; |
386 | 430 |
387 private: | 431 private: |
388 // Some code paths compute the size of the image as "width * height * 4" | 432 // Some code paths compute the size of the image as "width * height * 4" |
389 // and return it as a (signed) int. Avoid overflow. | 433 // and return it as a (signed) int. Avoid overflow. |
390 static bool isOverSize(unsigned width, unsigned height) | 434 static bool isOverSize(unsigned width, unsigned height) |
391 { | 435 { |
392 unsigned long long total_size = static_cast<unsigned long long>(widt h) | 436 unsigned long long total_size = static_cast<unsigned long long>(widt h) |
393 * static_cast<unsigned long long>(heig ht); | 437 * static_cast<unsigned long long>(heig ht); |
394 return total_size > ((1 << 29) - 1); | 438 return total_size > ((1 << 29) - 1); |
395 } | 439 } |
396 | 440 |
397 IntSize m_size; | 441 IntSize m_size; |
398 bool m_sizeAvailable; | 442 bool m_sizeAvailable; |
399 bool m_isAllDataReceived; | 443 bool m_isAllDataReceived; |
400 bool m_failed; | 444 bool m_failed; |
401 }; | 445 }; |
402 | 446 |
403 } // namespace WebCore | 447 } // namespace WebCore |
404 | 448 |
405 #endif | 449 #endif |
OLD | NEW |