OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 BitmapImageTest(bool enableDeferredDecoding) : m_enableDeferredDecoding(enab
leDeferredDecoding) { } | 69 BitmapImageTest(bool enableDeferredDecoding) : m_enableDeferredDecoding(enab
leDeferredDecoding) { } |
70 | 70 |
71 static PassRefPtr<SharedBuffer> readFile(const char* fileName) | 71 static PassRefPtr<SharedBuffer> readFile(const char* fileName) |
72 { | 72 { |
73 String filePath = testing::blinkRootDir(); | 73 String filePath = testing::blinkRootDir(); |
74 filePath.append(fileName); | 74 filePath.append(fileName); |
75 return testing::readFromFile(filePath); | 75 return testing::readFromFile(filePath); |
76 } | 76 } |
77 | 77 |
78 // Accessors to BitmapImage's protected methods. | 78 // Accessors to BitmapImage's protected methods. |
79 void destroyDecodedData(bool destroyAll) { m_image->destroyDecodedData(destr
oyAll); } | 79 void destroyDecodedData() { m_image->destroyDecodedData(); } |
80 size_t frameCount() { return m_image->frameCount(); } | 80 size_t frameCount() { return m_image->frameCount(); } |
81 void frameAtIndex(size_t index) | 81 PassRefPtr<SkImage> frameAtIndex(size_t index) |
82 { | 82 { |
83 m_image->frameAtIndex(index); | 83 return m_image->frameAtIndex(index); |
84 } | 84 } |
85 void setCurrentFrame(size_t frame) { m_image->m_currentFrame = frame; } | 85 void setCurrentFrame(size_t frame) { m_image->m_currentFrame = frame; } |
86 size_t frameDecodedSize(size_t frame) { return m_image->m_frames[frame].m_fr
ameBytes; } | 86 size_t frameDecodedSize(size_t frame) { return m_image->m_frames[frame].m_fr
ameBytes; } |
87 size_t decodedFramesCount() const { return m_image->m_frames.size(); } | 87 size_t decodedFramesCount() const { return m_image->m_frames.size(); } |
88 | 88 |
89 void setFirstFrameNotComplete() { m_image->m_frames[0].m_isComplete = false;
} | 89 void setFirstFrameNotComplete() { m_image->m_frames[0].m_isComplete = false;
} |
90 | 90 |
91 void loadImage(const char* fileName, bool loadAllFrames = true) | 91 void loadImage(const char* fileName, bool loadAllFrames = true) |
92 { | 92 { |
93 RefPtr<SharedBuffer> imageData = readFile(fileName); | 93 RefPtr<SharedBuffer> imageData = readFile(fileName); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 int animationFinished() | 130 int animationFinished() |
131 { | 131 { |
132 return m_image->m_animationFinished; | 132 return m_image->m_animationFinished; |
133 } | 133 } |
134 | 134 |
135 PassRefPtr<Image> imageForDefaultFrame() | 135 PassRefPtr<Image> imageForDefaultFrame() |
136 { | 136 { |
137 return m_image->imageForDefaultFrame(); | 137 return m_image->imageForDefaultFrame(); |
138 } | 138 } |
139 | 139 |
| 140 int lastDecodedSizeChange() |
| 141 { |
| 142 return m_imageObserver->m_lastDecodedSizeChangedDelta; |
| 143 } |
| 144 |
140 protected: | 145 protected: |
141 void SetUp() override | 146 void SetUp() override |
142 { | 147 { |
143 DeferredImageDecoder::setEnabled(m_enableDeferredDecoding); | 148 DeferredImageDecoder::setEnabled(m_enableDeferredDecoding); |
144 m_imageObserver = new FakeImageObserver; | 149 m_imageObserver = new FakeImageObserver; |
145 m_image = BitmapImage::create(m_imageObserver.get()); | 150 m_image = BitmapImage::create(m_imageObserver.get()); |
146 } | 151 } |
147 | 152 |
148 Persistent<FakeImageObserver> m_imageObserver; | 153 Persistent<FakeImageObserver> m_imageObserver; |
149 RefPtr<BitmapImage> m_image; | 154 RefPtr<BitmapImage> m_image; |
150 | 155 |
151 private: | 156 private: |
152 bool m_enableDeferredDecoding; | 157 bool m_enableDeferredDecoding; |
153 }; | 158 }; |
154 | 159 |
155 TEST_F(BitmapImageTest, destroyDecodedDataExceptCurrentFrame) | 160 TEST_F(BitmapImageTest, destroyDecodedData) |
156 { | |
157 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); | |
158 size_t totalSize = decodedSize(); | |
159 size_t frame = frameCount() / 2; | |
160 setCurrentFrame(frame); | |
161 size_t size = frameDecodedSize(frame); | |
162 destroyDecodedData(false); | |
163 EXPECT_LT(m_imageObserver->m_lastDecodedSizeChangedDelta, 0); | |
164 EXPECT_GE(m_imageObserver->m_lastDecodedSizeChangedDelta, -static_cast<int>(
totalSize - size)); | |
165 } | |
166 | |
167 TEST_F(BitmapImageTest, destroyAllDecodedData) | |
168 { | 161 { |
169 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); | 162 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); |
170 size_t totalSize = decodedSize(); | 163 size_t totalSize = decodedSize(); |
171 EXPECT_GT(totalSize, 0u); | 164 EXPECT_GT(totalSize, 0u); |
172 destroyDecodedData(true); | 165 destroyDecodedData(); |
173 EXPECT_EQ(-static_cast<int>(totalSize), m_imageObserver->m_lastDecodedSizeCh
angedDelta); | 166 EXPECT_EQ(-static_cast<int>(totalSize), lastDecodedSizeChange()); |
174 EXPECT_EQ(0u, decodedSize()); | 167 EXPECT_EQ(0u, decodedSize()); |
175 } | 168 } |
176 | 169 |
177 TEST_F(BitmapImageTest, maybeAnimated) | 170 TEST_F(BitmapImageTest, maybeAnimated) |
178 { | 171 { |
179 loadImage("/LayoutTests/fast/images/resources/gif-loop-count.gif"); | 172 loadImage("/LayoutTests/fast/images/resources/gif-loop-count.gif"); |
180 for (size_t i = 0; i < frameCount(); ++i) { | 173 for (size_t i = 0; i < frameCount(); ++i) { |
181 EXPECT_TRUE(m_image->maybeAnimated()); | 174 EXPECT_TRUE(m_image->maybeAnimated()); |
182 advanceAnimation(); | 175 advanceAnimation(); |
183 } | 176 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 258 } |
266 | 259 |
267 TEST_F(BitmapImageTest, correctDecodedDataSize) | 260 TEST_F(BitmapImageTest, correctDecodedDataSize) |
268 { | 261 { |
269 // When requesting a frame of a multi-frame GIF causes another frame to be | 262 // When requesting a frame of a multi-frame GIF causes another frame to be |
270 // decoded as well, both frames' sizes should be reported by the source and | 263 // decoded as well, both frames' sizes should be reported by the source and |
271 // thus included in the decoded size changed notification. | 264 // thus included in the decoded size changed notification. |
272 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); | 265 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); |
273 frameAtIndex(1); | 266 frameAtIndex(1); |
274 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame:
:PixelData)); | 267 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame:
:PixelData)); |
275 EXPECT_EQ(frameSize * 2, m_imageObserver->m_lastDecodedSizeChangedDelta); | 268 EXPECT_EQ(frameSize * 2, lastDecodedSizeChange()); |
276 | |
277 // Trying to destroy all data except an undecoded frame should cause the | |
278 // decoder to seek backwards and preserve the most recent previous frame | |
279 // necessary to decode that undecoded frame, and destroy all other frames. | |
280 setCurrentFrame(2); | |
281 destroyDecodedData(false); | |
282 EXPECT_EQ(-frameSize, m_imageObserver->m_lastDecodedSizeChangedDelta); | |
283 } | 269 } |
284 | 270 |
285 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) | 271 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) |
286 { | 272 { |
287 loadImage("/LayoutTests/fast/images/resources/green.jpg"); | 273 loadImage("/LayoutTests/fast/images/resources/green.jpg"); |
288 setFirstFrameNotComplete(); | 274 setFirstFrameNotComplete(); |
289 EXPECT_GT(m_imageObserver->m_lastDecodedSizeChangedDelta, 0); | 275 EXPECT_GT(lastDecodedSizeChange(), 0); |
290 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; | 276 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; |
291 | 277 |
292 // Calling dataChanged causes the cache to flush, but doesn't affect the | 278 // Calling dataChanged causes the cache to flush, but doesn't affect the |
293 // source's decoded frames. It shouldn't affect decoded size. | 279 // source's decoded frames. It shouldn't affect decoded size. |
294 m_image->dataChanged(true); | 280 m_image->dataChanged(true); |
295 EXPECT_EQ(0, m_imageObserver->m_lastDecodedSizeChangedDelta); | 281 EXPECT_EQ(0, lastDecodedSizeChange()); |
296 // Recaching the first frame also shouldn't affect decoded size. | 282 // Recaching the first frame also shouldn't affect decoded size. |
297 m_image->imageForCurrentFrame(); | 283 m_image->imageForCurrentFrame(); |
298 EXPECT_EQ(0, m_imageObserver->m_lastDecodedSizeChangedDelta); | 284 EXPECT_EQ(0, lastDecodedSizeChange()); |
299 } | 285 } |
300 | 286 |
301 class BitmapImageDeferredDecodingTest : public BitmapImageTest { | 287 class BitmapImageDeferredDecodingTest : public BitmapImageTest { |
302 public: | 288 public: |
303 BitmapImageDeferredDecodingTest() : BitmapImageTest(true) { } | 289 BitmapImageDeferredDecodingTest() : BitmapImageTest(true) { } |
304 }; | 290 }; |
305 | 291 |
306 TEST_F(BitmapImageDeferredDecodingTest, correctDecodedDataSize) | 292 TEST_F(BitmapImageDeferredDecodingTest, correctDecodedDataSize) |
307 { | 293 { |
308 // When deferred decoding is enabled, requesting any one frame shouldn't | 294 // When deferred decoding is enabled, requesting any one frame shouldn't |
309 // result in decoding any other frames. | 295 // result in decoding any other frames. |
310 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); | 296 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); |
311 frameAtIndex(1); | 297 frameAtIndex(1); |
312 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame:
:PixelData)); | 298 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame:
:PixelData)); |
313 EXPECT_EQ(frameSize, m_imageObserver->m_lastDecodedSizeChangedDelta); | 299 EXPECT_EQ(frameSize, lastDecodedSizeChange()); |
314 frameAtIndex(0); | |
315 | |
316 // Trying to destroy all data except an undecoded frame should go ahead and | |
317 // destroy all other frames. | |
318 setCurrentFrame(2); | |
319 destroyDecodedData(false); | |
320 EXPECT_EQ(-frameSize * 2, m_imageObserver->m_lastDecodedSizeChangedDelta); | |
321 } | 300 } |
322 | 301 |
323 template <typename HistogramEnumType> | 302 template <typename HistogramEnumType> |
324 struct HistogramTestParams { | 303 struct HistogramTestParams { |
325 const char* filename; | 304 const char* filename; |
326 HistogramEnumType type; | 305 HistogramEnumType type; |
327 }; | 306 }; |
328 | 307 |
329 template <typename HistogramEnumType> | 308 template <typename HistogramEnumType> |
330 class BitmapHistogramTest | 309 class BitmapHistogramTest |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 {"/LayoutTests/fast/images/resources/exif-orientation-5-lu.jpg", OriginLeftT
op}, | 352 {"/LayoutTests/fast/images/resources/exif-orientation-5-lu.jpg", OriginLeftT
op}, |
374 {"/LayoutTests/fast/images/resources/exif-orientation-6-ru.jpg", OriginRight
Top}, | 353 {"/LayoutTests/fast/images/resources/exif-orientation-6-ru.jpg", OriginRight
Top}, |
375 {"/LayoutTests/fast/images/resources/exif-orientation-7-rl.jpg", OriginRight
Bottom}, | 354 {"/LayoutTests/fast/images/resources/exif-orientation-7-rl.jpg", OriginRight
Bottom}, |
376 {"/LayoutTests/fast/images/resources/exif-orientation-8-llo.jpg", OriginLeft
Bottom} | 355 {"/LayoutTests/fast/images/resources/exif-orientation-8-llo.jpg", OriginLeft
Bottom} |
377 }; | 356 }; |
378 | 357 |
379 INSTANTIATE_TEST_CASE_P(DecodedImageOrientationHistogramTest, DecodedImageOrient
ationHistogramTest, | 358 INSTANTIATE_TEST_CASE_P(DecodedImageOrientationHistogramTest, DecodedImageOrient
ationHistogramTest, |
380 ::testing::ValuesIn(kDecodedImageOrientationHistogramTestParams)); | 359 ::testing::ValuesIn(kDecodedImageOrientationHistogramTestParams)); |
381 | 360 |
382 } // namespace blink | 361 } // namespace blink |
OLD | NEW |