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

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

Issue 688423004: Remove multi-frame image decoder when the image is completely decoded (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix DeferredImageDecoderTest crash Created 6 years, 1 month 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 public: 52 public:
53 virtual void SetUp() override 53 virtual void SetUp() override
54 { 54 {
55 ImageDecodingStore::instance()->setCacheLimitInBytes(1024 * 1024); 55 ImageDecodingStore::instance()->setCacheLimitInBytes(1024 * 1024);
56 m_data = SharedBuffer::create(); 56 m_data = SharedBuffer::create();
57 m_generator = ImageFrameGenerator::create(fullSize(), m_data, false); 57 m_generator = ImageFrameGenerator::create(fullSize(), m_data, false);
58 useMockImageDecoderFactory(); 58 useMockImageDecoderFactory();
59 m_decodersDestroyed = 0; 59 m_decodersDestroyed = 0;
60 m_frameBufferRequestCount = 0; 60 m_frameBufferRequestCount = 0;
61 m_status = ImageFrame::FrameEmpty; 61 m_status = ImageFrame::FrameEmpty;
62 m_frameCount = 1;
62 } 63 }
63 64
64 virtual void TearDown() override 65 virtual void TearDown() override
65 { 66 {
66 ImageDecodingStore::instance()->clear(); 67 ImageDecodingStore::instance()->clear();
67 } 68 }
68 69
69 virtual void decoderBeingDestroyed() override 70 virtual void decoderBeingDestroyed() override
70 { 71 {
71 ++m_decodersDestroyed; 72 ++m_decodersDestroyed;
72 } 73 }
73 74
74 virtual void frameBufferRequested() override 75 virtual void frameBufferRequested() override
75 { 76 {
76 ++m_frameBufferRequestCount; 77 ++m_frameBufferRequestCount;
77 } 78 }
78 79
79 virtual ImageFrame::Status status() override 80 virtual ImageFrame::Status status() override
80 { 81 {
81 ImageFrame::Status currentStatus = m_status; 82 ImageFrame::Status currentStatus = m_status;
82 m_status = m_nextFrameStatus; 83 m_status = m_nextFrameStatus;
83 return currentStatus; 84 return currentStatus;
84 } 85 }
85 86
86 virtual size_t frameCount() override { return 1; } 87 virtual size_t frameCount() override { return m_frameCount; }
87 virtual int repetitionCount() const override { return cAnimationNone; } 88 virtual int repetitionCount() const override { return m_frameCount == 1 ? cA nimationNone:cAnimationLoopOnce; }
88 virtual float frameDuration() const override { return 0; } 89 virtual float frameDuration() const override { return 0; }
89 90
90 protected: 91 protected:
91 void useMockImageDecoderFactory() 92 void useMockImageDecoderFactory()
92 { 93 {
93 m_generator->setImageDecoderFactory(MockImageDecoderFactory::create(this , fullSize())); 94 m_generator->setImageDecoderFactory(MockImageDecoderFactory::create(this , fullSize()));
94 } 95 }
95 96
96 void addNewData() 97 void addNewData()
97 { 98 {
98 m_data->append("g", 1); 99 m_data->append("g", 1);
99 m_generator->setData(m_data, false); 100 m_generator->setData(m_data, false);
100 } 101 }
101 102
102 void setFrameStatus(ImageFrame::Status status) { m_status = m_nextFrameStat us = status; } 103 void setFrameStatus(ImageFrame::Status status) { m_status = m_nextFrameStat us = status; }
103 void setNextFrameStatus(ImageFrame::Status status) { m_nextFrameStatus = st atus; } 104 void setNextFrameStatus(ImageFrame::Status status) { m_nextFrameStatus = st atus; }
105 void setFrameCount(size_t count)
106 {
107 m_frameCount = count;
108 if (count > 1) {
109 m_generator.clear();
110 m_generator = ImageFrameGenerator::create(fullSize(), m_data, true, true);
111 useMockImageDecoderFactory();
112 }
113 }
104 114
105 RefPtr<SharedBuffer> m_data; 115 RefPtr<SharedBuffer> m_data;
106 RefPtr<ImageFrameGenerator> m_generator; 116 RefPtr<ImageFrameGenerator> m_generator;
107 int m_decodersDestroyed; 117 int m_decodersDestroyed;
108 int m_frameBufferRequestCount; 118 int m_frameBufferRequestCount;
109 ImageFrame::Status m_status; 119 ImageFrame::Status m_status;
110 ImageFrame::Status m_nextFrameStatus; 120 ImageFrame::Status m_nextFrameStatus;
121 size_t m_frameCount;
111 }; 122 };
112 123
113 TEST_F(ImageFrameGeneratorTest, incompleteDecode) 124 TEST_F(ImageFrameGeneratorTest, incompleteDecode)
114 { 125 {
115 setFrameStatus(ImageFrame::FramePartial); 126 setFrameStatus(ImageFrame::FramePartial);
116 127
117 char buffer[100 * 100 * 4]; 128 char buffer[100 * 100 * 4];
118 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 129 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
119 EXPECT_EQ(1, m_frameBufferRequestCount); 130 EXPECT_EQ(1, m_frameBufferRequestCount);
120 131
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // Decoder created again. 183 // Decoder created again.
173 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 184 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
174 EXPECT_EQ(3, m_frameBufferRequestCount); 185 EXPECT_EQ(3, m_frameBufferRequestCount);
175 } 186 }
176 187
177 TEST_F(ImageFrameGeneratorTest, frameHasAlpha) 188 TEST_F(ImageFrameGeneratorTest, frameHasAlpha)
178 { 189 {
179 setFrameStatus(ImageFrame::FramePartial); 190 setFrameStatus(ImageFrame::FramePartial);
180 191
181 char buffer[100 * 100 * 4]; 192 char buffer[100 * 100 * 4];
182 m_generator->decodeAndScale(imageInfo(), 1, buffer, 100 * 4); 193 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
183 EXPECT_TRUE(m_generator->hasAlpha(1)); 194 EXPECT_TRUE(m_generator->hasAlpha(0));
184 EXPECT_EQ(1, m_frameBufferRequestCount); 195 EXPECT_EQ(1, m_frameBufferRequestCount);
185 196
186 ImageDecoder* tempDecoder = 0; 197 ImageDecoder* tempDecoder = 0;
187 EXPECT_TRUE(ImageDecodingStore::instance()->lockDecoder(m_generator.get(), f ullSize(), &tempDecoder)); 198 EXPECT_TRUE(ImageDecodingStore::instance()->lockDecoder(m_generator.get(), f ullSize(), &tempDecoder));
188 ASSERT_TRUE(tempDecoder); 199 ASSERT_TRUE(tempDecoder);
189 static_cast<MockImageDecoder*>(tempDecoder)->setFrameHasAlpha(false); 200 static_cast<MockImageDecoder*>(tempDecoder)->setFrameHasAlpha(false);
190 ImageDecodingStore::instance()->unlockDecoder(m_generator.get(), tempDecoder ); 201 ImageDecodingStore::instance()->unlockDecoder(m_generator.get(), tempDecoder );
191 202
192 setFrameStatus(ImageFrame::FrameComplete); 203 setFrameStatus(ImageFrame::FrameComplete);
204 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
205 EXPECT_EQ(2, m_frameBufferRequestCount);
206 EXPECT_FALSE(m_generator->hasAlpha(0));
207 }
208
209 TEST_F(ImageFrameGeneratorTest, removeMultiFrameDecoder)
210 {
211 setFrameCount(3);
212 setFrameStatus(ImageFrame::FrameComplete);
213
214 char buffer[100 * 100 * 4];
215 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
216 EXPECT_EQ(1, m_frameBufferRequestCount);
217 EXPECT_EQ(0, m_decodersDestroyed);
218
219 setFrameStatus(ImageFrame::FrameComplete);
220
193 m_generator->decodeAndScale(imageInfo(), 1, buffer, 100 * 4); 221 m_generator->decodeAndScale(imageInfo(), 1, buffer, 100 * 4);
194 EXPECT_EQ(2, m_frameBufferRequestCount); 222 EXPECT_EQ(2, m_frameBufferRequestCount);
195 EXPECT_FALSE(m_generator->hasAlpha(1)); 223 EXPECT_EQ(0, m_decodersDestroyed);
224
225 setFrameStatus(ImageFrame::FrameComplete);
226
227 // Multi frame decoder should be removed.
228 m_generator->decodeAndScale(imageInfo(), 2, buffer, 100 * 4);
229 EXPECT_EQ(3, m_frameBufferRequestCount);
230 EXPECT_EQ(1, m_decodersDestroyed);
196 } 231 }
197 232
198 } // namespace blink 233 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/ImageFrameGenerator.cpp ('k') | Source/platform/graphics/test/MockImageDecoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698