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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 class PLATFORM_EXPORT BitmapImage final : public Image { | 46 class PLATFORM_EXPORT BitmapImage final : public Image { |
47 friend class BitmapImageTest; | 47 friend class BitmapImageTest; |
48 friend class CrossfadeGeneratedImage; | 48 friend class CrossfadeGeneratedImage; |
49 friend class GeneratedImage; | 49 friend class GeneratedImage; |
50 friend class GradientGeneratedImage; | 50 friend class GradientGeneratedImage; |
51 friend class GraphicsContext; | 51 friend class GraphicsContext; |
52 | 52 |
53 public: | 53 public: |
54 static PassRefPtr<BitmapImage> Create(ImageObserver* observer = 0) { | 54 static PassRefPtr<BitmapImage> CreateGlobal() { |
55 return AdoptRef(new BitmapImage(observer)); | 55 return AdoptRef(new BitmapImage()); |
56 } | |
57 | |
58 static PassRefPtr<BitmapImage> Create(RefPtr<WebTaskRunner> task_runner, | |
59 ImageObserver* observer = 0) { | |
60 return AdoptRef(new BitmapImage(task_runner, observer)); | |
56 } | 61 } |
57 | 62 |
58 ~BitmapImage() override; | 63 ~BitmapImage() override; |
59 | 64 |
60 bool IsBitmapImage() const override { return true; } | 65 bool IsBitmapImage() const override { return true; } |
61 | 66 |
62 bool CurrentFrameHasSingleSecurityOrigin() const override; | 67 bool CurrentFrameHasSingleSecurityOrigin() const override; |
63 | 68 |
64 IntSize Size() const override; | 69 IntSize Size() const override; |
65 IntSize SizeRespectingOrientation() const; | 70 IntSize SizeRespectingOrientation() const; |
(...skipping 20 matching lines...) Expand all Loading... | |
86 PassRefPtr<Image> ImageForDefaultFrame() override; | 91 PassRefPtr<Image> ImageForDefaultFrame() override; |
87 | 92 |
88 bool CurrentFrameKnownToBeOpaque(MetadataMode = kUseCurrentMetadata) override; | 93 bool CurrentFrameKnownToBeOpaque(MetadataMode = kUseCurrentMetadata) override; |
89 bool CurrentFrameIsComplete() override; | 94 bool CurrentFrameIsComplete() override; |
90 bool CurrentFrameIsLazyDecoded() override; | 95 bool CurrentFrameIsLazyDecoded() override; |
91 | 96 |
92 ImageOrientation CurrentFrameOrientation(); | 97 ImageOrientation CurrentFrameOrientation(); |
93 | 98 |
94 // Construct a BitmapImage with the given orientation. | 99 // Construct a BitmapImage with the given orientation. |
95 static PassRefPtr<BitmapImage> CreateWithOrientationForTesting( | 100 static PassRefPtr<BitmapImage> CreateWithOrientationForTesting( |
101 RefPtr<WebTaskRunner>, | |
96 const SkBitmap&, | 102 const SkBitmap&, |
97 ImageOrientation); | 103 ImageOrientation); |
98 // Advance the image animation by one frame. | 104 // Advance the image animation by one frame. |
99 void AdvanceAnimationForTesting() override { InternalAdvanceAnimation(); } | 105 void AdvanceAnimationForTesting() override { InternalAdvanceAnimation(); } |
100 | 106 |
101 private: | 107 private: |
102 enum RepetitionCountStatus { | 108 enum RepetitionCountStatus { |
103 kUnknown, // We haven't checked the source's repetition count. | 109 kUnknown, // We haven't checked the source's repetition count. |
104 kUncertain, // We have a repetition count, but it might be wrong (some GIFs | 110 kUncertain, // We have a repetition count, but it might be wrong (some GIFs |
105 // have a count after the image data, and will report "loop | 111 // have a count after the image data, and will report "loop |
106 // once" until all data has been decoded). | 112 // once" until all data has been decoded). |
107 kCertain // The repetition count is known to be correct. | 113 kCertain // The repetition count is known to be correct. |
108 }; | 114 }; |
109 | 115 |
110 BitmapImage(const SkBitmap&, ImageObserver* = 0); | 116 BitmapImage(); |
111 BitmapImage(ImageObserver* = 0); | 117 |
118 BitmapImage(RefPtr<WebTaskRunner>, const SkBitmap&, ImageObserver* = 0); | |
Sami
2017/04/27 17:38:17
Should we make these two explicit?
Dan Elphick
2017/05/03 09:41:06
no longer required
| |
119 BitmapImage(RefPtr<WebTaskRunner>, ImageObserver* = 0); | |
112 | 120 |
113 void Draw(PaintCanvas*, | 121 void Draw(PaintCanvas*, |
114 const PaintFlags&, | 122 const PaintFlags&, |
115 const FloatRect& dst_rect, | 123 const FloatRect& dst_rect, |
116 const FloatRect& src_rect, | 124 const FloatRect& src_rect, |
117 RespectImageOrientationEnum, | 125 RespectImageOrientationEnum, |
118 ImageClampingMode) override; | 126 ImageClampingMode) override; |
119 | 127 |
120 size_t CurrentFrame() const { return current_frame_; } | 128 size_t CurrentFrame() const { return current_frame_; } |
121 size_t FrameCount(); | 129 size_t FrameCount(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 | 193 |
186 size_t current_frame_; // The index of the current frame of animation. | 194 size_t current_frame_; // The index of the current frame of animation. |
187 Vector<FrameData, 1> frames_; // An array of the cached frames of the | 195 Vector<FrameData, 1> frames_; // An array of the cached frames of the |
188 // animation. We have to ref frames to pin | 196 // animation. We have to ref frames to pin |
189 // them in the cache. | 197 // them in the cache. |
190 | 198 |
191 sk_sp<SkImage> | 199 sk_sp<SkImage> |
192 cached_frame_; // A cached copy of the most recently-accessed frame. | 200 cached_frame_; // A cached copy of the most recently-accessed frame. |
193 size_t cached_frame_index_; // Index of the frame that is cached. | 201 size_t cached_frame_index_; // Index of the frame that is cached. |
194 | 202 |
195 std::unique_ptr<Timer<BitmapImage>> frame_timer_; | 203 std::unique_ptr<TaskRunnerTimer<BitmapImage>> frame_timer_; |
196 int repetition_count_; // How many total animation loops we should do. This | 204 int repetition_count_; // How many total animation loops we should do. This |
197 // will be cAnimationNone if this image type is | 205 // will be cAnimationNone if this image type is |
198 // incapable of animation. | 206 // incapable of animation. |
199 RepetitionCountStatus repetition_count_status_; | 207 RepetitionCountStatus repetition_count_status_; |
200 int repetitions_complete_; // How many repetitions we've finished. | 208 int repetitions_complete_; // How many repetitions we've finished. |
201 double desired_frame_start_time_; // The system time at which we hope to see | 209 double desired_frame_start_time_; // The system time at which we hope to see |
202 // the next call to startAnimation(). | 210 // the next call to startAnimation(). |
203 | 211 |
204 size_t frame_count_; | 212 size_t frame_count_; |
205 | 213 |
206 ImageAnimationPolicy | 214 ImageAnimationPolicy |
207 animation_policy_; // Whether or not we can play animation. | 215 animation_policy_; // Whether or not we can play animation. |
208 | 216 |
209 bool animation_finished_ : 1; // Whether we've completed the entire | 217 bool animation_finished_ : 1; // Whether we've completed the entire |
210 // animation. | 218 // animation. |
211 | 219 |
212 bool all_data_received_ : 1; // Whether we've received all our data. | 220 bool all_data_received_ : 1; // Whether we've received all our data. |
213 mutable bool have_size_ : 1; // Whether our |m_size| member variable has the | 221 mutable bool have_size_ : 1; // Whether our |m_size| member variable has the |
214 // final overall image size yet. | 222 // final overall image size yet. |
215 bool size_available_ : 1; // Whether we can obtain the size of the first | 223 bool size_available_ : 1; // Whether we can obtain the size of the first |
216 // image frame from ImageIO yet. | 224 // image frame from ImageIO yet. |
217 mutable bool have_frame_count_ : 1; | 225 mutable bool have_frame_count_ : 1; |
226 | |
227 RefPtr<WebTaskRunner> task_runner_; | |
218 }; | 228 }; |
219 | 229 |
220 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); | 230 DEFINE_IMAGE_TYPE_CASTS(BitmapImage); |
221 | 231 |
222 } // namespace blink | 232 } // namespace blink |
223 | 233 |
224 #endif | 234 #endif |
OLD | NEW |