| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. |
| 4 * Copyright (C) 2008-2009 Torch Mobile, Inc. | 4 * Copyright (C) 2008-2009 Torch Mobile, Inc. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
| 14 * | 14 * |
| 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #ifndef BitmapImage_h | 28 #ifndef BitmapImage_h |
| 29 #define BitmapImage_h | 29 #define BitmapImage_h |
| 30 | 30 |
| 31 #include "core/platform/graphics/Color.h" | 31 #include "core/platform/graphics/Color.h" |
| 32 #include "core/platform/graphics/Image.h" | 32 #include "core/platform/graphics/Image.h" |
| 33 #include "core/platform/graphics/ImageOrientation.h" | 33 #include "core/platform/graphics/ImageOrientation.h" |
| 34 #include "core/platform/graphics/ImageSource.h" | 34 #include "core/platform/graphics/ImageSource.h" |
| 35 #include "core/platform/graphics/IntSize.h" | 35 #include "core/platform/graphics/IntSize.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 54 | 54 |
| 55 struct FrameData { | 55 struct FrameData { |
| 56 WTF_MAKE_NONCOPYABLE(FrameData); | 56 WTF_MAKE_NONCOPYABLE(FrameData); |
| 57 public: | 57 public: |
| 58 FrameData() | 58 FrameData() |
| 59 : m_frame(0) | 59 : m_frame(0) |
| 60 , m_orientation(DefaultImageOrientation) | 60 , m_orientation(DefaultImageOrientation) |
| 61 , m_duration(0) | 61 , m_duration(0) |
| 62 , m_haveMetadata(false) | 62 , m_haveMetadata(false) |
| 63 , m_isComplete(false) | 63 , m_isComplete(false) |
| 64 , m_hasAlpha(true) | 64 , m_hasAlpha(true) |
| 65 , m_frameBytes(0) | 65 , m_frameBytes(0) |
| 66 { | 66 { |
| 67 } | 67 } |
| 68 | 68 |
| 69 ~FrameData() | 69 ~FrameData() |
| 70 { | 70 { |
| 71 clear(true); | 71 clear(true); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Clear the cached image data on the frame, and (optionally) the metadata. | 74 // Clear the cached image data on the frame, and (optionally) the metadata. |
| 75 // Returns whether there was cached image data to clear. | 75 // Returns whether there was cached image data to clear. |
| 76 bool clear(bool clearMetadata); | 76 bool clear(bool clearMetadata); |
| 77 | 77 |
| 78 void reportMemoryUsage(MemoryObjectInfo*) const; | 78 void reportMemoryUsage(MemoryObjectInfo*) const; |
| 79 | 79 |
| 80 NativeImagePtr m_frame; | 80 NativeImagePtr m_frame; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 98 public: | 98 public: |
| 99 static PassRefPtr<BitmapImage> create(PassNativeImagePtr nativeImage, ImageO
bserver* observer = 0) | 99 static PassRefPtr<BitmapImage> create(PassNativeImagePtr nativeImage, ImageO
bserver* observer = 0) |
| 100 { | 100 { |
| 101 return adoptRef(new BitmapImage(nativeImage, observer)); | 101 return adoptRef(new BitmapImage(nativeImage, observer)); |
| 102 } | 102 } |
| 103 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) | 103 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) |
| 104 { | 104 { |
| 105 return adoptRef(new BitmapImage(observer)); | 105 return adoptRef(new BitmapImage(observer)); |
| 106 } | 106 } |
| 107 virtual ~BitmapImage(); | 107 virtual ~BitmapImage(); |
| 108 | 108 |
| 109 virtual bool isBitmapImage() const OVERRIDE; | 109 virtual bool isBitmapImage() const OVERRIDE; |
| 110 | 110 |
| 111 virtual bool hasSingleSecurityOrigin() const OVERRIDE; | 111 virtual bool hasSingleSecurityOrigin() const OVERRIDE; |
| 112 | 112 |
| 113 virtual IntSize size() const OVERRIDE; | 113 virtual IntSize size() const OVERRIDE; |
| 114 IntSize sizeRespectingOrientation() const; | 114 IntSize sizeRespectingOrientation() const; |
| 115 IntSize currentFrameSize() const; | 115 IntSize currentFrameSize() const; |
| 116 virtual bool getHotSpot(IntPoint&) const OVERRIDE; | 116 virtual bool getHotSpot(IntPoint&) const OVERRIDE; |
| 117 | 117 |
| 118 virtual bool dataChanged(bool allDataReceived) OVERRIDE; | 118 virtual bool dataChanged(bool allDataReceived) OVERRIDE; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 143 protected: | 143 protected: |
| 144 enum RepetitionCountStatus { | 144 enum RepetitionCountStatus { |
| 145 Unknown, // We haven't checked the source's repetition count. | 145 Unknown, // We haven't checked the source's repetition count. |
| 146 Uncertain, // We have a repetition count, but it might be wrong (some GIF
s have a count after the image data, and will report "loop once" until all data
has been decoded). | 146 Uncertain, // We have a repetition count, but it might be wrong (some GIF
s have a count after the image data, and will report "loop once" until all data
has been decoded). |
| 147 Certain // The repetition count is known to be correct. | 147 Certain // The repetition count is known to be correct. |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 BitmapImage(PassNativeImagePtr, ImageObserver* = 0); | 150 BitmapImage(PassNativeImagePtr, ImageObserver* = 0); |
| 151 BitmapImage(ImageObserver* = 0); | 151 BitmapImage(ImageObserver* = 0); |
| 152 | 152 |
| 153 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode) OVERRIDE; | 153 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, CompositeOperator, BlendMode) OVERRIDE; |
| 154 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, ColorSpace styleColorSpace, CompositeOperator, BlendMode, RespectIma
geOrientationEnum) OVERRIDE; | 154 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, CompositeOperator, BlendMode, RespectImageOrientationEnum) OVERRIDE; |
| 155 | 155 |
| 156 size_t currentFrame() const { return m_currentFrame; } | 156 size_t currentFrame() const { return m_currentFrame; } |
| 157 size_t frameCount(); | 157 size_t frameCount(); |
| 158 PassNativeImagePtr frameAtIndex(size_t); | 158 PassNativeImagePtr frameAtIndex(size_t); |
| 159 bool frameIsCompleteAtIndex(size_t); | 159 bool frameIsCompleteAtIndex(size_t); |
| 160 float frameDurationAtIndex(size_t); | 160 float frameDurationAtIndex(size_t); |
| 161 bool frameHasAlphaAtIndex(size_t); | 161 bool frameHasAlphaAtIndex(size_t); |
| 162 ImageOrientation frameOrientationAtIndex(size_t); | 162 ImageOrientation frameOrientationAtIndex(size_t); |
| 163 | 163 |
| 164 // Decodes and caches a frame. Never accessed except internally. | 164 // Decodes and caches a frame. Never accessed except internally. |
| 165 void cacheFrame(size_t index); | 165 void cacheFrame(size_t index); |
| 166 // Called before accessing m_frames[index]. Returns false on index out of bo
unds. | 166 // Called before accessing m_frames[index]. Returns false on index out of bo
unds. |
| 167 bool ensureFrameIsCached(size_t index); | 167 bool ensureFrameIsCached(size_t index); |
| 168 | 168 |
| 169 // Called to invalidate cached data. This is used while animating large | 169 // Called to invalidate cached data. This is used while animating large |
| 170 // images to keep memory footprint low. The decoder may preserve some frames | 170 // images to keep memory footprint low. The decoder may preserve some frames |
| 171 // to avoid redecoding the whole image on every frame. | 171 // to avoid redecoding the whole image on every frame. |
| 172 virtual void destroyDecodedData() OVERRIDE; | 172 virtual void destroyDecodedData() OVERRIDE; |
| 173 | 173 |
| 174 // If the image is large enough, calls destroyDecodedData(). | 174 // If the image is large enough, calls destroyDecodedData(). |
| 175 void destroyDecodedDataIfNecessary(); | 175 void destroyDecodedDataIfNecessary(); |
| 176 | 176 |
| 177 // Generally called by destroyDecodedData(), destroys whole-image metadata | 177 // Generally called by destroyDecodedData(), destroys whole-image metadata |
| 178 // and notifies observers that the memory footprint has (hopefully) | 178 // and notifies observers that the memory footprint has (hopefully) |
| 179 // decreased by |frameBytesCleared|. | 179 // decreased by |frameBytesCleared|. |
| 180 void destroyMetadataAndNotify(size_t frameBytesCleared); | 180 void destroyMetadataAndNotify(size_t frameBytesCleared); |
| 181 | 181 |
| 182 // Whether or not size is available yet. | 182 // Whether or not size is available yet. |
| 183 bool isSizeAvailable(); | 183 bool isSizeAvailable(); |
| 184 | 184 |
| 185 // Called after asking the source for any information that may require | 185 // Called after asking the source for any information that may require |
| 186 // decoding part of the image (e.g., the image size). We need to report | 186 // decoding part of the image (e.g., the image size). We need to report |
| 187 // the partially decoded data to our observer so it has an accurate | 187 // the partially decoded data to our observer so it has an accurate |
| 188 // account of the BitmapImage's memory usage. | 188 // account of the BitmapImage's memory usage. |
| 189 void didDecodeProperties() const; | 189 void didDecodeProperties() const; |
| 190 | 190 |
| 191 // Animation. | 191 // Animation. |
| 192 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet
e| should be set if the caller knows the entire image has been decoded. | 192 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet
e| should be set if the caller knows the entire image has been decoded. |
| 193 bool shouldAnimate(); | 193 bool shouldAnimate(); |
| 194 virtual void startAnimation(bool catchUpIfNecessary = true) OVERRIDE; | 194 virtual void startAnimation(bool catchUpIfNecessary = true) OVERRIDE; |
| 195 void advanceAnimation(Timer<BitmapImage>*); | 195 void advanceAnimation(Timer<BitmapImage>*); |
| 196 | 196 |
| 197 // Function that does the real work of advancing the animation. When | 197 // Function that does the real work of advancing the animation. When |
| 198 // skippingFrames is true, we're in the middle of a loop trying to skip over | 198 // skippingFrames is true, we're in the middle of a loop trying to skip over |
| 199 // a bunch of animation frames, so we should not do things like decode each | 199 // a bunch of animation frames, so we should not do things like decode each |
| 200 // one or notify our observers. | 200 // one or notify our observers. |
| 201 // Returns whether the animation was advanced. | 201 // Returns whether the animation was advanced. |
| 202 bool internalAdvanceAnimation(bool skippingFrames); | 202 bool internalAdvanceAnimation(bool skippingFrames); |
| 203 | 203 |
| 204 // Checks to see if the image is a 1x1 solid color. We optimize these image
s and just do a fill rect instead. | 204 // Checks to see if the image is a 1x1 solid color. We optimize these image
s and just do a fill rect instead. |
| 205 // This check should happen regardless whether m_checkedForSolidColor is alr
eady set, as the frame may have | 205 // This check should happen regardless whether m_checkedForSolidColor is alr
eady set, as the frame may have |
| 206 // changed. | 206 // changed. |
| 207 void checkForSolidColor(); | 207 void checkForSolidColor(); |
| 208 | 208 |
| 209 virtual bool mayFillWithSolidColor(); | 209 virtual bool mayFillWithSolidColor(); |
| 210 virtual Color solidColor() const; | 210 virtual Color solidColor() const; |
| 211 | 211 |
| 212 ImageSource m_source; | 212 ImageSource m_source; |
| 213 mutable IntSize m_size; // The size to use for the overall image (will just
be the size of the first image). | 213 mutable IntSize m_size; // The size to use for the overall image (will just
be the size of the first image). |
| 214 mutable IntSize m_sizeRespectingOrientation; | 214 mutable IntSize m_sizeRespectingOrientation; |
| 215 | 215 |
| 216 size_t m_currentFrame; // The index of the current frame of animation. | 216 size_t m_currentFrame; // The index of the current frame of animation. |
| 217 Vector<FrameData, 1> m_frames; // An array of the cached frames of the anima
tion. We have to ref frames to pin them in the cache. | 217 Vector<FrameData, 1> m_frames; // An array of the cached frames of the anima
tion. We have to ref frames to pin them in the cache. |
| 218 | 218 |
| 219 Timer<BitmapImage>* m_frameTimer; | 219 Timer<BitmapImage>* m_frameTimer; |
| 220 int m_repetitionCount; // How many total animation loops we should do. This
will be cAnimationNone if this image type is incapable of animation. | 220 int m_repetitionCount; // How many total animation loops we should do. This
will be cAnimationNone if this image type is incapable of animation. |
| 221 RepetitionCountStatus m_repetitionCountStatus; | 221 RepetitionCountStatus m_repetitionCountStatus; |
| 222 int m_repetitionsComplete; // How many repetitions we've finished. | 222 int m_repetitionsComplete; // How many repetitions we've finished. |
| 223 double m_desiredFrameStartTime; // The system time at which we hope to see
the next call to startAnimation(). | 223 double m_desiredFrameStartTime; // The system time at which we hope to see
the next call to startAnimation(). |
| 224 | 224 |
| 225 Color m_solidColor; // If we're a 1x1 solid color, this is the color to use
to fill. | 225 Color m_solidColor; // If we're a 1x1 solid color, this is the color to use
to fill. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 236 bool m_allDataReceived : 1; // Whether or not we've received all our data. | 236 bool m_allDataReceived : 1; // Whether or not we've received all our data. |
| 237 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable
has the final overall image size yet. | 237 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable
has the final overall image size yet. |
| 238 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. | 238 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. |
| 239 mutable bool m_hasUniformFrameSize : 1; | 239 mutable bool m_hasUniformFrameSize : 1; |
| 240 mutable bool m_haveFrameCount : 1; | 240 mutable bool m_haveFrameCount : 1; |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 } | 243 } |
| 244 | 244 |
| 245 #endif | 245 #endif |
| OLD | NEW |