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 11 matching lines...) Expand all Loading... |
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #ifndef BitmapImage_h | 28 #ifndef BitmapImage_h |
29 #define BitmapImage_h | 29 #define BitmapImage_h |
30 | 30 |
31 #include "platform/geometry/IntSize.h" | 31 #include "platform/geometry/IntSize.h" |
32 #include "platform/graphics/Color.h" | |
33 #include "platform/graphics/FrameData.h" | 32 #include "platform/graphics/FrameData.h" |
34 #include "platform/graphics/Image.h" | 33 #include "platform/graphics/Image.h" |
35 #include "platform/graphics/ImageAnimationPolicy.h" | 34 #include "platform/graphics/ImageAnimationPolicy.h" |
36 #include "platform/graphics/ImageOrientation.h" | 35 #include "platform/graphics/ImageOrientation.h" |
37 #include "platform/graphics/ImageSource.h" | 36 #include "platform/graphics/ImageSource.h" |
38 #include "platform/image-decoders/ImageAnimation.h" | 37 #include "platform/image-decoders/ImageAnimation.h" |
39 #include "wtf/Forward.h" | 38 #include "wtf/Forward.h" |
40 #include "wtf/OwnPtr.h" | 39 #include "wtf/OwnPtr.h" |
41 | 40 |
42 namespace blink { | 41 namespace blink { |
43 | 42 |
44 template <typename T> class Timer; | 43 template <typename T> class Timer; |
45 | 44 |
46 class PLATFORM_EXPORT BitmapImage final : public Image { | 45 class PLATFORM_EXPORT BitmapImage final : public Image { |
47 friend class GeneratedImage; | 46 friend class GeneratedImage; |
48 friend class CrossfadeGeneratedImage; | 47 friend class CrossfadeGeneratedImage; |
49 friend class GradientGeneratedImage; | 48 friend class GradientGeneratedImage; |
50 friend class GraphicsContext; | 49 friend class GraphicsContext; |
51 public: | 50 public: |
52 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) | 51 static PassRefPtr<BitmapImage> create(ImageObserver* observer = 0) |
53 { | 52 { |
54 return adoptRef(new BitmapImage(observer)); | 53 return adoptRef(new BitmapImage(observer)); |
55 } | 54 } |
56 | 55 |
57 // This allows constructing a BitmapImage with a forced non-default orientat
ion. | |
58 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma
p&, ImageOrientation); | |
59 | |
60 ~BitmapImage() override; | 56 ~BitmapImage() override; |
61 | 57 |
62 bool isBitmapImage() const override; | 58 bool isBitmapImage() const override { return true; }; |
63 | 59 |
64 bool currentFrameHasSingleSecurityOrigin() const override; | 60 bool currentFrameHasSingleSecurityOrigin() const override { return true; }; |
65 | 61 |
66 IntSize size() const override; | 62 IntSize size() const override; |
67 IntSize sizeRespectingOrientation() const; | 63 IntSize sizeRespectingOrientation() const; |
68 bool getHotSpot(IntPoint&) const override; | 64 bool getHotSpot(IntPoint&) const override; |
69 String filenameExtension() const override; | 65 String filenameExtension() const override; |
| 66 |
70 bool dataChanged(bool allDataReceived) override; | 67 bool dataChanged(bool allDataReceived) override; |
| 68 bool isAllDataReceived() const { return m_allDataReceived; } |
71 | 69 |
72 bool isAllDataReceived() const { return m_allDataReceived; } | |
73 bool hasColorProfile() const; | 70 bool hasColorProfile() const; |
| 71 PassRefPtr<ColorSpaceProfile> colorProfile() const { return m_source.colorPr
ofile(); } |
| 72 void setDrawingToCanvasElement(bool status) { m_drawingToCanvasElement = sta
tus; } // FIXME: remove. |
| 73 bool drawingToCanvasElement() { return m_drawingToCanvasElement; } // FIXME:
remove. |
| 74 PassRefPtr<SkColorFilter> imageColorTransform(); |
74 | 75 |
75 // It may look unusual that there's no start animation call as public API. | 76 // It may look unusual that there's no start animation call as public API. |
76 // This because we start and stop animating lazily. Animation starts when | 77 // This because we start and stop animating lazily. Animation starts when |
77 // the image is rendered, and automatically pauses once all observers no | 78 // the image is rendered, and automatically pauses once all observers no |
78 // longer want to render the image. | 79 // longer want to render the image. |
79 void stopAnimation() override; | 80 void stopAnimation() override; |
80 void resetAnimation() override; | 81 void resetAnimation() override; |
81 bool maybeAnimated() override; | 82 bool maybeAnimated() override; |
82 | 83 |
83 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP
olicy = policy; } | 84 void setAnimationPolicy(ImageAnimationPolicy policy) override { m_animationP
olicy = policy; } |
84 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy;
} | 85 ImageAnimationPolicy animationPolicy() override { return m_animationPolicy;
} |
85 void advanceTime(double deltaTimeInSeconds) override; | 86 void advanceTime(double deltaTimeInSeconds) override; |
86 | 87 |
87 // Advance the image animation by one frame. | |
88 void advanceAnimationForTesting() override { internalAdvanceAnimation(false)
; } | |
89 | |
90 PassRefPtr<SkImage> imageForCurrentFrame() override; | 88 PassRefPtr<SkImage> imageForCurrentFrame() override; |
91 PassRefPtr<Image> imageForDefaultFrame() override; | 89 PassRefPtr<Image> imageForDefaultFrame() override; |
| 90 |
92 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override
; | 91 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override
; |
93 bool currentFrameIsComplete() override; | 92 bool currentFrameIsComplete() override; |
94 bool currentFrameIsLazyDecoded() override; | 93 bool currentFrameIsLazyDecoded() override; |
95 | 94 |
| 95 // FIXME: consider renaming this to orientationForCurrentFrame(), or perhaps |
| 96 // imageOrientation, since orientation is the same for all image frames. |
96 ImageOrientation currentFrameOrientation(); | 97 ImageOrientation currentFrameOrientation(); |
97 | 98 |
| 99 // Construct a BitmapImage with the given orientation. |
| 100 static PassRefPtr<BitmapImage> createWithOrientationForTesting(const SkBitma
p&, ImageOrientation); |
| 101 // Advance an animated image by one frame. |
| 102 void advanceAnimationForTesting() override { internalAdvanceAnimation(false)
; } |
| 103 |
98 private: | 104 private: |
99 friend class BitmapImageTest; | 105 friend class BitmapImageTest; |
100 | 106 |
101 void updateSize() const; | 107 void updateSize() const; |
102 | 108 |
103 private: | 109 private: |
104 enum RepetitionCountStatus { | 110 enum RepetitionCountStatus { |
105 Unknown, // We haven't checked the source's repetition count. | 111 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). | 112 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. | 113 Certain // The repetition count is known to be correct. |
108 }; | 114 }; |
109 | 115 |
110 BitmapImage(const SkBitmap &, ImageObserver* = 0); | 116 BitmapImage(const SkBitmap &, ImageObserver* = 0); |
111 BitmapImage(ImageObserver* = 0); | 117 BitmapImage(ImageObserver* = 0); |
112 | 118 |
113 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; | 119 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override; |
| 120 void didDraw(); |
114 | 121 |
115 size_t currentFrame() const { return m_currentFrame; } | 122 size_t currentFrame() const { return m_currentFrame; } |
116 size_t frameCount(); | 123 size_t frameCount(); |
117 | 124 |
118 PassRefPtr<SkImage> frameAtIndex(size_t); | 125 PassRefPtr<SkImage> frameAtIndex(size_t); |
119 | 126 |
120 bool frameIsCompleteAtIndex(size_t); | 127 bool frameIsCompleteAtIndex(size_t); |
121 float frameDurationAtIndex(size_t); | 128 float frameDurationAtIndex(size_t); |
122 bool frameHasAlphaAtIndex(size_t); | 129 bool frameHasAlphaAtIndex(size_t); |
123 ImageOrientation frameOrientationAtIndex(size_t); | 130 ImageOrientation frameOrientationAtIndex(size_t); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 191 |
185 ImageAnimationPolicy m_animationPolicy; // Whether or not we can play animat
ion. | 192 ImageAnimationPolicy m_animationPolicy; // Whether or not we can play animat
ion. |
186 | 193 |
187 bool m_animationFinished : 1; // Whether or not we've completed the entire a
nimation. | 194 bool m_animationFinished : 1; // Whether or not we've completed the entire a
nimation. |
188 | 195 |
189 bool m_allDataReceived : 1; // Whether or not we've received all our data. | 196 bool m_allDataReceived : 1; // Whether or not we've received all our data. |
190 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable
has the final overall image size yet. | 197 mutable bool m_haveSize : 1; // Whether or not our |m_size| member variable
has the final overall image size yet. |
191 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. | 198 bool m_sizeAvailable : 1; // Whether or not we can obtain the size of the fi
rst image frame yet from ImageIO. |
192 mutable bool m_hasUniformFrameSize : 1; | 199 mutable bool m_hasUniformFrameSize : 1; |
193 mutable bool m_haveFrameCount : 1; | 200 mutable bool m_haveFrameCount : 1; |
| 201 // DEBUG: whether or not <canvas> is drawing this bitmap image. FIXME: remov
e. |
| 202 mutable bool m_drawingToCanvasElement : 1; |
194 }; | 203 }; |
195 | 204 |
196 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); | 205 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); |
197 | 206 |
198 } // namespace blink | 207 } // namespace blink |
199 | 208 |
200 #endif | 209 #endif |
OLD | NEW |