Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: Source/platform/graphics/BitmapImage.h

Issue 1093673002: Removing the dependency on GraphicsContext for drawing images in 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix for overdraw optimization failures and fix for mac build Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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) 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);
122 124
123 // Decodes and caches a frame. Never accessed except internally. 125 // Decodes and caches a frame. Never accessed except internally.
124 void cacheFrame(size_t index); 126 void cacheFrame(size_t index);
125 127
126 // Called before accessing m_frames[index]. Returns false on index out of bo unds. 128 // Called before accessing m_frames[index]. Returns false on index out of bo unds.
127 bool ensureFrameIsCached(size_t index); 129 bool ensureFrameIsCached(size_t index);
128 130
129 // Called to invalidate cached data. When |destroyAll| is true, we wipe out 131 // Called to invalidate cached data. When |destroyAll| is true, we wipe out
130 // the entire frame buffer cache and tell the image source to destroy 132 // the entire frame buffer cache and tell the image source to destroy
131 // everything; this is used when e.g. we want to free some room in the image 133 // everything; this is used when e.g. we want to free some room in the image
132 // cache. If |destroyAll| is false, we delete frames except the current 134 // cache. If |destroyAll| is false, we delete frames except the current
133 // frame; this is used while animating large images to keep memory footprint 135 // frame; this is used while animating large images to keep memory footprint
134 // low; the decoder should preserve the current frame and may preserve some 136 // low; the decoder should preserve the current frame and may preserve some
135 // other frames to avoid redecoding the whole image on every frame. 137 // other frames to avoid redecoding the whole image on every frame.
136 virtual void destroyDecodedData(bool destroyAll) override; 138 void destroyDecodedData(bool destroyAll) override;
137 139
138 // If the image is large enough, calls destroyDecodedData(). 140 // If the image is large enough, calls destroyDecodedData().
139 void destroyDecodedDataIfNecessary(); 141 void destroyDecodedDataIfNecessary();
140 142
141 // Generally called by destroyDecodedData(), destroys whole-image metadata 143 // Generally called by destroyDecodedData(), destroys whole-image metadata
142 // and notifies observers that the memory footprint has (hopefully) 144 // and notifies observers that the memory footprint has (hopefully)
143 // decreased by |frameBytesCleared|. 145 // decreased by |frameBytesCleared|.
144 void destroyMetadataAndNotify(size_t frameBytesCleared); 146 void destroyMetadataAndNotify(size_t frameBytesCleared);
145 147
146 // Whether or not size is available yet. 148 // Whether or not size is available yet.
147 bool isSizeAvailable(); 149 bool isSizeAvailable();
148 150
149 // Animation. 151 // Animation.
150 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet e| should be set if the caller knows the entire image has been decoded. 152 int repetitionCount(bool imageKnownToBeComplete); // |imageKnownToBeComplet e| should be set if the caller knows the entire image has been decoded.
151 bool shouldAnimate(); 153 bool shouldAnimate();
152 virtual void startAnimation(CatchUpAnimation = CatchUp) override; 154 void startAnimation(CatchUpAnimation = CatchUp) override;
153 void advanceAnimation(Timer<BitmapImage>*); 155 void advanceAnimation(Timer<BitmapImage>*);
154 156
155 // Function that does the real work of advancing the animation. When 157 // Function that does the real work of advancing the animation. When
156 // skippingFrames is true, we're in the middle of a loop trying to skip over 158 // skippingFrames is true, we're in the middle of a loop trying to skip over
157 // a bunch of animation frames, so we should not do things like decode each 159 // a bunch of animation frames, so we should not do things like decode each
158 // one or notify our observers. 160 // one or notify our observers.
159 // Returns whether the animation was advanced. 161 // Returns whether the animation was advanced.
160 bool internalAdvanceAnimation(bool skippingFrames); 162 bool internalAdvanceAnimation(bool skippingFrames);
161 163
162 // Checks to see if the image is a 1x1 solid color. We optimize these image s and just do a fill rect instead. 164 // Checks to see if the image is a 1x1 solid color. We optimize these image s and just do a fill rect instead.
163 // This check should happen regardless whether m_checkedForSolidColor is alr eady set, as the frame may have 165 // This check should happen regardless whether m_checkedForSolidColor is alr eady set, as the frame may have
164 // changed. 166 // changed.
165 void checkForSolidColor(); 167 void checkForSolidColor();
166 168
167 virtual bool mayFillWithSolidColor() override; 169 bool mayFillWithSolidColor() override;
168 virtual Color solidColor() const override; 170 Color solidColor() const override;
169 171
170 ImageSource m_source; 172 ImageSource m_source;
171 mutable IntSize m_size; // The size to use for the overall image (will just be the size of the first image). 173 mutable IntSize m_size; // The size to use for the overall image (will just be the size of the first image).
172 mutable IntSize m_sizeRespectingOrientation; 174 mutable IntSize m_sizeRespectingOrientation;
173 175
174 size_t m_currentFrame; // The index of the current frame of animation. 176 size_t m_currentFrame; // The index of the current frame of animation.
175 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. 177 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.
176 178
177 Timer<BitmapImage>* m_frameTimer; 179 Timer<BitmapImage>* m_frameTimer;
178 int m_repetitionCount; // How many total animation loops we should do. This will be cAnimationNone if this image type is incapable of animation. 180 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
196 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.
197 mutable bool m_hasUniformFrameSize : 1; 199 mutable bool m_hasUniformFrameSize : 1;
198 mutable bool m_haveFrameCount : 1; 200 mutable bool m_haveFrameCount : 1;
199 }; 201 };
200 202
201 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); 203 DEFINE_IMAGE_TYPE_CASTS(BitmapImage);
202 204
203 } // namespace blink 205 } // namespace blink
204 206
205 #endif 207 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698