Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: Source/core/platform/graphics/BitmapImage.h

Issue 15969015: Reland again "Decode GIF image frames on demand". (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: For landing Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; 109 virtual bool isBitmapImage() const OVERRIDE;
110 110
111 virtual bool hasSingleSecurityOrigin() const; 111 virtual bool hasSingleSecurityOrigin() const OVERRIDE;
112 112
113 virtual IntSize size() const; 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; 116 virtual bool getHotSpot(IntPoint&) const OVERRIDE;
117 117
118 virtual bool dataChanged(bool allDataReceived); 118 virtual bool dataChanged(bool allDataReceived) OVERRIDE;
119 virtual String filenameExtension() const; 119 virtual String filenameExtension() const OVERRIDE;
120 120
121 // It may look unusual that there is no start animation call as public API. This is because 121 // It may look unusual that there is no start animation call as public API. This is because
122 // we start and stop animating lazily. Animation begins whenever someone dr aws the image. It will 122 // we start and stop animating lazily. Animation begins whenever someone dr aws the image. It will
123 // automatically pause once all observers no longer want to render the image anywhere. 123 // automatically pause once all observers no longer want to render the image anywhere.
124 virtual void stopAnimation(); 124 virtual void stopAnimation() OVERRIDE;
125 virtual void resetAnimation(); 125 virtual void resetAnimation() OVERRIDE;
126 126
127 virtual unsigned decodedSize() const; 127 virtual unsigned decodedSize() const OVERRIDE;
128 128
129 virtual PassNativeImagePtr nativeImageForCurrentFrame() OVERRIDE; 129 virtual PassNativeImagePtr nativeImageForCurrentFrame() OVERRIDE;
130 virtual bool currentFrameKnownToBeOpaque() OVERRIDE; 130 virtual bool currentFrameKnownToBeOpaque() OVERRIDE;
131 131
132 ImageOrientation currentFrameOrientation(); 132 ImageOrientation currentFrameOrientation();
133 133
134 #if !ASSERT_DISABLED 134 #if !ASSERT_DISABLED
135 virtual bool notSolidColor(); 135 virtual bool notSolidColor() OVERRIDE;
136 #endif 136 #endif
137 137
138 void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE; 138 void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
139 139
140 private: 140 private:
141 void updateSize() const; 141 void updateSize() const;
142 142
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); 153 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec t& srcRect, ColorSpace styleColorSpace, 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, ColorSpace styleColorSpace, CompositeOperator, BlendMode, RespectIma geOrientationEnum) OVERRIDE;
155 155
156 size_t currentFrame() const { return m_currentFrame; } 156 size_t currentFrame() const { return m_currentFrame; }
157 virtual 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. When |destroyAll| is true, we wipe out 169 // Called to invalidate cached data. This is used while animating large
170 // the entire frame buffer cache and tell the image source to destroy 170 // images to keep memory footprint low. The decoder may preserve some frames
171 // everything; this is used when e.g. we want to free some room in the image 171 // to avoid redecoding the whole image on every frame.
172 // cache. If |destroyAll| is false, we only delete frames up to the current 172 virtual void destroyDecodedData() OVERRIDE;
173 // one; this is used while animating large images to keep memory footprint
174 // low without redecoding the whole image on every frame.
175 virtual void destroyDecodedData(bool destroyAll = true);
176 173
177 // If the image is large enough, calls destroyDecodedData() and passes 174 // If the image is large enough, calls destroyDecodedData().
178 // |destroyAll| along. 175 void destroyDecodedDataIfNecessary();
179 void destroyDecodedDataIfNecessary(bool destroyAll);
180 176
181 // Generally called by destroyDecodedData(), destroys whole-image metadata 177 // Generally called by destroyDecodedData(), destroys whole-image metadata
182 // and notifies observers that the memory footprint has (hopefully) 178 // and notifies observers that the memory footprint has (hopefully)
183 // decreased by |frameBytesCleared|. 179 // decreased by |frameBytesCleared|.
184 void destroyMetadataAndNotify(unsigned frameBytesCleared); 180 void destroyMetadataAndNotify(size_t frameBytesCleared);
185 181
186 // Whether or not size is available yet. 182 // Whether or not size is available yet.
187 bool isSizeAvailable(); 183 bool isSizeAvailable();
188 184
189 // Called after asking the source for any information that may require 185 // Called after asking the source for any information that may require
190 // 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
191 // 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
192 // account of the BitmapImage's memory usage. 188 // account of the BitmapImage's memory usage.
193 void didDecodeProperties() const; 189 void didDecodeProperties() const;
194 190
195 // Animation. 191 // Animation.
196 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.
197 bool shouldAnimate(); 193 bool shouldAnimate();
198 virtual void startAnimation(bool catchUpIfNecessary = true); 194 virtual void startAnimation(bool catchUpIfNecessary = true) OVERRIDE;
199 void advanceAnimation(Timer<BitmapImage>*); 195 void advanceAnimation(Timer<BitmapImage>*);
200 196
201 // Function that does the real work of advancing the animation. When 197 // Function that does the real work of advancing the animation. When
202 // 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
203 // 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
204 // one or notify our observers. 200 // one or notify our observers.
205 // Returns whether the animation was advanced. 201 // Returns whether the animation was advanced.
206 bool internalAdvanceAnimation(bool skippingFrames); 202 bool internalAdvanceAnimation(bool skippingFrames);
207 203
208 // 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.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 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.
241 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.
242 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.
243 mutable bool m_hasUniformFrameSize : 1; 239 mutable bool m_hasUniformFrameSize : 1;
244 mutable bool m_haveFrameCount : 1; 240 mutable bool m_haveFrameCount : 1;
245 }; 241 };
246 242
247 } 243 }
248 244
249 #endif 245 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698