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

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

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add tests for other formats 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) 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 12 matching lines...) Expand all
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "platform/graphics/DeferredImageDecoder.h" 26 #include "platform/graphics/DeferredImageDecoder.h"
27 27
28 #include "platform/SharedBuffer.h" 28 #include "platform/SharedBuffer.h"
29 #include "platform/ThreadSafeFunctional.h" 29 #include "platform/ThreadSafeFunctional.h"
30 #include "platform/graphics/ImageDecodingStore.h" 30 #include "platform/graphics/ImageDecodingStore.h"
31 #include "platform/graphics/ImageFrameGenerator.h" 31 #include "platform/graphics/ImageFrameGenerator.h"
32 #include "platform/graphics/test/MockImageDecoder.h" 32 #include "platform/graphics/test/MockImageDecoder.h"
33 #include "platform/testing/UnitTestHelpers.h"
33 #include "public/platform/Platform.h" 34 #include "public/platform/Platform.h"
34 #include "public/platform/WebTaskRunner.h" 35 #include "public/platform/WebTaskRunner.h"
35 #include "public/platform/WebThread.h" 36 #include "public/platform/WebThread.h"
36 #include "public/platform/WebTraceLocation.h" 37 #include "public/platform/WebTraceLocation.h"
37 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
38 #include "third_party/skia/include/core/SkCanvas.h" 39 #include "third_party/skia/include/core/SkCanvas.h"
39 #include "third_party/skia/include/core/SkImage.h" 40 #include "third_party/skia/include/core/SkImage.h"
40 #include "third_party/skia/include/core/SkPicture.h" 41 #include "third_party/skia/include/core/SkPicture.h"
41 #include "third_party/skia/include/core/SkPictureRecorder.h" 42 #include "third_party/skia/include/core/SkPictureRecorder.h"
42 #include "third_party/skia/include/core/SkPixmap.h" 43 #include "third_party/skia/include/core/SkPixmap.h"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 m_lazyDecoder->setData(*m_data, false); 402 m_lazyDecoder->setData(*m_data, false);
402 m_lazyDecoder->createFrameAtIndex(0); 403 m_lazyDecoder->createFrameAtIndex(0);
403 m_lazyDecoder->createFrameAtIndex(1); 404 m_lazyDecoder->createFrameAtIndex(1);
404 m_lazyDecoder->setData(*m_data, true); 405 m_lazyDecoder->setData(*m_data, true);
405 // Clears only the first frame (0 bytes). If DeferredImageDecoder doesn't 406 // Clears only the first frame (0 bytes). If DeferredImageDecoder doesn't
406 // check with the actual decoder it reports 4 bytes instead. 407 // check with the actual decoder it reports 4 bytes instead.
407 size_t frameBytesCleared = m_lazyDecoder->clearCacheExceptFrame(1); 408 size_t frameBytesCleared = m_lazyDecoder->clearCacheExceptFrame(1);
408 EXPECT_EQ(static_cast<size_t>(0), frameBytesCleared); 409 EXPECT_EQ(static_cast<size_t>(0), frameBytesCleared);
409 } 410 }
410 411
412 // FIXME (scroggo): combine this with ImageDecoderTestHelpers?
Peter Kasting 2016/04/12 22:56:25 Nit: We prefer TODO to FIXME, I believe.
scroggo_chromium 2016/04/13 12:16:42 Done.
413 static PassRefPtr<SharedBuffer> readFile(const char* fileName)
414 {
415 String filePath = testing::blinkRootDir();
416 filePath.append(fileName);
417 return testing::readFromFile(filePath);
418 }
419
420 /**
421 * Used to test decoding SkImages out of order.
422 * e.g.
423 * SkImage* imageA = decoder.createFrameAtIndex(0);
424 * // supply more (but not all) data to the decoder
425 * SkImage* imageB = decoder.createFrameAtIndex(laterFrame);
426 * imageB->preroll();
427 * imageA->preroll();
428 *
429 * This results in using the same ImageDecoder (in the ImageDecodingStore) to
430 * decode less data the second time. This test ensures that it is safe to do
431 * so.
432 *
433 * @param fileName File to decode
434 * @param bytesForFirstFrame Number of bytes needed to return an SkImage
435 * @param laterFrame Frame to decode with almost complete data. Can be 0.
436 */
437 static void mixImages(const char* fileName, size_t bytesForFirstFrame, size_t la terFrame)
438 {
439 RefPtr<SharedBuffer> file = readFile(fileName);
440 ASSERT_NE(file, nullptr);
441
442 OwnPtr<DeferredImageDecoder> decoder = DeferredImageDecoder::create(*file.ge t(), ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored );
443 ASSERT_NE(decoder, nullptr);
444
445 RefPtr<SharedBuffer> partialFile = SharedBuffer::create(file->data(), bytesF orFirstFrame);
446 decoder->setData(*partialFile.get(), false);
447 RefPtr<SkImage> partialImage = decoder->createFrameAtIndex(0);
448
449 RefPtr<SharedBuffer> almostCompleteFile = SharedBuffer::create(file->data(), file->size() - 1);
450 decoder->setData(*almostCompleteFile.get(), false);
451 RefPtr<SkImage> imageWithMoreData = decoder->createFrameAtIndex(laterFrame);
452
453 imageWithMoreData->preroll();
454 partialImage->preroll();
455 }
456
457 TEST_F(DeferredImageDecoderTest, mixImagesGif)
458 {
459 mixImages("/LayoutTests/fast/images/resources/animated.gif", 818u, 1u);
460 }
461
462 TEST_F(DeferredImageDecoderTest, mixImagesPng)
463 {
464 mixImages("/LayoutTests/fast/images/resources/mu.png", 910u, 0u);
465 }
466
467 TEST_F(DeferredImageDecoderTest, mixImagesJpg)
468 {
469 mixImages("/LayoutTests/fast/images/resources/2-dht.jpg", 177u, 0u);
470 }
471
472 TEST_F(DeferredImageDecoderTest, mixImagesWebp)
473 {
474 mixImages("/LayoutTests/fast/images/resources/webp-animated.webp", 142u, 1u) ;
475 }
476
477 TEST_F(DeferredImageDecoderTest, mixImagesBmp)
478 {
479 mixImages("/LayoutTests/fast/images/resources/lenna.bmp", 122u, 0u);
480 }
481
482 TEST_F(DeferredImageDecoderTest, mixImagesIco)
483 {
484 mixImages("/LayoutTests/fast/images/resources/1bit.ico", 70u, 0u);
485 }
486
411 } // namespace blink 487 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698