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. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 String filenameExtension() const override; | 66 String filenameExtension() const override; |
67 bool dataChanged(bool allDataReceived) override; | 67 bool dataChanged(bool allDataReceived) override; |
68 | 68 |
69 bool isAllDataReceived() const { return m_allDataReceived; } | 69 bool isAllDataReceived() const { return m_allDataReceived; } |
70 bool hasColorProfile() const; | 70 bool hasColorProfile() const; |
71 | 71 |
72 // It may look unusual that there's no start animation call as public API. | 72 // It may look unusual that there's no start animation call as public API. |
73 // This because we start and stop animating lazily. Animation starts when | 73 // This because we start and stop animating lazily. Animation starts when |
74 // the image is rendered, and automatically pauses once all observers no | 74 // the image is rendered, and automatically pauses once all observers no |
75 // longer want to render the image. | 75 // longer want to render the image. |
76 void stopAnimation() override; | 76 void stopAnimation(); |
77 void resetAnimation() override; | 77 void resetAnimation() override; |
78 bool maybeAnimated() override; | 78 bool maybeAnimated() override; |
79 | 79 |
80 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP olicy = policy; } | 80 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP olicy = policy; } |
81 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy; } | 81 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy; } |
82 void advanceTime(double deltaTimeInSeconds) override; | 82 void advanceTime(double deltaTimeInSeconds) override; |
83 | 83 |
84 PassRefPtr<SkImage> imageForCurrentFrame() override; | 84 PassRefPtr<SkImage> imageForCurrentFrame() override; |
85 PassRefPtr<Image> imageForDefaultFrame() override; | 85 PassRefPtr<Image> imageForDefaultFrame() override; |
86 | 86 |
87 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override ; | 87 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override ; |
88 bool currentFrameIsComplete() override; | 88 bool currentFrameIsComplete() override; |
89 bool currentFrameIsLazyDecoded() override; | 89 bool currentFrameIsLazyDecoded() override; |
90 | 90 |
91 // Called to wipe out the entire frame buffer cache and tell the image | |
92 // source to destroy everything; this is used when e.g. we want to free | |
93 // some room in the image cache. | |
94 void destroyDecodedData() override; | |
95 | |
91 ImageOrientation currentFrameOrientation(); | 96 ImageOrientation currentFrameOrientation(); |
92 | 97 |
93 // Construct a BitmapImage with the given orientation. | 98 // Construct a BitmapImage with the given orientation. |
94 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma p&, ImageOrientation); | 99 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma p&, ImageOrientation); |
95 // Advance the image animation by one frame. | 100 // Advance the image animation by one frame. |
96 void advanceAnimationForTesting() override { internalAdvanceAnimation(false) ; } | 101 void advanceAnimationForTesting() override { internalAdvanceAnimation(false) ; } |
97 | 102 |
98 private: | 103 private: |
99 friend class BitmapImageTest; | 104 friend class BitmapImageTest; |
100 | 105 |
101 void updateSize() const; | 106 void updateSize() const; |
107 static void setAnimationCacheSizeForTesting(size_t maxCacheSize, size_t maxA nimationSizeInCache); | |
102 | 108 |
103 private: | 109 private: |
Peter Kasting
2016/04/28 23:07:54
Nit: While here: It's weird to have two private: s
aleksandar.stojiljkovic
2016/04/29 17:17:43
Done.
| |
104 enum RepetitionCountStatus { | 110 enum RepetitionCountStatus { |
105 Unknown, // We haven't checked the source's repetition count. | 111 Unknown, // We haven't checked the source's repetition count. |
106 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). | 112 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). |
107 Certain // The repetition count is known to be correct. | 113 Certain // The repetition count is known to be correct. |
108 }; | 114 }; |
109 | 115 |
110 BitmapImage(const SkBitmap &, ImageObserver* = 0); | 116 BitmapImage(const SkBitmap &, ImageObserver* = 0); |
111 BitmapImage(ImageObserver* = 0); | 117 BitmapImage(ImageObserver* = 0); |
112 | 118 |
113 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; | 119 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; |
114 | 120 |
115 size_t currentFrame() const { return m_currentFrame; } | 121 size_t currentFrame() const { return m_currentFrame; } |
116 size_t frameCount(); | 122 size_t frameCount(); |
117 | 123 |
118 PassRefPtr<SkImage> frameAtIndex(size_t); | 124 PassRefPtr<SkImage> frameAtIndex(size_t); |
119 | 125 |
120 bool frameIsCompleteAtIndex(size_t); | 126 bool frameIsCompleteAtIndex(size_t); |
121 float frameDurationAtIndex(size_t); | 127 float frameDurationAtIndex(size_t); |
122 bool frameHasAlphaAtIndex(size_t); | 128 bool frameHasAlphaAtIndex(size_t); |
123 ImageOrientation frameOrientationAtIndex(size_t); | 129 ImageOrientation frameOrientationAtIndex(size_t); |
124 | 130 |
125 // Decodes and caches a frame. Never accessed except internally. | 131 // Decodes and caches a frame. Never accessed except internally. |
126 void cacheFrame(size_t index); | 132 PassRefPtr<SkImage> cacheFrame(size_t index); |
127 | 133 |
128 // Called before accessing m_frames[index]. Returns false on index out of bo unds. | 134 // Helper method that is limiting cache size when animation frame gets cache d. |
129 bool ensureFrameIsCached(size_t index); | 135 void onAnimationFrameCached(size_t index); |
130 | 136 |
131 // Returns the total number of bytes allocated for all framebuffers, i.e. | 137 // Returns the total number of bytes allocated for all framebuffers, i.e. |
132 // the sum of m_source.frameBytesAtIndex(...) for all frames. This is | 138 // the sum of m_source.frameBytesAtIndex(...) for all frames. This is |
133 // returned as an int for caller convenience, to allow safely subtracting | 139 // returned as an int for caller convenience, to allow safely subtracting |
134 // the values from successive calls as signed expressions. | 140 // the values from successive calls as signed expressions. |
135 int totalFrameBytes(); | 141 int totalFrameBytes(); |
136 | 142 |
137 // Called to invalidate cached data. When |destroyAll| is true, we wipe out | |
138 // the entire frame buffer cache and tell the image source to destroy | |
139 // everything; this is used when e.g. we want to free some room in the image | |
140 // cache. If |destroyAll| is false, we delete frames except the current | |
141 // frame; this is used while animating large images to keep memory footprint | |
142 // low; the decoder should preserve the current frame and may preserve some | |
143 // other frames to avoid redecoding the whole image on every frame. | |
144 void destroyDecodedData(bool destroyAll) override; | |
145 | |
146 // If the image is large enough, calls destroyDecodedData(). | |
147 void destroyDecodedDataIfNecessary(); | |
148 | |
149 // Notifies observers that the memory footprint has changed. | 143 // Notifies observers that the memory footprint has changed. |
150 void notifyMemoryChanged(int delta); | 144 void notifyMemoryChanged(int delta); |
151 | 145 |
152 // Whether or not size is available yet. | 146 // Whether or not size is available yet. |
153 bool isSizeAvailable(); | 147 bool isSizeAvailable(); |
154 | 148 |
155 // Animation. | 149 // Animation. |
156 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet e| should be set if the caller knows the entire image has been decoded. | 150 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet e| should be set if the caller knows the entire image has been decoded. |
157 bool shouldAnimate(); | 151 bool shouldAnimate(); |
158 void startAnimation(CatchUpAnimation = CatchUp) override; | 152 void startAnimation(CatchUpAnimation = CatchUp) override; |
159 void advanceAnimation(Timer<BitmapImage>*); | 153 void advanceAnimation(Timer<BitmapImage>*); |
154 bool shouldCacheFrame(size_t index); | |
160 | 155 |
161 // Function that does the real work of advancing the animation. When | 156 // Function that does the real work of advancing the animation. When |
162 // skippingFrames is true, we're in the middle of a loop trying to skip over | 157 // skippingFrames is true, we're in the middle of a loop trying to skip over |
163 // a bunch of animation frames, so we should not do things like decode each | 158 // a bunch of animation frames, so we should not do things like decode each |
164 // one or notify our observers. | 159 // one or notify our observers. |
165 // Returns whether the animation was advanced. | 160 // Returns whether the animation was advanced. |
166 bool internalAdvanceAnimation(bool skippingFrames); | 161 bool internalAdvanceAnimation(bool skippingFrames); |
167 | 162 |
168 ImageSource m_source; | 163 ImageSource m_source; |
169 mutable IntSize m_size; // The size to use for the overall image (will just be the size of the first image). | 164 mutable IntSize m_size; // The size to use for the overall image (will just be the size of the first image). |
170 mutable IntSize m_sizeRespectingOrientation; | 165 mutable IntSize m_sizeRespectingOrientation; |
171 | 166 |
172 size_t m_currentFrame; // The index of the current frame of animation. | 167 size_t m_currentFrame; // The index of the current frame of animation. |
168 size_t m_disposeLaterFrame; // The index of the cached frame that should be disposed before accessing another one. | |
173 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. | 169 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. |
174 | 170 |
175 OwnPtr<Timer<BitmapImage>> m_frameTimer; | 171 OwnPtr<Timer<BitmapImage>> m_frameTimer; |
176 int m_repetitionCount; // How many total animation loops we should do. This will be cAnimationNone if this image type is incapable of animation. | 172 int m_repetitionCount; // How many total animation loops we should do. This will be cAnimationNone if this image type is incapable of animation. |
177 RepetitionCountStatus m_repetitionCountStatus; | 173 RepetitionCountStatus m_repetitionCountStatus; |
178 int m_repetitionsComplete; // How many repetitions we've finished. | 174 int m_repetitionsComplete; // How many repetitions we've finished. |
179 double m_desiredFrameStartTime; // The system time at which we hope to see the next call to startAnimation(). | 175 double m_desiredFrameStartTime; // The system time at which we hope to see the next call to startAnimation(). |
180 | 176 |
181 size_t m_frameCount; | 177 size_t m_frameCount; |
182 | 178 |
183 ImageAnimationPolicy m_animationPolicy; // Whether or not we can play animat ion. | 179 ImageAnimationPolicy m_animationPolicy; // Whether or not we can play animat ion. |
184 | 180 |
185 bool m_animationFinished : 1; // Whether or not we've completed the entire a nimation. | 181 bool m_animationFinished : 1; // Whether or not we've completed the entire a nimation. |
186 | 182 |
187 bool m_allDataReceived : 1; // Whether or not we've received all our data. | 183 bool m_allDataReceived : 1; // Whether or not we've received all our data. |
188 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable has the final overall image size yet. | 184 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable has the final overall image size yet. |
189 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi rst image frame yet from ImageIO. | 185 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi rst image frame yet from ImageIO. |
190 mutable bool m_hasUniformFrameSize : 1; | 186 mutable bool m_hasUniformFrameSize : 1; |
191 mutable bool m_haveFrameCount : 1; | 187 mutable bool m_haveFrameCount : 1; |
192 }; | 188 }; |
193 | 189 |
194 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); | 190 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); |
195 | 191 |
196 } // namespace blink | 192 } // namespace blink |
197 | 193 |
198 #endif | 194 #endif |
OLD | NEW |