| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) | 53 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) |
| 54 { | 54 { |
| 55 return adoptRef(new BitmapImage(observer)); | 55 return adoptRef(new BitmapImage(observer)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // This allows constructing a BitmapImage with a forced non-default orientat
ion. | 58 // This allows constructing a BitmapImage with a forced non-default orientat
ion. |
| 59 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma
p&, ImageOrientation); | 59 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma
p&, ImageOrientation); |
| 60 | 60 |
| 61 virtual ~BitmapImage(); | 61 virtual ~BitmapImage(); |
| 62 | 62 |
| 63 virtual bool isBitmapImage() const override; | 63 bool isBitmapImage() const override; |
| 64 bool isLazyDecodedBitmap() override; |
| 65 bool isImmutableBitmap() override; |
| 64 | 66 |
| 65 virtual bool currentFrameHasSingleSecurityOrigin() const override; | 67 bool currentFrameHasSingleSecurityOrigin() const override; |
| 66 | 68 |
| 67 virtual IntSize size() const override; | 69 IntSize size() const override; |
| 68 IntSize sizeRespectingOrientation() const; | 70 IntSize sizeRespectingOrientation() const; |
| 69 virtual bool getHotSpot(IntPoint&) const override; | 71 bool getHotSpot(IntPoint&) const override; |
| 70 virtual String filenameExtension() const override; | 72 String filenameExtension() const override; |
| 71 virtual bool dataChanged(bool allDataReceived) override; | 73 bool dataChanged(bool allDataReceived) override; |
| 72 | 74 |
| 73 bool isAllDataReceived() const { return m_allDataReceived; } | 75 bool isAllDataReceived() const { return m_allDataReceived; } |
| 74 bool hasColorProfile() const; | 76 bool hasColorProfile() const; |
| 75 | 77 |
| 76 // It may look unusual that there's no start animation call as public API. | 78 // It may look unusual that there's no start animation call as public API. |
| 77 // This because we start and stop animating lazily. Animation starts when | 79 // This because we start and stop animating lazily. Animation starts when |
| 78 // the image is rendered, and automatically pauses once all observers no | 80 // the image is rendered, and automatically pauses once all observers no |
| 79 // longer want to render the image. | 81 // longer want to render the image. |
| 80 virtual void stopAnimation() override; | 82 void stopAnimation() override; |
| 81 virtual void resetAnimation() override; | 83 void resetAnimation() override; |
| 82 virtual bool maybeAnimated() override; | 84 bool maybeAnimated() override; |
| 83 | 85 |
| 84 virtual void setAnimationPolicy(ImageAnimationPolicy policy) override { m_an
imationPolicy = policy; } | 86 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP
olicy = policy; } |
| 85 virtual ImageAnimationPolicy animationPolicy() override { return m_animation
Policy; } | 87 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy;
} |
| 86 | 88 |
| 87 virtual bool bitmapForCurrentFrame(SkBitmap*) override; | 89 bool bitmapForCurrentFrame(SkBitmap*) override; |
| 88 virtual PassRefPtr<Image> imageForDefaultFrame() override; | 90 PassRefPtr<Image> imageForDefaultFrame() override; |
| 89 virtual bool currentFrameKnownToBeOpaque() override; | 91 bool currentFrameKnownToBeOpaque() override; |
| 90 ImageOrientation currentFrameOrientation(); | 92 ImageOrientation currentFrameOrientation(); |
| 91 | 93 |
| 92 #if ENABLE(ASSERT) | 94 #if ENABLE(ASSERT) |
| 93 virtual bool notSolidColor() override; | 95 bool notSolidColor() override; |
| 94 #endif | 96 #endif |
| 95 | 97 |
| 96 private: | 98 private: |
| 97 friend class BitmapImageTest; | 99 friend class BitmapImageTest; |
| 98 | 100 |
| 99 void updateSize() const; | 101 void updateSize() const; |
| 100 | 102 |
| 101 private: | 103 private: |
| 102 enum RepetitionCountStatus { | 104 enum RepetitionCountStatus { |
| 103 Unknown, // We haven't checked the source's repetition count. | 105 Unknown, // We haven't checked the source's repetition count. |
| 104 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). | 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). |
| 105 Certain // The repetition count is known to be correct. | 107 Certain // The repetition count is known to be correct. |
| 106 }; | 108 }; |
| 107 | 109 |
| 108 BitmapImage(const SkBitmap &, ImageObserver* = 0); | 110 BitmapImage(const SkBitmap &, ImageObserver* = 0); |
| 109 BitmapImage(ImageObserver* = 0); | 111 BitmapImage(ImageObserver* = 0); |
| 110 | 112 |
| 111 void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRe
ct, SkXfermode::Mode, RespectImageOrientationEnum) override; | 113 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, bool shouldClampToSourceRect) override
; |
| 112 | 114 |
| 113 size_t currentFrame() const { return m_currentFrame; } | 115 size_t currentFrame() const { return m_currentFrame; } |
| 114 size_t frameCount(); | 116 size_t frameCount(); |
| 115 | 117 |
| 116 bool frameAtIndex(size_t, SkBitmap*) WARN_UNUSED_RETURN; | 118 bool frameAtIndex(size_t, SkBitmap*) WARN_UNUSED_RETURN; |
| 117 | 119 |
| 118 bool frameIsCompleteAtIndex(size_t); | 120 bool frameIsCompleteAtIndex(size_t); |
| 119 float frameDurationAtIndex(size_t); | 121 float frameDurationAtIndex(size_t); |
| 120 bool frameHasAlphaAtIndex(size_t); | 122 bool frameHasAlphaAtIndex(size_t); |
| 121 ImageOrientation frameOrientationAtIndex(size_t); | 123 ImageOrientation frameOrientationAtIndex(size_t); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 132 // the values from successive calls as signed expressions. | 134 // the values from successive calls as signed expressions. |
| 133 int totalFrameBytes(); | 135 int totalFrameBytes(); |
| 134 | 136 |
| 135 // Called to invalidate cached data. When |destroyAll| is true, we wipe out | 137 // Called to invalidate cached data. When |destroyAll| is true, we wipe out |
| 136 // the entire frame buffer cache and tell the image source to destroy | 138 // the entire frame buffer cache and tell the image source to destroy |
| 137 // everything; this is used when e.g. we want to free some room in the image | 139 // everything; this is used when e.g. we want to free some room in the image |
| 138 // cache. If |destroyAll| is false, we delete frames except the current | 140 // cache. If |destroyAll| is false, we delete frames except the current |
| 139 // frame; this is used while animating large images to keep memory footprint | 141 // frame; this is used while animating large images to keep memory footprint |
| 140 // low; the decoder should preserve the current frame and may preserve some | 142 // low; the decoder should preserve the current frame and may preserve some |
| 141 // other frames to avoid redecoding the whole image on every frame. | 143 // other frames to avoid redecoding the whole image on every frame. |
| 142 virtual void destroyDecodedData(bool destroyAll) override; | 144 void destroyDecodedData(bool destroyAll) override; |
| 143 | 145 |
| 144 // If the image is large enough, calls destroyDecodedData(). | 146 // If the image is large enough, calls destroyDecodedData(). |
| 145 void destroyDecodedDataIfNecessary(); | 147 void destroyDecodedDataIfNecessary(); |
| 146 | 148 |
| 147 // Generally called by destroyDecodedData(), destroys whole-image metadata | 149 // Generally called by destroyDecodedData(), destroys whole-image metadata |
| 148 // and notifies observers that the memory footprint has (hopefully) | 150 // and notifies observers that the memory footprint has (hopefully) |
| 149 // decreased by |frameBytesCleared|. | 151 // decreased by |frameBytesCleared|. |
| 150 void destroyMetadataAndNotify(size_t frameBytesCleared); | 152 void destroyMetadataAndNotify(size_t frameBytesCleared); |
| 151 | 153 |
| 152 // Whether or not size is available yet. | 154 // Whether or not size is available yet. |
| 153 bool isSizeAvailable(); | 155 bool isSizeAvailable(); |
| 154 | 156 |
| 155 // Animation. | 157 // Animation. |
| 156 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet
e| should be set if the caller knows the entire image has been decoded. | 158 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet
e| should be set if the caller knows the entire image has been decoded. |
| 157 bool shouldAnimate(); | 159 bool shouldAnimate(); |
| 158 virtual void startAnimation(CatchUpAnimation = CatchUp) override; | 160 void startAnimation(CatchUpAnimation = CatchUp) override; |
| 159 void advanceAnimation(Timer<BitmapImage>*); | 161 void advanceAnimation(Timer<BitmapImage>*); |
| 160 | 162 |
| 161 // Function that does the real work of advancing the animation. When | 163 // 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 | 164 // 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 | 165 // a bunch of animation frames, so we should not do things like decode each |
| 164 // one or notify our observers. | 166 // one or notify our observers. |
| 165 // Returns whether the animation was advanced. | 167 // Returns whether the animation was advanced. |
| 166 bool internalAdvanceAnimation(bool skippingFrames); | 168 bool internalAdvanceAnimation(bool skippingFrames); |
| 167 | 169 |
| 168 // Checks to see if the image is a 1x1 solid color. We optimize these image
s and just do a fill rect instead. | 170 // Checks to see if the image is a 1x1 solid color. We optimize these image
s and just do a fill rect instead. |
| 169 // This check should happen regardless whether m_checkedForSolidColor is alr
eady set, as the frame may have | 171 // This check should happen regardless whether m_checkedForSolidColor is alr
eady set, as the frame may have |
| 170 // changed. | 172 // changed. |
| 171 void checkForSolidColor(); | 173 void checkForSolidColor(); |
| 172 | 174 |
| 173 virtual bool mayFillWithSolidColor() override; | 175 bool mayFillWithSolidColor() override; |
| 174 virtual Color solidColor() const override; | 176 Color solidColor() const override; |
| 175 | 177 |
| 176 ImageSource m_source; | 178 ImageSource m_source; |
| 177 mutable IntSize m_size; // The size to use for the overall image (will just
be the size of the first image). | 179 mutable IntSize m_size; // The size to use for the overall image (will just
be the size of the first image). |
| 178 mutable IntSize m_sizeRespectingOrientation; | 180 mutable IntSize m_sizeRespectingOrientation; |
| 179 | 181 |
| 180 size_t m_currentFrame; // The index of the current frame of animation. | 182 size_t m_currentFrame; // The index of the current frame of animation. |
| 181 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. | 183 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. |
| 182 | 184 |
| 183 Timer<BitmapImage>* m_frameTimer; | 185 Timer<BitmapImage>* m_frameTimer; |
| 184 int m_repetitionCount; // How many total animation loops we should do. This
will be cAnimationNone if this image type is incapable of animation. | 186 int m_repetitionCount; // How many total animation loops we should do. This
will be cAnimationNone if this image type is incapable of animation. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 202 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. | 204 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. |
| 203 mutable bool m_hasUniformFrameSize : 1; | 205 mutable bool m_hasUniformFrameSize : 1; |
| 204 mutable bool m_haveFrameCount : 1; | 206 mutable bool m_haveFrameCount : 1; |
| 205 }; | 207 }; |
| 206 | 208 |
| 207 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); | 209 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); |
| 208 | 210 |
| 209 } // namespace blink | 211 } // namespace blink |
| 210 | 212 |
| 211 #endif | 213 #endif |
| OLD | NEW |