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

Side by Side Diff: Source/core/platform/graphics/chromium/DeferredImageDecoderTest.cpp

Issue 17999003: Deferred image decoding to support animated GIFs (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: done Created 7 years, 5 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 public: 72 public:
73 virtual void SetUp() 73 virtual void SetUp()
74 { 74 {
75 ImageDecodingStore::initializeOnce(); 75 ImageDecodingStore::initializeOnce();
76 DeferredImageDecoder::setEnabled(true); 76 DeferredImageDecoder::setEnabled(true);
77 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG)); 77 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG));
78 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(this); 78 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(this);
79 m_actualDecoder = decoder.get(); 79 m_actualDecoder = decoder.get();
80 m_actualDecoder->setSize(1, 1); 80 m_actualDecoder->setSize(1, 1);
81 m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release() ); 81 m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release() );
82 m_lazyDecoder->setData(m_data.get(), true);
83 m_canvas.reset(createRasterCanvas(100, 100)); 82 m_canvas.reset(createRasterCanvas(100, 100));
84 m_frameBufferRequestCount = 0; 83 m_frameBufferRequestCount = 0;
84 m_frameCount = 1;
85 m_repetitionCount = cAnimationNone;
86 m_frameStatus = ImageFrame::FrameComplete;
87 m_frameDuration = 0;
85 } 88 }
86 89
87 virtual void TearDown() 90 virtual void TearDown()
88 { 91 {
89 ImageDecodingStore::shutdown(); 92 ImageDecodingStore::shutdown();
90 } 93 }
91 94
92 virtual void decoderBeingDestroyed() 95 virtual void decoderBeingDestroyed()
93 { 96 {
94 m_actualDecoder = 0; 97 m_actualDecoder = 0;
95 } 98 }
96 99
97 virtual void frameBufferRequested() 100 virtual void frameBufferRequested()
98 { 101 {
99 ++m_frameBufferRequestCount; 102 ++m_frameBufferRequestCount;
100 } 103 }
101 104
105 virtual size_t frameCount()
106 {
107 return m_frameCount;
108 }
109
110 virtual int repetitionCount() const
111 {
112 return m_repetitionCount;
113 }
114
102 virtual ImageFrame::FrameStatus frameStatus() 115 virtual ImageFrame::FrameStatus frameStatus()
103 { 116 {
104 return ImageFrame::FrameComplete; 117 return m_frameStatus;
118 }
119
120 virtual float frameDuration() const
121 {
122 return m_frameDuration;
105 } 123 }
106 124
107 protected: 125 protected:
108 // Don't own this but saves the pointer to query states. 126 // Don't own this but saves the pointer to query states.
109 MockImageDecoder* m_actualDecoder; 127 MockImageDecoder* m_actualDecoder;
110 OwnPtr<DeferredImageDecoder> m_lazyDecoder; 128 OwnPtr<DeferredImageDecoder> m_lazyDecoder;
111 SkPicture m_picture; 129 SkPicture m_picture;
112 SkAutoTUnref<SkCanvas> m_canvas; 130 SkAutoTUnref<SkCanvas> m_canvas;
113 int m_frameBufferRequestCount; 131 int m_frameBufferRequestCount;
114 RefPtr<SharedBuffer> m_data; 132 RefPtr<SharedBuffer> m_data;
133 size_t m_frameCount;
134 int m_repetitionCount;
135 ImageFrame::FrameStatus m_frameStatus;
136 float m_frameDuration;
115 }; 137 };
116 138
117 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) 139 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture)
118 { 140 {
141 m_lazyDecoder->setData(m_data.get(), true);
119 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 142 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage();
120 EXPECT_EQ(1, image->bitmap().width()); 143 EXPECT_EQ(1, image->bitmap().width());
121 EXPECT_EQ(1, image->bitmap().height()); 144 EXPECT_EQ(1, image->bitmap().height());
122 EXPECT_FALSE(image->bitmap().isNull()); 145 EXPECT_FALSE(image->bitmap().isNull());
123 EXPECT_TRUE(image->bitmap().isImmutable()); 146 EXPECT_TRUE(image->bitmap().isImmutable());
124 147
125 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 148 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
126 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 149 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
127 m_picture.endRecording(); 150 m_picture.endRecording();
128 EXPECT_EQ(0, m_frameBufferRequestCount); 151 EXPECT_EQ(0, m_frameBufferRequestCount);
129 152
130 m_canvas->drawPicture(m_picture); 153 m_canvas->drawPicture(m_picture);
131 EXPECT_EQ(0, m_frameBufferRequestCount); 154 EXPECT_EQ(0, m_frameBufferRequestCount);
132 155
133 SkBitmap canvasBitmap; 156 SkBitmap canvasBitmap;
134 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 157 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
135 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 158 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0));
136 SkAutoLockPixels autoLock(canvasBitmap); 159 SkAutoLockPixels autoLock(canvasBitmap);
137 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 160 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
138 } 161 }
139 162
140 TEST_F(DeferredImageDecoderTest, DISABLED_drawScaledIntoSkPicture) 163 TEST_F(DeferredImageDecoderTest, DISABLED_drawScaledIntoSkPicture)
141 { 164 {
165 m_lazyDecoder->setData(m_data.get(), true);
142 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 166 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage();
143 SkBitmap scaledBitmap = image->resizedBitmap(SkISize::Make(50, 51), SkIRect: :MakeWH(50, 51)); 167 SkBitmap scaledBitmap = image->resizedBitmap(SkISize::Make(50, 51), SkIRect: :MakeWH(50, 51));
144 EXPECT_FALSE(scaledBitmap.isNull()); 168 EXPECT_FALSE(scaledBitmap.isNull());
145 EXPECT_TRUE(scaledBitmap.isImmutable()); 169 EXPECT_TRUE(scaledBitmap.isImmutable());
146 EXPECT_EQ(50, scaledBitmap.width()); 170 EXPECT_EQ(50, scaledBitmap.width());
147 EXPECT_EQ(51, scaledBitmap.height()); 171 EXPECT_EQ(51, scaledBitmap.height());
148 EXPECT_EQ(0, m_frameBufferRequestCount); 172 EXPECT_EQ(0, m_frameBufferRequestCount);
149 173
150 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 174 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
151 tempCanvas->drawBitmap(scaledBitmap, 0, 0); 175 tempCanvas->drawBitmap(scaledBitmap, 0, 0);
(...skipping 12 matching lines...) Expand all
164 } 188 }
165 189
166 static void rasterizeMain(void* arg) 190 static void rasterizeMain(void* arg)
167 { 191 {
168 Rasterizer* rasterizer = static_cast<Rasterizer*>(arg); 192 Rasterizer* rasterizer = static_cast<Rasterizer*>(arg);
169 rasterizer->canvas->drawPicture(*rasterizer->picture); 193 rasterizer->canvas->drawPicture(*rasterizer->picture);
170 } 194 }
171 195
172 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) 196 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread)
173 { 197 {
198 m_lazyDecoder->setData(m_data.get(), true);
174 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 199 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage();
175 EXPECT_EQ(1, image->bitmap().width()); 200 EXPECT_EQ(1, image->bitmap().width());
176 EXPECT_EQ(1, image->bitmap().height()); 201 EXPECT_EQ(1, image->bitmap().height());
177 EXPECT_FALSE(image->bitmap().isNull()); 202 EXPECT_FALSE(image->bitmap().isNull());
178 EXPECT_TRUE(image->bitmap().isImmutable()); 203 EXPECT_TRUE(image->bitmap().isImmutable());
179 204
180 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 205 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
181 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 206 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
182 m_picture.endRecording(); 207 m_picture.endRecording();
183 EXPECT_EQ(0, m_frameBufferRequestCount); 208 EXPECT_EQ(0, m_frameBufferRequestCount);
184 209
185 // Create a thread to rasterize SkPicture. 210 // Create a thread to rasterize SkPicture.
186 Rasterizer rasterizer; 211 Rasterizer rasterizer;
187 rasterizer.canvas = m_canvas; 212 rasterizer.canvas = m_canvas;
188 rasterizer.picture = &m_picture; 213 rasterizer.picture = &m_picture;
189 ThreadIdentifier threadID = createThread(&rasterizeMain, &rasterizer, "Raste rThread"); 214 ThreadIdentifier threadID = createThread(&rasterizeMain, &rasterizer, "Raste rThread");
190 waitForThreadCompletion(threadID); 215 waitForThreadCompletion(threadID);
191 EXPECT_EQ(0, m_frameBufferRequestCount); 216 EXPECT_EQ(0, m_frameBufferRequestCount);
192 217
193 SkBitmap canvasBitmap; 218 SkBitmap canvasBitmap;
194 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 219 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
195 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 220 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0));
196 SkAutoLockPixels autoLock(canvasBitmap); 221 SkAutoLockPixels autoLock(canvasBitmap);
197 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 222 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
198 } 223 }
199 224
225 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading)
226 {
227 m_frameStatus = ImageFrame::FramePartial;
228 m_lazyDecoder->setData(m_data.get(), false);
229 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
230 ImageFrame* frame = m_lazyDecoder->frameBufferAtIndex(0);
231 EXPECT_EQ(ImageFrame::FramePartial, frame->status());
232 EXPECT_TRUE(m_actualDecoder);
233
234 m_frameStatus = ImageFrame::FrameComplete;
235 m_lazyDecoder->setData(m_data.get(), true);
236 EXPECT_FALSE(m_actualDecoder);
237 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
238 frame = m_lazyDecoder->frameBufferAtIndex(0);
239 EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
240 EXPECT_FALSE(m_frameBufferRequestCount);
241 }
242
243 TEST_F(DeferredImageDecoderTest, multiFrameImageLoading)
244 {
245 m_repetitionCount = 10;
246 m_frameCount = 1;
247 m_frameDuration = 10;
248 m_frameStatus = ImageFrame::FramePartial;
249 m_lazyDecoder->setData(m_data.get(), false);
250 EXPECT_EQ(ImageFrame::FramePartial, m_lazyDecoder->frameBufferAtIndex(0)->st atus());
251 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
252 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
253 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0));
254
255 m_frameCount = 2;
256 m_frameDuration = 20;
257 m_frameStatus = ImageFrame::FrameComplete;
258 m_lazyDecoder->setData(m_data.get(), false);
259 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->s tatus());
260 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->s tatus());
261 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
262 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1));
263 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1));
264 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
265 EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration());
266 EXPECT_TRUE(m_actualDecoder);
267
268 m_frameCount = 3;
269 m_frameDuration = 30;
270 m_frameStatus = ImageFrame::FrameComplete;
271 m_lazyDecoder->setData(m_data.get(), true);
272 EXPECT_FALSE(m_actualDecoder);
273 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->s tatus());
274 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->s tatus());
275 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(2)->s tatus());
276 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
277 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1));
278 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(2));
279 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0));
280 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1));
281 EXPECT_EQ(30.0f, m_lazyDecoder->frameDurationAtIndex(2));
282 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
283 EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration());
284 EXPECT_EQ(30.0f, m_lazyDecoder->frameBufferAtIndex(2)->duration());
285 EXPECT_EQ(10, m_lazyDecoder->repetitionCount());
286 }
287
200 } // namespace 288 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698