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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/BitmapImageTest.cpp

Issue 1857543002: Don't recreate SkImages for high-res (GIF, WEBP...) animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review #4 fix. Thanks @pkasting. Created 4 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
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 BitmapImageTest(bool enableDeferredDecoding) : m_enableDeferredDecoding(enab leDeferredDecoding) { } 62 BitmapImageTest(bool enableDeferredDecoding) : m_enableDeferredDecoding(enab leDeferredDecoding) { }
63 63
64 static PassRefPtr<SharedBuffer> readFile(const char* fileName) 64 static PassRefPtr<SharedBuffer> readFile(const char* fileName)
65 { 65 {
66 String filePath = testing::blinkRootDir(); 66 String filePath = testing::blinkRootDir();
67 filePath.append(fileName); 67 filePath.append(fileName);
68 return testing::readFromFile(filePath); 68 return testing::readFromFile(filePath);
69 } 69 }
70 70
71 // Accessors to BitmapImage's protected methods. 71 // Accessors to BitmapImage's protected methods.
72 void destroyDecodedData(bool destroyAll) { m_image->destroyDecodedData(destr oyAll); } 72 void destroyDecodedData() { m_image->destroyDecodedData(); }
73 size_t frameCount() { return m_image->frameCount(); } 73 size_t frameCount() { return m_image->frameCount(); }
74 void frameAtIndex(size_t index) 74 void frameAtIndex(size_t index)
75 { 75 {
76 m_image->frameAtIndex(index); 76 m_image->frameAtIndex(index);
77 } 77 }
78 void setCurrentFrame(size_t frame) { m_image->m_currentFrame = frame; } 78 void setCurrentFrame(size_t frame) { m_image->m_currentFrame = frame; }
79 size_t frameDecodedSize(size_t frame) { return m_image->m_frames[frame].m_fr ameBytes; } 79 size_t frameDecodedSize(size_t frame) { return m_image->m_frames[frame].m_fr ameBytes; }
80 size_t decodedFramesCount() const { return m_image->m_frames.size(); } 80 size_t decodedFramesCount() const { return m_image->m_frames.size(); }
81 81
82 void setFirstFrameNotComplete() { m_image->m_frames[0].m_isComplete = false; } 82 void setFirstFrameNotComplete() { m_image->m_frames[0].m_isComplete = false; }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 m_image = BitmapImage::create(m_imageObserver.get()); 138 m_image = BitmapImage::create(m_imageObserver.get());
139 } 139 }
140 140
141 OwnPtrWillBePersistent<FakeImageObserver> m_imageObserver; 141 OwnPtrWillBePersistent<FakeImageObserver> m_imageObserver;
142 RefPtr<BitmapImage> m_image; 142 RefPtr<BitmapImage> m_image;
143 143
144 private: 144 private:
145 bool m_enableDeferredDecoding; 145 bool m_enableDeferredDecoding;
146 }; 146 };
147 147
148 TEST_F(BitmapImageTest, destroyDecodedDataExceptCurrentFrame)
149 {
150 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif");
151 size_t totalSize = decodedSize();
152 size_t frame = frameCount() / 2;
153 setCurrentFrame(frame);
154 size_t size = frameDecodedSize(frame);
155 destroyDecodedData(false);
156 EXPECT_LT(m_imageObserver->m_lastDecodedSizeChangedDelta, 0);
157 EXPECT_GE(m_imageObserver->m_lastDecodedSizeChangedDelta, -static_cast<int>( totalSize - size));
158 }
159
160 TEST_F(BitmapImageTest, destroyAllDecodedData) 148 TEST_F(BitmapImageTest, destroyAllDecodedData)
161 { 149 {
162 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif"); 150 loadImage("/LayoutTests/fast/images/resources/animated-10color.gif");
163 size_t totalSize = decodedSize(); 151 size_t totalSize = decodedSize();
164 EXPECT_GT(totalSize, 0u); 152 EXPECT_GT(totalSize, 0u);
165 destroyDecodedData(true); 153 destroyDecodedData();
166 EXPECT_EQ(-static_cast<int>(totalSize), m_imageObserver->m_lastDecodedSizeCh angedDelta); 154 EXPECT_EQ(-static_cast<int>(totalSize), m_imageObserver->m_lastDecodedSizeCh angedDelta);
167 EXPECT_EQ(0u, decodedSize()); 155 EXPECT_EQ(0u, decodedSize());
168 } 156 }
169 157
170 TEST_F(BitmapImageTest, maybeAnimated) 158 TEST_F(BitmapImageTest, maybeAnimated)
171 { 159 {
172 loadImage("/LayoutTests/fast/images/resources/gif-loop-count.gif"); 160 loadImage("/LayoutTests/fast/images/resources/gif-loop-count.gif");
173 for (size_t i = 0; i < frameCount(); ++i) { 161 for (size_t i = 0; i < frameCount(); ++i) {
174 EXPECT_TRUE(m_image->maybeAnimated()); 162 EXPECT_TRUE(m_image->maybeAnimated());
175 advanceAnimation(); 163 advanceAnimation();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 247
260 TEST_F(BitmapImageTest, correctDecodedDataSize) 248 TEST_F(BitmapImageTest, correctDecodedDataSize)
261 { 249 {
262 // When requesting a frame of a multi-frame GIF causes another frame to be 250 // When requesting a frame of a multi-frame GIF causes another frame to be
263 // decoded as well, both frames' sizes should be reported by the source and 251 // decoded as well, both frames' sizes should be reported by the source and
264 // thus included in the decoded size changed notification. 252 // thus included in the decoded size changed notification.
265 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); 253 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false);
266 frameAtIndex(1); 254 frameAtIndex(1);
267 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); 255 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData));
268 EXPECT_EQ(frameSize * 2, m_imageObserver->m_lastDecodedSizeChangedDelta); 256 EXPECT_EQ(frameSize * 2, m_imageObserver->m_lastDecodedSizeChangedDelta);
269
270 // Trying to destroy all data except an undecoded frame should cause the
271 // decoder to seek backwards and preserve the most recent previous frame
272 // necessary to decode that undecoded frame, and destroy all other frames.
273 setCurrentFrame(2);
274 destroyDecodedData(false);
275 EXPECT_EQ(-frameSize, m_imageObserver->m_lastDecodedSizeChangedDelta);
276 } 257 }
277 258
278 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged) 259 TEST_F(BitmapImageTest, recachingFrameAfterDataChanged)
279 { 260 {
280 loadImage("/LayoutTests/fast/images/resources/green.jpg"); 261 loadImage("/LayoutTests/fast/images/resources/green.jpg");
281 setFirstFrameNotComplete(); 262 setFirstFrameNotComplete();
282 EXPECT_GT(m_imageObserver->m_lastDecodedSizeChangedDelta, 0); 263 EXPECT_GT(m_imageObserver->m_lastDecodedSizeChangedDelta, 0);
283 m_imageObserver->m_lastDecodedSizeChangedDelta = 0; 264 m_imageObserver->m_lastDecodedSizeChangedDelta = 0;
284 265
285 // Calling dataChanged causes the cache to flush, but doesn't affect the 266 // Calling dataChanged causes the cache to flush, but doesn't affect the
(...skipping 11 matching lines...) Expand all
297 }; 278 };
298 279
299 TEST_F(BitmapImageDeferredDecodingTest, correctDecodedDataSize) 280 TEST_F(BitmapImageDeferredDecodingTest, correctDecodedDataSize)
300 { 281 {
301 // When deferred decoding is enabled, requesting any one frame shouldn't 282 // When deferred decoding is enabled, requesting any one frame shouldn't
302 // result in decoding any other frames. 283 // result in decoding any other frames.
303 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false); 284 loadImage("/LayoutTests/fast/images/resources/anim_none.gif", false);
304 frameAtIndex(1); 285 frameAtIndex(1);
305 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData)); 286 int frameSize = static_cast<int>(m_image->size().area() * sizeof(ImageFrame: :PixelData));
306 EXPECT_EQ(frameSize, m_imageObserver->m_lastDecodedSizeChangedDelta); 287 EXPECT_EQ(frameSize, m_imageObserver->m_lastDecodedSizeChangedDelta);
307 frameAtIndex(0); 288 frameAtIndex(0);
Peter Kasting 2016/04/05 01:55:58 This frameAtIndex() call should be removed as well
308
309 // Trying to destroy all data except an undecoded frame should go ahead and
310 // destroy all other frames.
311 setCurrentFrame(2);
312 destroyDecodedData(false);
313 EXPECT_EQ(-frameSize * 2, m_imageObserver->m_lastDecodedSizeChangedDelta);
314 } 289 }
315 290
316 } // namespace blink 291 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698