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

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

Issue 1484853003: Ganesh: images upload to GPU performance fix (skip copying encoded data) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: process comment #101 and rebase to latest Created 5 years 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 size_t frameCount() override { return m_frameCount; } 89 size_t frameCount() override { return m_frameCount; }
90 int repetitionCount() const override { return m_frameCount == 1 ? cAnimation None:cAnimationLoopOnce; } 90 int repetitionCount() const override { return m_frameCount == 1 ? cAnimation None:cAnimationLoopOnce; }
91 float frameDuration() const override { return 0; } 91 float frameDuration() const override { return 0; }
92 92
93 protected: 93 protected:
94 void useMockImageDecoderFactory() 94 void useMockImageDecoderFactory()
95 { 95 {
96 m_generator->setImageDecoderFactory(MockImageDecoderFactory::create(this , fullSize())); 96 m_generator->setImageDecoderFactory(MockImageDecoderFactory::create(this , fullSize()));
97 } 97 }
98 98
99 void addNewData() 99 void addNewData(bool allDataReceived = false)
100 { 100 {
101 m_data->append("g", 1); 101 m_data->append("g", 1);
102 m_generator->setData(m_data, false); 102 m_generator->setData(m_data, allDataReceived);
103 } 103 }
104 104
105 void setFrameStatus(ImageFrame::Status status) { m_status = m_nextFrameStat us = status; } 105 void setFrameStatus(ImageFrame::Status status) { m_status = m_nextFrameStat us = status; }
106 void setNextFrameStatus(ImageFrame::Status status) { m_nextFrameStatus = st atus; } 106 void setNextFrameStatus(ImageFrame::Status status) { m_nextFrameStatus = st atus; }
107 void setFrameCount(size_t count) 107 void setFrameCount(size_t count)
108 { 108 {
109 m_frameCount = count; 109 m_frameCount = count;
110 if (count > 1) { 110 if (count > 1) {
111 m_generator.clear(); 111 m_generator.clear();
112 m_generator = ImageFrameGenerator::create(fullSize(), m_data, true, true); 112 m_generator = ImageFrameGenerator::create(fullSize(), m_data, true, true);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 157 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
158 EXPECT_EQ(3, m_decodeRequestCount); 158 EXPECT_EQ(3, m_decodeRequestCount);
159 } 159 }
160 160
161 static void decodeThreadMain(ImageFrameGenerator* generator) 161 static void decodeThreadMain(ImageFrameGenerator* generator)
162 { 162 {
163 char buffer[100 * 100 * 4]; 163 char buffer[100 * 100 * 4];
164 generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 164 generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
165 } 165 }
166 166
167 static void decodeThreadWithRefEncodedMain(ImageFrameGenerator* generator)
168 {
169 // Image must be complete - refEncodedData otherwise returns null.
170 char buffer[100 * 100 * 4];
171 SkData* data = generator->refEncodedData();
172 generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
173 data->unref();
174 }
175
167 TEST_F(ImageFrameGeneratorTest, incompleteDecodeBecomesCompleteMultiThreaded) 176 TEST_F(ImageFrameGeneratorTest, incompleteDecodeBecomesCompleteMultiThreaded)
168 { 177 {
169 setFrameStatus(ImageFrame::FramePartial); 178 setFrameStatus(ImageFrame::FramePartial);
170 179
171 char buffer[100 * 100 * 4]; 180 char buffer[100 * 100 * 4];
172 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 181 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
173 EXPECT_EQ(1, m_decodeRequestCount); 182 EXPECT_EQ(1, m_decodeRequestCount);
174 EXPECT_EQ(0, m_decodersDestroyed); 183 EXPECT_EQ(0, m_decodersDestroyed);
184 SkData* data = m_generator->refEncodedData();
185 EXPECT_EQ(nullptr, data);
175 186
176 // LocalFrame can now be decoded completely. 187 // LocalFrame can now be decoded completely.
177 setFrameStatus(ImageFrame::FrameComplete); 188 setFrameStatus(ImageFrame::FrameComplete);
178 addNewData(); 189 addNewData();
190 // addNewData is calling m_generator->setData with allDataReceived == false, which means that
191 // refEncodedData should return null.
192 data = m_generator->refEncodedData();
193 EXPECT_EQ(nullptr, data);
179 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Decod eThread")); 194 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Decod eThread"));
180 thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&dec odeThreadMain, AllowCrossThreadAccess(m_generator.get())))); 195 thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&dec odeThreadMain, AllowCrossThreadAccess(m_generator.get()))));
181 thread.clear(); 196 thread.clear();
182 EXPECT_EQ(2, m_decodeRequestCount); 197 EXPECT_EQ(2, m_decodeRequestCount);
183 EXPECT_EQ(1, m_decodersDestroyed); 198 EXPECT_EQ(1, m_decodersDestroyed);
184 199
185 // Decoder created again. 200 // Decoder created again.
186 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 201 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
187 EXPECT_EQ(3, m_decodeRequestCount); 202 EXPECT_EQ(3, m_decodeRequestCount);
203
204 addNewData(true);
205 data = m_generator->refEncodedData();
206 ASSERT_TRUE(data);
207 // To prevent data writting, SkData::unique() should be false.
208 ASSERT_TRUE(!data->unique());
209
210 // Thread will also ref and unref the data.
211 thread = adoptPtr(Platform::current()->createThread("RefEncodedDataThread")) ;
212 thread->taskRunner()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&dec odeThreadWithRefEncodedMain, AllowCrossThreadAccess(m_generator.get()))));
213 thread.clear();
214 EXPECT_EQ(4, m_decodeRequestCount);
215
216 data->unref();
217 // m_generator is holding the only reference to SkData now.
218 ASSERT_TRUE(data->unique());
219
220 data = m_generator->refEncodedData();
221 ASSERT_TRUE(data && !data->unique());
222
223 // Delete generator, and SkData should have the only reference.
224 m_generator = nullptr;
225 ASSERT_TRUE(data->unique());
226 data->unref();
188 } 227 }
189 228
190 TEST_F(ImageFrameGeneratorTest, frameHasAlpha) 229 TEST_F(ImageFrameGeneratorTest, frameHasAlpha)
191 { 230 {
192 setFrameStatus(ImageFrame::FramePartial); 231 setFrameStatus(ImageFrame::FramePartial);
193 232
194 char buffer[100 * 100 * 4]; 233 char buffer[100 * 100 * 4];
195 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 234 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
196 EXPECT_TRUE(m_generator->hasAlpha(0)); 235 EXPECT_TRUE(m_generator->hasAlpha(0));
197 EXPECT_EQ(1, m_decodeRequestCount); 236 EXPECT_EQ(1, m_decodeRequestCount);
(...skipping 29 matching lines...) Expand all
227 266
228 setFrameStatus(ImageFrame::FrameComplete); 267 setFrameStatus(ImageFrame::FrameComplete);
229 268
230 // Multi frame decoder should be removed. 269 // Multi frame decoder should be removed.
231 m_generator->decodeAndScale(imageInfo(), 2, buffer, 100 * 4); 270 m_generator->decodeAndScale(imageInfo(), 2, buffer, 100 * 4);
232 EXPECT_EQ(3, m_decodeRequestCount); 271 EXPECT_EQ(3, m_decodeRequestCount);
233 EXPECT_EQ(1, m_decodersDestroyed); 272 EXPECT_EQ(1, m_decodersDestroyed);
234 } 273 }
235 274
236 } // namespace blink 275 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698