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

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

Issue 985583002: Don't cache any SkBitmaps in DeferredImageDecoder (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: done now Created 5 years, 9 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 size_t m_frameCount; 145 size_t m_frameCount;
146 int m_repetitionCount; 146 int m_repetitionCount;
147 ImageFrame::Status m_status; 147 ImageFrame::Status m_status;
148 float m_frameDuration; 148 float m_frameDuration;
149 IntSize m_decodedSize; 149 IntSize m_decodedSize;
150 }; 150 };
151 151
152 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture) 152 TEST_F(DeferredImageDecoderTest, drawIntoSkPicture)
153 { 153 {
154 m_lazyDecoder->setData(*m_data, true); 154 m_lazyDecoder->setData(*m_data, true);
155 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 155 RefPtr<NativeImageSkia> image = m_lazyDecoder->createFrameAtIndex(0);
156 EXPECT_EQ(1, image->bitmap().width()); 156 EXPECT_EQ(1, image->bitmap().width());
157 EXPECT_EQ(1, image->bitmap().height()); 157 EXPECT_EQ(1, image->bitmap().height());
158 EXPECT_FALSE(image->bitmap().isNull()); 158 EXPECT_FALSE(image->bitmap().isNull());
159 EXPECT_TRUE(image->bitmap().isImmutable()); 159 EXPECT_TRUE(image->bitmap().isImmutable());
160 160
161 SkPictureRecorder recorder; 161 SkPictureRecorder recorder;
162 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 162 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
163 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 163 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
164 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 164 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
165 EXPECT_EQ(0, m_frameBufferRequestCount); 165 EXPECT_EQ(0, m_frameBufferRequestCount);
166 166
167 m_surface->getCanvas()->drawPicture(picture.get()); 167 m_surface->getCanvas()->drawPicture(picture.get());
168 EXPECT_EQ(0, m_frameBufferRequestCount); 168 EXPECT_EQ(0, m_frameBufferRequestCount);
169 169
170 SkBitmap canvasBitmap; 170 SkBitmap canvasBitmap;
171 canvasBitmap.allocN32Pixels(100, 100); 171 canvasBitmap.allocN32Pixels(100, 100);
172 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); 172 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
173 SkAutoLockPixels autoLock(canvasBitmap); 173 SkAutoLockPixels autoLock(canvasBitmap);
174 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 174 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
175 } 175 }
176 176
177 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) 177 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive)
178 { 178 {
179 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10); 179 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10);
180 180
181 // Received only half the file. 181 // Received only half the file.
182 m_lazyDecoder->setData(*partialData, false); 182 m_lazyDecoder->setData(*partialData, false);
183 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 183 RefPtr<NativeImageSkia> image = m_lazyDecoder->createFrameAtIndex(0);
184 SkPictureRecorder recorder; 184 SkPictureRecorder recorder;
185 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 185 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
186 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 186 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
187 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 187 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
188 m_surface->getCanvas()->drawPicture(picture.get()); 188 m_surface->getCanvas()->drawPicture(picture.get());
189 189
190 // Fully received the file and draw the SkPicture again. 190 // Fully received the file and draw the SkPicture again.
191 m_lazyDecoder->setData(*m_data, true); 191 m_lazyDecoder->setData(*m_data, true);
192 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); 192 image = m_lazyDecoder->createFrameAtIndex(0);
193 tempCanvas = recorder.beginRecording(100, 100, 0, 0); 193 tempCanvas = recorder.beginRecording(100, 100, 0, 0);
194 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 194 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
195 picture = adoptRef(recorder.endRecording()); 195 picture = adoptRef(recorder.endRecording());
196 m_surface->getCanvas()->drawPicture(picture.get()); 196 m_surface->getCanvas()->drawPicture(picture.get());
197 197
198 SkBitmap canvasBitmap; 198 SkBitmap canvasBitmap;
199 canvasBitmap.allocN32Pixels(100, 100); 199 canvasBitmap.allocN32Pixels(100, 100);
200 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); 200 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
201 SkAutoLockPixels autoLock(canvasBitmap); 201 SkAutoLockPixels autoLock(canvasBitmap);
202 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 202 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
203 } 203 }
204 204
205 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) 205 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture)
206 { 206 {
207 canvas->drawPicture(picture); 207 canvas->drawPicture(picture);
208 } 208 }
209 209
210 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) 210 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread)
211 { 211 {
212 m_lazyDecoder->setData(*m_data, true); 212 m_lazyDecoder->setData(*m_data, true);
213 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 213 RefPtr<NativeImageSkia> image = m_lazyDecoder->createFrameAtIndex(0);
214 EXPECT_EQ(1, image->bitmap().width()); 214 EXPECT_EQ(1, image->bitmap().width());
215 EXPECT_EQ(1, image->bitmap().height()); 215 EXPECT_EQ(1, image->bitmap().height());
216 EXPECT_FALSE(image->bitmap().isNull()); 216 EXPECT_FALSE(image->bitmap().isNull());
217 EXPECT_TRUE(image->bitmap().isImmutable()); 217 EXPECT_TRUE(image->bitmap().isImmutable());
218 218
219 SkPictureRecorder recorder; 219 SkPictureRecorder recorder;
220 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 220 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
221 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 221 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
222 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 222 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
223 EXPECT_EQ(0, m_frameBufferRequestCount); 223 EXPECT_EQ(0, m_frameBufferRequestCount);
224 224
225 // Create a thread to rasterize SkPicture. 225 // Create a thread to rasterize SkPicture.
226 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Raste rThread")); 226 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Raste rThread"));
227 thread->postTask(FROM_HERE, new Task(WTF::bind(&rasterizeMain, m_surface->ge tCanvas(), picture.get()))); 227 thread->postTask(FROM_HERE, new Task(WTF::bind(&rasterizeMain, m_surface->ge tCanvas(), picture.get())));
228 thread.clear(); 228 thread.clear();
229 EXPECT_EQ(0, m_frameBufferRequestCount); 229 EXPECT_EQ(0, m_frameBufferRequestCount);
230 230
231 SkBitmap canvasBitmap; 231 SkBitmap canvasBitmap;
232 canvasBitmap.allocN32Pixels(100, 100); 232 canvasBitmap.allocN32Pixels(100, 100);
233 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); 233 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
234 SkAutoLockPixels autoLock(canvasBitmap); 234 SkAutoLockPixels autoLock(canvasBitmap);
235 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 235 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
236 } 236 }
237 237
238 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading) 238 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading)
239 { 239 {
240 m_status = ImageFrame::FramePartial; 240 m_status = ImageFrame::FramePartial;
241 m_lazyDecoder->setData(*m_data, false); 241 m_lazyDecoder->setData(*m_data, false);
242 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); 242 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
243 ImageFrame* frame = m_lazyDecoder->frameBufferAtIndex(0); 243 unsigned firstId = m_lazyDecoder->createFrameAtIndex(0)->bitmap().getGenerat ionID();
244 unsigned firstId = frame->getSkBitmap().getGenerationID(); 244 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
245 EXPECT_EQ(ImageFrame::FramePartial, frame->status());
246 EXPECT_TRUE(m_actualDecoder); 245 EXPECT_TRUE(m_actualDecoder);
247 246
248 m_status = ImageFrame::FrameComplete; 247 m_status = ImageFrame::FrameComplete;
249 m_data->append(" ", 1); 248 m_data->append(" ", 1);
250 m_lazyDecoder->setData(*m_data, true); 249 m_lazyDecoder->setData(*m_data, true);
251 EXPECT_FALSE(m_actualDecoder); 250 EXPECT_FALSE(m_actualDecoder);
252 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); 251 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
253 frame = m_lazyDecoder->frameBufferAtIndex(0); 252 unsigned secondId = m_lazyDecoder->createFrameAtIndex(0)->bitmap().getGenera tionID();
254 unsigned secondId = frame->getSkBitmap().getGenerationID();
255 EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
256 EXPECT_FALSE(m_frameBufferRequestCount); 253 EXPECT_FALSE(m_frameBufferRequestCount);
257 EXPECT_NE(firstId, secondId); 254 EXPECT_NE(firstId, secondId);
258
259 EXPECT_EQ(secondId, m_lazyDecoder->frameBufferAtIndex(0)->getSkBitmap().getG enerationID());
260 } 255 }
261 256
262 TEST_F(DeferredImageDecoderTest, multiFrameImageLoading) 257 TEST_F(DeferredImageDecoderTest, multiFrameImageLoading)
263 { 258 {
264 m_repetitionCount = 10; 259 m_repetitionCount = 10;
265 m_frameCount = 1; 260 m_frameCount = 1;
266 m_frameDuration = 10; 261 m_frameDuration = 10;
267 m_status = ImageFrame::FramePartial; 262 m_status = ImageFrame::FramePartial;
268 m_lazyDecoder->setData(*m_data, false); 263 m_lazyDecoder->setData(*m_data, false);
269 EXPECT_EQ(ImageFrame::FramePartial, m_lazyDecoder->frameBufferAtIndex(0)->st atus()); 264 unsigned firstId = m_lazyDecoder->createFrameAtIndex(0)->bitmap().getGenerat ionID();
270 unsigned firstId = m_lazyDecoder->frameBufferAtIndex(0)->getSkBitmap().getGe nerationID();
271 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); 265 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
272 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
273 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0)); 266 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0));
274 267
275 m_frameCount = 2; 268 m_frameCount = 2;
276 m_frameDuration = 20; 269 m_frameDuration = 20;
277 m_status = ImageFrame::FrameComplete; 270 m_status = ImageFrame::FrameComplete;
278 m_data->append(" ", 1); 271 m_data->append(" ", 1);
279 m_lazyDecoder->setData(*m_data, false); 272 m_lazyDecoder->setData(*m_data, false);
280 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->s tatus()); 273 unsigned secondId = m_lazyDecoder->createFrameAtIndex(0)->bitmap().getGenera tionID();
281 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->s tatus());
282 unsigned secondId = m_lazyDecoder->frameBufferAtIndex(0)->getSkBitmap().getG enerationID();
283 EXPECT_NE(firstId, secondId); 274 EXPECT_NE(firstId, secondId);
284 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); 275 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
285 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1)); 276 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1));
286 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1)); 277 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1));
287 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
288 EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration());
289 EXPECT_TRUE(m_actualDecoder); 278 EXPECT_TRUE(m_actualDecoder);
290 279
291 m_frameCount = 3; 280 m_frameCount = 3;
292 m_frameDuration = 30; 281 m_frameDuration = 30;
293 m_status = ImageFrame::FrameComplete; 282 m_status = ImageFrame::FrameComplete;
294 m_lazyDecoder->setData(*m_data, true); 283 m_lazyDecoder->setData(*m_data, true);
295 EXPECT_FALSE(m_actualDecoder); 284 EXPECT_FALSE(m_actualDecoder);
296 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->s tatus());
297 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->s tatus());
298 EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(2)->s tatus());
299 EXPECT_EQ(secondId, m_lazyDecoder->frameBufferAtIndex(0)->getSkBitmap().getG enerationID());
300 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0)); 285 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
301 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1)); 286 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1));
302 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(2)); 287 EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(2));
303 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0)); 288 EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0));
304 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1)); 289 EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1));
305 EXPECT_EQ(30.0f, m_lazyDecoder->frameDurationAtIndex(2)); 290 EXPECT_EQ(30.0f, m_lazyDecoder->frameDurationAtIndex(2));
306 EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
307 EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration());
308 EXPECT_EQ(30.0f, m_lazyDecoder->frameBufferAtIndex(2)->duration());
309 EXPECT_EQ(10, m_lazyDecoder->repetitionCount()); 291 EXPECT_EQ(10, m_lazyDecoder->repetitionCount());
310 } 292 }
311 293
312 TEST_F(DeferredImageDecoderTest, decodedSize) 294 TEST_F(DeferredImageDecoderTest, decodedSize)
313 { 295 {
314 m_decodedSize = IntSize(22, 33); 296 m_decodedSize = IntSize(22, 33);
315 m_lazyDecoder->setData(*m_data, true); 297 m_lazyDecoder->setData(*m_data, true);
316 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 298 RefPtr<NativeImageSkia> image = m_lazyDecoder->createFrameAtIndex(0);
317 EXPECT_EQ(m_decodedSize.width(), image->bitmap().width()); 299 EXPECT_EQ(m_decodedSize.width(), image->bitmap().width());
318 EXPECT_EQ(m_decodedSize.height(), image->bitmap().height()); 300 EXPECT_EQ(m_decodedSize.height(), image->bitmap().height());
319 EXPECT_FALSE(image->bitmap().isNull()); 301 EXPECT_FALSE(image->bitmap().isNull());
320 EXPECT_TRUE(image->bitmap().isImmutable()); 302 EXPECT_TRUE(image->bitmap().isImmutable());
321 303
322 useMockImageDecoderFactory(); 304 useMockImageDecoderFactory();
323 305
324 // The following code should not fail any assert. 306 // The following code should not fail any assert.
325 SkPictureRecorder recorder; 307 SkPictureRecorder recorder;
326 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 308 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0);
(...skipping 11 matching lines...) Expand all
338 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); 320 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount());
339 m_frameCount = 2; 321 m_frameCount = 2;
340 m_lazyDecoder->setData(*m_data, false); 322 m_lazyDecoder->setData(*m_data, false);
341 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); 323 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount());
342 m_frameCount = 0; 324 m_frameCount = 0;
343 m_lazyDecoder->setData(*m_data, true); 325 m_lazyDecoder->setData(*m_data, true);
344 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); 326 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount());
345 } 327 }
346 328
347 } // namespace blink 329 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/DeferredImageDecoder.cpp ('k') | Source/platform/graphics/ImageSource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698