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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp b/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp
index bf6e341d702d1bc5f8d8e782b31c19f96d077e87..431c3a111405ecf3350865ae22a087e7239d8914 100644
--- a/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp
+++ b/third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp
@@ -30,6 +30,7 @@
#include "platform/graphics/ImageDecodingStore.h"
#include "platform/graphics/ImageFrameGenerator.h"
#include "platform/graphics/test/MockImageDecoder.h"
+#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/Platform.h"
#include "public/platform/WebTaskRunner.h"
#include "public/platform/WebThread.h"
@@ -408,4 +409,79 @@ TEST_F(DeferredImageDecoderTest, respectActualDecoderSizeOnCreate)
EXPECT_EQ(static_cast<size_t>(0), frameBytesCleared);
}
+// 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.
+static PassRefPtr<SharedBuffer> readFile(const char* fileName)
+{
+ String filePath = testing::blinkRootDir();
+ filePath.append(fileName);
+ return testing::readFromFile(filePath);
+}
+
+/**
+ * Used to test decoding SkImages out of order.
+ * e.g.
+ * SkImage* imageA = decoder.createFrameAtIndex(0);
+ * // supply more (but not all) data to the decoder
+ * SkImage* imageB = decoder.createFrameAtIndex(laterFrame);
+ * imageB->preroll();
+ * imageA->preroll();
+ *
+ * This results in using the same ImageDecoder (in the ImageDecodingStore) to
+ * decode less data the second time. This test ensures that it is safe to do
+ * so.
+ *
+ * @param fileName File to decode
+ * @param bytesForFirstFrame Number of bytes needed to return an SkImage
+ * @param laterFrame Frame to decode with almost complete data. Can be 0.
+ */
+static void mixImages(const char* fileName, size_t bytesForFirstFrame, size_t laterFrame)
+{
+ RefPtr<SharedBuffer> file = readFile(fileName);
+ ASSERT_NE(file, nullptr);
+
+ OwnPtr<DeferredImageDecoder> decoder = DeferredImageDecoder::create(*file.get(), ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored);
+ ASSERT_NE(decoder, nullptr);
+
+ RefPtr<SharedBuffer> partialFile = SharedBuffer::create(file->data(), bytesForFirstFrame);
+ decoder->setData(*partialFile.get(), false);
+ RefPtr<SkImage> partialImage = decoder->createFrameAtIndex(0);
+
+ RefPtr<SharedBuffer> almostCompleteFile = SharedBuffer::create(file->data(), file->size() - 1);
+ decoder->setData(*almostCompleteFile.get(), false);
+ RefPtr<SkImage> imageWithMoreData = decoder->createFrameAtIndex(laterFrame);
+
+ imageWithMoreData->preroll();
+ partialImage->preroll();
+}
+
+TEST_F(DeferredImageDecoderTest, mixImagesGif)
+{
+ mixImages("/LayoutTests/fast/images/resources/animated.gif", 818u, 1u);
+}
+
+TEST_F(DeferredImageDecoderTest, mixImagesPng)
+{
+ mixImages("/LayoutTests/fast/images/resources/mu.png", 910u, 0u);
+}
+
+TEST_F(DeferredImageDecoderTest, mixImagesJpg)
+{
+ mixImages("/LayoutTests/fast/images/resources/2-dht.jpg", 177u, 0u);
+}
+
+TEST_F(DeferredImageDecoderTest, mixImagesWebp)
+{
+ mixImages("/LayoutTests/fast/images/resources/webp-animated.webp", 142u, 1u);
+}
+
+TEST_F(DeferredImageDecoderTest, mixImagesBmp)
+{
+ mixImages("/LayoutTests/fast/images/resources/lenna.bmp", 122u, 0u);
+}
+
+TEST_F(DeferredImageDecoderTest, mixImagesIco)
+{
+ mixImages("/LayoutTests/fast/images/resources/1bit.ico", 70u, 0u);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698