| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "platform/Timer.h" | 31 #include "platform/Timer.h" |
| 32 #include "platform/geometry/IntSize.h" | 32 #include "platform/geometry/IntSize.h" |
| 33 #include "platform/graphics/Color.h" | 33 #include "platform/graphics/Color.h" |
| 34 #include "platform/graphics/FrameData.h" | 34 #include "platform/graphics/FrameData.h" |
| 35 #include "platform/graphics/Image.h" | 35 #include "platform/graphics/Image.h" |
| 36 #include "platform/graphics/ImageAnimationPolicy.h" | 36 #include "platform/graphics/ImageAnimationPolicy.h" |
| 37 #include "platform/graphics/ImageOrientation.h" | 37 #include "platform/graphics/ImageOrientation.h" |
| 38 #include "platform/graphics/ImageSource.h" | 38 #include "platform/graphics/ImageSource.h" |
| 39 #include "platform/image-decoders/ImageAnimation.h" | 39 #include "platform/image-decoders/ImageAnimation.h" |
| 40 #include "third_party/skia/include/core/SkRefCnt.h" |
| 40 #include "wtf/Forward.h" | 41 #include "wtf/Forward.h" |
| 41 #include <memory> | 42 #include <memory> |
| 42 | 43 |
| 43 namespace blink { | 44 namespace blink { |
| 44 | 45 |
| 45 class PLATFORM_EXPORT BitmapImage final : public Image { | 46 class PLATFORM_EXPORT BitmapImage final : public Image { |
| 46 friend class BitmapImageTest; | 47 friend class BitmapImageTest; |
| 47 friend class CrossfadeGeneratedImage; | 48 friend class CrossfadeGeneratedImage; |
| 48 friend class GeneratedImage; | 49 friend class GeneratedImage; |
| 49 friend class GradientGeneratedImage; | 50 friend class GradientGeneratedImage; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 71 bool isAllDataReceived() const { return m_allDataReceived; } | 72 bool isAllDataReceived() const { return m_allDataReceived; } |
| 72 bool hasColorProfile() const; | 73 bool hasColorProfile() const; |
| 73 | 74 |
| 74 void resetAnimation() override; | 75 void resetAnimation() override; |
| 75 bool maybeAnimated() override; | 76 bool maybeAnimated() override; |
| 76 | 77 |
| 77 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP
olicy = policy; } | 78 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP
olicy = policy; } |
| 78 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy;
} | 79 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy;
} |
| 79 void advanceTime(double deltaTimeInSeconds) override; | 80 void advanceTime(double deltaTimeInSeconds) override; |
| 80 | 81 |
| 81 PassRefPtr<SkImage> imageForCurrentFrame() override; | 82 sk_sp<SkImage> imageForCurrentFrame() override; |
| 82 PassRefPtr<Image> imageForDefaultFrame() override; | 83 PassRefPtr<Image> imageForDefaultFrame() override; |
| 83 | 84 |
| 84 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override
; | 85 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override
; |
| 85 bool currentFrameIsComplete() override; | 86 bool currentFrameIsComplete() override; |
| 86 bool currentFrameIsLazyDecoded() override; | 87 bool currentFrameIsLazyDecoded() override; |
| 87 | 88 |
| 88 ImageOrientation currentFrameOrientation(); | 89 ImageOrientation currentFrameOrientation(); |
| 89 | 90 |
| 90 // Construct a BitmapImage with the given orientation. | 91 // Construct a BitmapImage with the given orientation. |
| 91 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma
p&, ImageOrientation); | 92 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma
p&, ImageOrientation); |
| 92 // Advance the image animation by one frame. | 93 // Advance the image animation by one frame. |
| 93 void advanceAnimationForTesting() override { internalAdvanceAnimation(); } | 94 void advanceAnimationForTesting() override { internalAdvanceAnimation(); } |
| 94 | 95 |
| 95 private: | 96 private: |
| 96 enum RepetitionCountStatus { | 97 enum RepetitionCountStatus { |
| 97 Unknown, // We haven't checked the source's repetition count. | 98 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). | 99 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. | 100 Certain // The repetition count is known to be correct. |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 BitmapImage(const SkBitmap &, ImageObserver* = 0); | 103 BitmapImage(const SkBitmap &, ImageObserver* = 0); |
| 103 BitmapImage(ImageObserver* = 0); | 104 BitmapImage(ImageObserver* = 0); |
| 104 | 105 |
| 105 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; | 106 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; |
| 106 | 107 |
| 107 size_t currentFrame() const { return m_currentFrame; } | 108 size_t currentFrame() const { return m_currentFrame; } |
| 108 size_t frameCount(); | 109 size_t frameCount(); |
| 109 | 110 |
| 110 PassRefPtr<SkImage> frameAtIndex(size_t); | 111 sk_sp<SkImage> frameAtIndex(size_t); |
| 111 | 112 |
| 112 bool frameIsCompleteAtIndex(size_t); | 113 bool frameIsCompleteAtIndex(size_t); |
| 113 float frameDurationAtIndex(size_t); | 114 float frameDurationAtIndex(size_t); |
| 114 bool frameHasAlphaAtIndex(size_t); | 115 bool frameHasAlphaAtIndex(size_t); |
| 115 ImageOrientation frameOrientationAtIndex(size_t); | 116 ImageOrientation frameOrientationAtIndex(size_t); |
| 116 | 117 |
| 117 PassRefPtr<SkImage> decodeAndCacheFrame(size_t index); | 118 sk_sp<SkImage> decodeAndCacheFrame(size_t index); |
| 118 void updateSize() const; | 119 void updateSize() const; |
| 119 | 120 |
| 120 // Returns the total number of bytes allocated for all framebuffers, i.e. | 121 // Returns the total number of bytes allocated for all framebuffers, i.e. |
| 121 // the sum of m_source.frameBytesAtIndex(...) for all frames. | 122 // the sum of m_source.frameBytesAtIndex(...) for all frames. |
| 122 size_t totalFrameBytes(); | 123 size_t totalFrameBytes(); |
| 123 | 124 |
| 124 // Called to wipe out the entire frame buffer cache and tell the image | 125 // Called to wipe out the entire frame buffer cache and tell the image |
| 125 // source to destroy everything; this is used when e.g. we want to free | 126 // source to destroy everything; this is used when e.g. we want to free |
| 126 // some room in the image cache. | 127 // some room in the image cache. |
| 127 void destroyDecodedData() override; | 128 void destroyDecodedData() override; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 164 |
| 164 void notifyObserversOfAnimationAdvance(TimerBase*); | 165 void notifyObserversOfAnimationAdvance(TimerBase*); |
| 165 | 166 |
| 166 ImageSource m_source; | 167 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). | 168 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; | 169 mutable IntSize m_sizeRespectingOrientation; |
| 169 | 170 |
| 170 size_t m_currentFrame; // The index of the current frame of animation. | 171 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. | 172 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 | 173 |
| 173 RefPtr<SkImage> m_cachedFrame; // A cached copy of the most recently-accesse
d frame. | 174 sk_sp<SkImage> m_cachedFrame; // A cached copy of the most recently-accessed
frame. |
| 174 size_t m_cachedFrameIndex; // Index of the frame that is cached. | 175 size_t m_cachedFrameIndex; // Index of the frame that is cached. |
| 175 | 176 |
| 176 std::unique_ptr<Timer<BitmapImage>> m_frameTimer; | 177 std::unique_ptr<Timer<BitmapImage>> m_frameTimer; |
| 177 int m_repetitionCount; // How many total animation loops we should do. This
will be cAnimationNone if this image type is incapable of animation. | 178 int m_repetitionCount; // How many total animation loops we should do. This
will be cAnimationNone if this image type is incapable of animation. |
| 178 RepetitionCountStatus m_repetitionCountStatus; | 179 RepetitionCountStatus m_repetitionCountStatus; |
| 179 int m_repetitionsComplete; // How many repetitions we've finished. | 180 int m_repetitionsComplete; // How many repetitions we've finished. |
| 180 double m_desiredFrameStartTime; // The system time at which we hope to see
the next call to startAnimation(). | 181 double m_desiredFrameStartTime; // The system time at which we hope to see
the next call to startAnimation(). |
| 181 | 182 |
| 182 size_t m_frameCount; | 183 size_t m_frameCount; |
| 183 | 184 |
| 184 ImageAnimationPolicy m_animationPolicy; // Whether or not we can play animat
ion. | 185 ImageAnimationPolicy m_animationPolicy; // Whether or not we can play animat
ion. |
| 185 | 186 |
| 186 bool m_animationFinished : 1; // Whether or not we've completed the entire a
nimation. | 187 bool m_animationFinished : 1; // Whether or not we've completed the entire a
nimation. |
| 187 | 188 |
| 188 bool m_allDataReceived : 1; // Whether or not we've received all our data. | 189 bool m_allDataReceived : 1; // Whether or not we've received all our data. |
| 189 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable
has the final overall image size yet. | 190 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable
has the final overall image size yet. |
| 190 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. | 191 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_haveFrameCount : 1; | 192 mutable bool m_haveFrameCount : 1; |
| 192 }; | 193 }; |
| 193 | 194 |
| 194 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); | 195 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); |
| 195 | 196 |
| 196 } // namespace blink | 197 } // namespace blink |
| 197 | 198 |
| 198 #endif | 199 #endif |
| OLD | NEW |