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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/platform/graphics/chromium/DeferredImageDecoderTest.cpp
diff --git a/Source/core/platform/graphics/chromium/DeferredImageDecoderTest.cpp b/Source/core/platform/graphics/chromium/DeferredImageDecoderTest.cpp
index 6a4edad75a9a0ff84758d2fde849b36b90327275..78857c85606c8b8fe9efad441fb046069484df29 100644
--- a/Source/core/platform/graphics/chromium/DeferredImageDecoderTest.cpp
+++ b/Source/core/platform/graphics/chromium/DeferredImageDecoderTest.cpp
@@ -79,9 +79,12 @@ public:
m_actualDecoder = decoder.get();
m_actualDecoder->setSize(1, 1);
m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release());
- m_lazyDecoder->setData(m_data.get(), true);
m_canvas.reset(createRasterCanvas(100, 100));
m_frameBufferRequestCount = 0;
+ m_frameCount = 1;
+ m_repetitionCount = cAnimationNone;
+ m_frameStatus = ImageFrame::FrameComplete;
+ m_frameDuration = 0;
}
virtual void TearDown()
@@ -99,9 +102,24 @@ public:
++m_frameBufferRequestCount;
}
+ virtual size_t frameCount()
+ {
+ return m_frameCount;
+ }
+
+ virtual int repetitionCount() const
+ {
+ return m_repetitionCount;
+ }
+
virtual ImageFrame::FrameStatus frameStatus()
{
- return ImageFrame::FrameComplete;
+ return m_frameStatus;
+ }
+
+ virtual float frameDuration() const
+ {
+ return m_frameDuration;
}
protected:
@@ -112,10 +130,15 @@ protected:
SkAutoTUnref<SkCanvas> m_canvas;
int m_frameBufferRequestCount;
RefPtr<SharedBuffer> m_data;
+ size_t m_frameCount;
+ int m_repetitionCount;
+ ImageFrame::FrameStatus m_frameStatus;
+ float m_frameDuration;
};
TEST_F(DeferredImageDecoderTest, drawIntoSkPicture)
{
+ m_lazyDecoder->setData(m_data.get(), true);
RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
EXPECT_EQ(1, image->bitmap().width());
EXPECT_EQ(1, image->bitmap().height());
@@ -139,6 +162,7 @@ TEST_F(DeferredImageDecoderTest, drawIntoSkPicture)
TEST_F(DeferredImageDecoderTest, DISABLED_drawScaledIntoSkPicture)
{
+ m_lazyDecoder->setData(m_data.get(), true);
RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
SkBitmap scaledBitmap = image->resizedBitmap(SkISize::Make(50, 51), SkIRect::MakeWH(50, 51));
EXPECT_FALSE(scaledBitmap.isNull());
@@ -171,6 +195,7 @@ static void rasterizeMain(void* arg)
TEST_F(DeferredImageDecoderTest, decodeOnOtherThread)
{
+ m_lazyDecoder->setData(m_data.get(), true);
RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
EXPECT_EQ(1, image->bitmap().width());
EXPECT_EQ(1, image->bitmap().height());
@@ -197,4 +222,67 @@ TEST_F(DeferredImageDecoderTest, decodeOnOtherThread)
EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
}
+TEST_F(DeferredImageDecoderTest, singleFrameImageLoading)
+{
+ m_frameStatus = ImageFrame::FramePartial;
+ m_lazyDecoder->setData(m_data.get(), false);
+ EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
+ ImageFrame* frame = m_lazyDecoder->frameBufferAtIndex(0);
+ EXPECT_EQ(ImageFrame::FramePartial, frame->status());
+ EXPECT_TRUE(m_actualDecoder);
+
+ m_frameStatus = ImageFrame::FrameComplete;
+ m_lazyDecoder->setData(m_data.get(), true);
+ EXPECT_FALSE(m_actualDecoder);
+ EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
+ frame = m_lazyDecoder->frameBufferAtIndex(0);
+ EXPECT_EQ(ImageFrame::FrameComplete, frame->status());
+ EXPECT_FALSE(m_frameBufferRequestCount);
+}
+
+TEST_F(DeferredImageDecoderTest, multiFrameImageLoading)
+{
+ m_repetitionCount = 10;
+ m_frameCount = 1;
+ m_frameDuration = 10;
+ m_frameStatus = ImageFrame::FramePartial;
+ m_lazyDecoder->setData(m_data.get(), false);
+ EXPECT_EQ(ImageFrame::FramePartial, m_lazyDecoder->frameBufferAtIndex(0)->status());
+ EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
+ EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
+ EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0));
+
+ m_frameCount = 2;
+ m_frameDuration = 20;
+ m_frameStatus = ImageFrame::FrameComplete;
+ m_lazyDecoder->setData(m_data.get(), false);
+ EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->status());
+ EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->status());
+ EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
+ EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1));
+ EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1));
+ EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
+ EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration());
+ EXPECT_TRUE(m_actualDecoder);
+
+ m_frameCount = 3;
+ m_frameDuration = 30;
+ m_frameStatus = ImageFrame::FrameComplete;
+ m_lazyDecoder->setData(m_data.get(), true);
+ EXPECT_FALSE(m_actualDecoder);
+ EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(0)->status());
+ EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(1)->status());
+ EXPECT_EQ(ImageFrame::FrameComplete, m_lazyDecoder->frameBufferAtIndex(2)->status());
+ EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(0));
+ EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(1));
+ EXPECT_TRUE(m_lazyDecoder->frameIsCompleteAtIndex(2));
+ EXPECT_EQ(10.0f, m_lazyDecoder->frameDurationAtIndex(0));
+ EXPECT_EQ(20.0f, m_lazyDecoder->frameDurationAtIndex(1));
+ EXPECT_EQ(30.0f, m_lazyDecoder->frameDurationAtIndex(2));
+ EXPECT_EQ(10.0f, m_lazyDecoder->frameBufferAtIndex(0)->duration());
+ EXPECT_EQ(20.0f, m_lazyDecoder->frameBufferAtIndex(1)->duration());
+ EXPECT_EQ(30.0f, m_lazyDecoder->frameBufferAtIndex(2)->duration());
+ EXPECT_EQ(10, m_lazyDecoder->repetitionCount());
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698