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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 enum FrameDisposalMethod { | 57 enum FrameDisposalMethod { |
58 // If you change the numeric values of these, make sure you audit | 58 // If you change the numeric values of these, make sure you audit |
59 // all users, as some users may cast raw values to/from these | 59 // all users, as some users may cast raw values to/from these |
60 // constants. | 60 // constants. |
61 DisposeNotSpecified, // Leave frame in framebuffer | 61 DisposeNotSpecified, // Leave frame in framebuffer |
62 DisposeKeep, // Leave frame in framebuffer | 62 DisposeKeep, // Leave frame in framebuffer |
63 DisposeOverwriteBgcolor, // Clear frame to transparent | 63 DisposeOverwriteBgcolor, // Clear frame to transparent |
64 DisposeOverwritePrevious // Clear frame to previous framebuffer | 64 DisposeOverwritePrevious // Clear frame to previous framebuffer |
65 // contents | 65 // contents |
66 }; | 66 }; |
67 // Indicates how transparent pixels of the current frame rectangles are | |
68 // blended with those of the previous frame buffer. | |
69 enum FrameBlendingMethod { | |
70 BlendWithPrevious, // Compose the rectangle of current frame by blen ding it with corresponding pixels in the previous (disposed) framebuffer. | |
71 BlendOverwrite, // Compose the rectangle of current frame by over-wr iting the corresponding pixels in the previous (disposed) framebuffer. | |
72 }; | |
Peter Kasting
2013/08/22 00:08:37
I don't think I really understand what's going on
urvang (Google)
2013/08/22 01:49:36
That's the idea, more of less.
To be more precise
| |
67 typedef uint32_t PixelData; | 73 typedef uint32_t PixelData; |
68 | 74 |
69 ImageFrame(); | 75 ImageFrame(); |
70 | 76 |
71 ImageFrame(const ImageFrame& other) { operator=(other); } | 77 ImageFrame(const ImageFrame& other) { operator=(other); } |
72 | 78 |
73 // For backends which refcount their data, this operator doesn't need to | 79 // For backends which refcount their data, this operator doesn't need to |
74 // create a new copy of the image data, only increase the ref count. | 80 // create a new copy of the image data, only increase the ref count. |
75 ImageFrame& operator=(const ImageFrame& other); | 81 ImageFrame& operator=(const ImageFrame& other); |
76 | 82 |
(...skipping 30 matching lines...) Expand all Loading... | |
107 // Returns a caller-owned pointer to the underlying native image data. | 113 // Returns a caller-owned pointer to the underlying native image data. |
108 // (Actual use: This pointer will be owned by BitmapImage and freed in | 114 // (Actual use: This pointer will be owned by BitmapImage and freed in |
109 // FrameData::clear()). | 115 // FrameData::clear()). |
110 PassRefPtr<NativeImageSkia> asNewNativeImage() const; | 116 PassRefPtr<NativeImageSkia> asNewNativeImage() const; |
111 | 117 |
112 bool hasAlpha() const; | 118 bool hasAlpha() const; |
113 const IntRect& originalFrameRect() const { return m_originalFrameRect; } | 119 const IntRect& originalFrameRect() const { return m_originalFrameRect; } |
114 FrameStatus status() const { return m_status; } | 120 FrameStatus status() const { return m_status; } |
115 unsigned duration() const { return m_duration; } | 121 unsigned duration() const { return m_duration; } |
116 FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } | 122 FrameDisposalMethod disposalMethod() const { return m_disposalMethod; } |
123 FrameBlendingMethod blendingMethod() const { return m_blendingMethod; } | |
117 bool premultiplyAlpha() const { return m_premultiplyAlpha; } | 124 bool premultiplyAlpha() const { return m_premultiplyAlpha; } |
118 SkBitmap::Allocator* allocator() const { return m_allocator; } | 125 SkBitmap::Allocator* allocator() const { return m_allocator; } |
119 const SkBitmap& getSkBitmap() const { return m_bitmap->bitmap(); } | 126 const SkBitmap& getSkBitmap() const { return m_bitmap->bitmap(); } |
120 | 127 |
121 size_t requiredPreviousFrameIndex() const | 128 size_t requiredPreviousFrameIndex() const |
122 { | 129 { |
123 ASSERT(m_requiredPreviousFrameIndexValid); | 130 ASSERT(m_requiredPreviousFrameIndexValid); |
124 return m_requiredPreviousFrameIndex; | 131 return m_requiredPreviousFrameIndex; |
125 } | 132 } |
126 #if !ASSERT_DISABLED | 133 #if !ASSERT_DISABLED |
127 bool requiredPreviousFrameIndexValid() const { return m_requiredPrevious FrameIndexValid; } | 134 bool requiredPreviousFrameIndexValid() const { return m_requiredPrevious FrameIndexValid; } |
128 #endif | 135 #endif |
129 void setHasAlpha(bool alpha); | 136 void setHasAlpha(bool alpha); |
130 void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } | 137 void setOriginalFrameRect(const IntRect& r) { m_originalFrameRect = r; } |
131 void setStatus(FrameStatus status); | 138 void setStatus(FrameStatus status); |
132 void setDuration(unsigned duration) { m_duration = duration; } | 139 void setDuration(unsigned duration) { m_duration = duration; } |
133 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } | 140 void setDisposalMethod(FrameDisposalMethod method) { m_disposalMethod = method; } |
141 void setBlendingMethod(FrameBlendingMethod method) { m_blendingMethod = method; } | |
134 void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = p remultiplyAlpha; } | 142 void setPremultiplyAlpha(bool premultiplyAlpha) { m_premultiplyAlpha = p remultiplyAlpha; } |
135 void setMemoryAllocator(SkBitmap::Allocator* allocator) { m_allocator = allocator; } | 143 void setMemoryAllocator(SkBitmap::Allocator* allocator) { m_allocator = allocator; } |
136 void setSkBitmap(const SkBitmap& bitmap) { m_bitmap = NativeImageSkia::c reate(bitmap); } | 144 void setSkBitmap(const SkBitmap& bitmap) { m_bitmap = NativeImageSkia::c reate(bitmap); } |
137 | 145 |
138 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) | 146 void setRequiredPreviousFrameIndex(size_t previousFrameIndex) |
139 { | 147 { |
140 m_requiredPreviousFrameIndex = previousFrameIndex; | 148 m_requiredPreviousFrameIndex = previousFrameIndex; |
141 #if !ASSERT_DISABLED | 149 #if !ASSERT_DISABLED |
142 m_requiredPreviousFrameIndexValid = true; | 150 m_requiredPreviousFrameIndexValid = true; |
143 #endif | 151 #endif |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 | 200 |
193 RefPtr<NativeImageSkia> m_bitmap; | 201 RefPtr<NativeImageSkia> m_bitmap; |
194 SkBitmap::Allocator* m_allocator; | 202 SkBitmap::Allocator* m_allocator; |
195 bool m_hasAlpha; | 203 bool m_hasAlpha; |
196 // This will always just be the entire buffer except for GIF or WebP | 204 // This will always just be the entire buffer except for GIF or WebP |
197 // frames whose original rect was smaller than the overall image size. | 205 // frames whose original rect was smaller than the overall image size. |
198 IntRect m_originalFrameRect; | 206 IntRect m_originalFrameRect; |
199 FrameStatus m_status; | 207 FrameStatus m_status; |
200 unsigned m_duration; | 208 unsigned m_duration; |
201 FrameDisposalMethod m_disposalMethod; | 209 FrameDisposalMethod m_disposalMethod; |
210 FrameBlendingMethod m_blendingMethod; | |
202 bool m_premultiplyAlpha; | 211 bool m_premultiplyAlpha; |
203 | 212 |
204 // The frame that must be decoded before this frame can be decoded. | 213 // The frame that must be decoded before this frame can be decoded. |
205 // WTF::notFound if this frame doesn't require any previous frame. | 214 // WTF::notFound if this frame doesn't require any previous frame. |
206 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never | 215 // This is used by ImageDecoder::clearCacheExceptFrame(), and will never |
207 // be read for image formats that do not have multiple frames. | 216 // be read for image formats that do not have multiple frames. |
208 size_t m_requiredPreviousFrameIndex; | 217 size_t m_requiredPreviousFrameIndex; |
209 #if !ASSERT_DISABLED | 218 #if !ASSERT_DISABLED |
210 bool m_requiredPreviousFrameIndexValid; | 219 bool m_requiredPreviousFrameIndexValid; |
211 #endif | 220 #endif |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 // If the image has a cursor hot-spot, stores it in the argument | 385 // If the image has a cursor hot-spot, stores it in the argument |
377 // and returns true. Otherwise returns false. | 386 // and returns true. Otherwise returns false. |
378 virtual bool hotSpot(IntPoint&) const { return false; } | 387 virtual bool hotSpot(IntPoint&) const { return false; } |
379 | 388 |
380 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) | 389 virtual void setMemoryAllocator(SkBitmap::Allocator* allocator) |
381 { | 390 { |
382 // FIXME: this doesn't work for images with multiple frames. | 391 // FIXME: this doesn't work for images with multiple frames. |
383 if (m_frameBufferCache.isEmpty()) { | 392 if (m_frameBufferCache.isEmpty()) { |
384 m_frameBufferCache.resize(1); | 393 m_frameBufferCache.resize(1); |
385 m_frameBufferCache[0].setRequiredPreviousFrameIndex( | 394 m_frameBufferCache[0].setRequiredPreviousFrameIndex( |
386 findRequiredPreviousFrame(0)); | 395 findRequiredPreviousFrame(0, false)); |
387 } | 396 } |
388 m_frameBufferCache[0].setMemoryAllocator(allocator); | 397 m_frameBufferCache[0].setMemoryAllocator(allocator); |
389 } | 398 } |
390 | 399 |
391 protected: | 400 protected: |
392 // Calculates the most recent frame whose image data may be needed in | 401 // Calculates the most recent frame whose image data may be needed in |
393 // order to decode frame |frameIndex|, based on frame disposal methods. | 402 // order to decode frame |frameIndex|, based on frame disposal methods |
403 // and 'frameRectIsOpaque', where 'frameRectIsOpaque' signifies whether | |
404 // the rectangle of frame at 'frameIndex' is known to be opaque. | |
394 // If no previous frame's data is required, returns WTF::notFound. | 405 // If no previous frame's data is required, returns WTF::notFound. |
395 // | 406 // |
396 // This function requires that the previous frame's | 407 // This function requires that the previous frame's |
397 // |m_requiredPreviousFrameIndex| member has been set correctly. The | 408 // |m_requiredPreviousFrameIndex| member has been set correctly. The |
398 // easiest way to ensure this is for subclasses to call this method and | 409 // easiest way to ensure this is for subclasses to call this method and |
399 // store the result on the frame via setRequiredPreviousFrameIndex() | 410 // store the result on the frame via setRequiredPreviousFrameIndex() |
400 // as soon as the frame has been created and parsed sufficiently to | 411 // as soon as the frame has been created and parsed sufficiently to |
401 // determine the disposal method; assuming this happens for all frames | 412 // determine the disposal method; assuming this happens for all frames |
402 // in order, the required invariant will hold. | 413 // in order, the required invariant will hold. |
403 // | 414 // |
404 // Image formats which do not use more than one frame do not need to | 415 // Image formats which do not use more than one frame do not need to |
405 // worry about this; see comments on | 416 // worry about this; see comments on |
406 // ImageFrame::m_requiredPreviousFrameIndex. | 417 // ImageFrame::m_requiredPreviousFrameIndex. |
407 size_t findRequiredPreviousFrame(size_t frameIndex); | 418 size_t findRequiredPreviousFrame(size_t frameIndex, bool frameRectIsOpaq ue); |
408 | 419 |
409 virtual void clearFrameBuffer(size_t frameIndex); | 420 virtual void clearFrameBuffer(size_t frameIndex); |
410 | 421 |
411 RefPtr<SharedBuffer> m_data; // The encoded data. | 422 RefPtr<SharedBuffer> m_data; // The encoded data. |
412 Vector<ImageFrame, 1> m_frameBufferCache; | 423 Vector<ImageFrame, 1> m_frameBufferCache; |
413 bool m_premultiplyAlpha; | 424 bool m_premultiplyAlpha; |
414 bool m_ignoreGammaAndColorProfile; | 425 bool m_ignoreGammaAndColorProfile; |
415 ImageOrientation m_orientation; | 426 ImageOrientation m_orientation; |
416 | 427 |
417 private: | 428 private: |
418 // Some code paths compute the size of the image as "width * height * 4" | 429 // Some code paths compute the size of the image as "width * height * 4" |
419 // and return it as a (signed) int. Avoid overflow. | 430 // and return it as a (signed) int. Avoid overflow. |
420 static bool isOverSize(unsigned width, unsigned height) | 431 static bool isOverSize(unsigned width, unsigned height) |
421 { | 432 { |
422 unsigned long long total_size = static_cast<unsigned long long>(widt h) | 433 unsigned long long total_size = static_cast<unsigned long long>(widt h) |
423 * static_cast<unsigned long long>(heig ht); | 434 * static_cast<unsigned long long>(heig ht); |
424 return total_size > ((1 << 29) - 1); | 435 return total_size > ((1 << 29) - 1); |
425 } | 436 } |
426 | 437 |
427 IntSize m_size; | 438 IntSize m_size; |
428 bool m_sizeAvailable; | 439 bool m_sizeAvailable; |
429 bool m_isAllDataReceived; | 440 bool m_isAllDataReceived; |
430 bool m_failed; | 441 bool m_failed; |
431 }; | 442 }; |
432 | 443 |
433 } // namespace WebCore | 444 } // namespace WebCore |
434 | 445 |
435 #endif | 446 #endif |
OLD | NEW |