Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 #include "platform/graphics/ImageSource.h" | 37 #include "platform/graphics/ImageSource.h" |
| 38 #include "platform/image-decoders/ImageAnimation.h" | 38 #include "platform/image-decoders/ImageAnimation.h" |
| 39 #include "wtf/Forward.h" | 39 #include "wtf/Forward.h" |
| 40 #include "wtf/OwnPtr.h" | 40 #include "wtf/OwnPtr.h" |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 template <typename T> class Timer; | 44 template <typename T> class Timer; |
| 45 | 45 |
| 46 class PLATFORM_EXPORT BitmapImage final : public Image { | 46 class PLATFORM_EXPORT BitmapImage final : public Image { |
| 47 friend class BitmapImageTest; | |
| 48 friend class CrossfadeGeneratedImage; | |
| 47 friend class GeneratedImage; | 49 friend class GeneratedImage; |
| 48 friend class CrossfadeGeneratedImage; | |
| 49 friend class GradientGeneratedImage; | 50 friend class GradientGeneratedImage; |
| 50 friend class GraphicsContext; | 51 friend class GraphicsContext; |
| 51 public: | 52 public: |
| 52 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) | 53 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) |
| 53 { | 54 { |
| 54 return adoptRef(new BitmapImage(observer)); | 55 return adoptRef(new BitmapImage(observer)); |
| 55 } | 56 } |
| 56 | 57 |
| 57 ~BitmapImage() override; | 58 ~BitmapImage() override; |
| 58 | 59 |
| 59 bool isBitmapImage() const override { return true; } | 60 bool isBitmapImage() const override { return true; } |
| 60 | 61 |
| 61 bool currentFrameHasSingleSecurityOrigin() const override; | 62 bool currentFrameHasSingleSecurityOrigin() const override; |
| 62 | 63 |
| 63 IntSize size() const override; | 64 IntSize size() const override; |
| 64 IntSize sizeRespectingOrientation() const; | 65 IntSize sizeRespectingOrientation() const; |
| 65 bool getHotSpot(IntPoint&) const override; | 66 bool getHotSpot(IntPoint&) const override; |
| 66 String filenameExtension() const override; | 67 String filenameExtension() const override; |
| 67 bool dataChanged(bool allDataReceived) override; | 68 bool dataChanged(bool allDataReceived) override; |
| 68 | |
| 69 bool isAllDataReceived() const { return m_allDataReceived; } | |
| 70 bool hasColorProfile() const; | |
| 71 | |
| 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 | |
| 74 // the image is rendered, and automatically pauses once all observers no | |
| 75 // longer want to render the image. | |
| 76 void stopAnimation() override; | |
| 77 void resetAnimation() override; | 69 void resetAnimation() override; |
| 78 bool maybeAnimated() override; | 70 bool maybeAnimated() override; |
| 79 | 71 |
| 80 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP olicy = policy; } | 72 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP olicy = policy; } |
| 81 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy; } | 73 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy; } |
| 82 void advanceTime(double deltaTimeInSeconds) override; | 74 void advanceTime(double deltaTimeInSeconds) override; |
| 83 | 75 |
| 84 PassRefPtr<SkImage> imageForCurrentFrame() override; | 76 PassRefPtr<SkImage> imageForCurrentFrame() override; |
| 85 PassRefPtr<Image> imageForDefaultFrame() override; | 77 PassRefPtr<Image> imageForDefaultFrame() override; |
| 86 | 78 |
| 87 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override ; | 79 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override ; |
| 88 bool currentFrameIsComplete() override; | 80 bool currentFrameIsComplete() override; |
| 89 bool currentFrameIsLazyDecoded() override; | 81 bool currentFrameIsLazyDecoded() override; |
| 90 | 82 |
| 83 // Called to wipe out the entire frame buffer cache and tell the image | |
| 84 // source to destroy everything; this is used when e.g. we want to free | |
| 85 // some room in the image cache. | |
| 86 void destroyDecodedData() override; | |
| 87 | |
| 88 bool isAllDataReceived() const { return m_allDataReceived; } | |
|
Peter Kasting
2016/05/09 22:31:25
Nit: When you move the declarations of functions,
aleksandar.stojiljkovic
2016/05/11 10:33:14
Difficult as there is already missmatch in order o
| |
| 89 bool hasColorProfile() const; | |
| 91 ImageOrientation currentFrameOrientation(); | 90 ImageOrientation currentFrameOrientation(); |
| 92 | 91 |
| 93 // Construct a BitmapImage with the given orientation. | 92 // Construct a BitmapImage with the given orientation. |
| 94 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma p&, ImageOrientation); | 93 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma p&, ImageOrientation); |
| 95 // Advance the image animation by one frame. | 94 // Advance the image animation by one frame. |
| 96 void advanceAnimationForTesting() override { internalAdvanceAnimation(false) ; } | 95 void advanceAnimationForTesting() override { internalAdvanceAnimation(false) ; } |
| 97 | 96 |
| 98 private: | 97 private: |
| 99 friend class BitmapImageTest; | |
| 100 | |
| 101 void updateSize() const; | |
| 102 | |
| 103 private: | |
| 104 enum RepetitionCountStatus { | 98 enum RepetitionCountStatus { |
| 105 Unknown, // We haven't checked the source's repetition count. | 99 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). | 100 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. | 101 Certain // The repetition count is known to be correct. |
| 108 }; | 102 }; |
| 109 | 103 |
| 110 BitmapImage(const SkBitmap &, ImageObserver* = 0); | 104 BitmapImage(const SkBitmap &, ImageObserver* = 0); |
| 111 BitmapImage(ImageObserver* = 0); | 105 BitmapImage(ImageObserver* = 0); |
| 112 | 106 |
| 113 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; | 107 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; |
| 114 | 108 |
| 109 void updateSize() const; | |
| 115 size_t currentFrame() const { return m_currentFrame; } | 110 size_t currentFrame() const { return m_currentFrame; } |
| 116 size_t frameCount(); | 111 size_t frameCount(); |
| 117 | 112 |
| 118 PassRefPtr<SkImage> frameAtIndex(size_t); | 113 PassRefPtr<SkImage> frameAtIndex(size_t); |
| 119 | 114 |
| 120 bool frameIsCompleteAtIndex(size_t); | 115 bool frameIsCompleteAtIndex(size_t); |
| 121 float frameDurationAtIndex(size_t); | 116 float frameDurationAtIndex(size_t); |
| 122 bool frameHasAlphaAtIndex(size_t); | 117 bool frameHasAlphaAtIndex(size_t); |
| 123 ImageOrientation frameOrientationAtIndex(size_t); | 118 ImageOrientation frameOrientationAtIndex(size_t); |
| 124 | 119 |
| 125 // Decodes and caches a frame. Never accessed except internally. | 120 PassRefPtr<SkImage> decodeAndCacheFrame(size_t index); |
| 126 void cacheFrame(size_t index); | |
| 127 | |
| 128 // Called before accessing m_frames[index]. Returns false on index out of bo unds. | |
| 129 bool ensureFrameIsCached(size_t index); | |
| 130 | 121 |
| 131 // Returns the total number of bytes allocated for all framebuffers, i.e. | 122 // Returns the total number of bytes allocated for all framebuffers, i.e. |
| 132 // the sum of m_source.frameBytesAtIndex(...) for all frames. | 123 // the sum of m_source.frameBytesAtIndex(...) for all frames. |
| 133 size_t totalFrameBytes(); | 124 size_t totalFrameBytes(); |
| 134 | 125 |
| 135 // 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 | |
| 137 // 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 | |
| 139 // 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 | |
| 141 // other frames to avoid redecoding the whole image on every frame. | |
| 142 void destroyDecodedData(bool destroyAll) override; | |
| 143 | |
| 144 // If the image is large enough, calls destroyDecodedData(). | |
| 145 void destroyDecodedDataIfNecessary(); | |
| 146 | |
| 147 // Notifies observers that the memory footprint has changed. | 126 // Notifies observers that the memory footprint has changed. |
| 148 void notifyMemoryChanged(); | 127 void notifyMemoryChanged(); |
| 149 | 128 |
| 150 // Whether or not size is available yet. | 129 // Whether or not size is available yet. |
| 151 bool isSizeAvailable(); | 130 bool isSizeAvailable(); |
| 152 | 131 |
| 153 // Animation. | 132 // Animation. |
| 154 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet e| should be set if the caller knows the entire image has been decoded. | 133 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet e| should be set if the caller knows the entire image has been decoded. |
| 155 bool shouldAnimate(); | 134 bool shouldAnimate(); |
| 156 void startAnimation(CatchUpAnimation = CatchUp) override; | 135 void startAnimation(CatchUpAnimation = CatchUp) override; |
| 157 void advanceAnimation(Timer<BitmapImage>*); | 136 void advanceAnimation(Timer<BitmapImage>*); |
| 158 | 137 |
| 138 // There's no start animation call because we start and stop animating | |
|
Peter Kasting
2016/05/09 22:31:25
Eh? startAnimation() is just a couple lines above
aleksandar.stojiljkovic
2016/05/11 10:33:14
Done.
| |
| 139 // lazily. Animation starts when the image is rendered, and automatically | |
| 140 // pauses once no observer wants to render the image. | |
| 141 void stopAnimation(); | |
| 142 | |
| 159 // Function that does the real work of advancing the animation. When | 143 // Function that does the real work of advancing the animation. When |
| 160 // skippingFrames is true, we're in the middle of a loop trying to skip over | 144 // skippingFrames is true, we're in the middle of a loop trying to skip over |
| 161 // a bunch of animation frames, so we should not do things like decode each | 145 // a bunch of animation frames, so we should not do things like decode each |
| 162 // one or notify our observers. | 146 // one or notify our observers. |
| 163 // Returns whether the animation was advanced. | 147 // Returns whether the animation was advanced. |
| 164 bool internalAdvanceAnimation(bool skippingFrames); | 148 bool internalAdvanceAnimation(bool skippingFrames); |
| 165 | 149 |
| 166 ImageSource m_source; | 150 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). | 151 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; | 152 mutable IntSize m_sizeRespectingOrientation; |
| 169 | 153 |
| 170 size_t m_currentFrame; // The index of the current frame of animation. | 154 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. | 155 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 | 156 |
| 157 RefPtr<SkImage> m_cachedFrame; // A cached copy of the most recently-accesse d frame. | |
| 158 size_t m_cachedFrameIndex; // Index of the frame that is cached. | |
| 159 | |
| 173 OwnPtr<Timer<BitmapImage>> m_frameTimer; | 160 OwnPtr<Timer<BitmapImage>> m_frameTimer; |
| 174 int m_repetitionCount; // How many total animation loops we should do. This will be cAnimationNone if this image type is incapable of animation. | 161 int m_repetitionCount; // How many total animation loops we should do. This will be cAnimationNone if this image type is incapable of animation. |
| 175 RepetitionCountStatus m_repetitionCountStatus; | 162 RepetitionCountStatus m_repetitionCountStatus; |
| 176 int m_repetitionsComplete; // How many repetitions we've finished. | 163 int m_repetitionsComplete; // How many repetitions we've finished. |
| 177 double m_desiredFrameStartTime; // The system time at which we hope to see the next call to startAnimation(). | 164 double m_desiredFrameStartTime; // The system time at which we hope to see the next call to startAnimation(). |
| 178 | 165 |
| 179 size_t m_frameCount; | 166 size_t m_frameCount; |
| 180 | 167 |
| 181 ImageAnimationPolicy m_animationPolicy; // Whether or not we can play animat ion. | 168 ImageAnimationPolicy m_animationPolicy; // Whether or not we can play animat ion. |
| 182 | 169 |
| 183 bool m_animationFinished : 1; // Whether or not we've completed the entire a nimation. | 170 bool m_animationFinished : 1; // Whether or not we've completed the entire a nimation. |
| 184 | 171 |
| 185 bool m_allDataReceived : 1; // Whether or not we've received all our data. | 172 bool m_allDataReceived : 1; // Whether or not we've received all our data. |
| 186 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable has the final overall image size yet. | 173 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable has the final overall image size yet. |
| 187 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi rst image frame yet from ImageIO. | 174 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi rst image frame yet from ImageIO. |
| 188 mutable bool m_hasUniformFrameSize : 1; | 175 mutable bool m_hasUniformFrameSize : 1; |
| 189 mutable bool m_haveFrameCount : 1; | 176 mutable bool m_haveFrameCount : 1; |
| 190 }; | 177 }; |
| 191 | 178 |
| 192 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); | 179 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); |
| 193 | 180 |
| 194 } // namespace blink | 181 } // namespace blink |
| 195 | 182 |
| 196 #endif | 183 #endif |
| OLD | NEW |