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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 public: | 49 public: |
50 static PassRefPtr<BitmapImage> create(PassRefPtr<NativeImageSkia>, ImageObse
rver* = 0); | 50 static PassRefPtr<BitmapImage> create(PassRefPtr<NativeImageSkia>, ImageObse
rver* = 0); |
51 | 51 |
52 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) | 52 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) |
53 { | 53 { |
54 return adoptRef(new BitmapImage(observer)); | 54 return adoptRef(new BitmapImage(observer)); |
55 } | 55 } |
56 | 56 |
57 virtual ~BitmapImage(); | 57 virtual ~BitmapImage(); |
58 | 58 |
59 virtual bool isBitmapImage() const OVERRIDE; | 59 virtual bool isBitmapImage() const override; |
60 | 60 |
61 virtual bool currentFrameHasSingleSecurityOrigin() const OVERRIDE; | 61 virtual bool currentFrameHasSingleSecurityOrigin() const override; |
62 | 62 |
63 virtual IntSize size() const OVERRIDE; | 63 virtual IntSize size() const override; |
64 IntSize sizeRespectingOrientation() const; | 64 IntSize sizeRespectingOrientation() const; |
65 virtual bool getHotSpot(IntPoint&) const OVERRIDE; | 65 virtual bool getHotSpot(IntPoint&) const override; |
66 virtual String filenameExtension() const OVERRIDE; | 66 virtual String filenameExtension() const override; |
67 virtual bool dataChanged(bool allDataReceived) OVERRIDE; | 67 virtual 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 void resetDecoder(); | 71 void resetDecoder(); |
72 | 72 |
73 // It may look unusual that there's no start animation call as public API. | 73 // It may look unusual that there's no start animation call as public API. |
74 // This because we start and stop animating lazily. Animation starts when | 74 // This because we start and stop animating lazily. Animation starts when |
75 // the image is rendered, and automatically pauses once all observers no | 75 // the image is rendered, and automatically pauses once all observers no |
76 // longer want to render the image. | 76 // longer want to render the image. |
77 virtual void stopAnimation() OVERRIDE; | 77 virtual void stopAnimation() override; |
78 virtual void resetAnimation() OVERRIDE; | 78 virtual void resetAnimation() override; |
79 virtual bool maybeAnimated() OVERRIDE; | 79 virtual bool maybeAnimated() override; |
80 | 80 |
81 virtual PassRefPtr<NativeImageSkia> nativeImageForCurrentFrame() OVERRIDE; | 81 virtual PassRefPtr<NativeImageSkia> nativeImageForCurrentFrame() override; |
82 virtual PassRefPtr<Image> imageForDefaultFrame() OVERRIDE; | 82 virtual PassRefPtr<Image> imageForDefaultFrame() override; |
83 virtual bool currentFrameKnownToBeOpaque() OVERRIDE; | 83 virtual bool currentFrameKnownToBeOpaque() override; |
84 ImageOrientation currentFrameOrientation(); | 84 ImageOrientation currentFrameOrientation(); |
85 | 85 |
86 #if ENABLE(ASSERT) | 86 #if ENABLE(ASSERT) |
87 virtual bool notSolidColor() OVERRIDE; | 87 virtual bool notSolidColor() override; |
88 #endif | 88 #endif |
89 | 89 |
90 private: | 90 private: |
91 friend class BitmapImageTest; | 91 friend class BitmapImageTest; |
92 | 92 |
93 void updateSize() const; | 93 void updateSize() const; |
94 | 94 |
95 protected: | 95 protected: |
96 enum RepetitionCountStatus { | 96 enum RepetitionCountStatus { |
97 Unknown, // We haven't checked the source's repetition count. | 97 Unknown, // We haven't checked the source's repetition count. |
98 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). | 98 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). |
99 Certain // The repetition count is known to be correct. | 99 Certain // The repetition count is known to be correct. |
100 }; | 100 }; |
101 | 101 |
102 BitmapImage(PassRefPtr<NativeImageSkia>, ImageObserver* = 0); | 102 BitmapImage(PassRefPtr<NativeImageSkia>, ImageObserver* = 0); |
103 BitmapImage(ImageObserver* = 0); | 103 BitmapImage(ImageObserver* = 0); |
104 | 104 |
105 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, CompositeOperator, WebBlendMode) OVERRIDE; | 105 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, CompositeOperator, WebBlendMode) override; |
106 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, CompositeOperator, WebBlendMode, RespectImageOrientationEnum) OVERRI
DE; | 106 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, CompositeOperator, WebBlendMode, RespectImageOrientationEnum) overri
de; |
107 | 107 |
108 size_t currentFrame() const { return m_currentFrame; } | 108 size_t currentFrame() const { return m_currentFrame; } |
109 size_t frameCount(); | 109 size_t frameCount(); |
110 | 110 |
111 PassRefPtr<NativeImageSkia> frameAtIndex(size_t); | 111 PassRefPtr<NativeImageSkia> frameAtIndex(size_t); |
112 | 112 |
113 bool frameIsCompleteAtIndex(size_t); | 113 bool frameIsCompleteAtIndex(size_t); |
114 float frameDurationAtIndex(size_t); | 114 float frameDurationAtIndex(size_t); |
115 bool frameHasAlphaAtIndex(size_t); | 115 bool frameHasAlphaAtIndex(size_t); |
116 ImageOrientation frameOrientationAtIndex(size_t); | 116 ImageOrientation frameOrientationAtIndex(size_t); |
117 | 117 |
118 // Decodes and caches a frame. Never accessed except internally. | 118 // Decodes and caches a frame. Never accessed except internally. |
119 void cacheFrame(size_t index); | 119 void cacheFrame(size_t index); |
120 | 120 |
121 // Called before accessing m_frames[index]. Returns false on index out of bo
unds. | 121 // Called before accessing m_frames[index]. Returns false on index out of bo
unds. |
122 bool ensureFrameIsCached(size_t index); | 122 bool ensureFrameIsCached(size_t index); |
123 | 123 |
124 // Called to invalidate cached data. When |destroyAll| is true, we wipe out | 124 // Called to invalidate cached data. When |destroyAll| is true, we wipe out |
125 // the entire frame buffer cache and tell the image source to destroy | 125 // the entire frame buffer cache and tell the image source to destroy |
126 // everything; this is used when e.g. we want to free some room in the image | 126 // everything; this is used when e.g. we want to free some room in the image |
127 // cache. If |destroyAll| is false, we delete frames except the current | 127 // cache. If |destroyAll| is false, we delete frames except the current |
128 // frame; this is used while animating large images to keep memory footprint | 128 // frame; this is used while animating large images to keep memory footprint |
129 // low; the decoder should preserve the current frame and may preserve some | 129 // low; the decoder should preserve the current frame and may preserve some |
130 // other frames to avoid redecoding the whole image on every frame. | 130 // other frames to avoid redecoding the whole image on every frame. |
131 virtual void destroyDecodedData(bool destroyAll) OVERRIDE; | 131 virtual void destroyDecodedData(bool destroyAll) override; |
132 | 132 |
133 // If the image is large enough, calls destroyDecodedData(). | 133 // If the image is large enough, calls destroyDecodedData(). |
134 void destroyDecodedDataIfNecessary(); | 134 void destroyDecodedDataIfNecessary(); |
135 | 135 |
136 // Generally called by destroyDecodedData(), destroys whole-image metadata | 136 // Generally called by destroyDecodedData(), destroys whole-image metadata |
137 // and notifies observers that the memory footprint has (hopefully) | 137 // and notifies observers that the memory footprint has (hopefully) |
138 // decreased by |frameBytesCleared|. | 138 // decreased by |frameBytesCleared|. |
139 void destroyMetadataAndNotify(size_t frameBytesCleared); | 139 void destroyMetadataAndNotify(size_t frameBytesCleared); |
140 | 140 |
141 // Whether or not size is available yet. | 141 // Whether or not size is available yet. |
142 bool isSizeAvailable(); | 142 bool isSizeAvailable(); |
143 | 143 |
144 // Animation. | 144 // Animation. |
145 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet
e| should be set if the caller knows the entire image has been decoded. | 145 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet
e| should be set if the caller knows the entire image has been decoded. |
146 bool shouldAnimate(); | 146 bool shouldAnimate(); |
147 virtual void startAnimation(CatchUpAnimation = CatchUp) OVERRIDE; | 147 virtual void startAnimation(CatchUpAnimation = CatchUp) override; |
148 void advanceAnimation(Timer<BitmapImage>*); | 148 void advanceAnimation(Timer<BitmapImage>*); |
149 | 149 |
150 // Function that does the real work of advancing the animation. When | 150 // Function that does the real work of advancing the animation. When |
151 // skippingFrames is true, we're in the middle of a loop trying to skip over | 151 // skippingFrames is true, we're in the middle of a loop trying to skip over |
152 // a bunch of animation frames, so we should not do things like decode each | 152 // a bunch of animation frames, so we should not do things like decode each |
153 // one or notify our observers. | 153 // one or notify our observers. |
154 // Returns whether the animation was advanced. | 154 // Returns whether the animation was advanced. |
155 bool internalAdvanceAnimation(bool skippingFrames); | 155 bool internalAdvanceAnimation(bool skippingFrames); |
156 | 156 |
157 // Checks to see if the image is a 1x1 solid color. We optimize these image
s and just do a fill rect instead. | 157 // Checks to see if the image is a 1x1 solid color. We optimize these image
s and just do a fill rect instead. |
158 // This check should happen regardless whether m_checkedForSolidColor is alr
eady set, as the frame may have | 158 // This check should happen regardless whether m_checkedForSolidColor is alr
eady set, as the frame may have |
159 // changed. | 159 // changed. |
160 void checkForSolidColor(); | 160 void checkForSolidColor(); |
161 | 161 |
162 virtual bool mayFillWithSolidColor() OVERRIDE; | 162 virtual bool mayFillWithSolidColor() override; |
163 virtual Color solidColor() const OVERRIDE; | 163 virtual Color solidColor() const override; |
164 | 164 |
165 private: | 165 private: |
166 ImageSource m_source; | 166 ImageSource m_source; |
167 mutable IntSize m_size; // The size to use for the overall image (will just
be the size of the first image). | 167 mutable IntSize m_size; // The size to use for the overall image (will just
be the size of the first image). |
168 mutable IntSize m_sizeRespectingOrientation; | 168 mutable IntSize m_sizeRespectingOrientation; |
169 | 169 |
170 size_t m_currentFrame; // The index of the current frame of animation. | 170 size_t m_currentFrame; // The index of the current frame of animation. |
171 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. | 171 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. |
172 | 172 |
173 Timer<BitmapImage>* m_frameTimer; | 173 Timer<BitmapImage>* m_frameTimer; |
(...skipping 16 matching lines...) Expand all Loading... |
190 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. | 190 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. |
191 mutable bool m_hasUniformFrameSize : 1; | 191 mutable bool m_hasUniformFrameSize : 1; |
192 mutable bool m_haveFrameCount : 1; | 192 mutable bool m_haveFrameCount : 1; |
193 }; | 193 }; |
194 | 194 |
195 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); | 195 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); |
196 | 196 |
197 } // namespace blink | 197 } // namespace blink |
198 | 198 |
199 #endif | 199 #endif |
OLD | NEW |