| 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 virtual void setAnimationPolicy(ImageAnimationPolicy policy) override { m_an
imationPolicy = policy; } |
| 85 virtual ImageAnimationPolicy animationPolicy() override { return m_animation
Policy; } | 87 virtual ImageAnimationPolicy animationPolicy() override { return m_animation
Policy; } |
| 86 virtual void advanceTime(double deltaTimeInSeconds) override; | 88 virtual void advanceTime(double deltaTimeInSeconds) override; |
| 87 | 89 |
| 88 virtual bool bitmapForCurrentFrame(SkBitmap*) override; | 90 bool bitmapForCurrentFrame(SkBitmap*) override; |
| 89 virtual PassRefPtr<Image> imageForDefaultFrame() override; | 91 PassRefPtr<Image> imageForDefaultFrame() override; |
| 90 virtual bool currentFrameKnownToBeOpaque() override; | 92 bool currentFrameKnownToBeOpaque() override; |
| 91 ImageOrientation currentFrameOrientation(); | 93 ImageOrientation currentFrameOrientation(); |
| 92 | 94 |
| 93 #if ENABLE(ASSERT) | 95 #if ENABLE(ASSERT) |
| 94 virtual bool notSolidColor() override; | 96 bool notSolidColor() override; |
| 95 #endif | 97 #endif |
| 96 | 98 |
| 97 private: | 99 private: |
| 98 friend class BitmapImageTest; | 100 friend class BitmapImageTest; |
| 99 | 101 |
| 100 void updateSize() const; | 102 void updateSize() const; |
| 101 | 103 |
| 102 private: | 104 private: |
| 103 enum RepetitionCountStatus { | 105 enum RepetitionCountStatus { |
| 104 Unknown, // We haven't checked the source's repetition count. | 106 Unknown, // We haven't checked the source's repetition count. |
| 105 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 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 Certain // The repetition count is known to be correct. | 108 Certain // The repetition count is known to be correct. |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 BitmapImage(const SkBitmap &, ImageObserver* = 0); | 111 BitmapImage(const SkBitmap &, ImageObserver* = 0); |
| 110 BitmapImage(ImageObserver* = 0); | 112 BitmapImage(ImageObserver* = 0); |
| 111 | 113 |
| 112 void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRe
ct, SkXfermode::Mode, RespectImageOrientationEnum) override; | 114 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, bool shouldClampToSourceRect) override
; |
| 113 | 115 |
| 114 size_t currentFrame() const { return m_currentFrame; } | 116 size_t currentFrame() const { return m_currentFrame; } |
| 115 size_t frameCount(); | 117 size_t frameCount(); |
| 116 | 118 |
| 117 bool frameAtIndex(size_t, SkBitmap*) WARN_UNUSED_RETURN; | 119 bool frameAtIndex(size_t, SkBitmap*) WARN_UNUSED_RETURN; |
| 118 | 120 |
| 119 bool frameIsCompleteAtIndex(size_t); | 121 bool frameIsCompleteAtIndex(size_t); |
| 120 float frameDurationAtIndex(size_t); | 122 float frameDurationAtIndex(size_t); |
| 121 bool frameHasAlphaAtIndex(size_t); | 123 bool frameHasAlphaAtIndex(size_t); |
| 122 ImageOrientation frameOrientationAtIndex(size_t); | 124 ImageOrientation frameOrientationAtIndex(size_t); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 133 // the values from successive calls as signed expressions. | 135 // the values from successive calls as signed expressions. |
| 134 int totalFrameBytes(); | 136 int totalFrameBytes(); |
| 135 | 137 |
| 136 // Called to invalidate cached data. When |destroyAll| is true, we wipe out | 138 // Called to invalidate cached data. When |destroyAll| is true, we wipe out |
| 137 // the entire frame buffer cache and tell the image source to destroy | 139 // the entire frame buffer cache and tell the image source to destroy |
| 138 // everything; this is used when e.g. we want to free some room in the image | 140 // everything; this is used when e.g. we want to free some room in the image |
| 139 // cache. If |destroyAll| is false, we delete frames except the current | 141 // cache. If |destroyAll| is false, we delete frames except the current |
| 140 // frame; this is used while animating large images to keep memory footprint | 142 // frame; this is used while animating large images to keep memory footprint |
| 141 // low; the decoder should preserve the current frame and may preserve some | 143 // low; the decoder should preserve the current frame and may preserve some |
| 142 // other frames to avoid redecoding the whole image on every frame. | 144 // other frames to avoid redecoding the whole image on every frame. |
| 143 virtual void destroyDecodedData(bool destroyAll) override; | 145 void destroyDecodedData(bool destroyAll) override; |
| 144 | 146 |
| 145 // If the image is large enough, calls destroyDecodedData(). | 147 // If the image is large enough, calls destroyDecodedData(). |
| 146 void destroyDecodedDataIfNecessary(); | 148 void destroyDecodedDataIfNecessary(); |
| 147 | 149 |
| 148 // Generally called by destroyDecodedData(), destroys whole-image metadata | 150 // Generally called by destroyDecodedData(), destroys whole-image metadata |
| 149 // and notifies observers that the memory footprint has (hopefully) | 151 // and notifies observers that the memory footprint has (hopefully) |
| 150 // decreased by |frameBytesCleared|. | 152 // decreased by |frameBytesCleared|. |
| 151 void destroyMetadataAndNotify(size_t frameBytesCleared); | 153 void destroyMetadataAndNotify(size_t frameBytesCleared); |
| 152 | 154 |
| 153 // Whether or not size is available yet. | 155 // Whether or not size is available yet. |
| 154 bool isSizeAvailable(); | 156 bool isSizeAvailable(); |
| 155 | 157 |
| 156 // Animation. | 158 // Animation. |
| 157 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet
e| should be set if the caller knows the entire image has been decoded. | 159 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet
e| should be set if the caller knows the entire image has been decoded. |
| 158 bool shouldAnimate(); | 160 bool shouldAnimate(); |
| 159 virtual void startAnimation(CatchUpAnimation = CatchUp) override; | 161 void startAnimation(CatchUpAnimation = CatchUp) override; |
| 160 void advanceAnimation(Timer<BitmapImage>*); | 162 void advanceAnimation(Timer<BitmapImage>*); |
| 161 | 163 |
| 162 // Function that does the real work of advancing the animation. When | 164 // Function that does the real work of advancing the animation. When |
| 163 // skippingFrames is true, we're in the middle of a loop trying to skip over | 165 // skippingFrames is true, we're in the middle of a loop trying to skip over |
| 164 // a bunch of animation frames, so we should not do things like decode each | 166 // a bunch of animation frames, so we should not do things like decode each |
| 165 // one or notify our observers. | 167 // one or notify our observers. |
| 166 // Returns whether the animation was advanced. | 168 // Returns whether the animation was advanced. |
| 167 bool internalAdvanceAnimation(bool skippingFrames); | 169 bool internalAdvanceAnimation(bool skippingFrames); |
| 168 | 170 |
| 169 // Checks to see if the image is a 1x1 solid color. We optimize these image
s and just do a fill rect instead. | 171 // Checks to see if the image is a 1x1 solid color. We optimize these image
s and just do a fill rect instead. |
| 170 // This check should happen regardless whether m_checkedForSolidColor is alr
eady set, as the frame may have | 172 // This check should happen regardless whether m_checkedForSolidColor is alr
eady set, as the frame may have |
| 171 // changed. | 173 // changed. |
| 172 void checkForSolidColor(); | 174 void checkForSolidColor(); |
| 173 | 175 |
| 174 virtual bool mayFillWithSolidColor() override; | 176 bool mayFillWithSolidColor() override; |
| 175 virtual Color solidColor() const override; | 177 Color solidColor() const override; |
| 176 | 178 |
| 177 ImageSource m_source; | 179 ImageSource m_source; |
| 178 mutable IntSize m_size; // The size to use for the overall image (will just
be the size of the first image). | 180 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_sizeRespectingOrientation; | 181 mutable IntSize m_sizeRespectingOrientation; |
| 180 | 182 |
| 181 size_t m_currentFrame; // The index of the current frame of animation. | 183 size_t m_currentFrame; // The index of the current frame of animation. |
| 182 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. | 184 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 | 185 |
| 184 Timer<BitmapImage>* m_frameTimer; | 186 Timer<BitmapImage>* m_frameTimer; |
| 185 int m_repetitionCount; // How many total animation loops we should do. This
will be cAnimationNone if this image type is incapable of animation. | 187 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... |
| 203 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. | 205 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. |
| 204 mutable bool m_hasUniformFrameSize : 1; | 206 mutable bool m_hasUniformFrameSize : 1; |
| 205 mutable bool m_haveFrameCount : 1; | 207 mutable bool m_haveFrameCount : 1; |
| 206 }; | 208 }; |
| 207 | 209 |
| 208 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); | 210 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); |
| 209 | 211 |
| 210 } // namespace blink | 212 } // namespace blink |
| 211 | 213 |
| 212 #endif | 214 #endif |
| OLD | NEW |