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 } | |
118 | 123 |
119 void setHasAlpha(bool alpha); | 124 void setHasAlpha(bool alpha); |
120 void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } | 125 void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } |
121 void setStatus(FrameStatus status); | 126 void setStatus(FrameStatus status); |
122 void setDuration(unsigned duration) { m_duration = duration; } | 127 void setDuration(unsigned duration) { m_duration = duration; } |
123 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } | 128 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
124 void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = p remultiplyAlpha; } | 129 void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = p remultiplyAlpha; } |
130 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) | |
131 { | |
132 m_requiredPreviousFrameIndex = previousFrameIndex; | |
133 #ifndef NDEBUG | |
134 m_requiredPreviousFrameIndexValid = true; | |
135 #endif | |
136 } | |
125 | 137 |
126 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, un signed a) | 138 inline void setRGBA(int x, int y, unsigned r, unsigned g, unsigned b, un signed a) |
127 { | 139 { |
128 setRGBA(getAddr(x, y), r, g, b, a); | 140 setRGBA(getAddr(x, y), r, g, b, a); |
129 } | 141 } |
130 | 142 |
131 inline PixelData* getAddr(int x, int y) | 143 inline PixelData* getAddr(int x, int y) |
132 { | 144 { |
133 return m_bitmap->bitmap().getAddr32(x, y); | 145 return m_bitmap->bitmap().getAddr32(x, y); |
134 } | 146 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 SkBitmap::Allocator* m_allocator; | 205 SkBitmap::Allocator* m_allocator; |
194 bool m_hasAlpha; | 206 bool m_hasAlpha; |
195 IntRect m_originalFrameRect; // This will always just be the entire | 207 IntRect m_originalFrameRect; // This will always just be the entire |
196 // buffer except for GIF frames whose | 208 // buffer except for GIF frames whose |
197 // original rect was smaller than the | 209 // original rect was smaller than the |
198 // overall image size. | 210 // overall image size. |
199 FrameStatus m_status; | 211 FrameStatus m_status; |
200 unsigned m_duration; | 212 unsigned m_duration; |
201 FrameDisposalMethod m_disposalMethod; | 213 FrameDisposalMethod m_disposalMethod; |
202 bool m_premultiplyAlpha; | 214 bool m_premultiplyAlpha; |
215 | |
216 // The frame that must be decoded before this frame can be decoded. | |
217 // |notFound| if this frame doesn't require any previous frame. | |
Peter Kasting
2013/05/29 02:02:18
Nit: Add this at end:
This is used by ImageDecode
Xianzhu
2013/05/29 18:37:01
Done.
| |
218 size_t m_requiredPreviousFrameIndex; | |
219 #ifndef NDEBUG | |
220 bool m_requiredPreviousFrameIndexValid; | |
221 #endif | |
203 }; | 222 }; |
204 | 223 |
205 // ImageDecoder is a base for all format-specific decoders | 224 // ImageDecoder is a base for all format-specific decoders |
206 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache. | 225 // (e.g. JPEGImageDecoder). This base manages the ImageFrame cache. |
207 class ImageDecoder { | 226 class ImageDecoder { |
208 WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED; | 227 WTF_MAKE_NONCOPYABLE(ImageDecoder); WTF_MAKE_FAST_ALLOCATED; |
209 public: | 228 public: |
210 ImageDecoder(ImageSource::AlphaOption alphaOption, ImageSource::GammaAnd ColorProfileOption gammaAndColorProfileOption) | 229 ImageDecoder(ImageSource::AlphaOption alphaOption, ImageSource::GammaAnd ColorProfileOption gammaAndColorProfileOption) |
211 : m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied) | 230 : m_premultiplyAlpha(alphaOption == ImageSource::AlphaPremultiplied) |
212 , m_ignoreGammaAndColorProfile(gammaAndColorProfileOption == ImageSo urce::GammaAndColorProfileIgnored) | 231 , 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 | 370 // to enable easy tailcalling. Subclasses may override this to also |
352 // clean up any local data. | 371 // clean up any local data. |
353 virtual bool setFailed() | 372 virtual bool setFailed() |
354 { | 373 { |
355 m_failed = true; | 374 m_failed = true; |
356 return false; | 375 return false; |
357 } | 376 } |
358 | 377 |
359 bool failed() const { return m_failed; } | 378 bool failed() const { return m_failed; } |
360 | 379 |
361 // Clears decoded pixel data from before the provided frame unless that | 380 // Clears decoded pixel data except the provided frame unless that |
362 // data may be needed to decode future frames (e.g. due to GIF frame | 381 // data may be needed to decode future frames (e.g. due to GIF frame |
363 // compositing). | 382 // compositing). Pass a value greater than the frame count to clear |
364 virtual void clearFrameBufferCache(size_t) { } | 383 // decoded pixel data of all frames. |
384 // Returns number of bytes of the cleared frames. | |
Peter Kasting
2013/05/29 02:02:18
Nit: How about this comment:
Clears decoded pixel
Xianzhu
2013/05/29 18:37:01
Done.
| |
385 size_t clearCacheExceptFrame(size_t); | |
365 | 386 |
366 // If the image has a cursor hot-spot, stores it in the argument | 387 // If the image has a cursor hot-spot, stores it in the argument |
367 // and returns true. Otherwise returns false. | 388 // and returns true. Otherwise returns false. |
368 virtual bool hotSpot(IntPoint&) const { return false; } | 389 virtual bool hotSpot(IntPoint&) const { return false; } |
369 | 390 |
370 virtual void reportMemoryUsage(MemoryObjectInfo*) const; | 391 virtual void reportMemoryUsage(MemoryObjectInfo*) const; |
371 | 392 |
372 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) | 393 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) |
373 { | 394 { |
374 // FIXME: this doesn't work for images with multiple frames. | 395 // FIXME: this doesn't work for images with multiple frames. |
375 if (m_frameBufferCache.isEmpty()) | 396 if (m_frameBufferCache.isEmpty()) |
376 m_frameBufferCache.resize(1); | 397 m_frameBufferCache.resize(1); |
377 m_frameBufferCache[0].setMemoryAllocator(allocator); | 398 m_frameBufferCache[0].setMemoryAllocator(allocator); |
378 } | 399 } |
379 | 400 |
380 protected: | 401 protected: |
402 // Finds the previous required frame for decoding the given frame based | |
403 // on the parsed meta data. Returns notFound if this frame doesn't | |
404 // require any previous frame. | |
405 // | |
406 // Subclasses should call this function and cache the result by calling | |
407 // ImageFrame::setRequiredPreviousFrame() when a new frame is created, | |
408 // and must ensure all previous frame's required previous frame has been | |
409 // cached before calling this method. | |
Peter Kasting
2013/05/29 02:02:18
Nit: How about this comment:
Calculates the most
Xianzhu
2013/05/29 18:37:01
Done.
| |
410 size_t findRequiredPreviousFrame(size_t frameIndex); | |
411 | |
412 virtual void clearFrameBuffer(size_t frameIndex); | |
413 | |
381 RefPtr<SharedBuffer> m_data; // The encoded data. | 414 RefPtr<SharedBuffer> m_data; // The encoded data. |
382 Vector<ImageFrame, 1> m_frameBufferCache; | 415 Vector<ImageFrame, 1> m_frameBufferCache; |
383 bool m_premultiplyAlpha; | 416 bool m_premultiplyAlpha; |
384 bool m_ignoreGammaAndColorProfile; | 417 bool m_ignoreGammaAndColorProfile; |
385 ImageOrientation m_orientation; | 418 ImageOrientation m_orientation; |
386 | 419 |
387 private: | 420 private: |
388 // Some code paths compute the size of the image as "width * height * 4" | 421 // Some code paths compute the size of the image as "width * height * 4" |
389 // and return it as a (signed) int. Avoid overflow. | 422 // and return it as a (signed) int. Avoid overflow. |
390 static bool isOverSize(unsigned width, unsigned height) | 423 static bool isOverSize(unsigned width, unsigned height) |
391 { | 424 { |
392 unsigned long long total_size = static_cast<unsigned long long>(widt h) | 425 unsigned long long total_size = static_cast<unsigned long long>(widt h) |
393 * static_cast<unsigned long long>(heig ht); | 426 * static_cast<unsigned long long>(heig ht); |
394 return total_size > ((1 << 29) - 1); | 427 return total_size > ((1 << 29) - 1); |
395 } | 428 } |
396 | 429 |
397 IntSize m_size; | 430 IntSize m_size; |
398 bool m_sizeAvailable; | 431 bool m_sizeAvailable; |
399 bool m_isAllDataReceived; | 432 bool m_isAllDataReceived; |
400 bool m_failed; | 433 bool m_failed; |
401 }; | 434 }; |
402 | 435 |
403 } // namespace WebCore | 436 } // namespace WebCore |
404 | 437 |
405 #endif | 438 #endif |
OLD | NEW |