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

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

Issue 2690583002: Make cc/paint have concrete types (Closed)
Patch Set: PaintRecord as typedef, fixup playback calls Created 3 years, 9 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 }; 141 };
142 142
143 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecord) { 143 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecord) {
144 m_lazyDecoder->setData(m_data, true); 144 m_lazyDecoder->setData(m_data, true);
145 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); 145 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
146 ASSERT_TRUE(image); 146 ASSERT_TRUE(image);
147 EXPECT_EQ(1, image->width()); 147 EXPECT_EQ(1, image->width());
148 EXPECT_EQ(1, image->height()); 148 EXPECT_EQ(1, image->height());
149 149
150 PaintRecorder recorder; 150 PaintRecorder recorder;
151 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 151 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100);
152 tempCanvas->drawImage(image.get(), 0, 0); 152 tempCanvas->drawImage(image.get(), 0, 0);
153 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); 153 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture();
154 EXPECT_EQ(0, m_decodeRequestCount); 154 EXPECT_EQ(0, m_decodeRequestCount);
155 155
156 m_surface->getCanvas()->drawPicture(record); 156 m_surface->getCanvas()->drawPicture(record);
157 EXPECT_EQ(0, m_decodeRequestCount); 157 EXPECT_EQ(0, m_decodeRequestCount);
158 158
159 SkBitmap canvasBitmap; 159 SkBitmap canvasBitmap;
160 canvasBitmap.allocN32Pixels(100, 100); 160 canvasBitmap.allocN32Pixels(100, 100);
161 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); 161 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
162 SkAutoLockPixels autoLock(canvasBitmap); 162 SkAutoLockPixels autoLock(canvasBitmap);
163 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 163 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
164 } 164 }
165 165
166 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) { 166 TEST_F(DeferredImageDecoderTest, drawIntoPaintRecordProgressive) {
167 RefPtr<SharedBuffer> partialData = 167 RefPtr<SharedBuffer> partialData =
168 SharedBuffer::create(m_data->data(), m_data->size() - 10); 168 SharedBuffer::create(m_data->data(), m_data->size() - 10);
169 169
170 // Received only half the file. 170 // Received only half the file.
171 m_lazyDecoder->setData(partialData, false); 171 m_lazyDecoder->setData(partialData, false);
172 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); 172 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
173 ASSERT_TRUE(image); 173 ASSERT_TRUE(image);
174 PaintRecorder recorder; 174 PaintRecorder recorder;
175 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 175 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100);
176 tempCanvas->drawImage(image.get(), 0, 0); 176 tempCanvas->drawImage(image.get(), 0, 0);
177 m_surface->getCanvas()->drawPicture(recorder.finishRecordingAsPicture()); 177 m_surface->getCanvas()->drawPicture(recorder.finishRecordingAsPicture());
178 178
179 // Fully received the file and draw the PaintRecord again. 179 // Fully received the file and draw the PaintRecord again.
180 m_lazyDecoder->setData(m_data, true); 180 m_lazyDecoder->setData(m_data, true);
181 image = m_lazyDecoder->createFrameAtIndex(0); 181 image = m_lazyDecoder->createFrameAtIndex(0);
182 ASSERT_TRUE(image); 182 ASSERT_TRUE(image);
183 tempCanvas = recorder.beginRecording(100, 100, 0, 0); 183 tempCanvas = recorder.beginRecording(100, 100);
184 tempCanvas->drawImage(image.get(), 0, 0); 184 tempCanvas->drawImage(image.get(), 0, 0);
185 m_surface->getCanvas()->drawPicture(recorder.finishRecordingAsPicture()); 185 m_surface->getCanvas()->drawPicture(recorder.finishRecordingAsPicture());
186 186
187 SkBitmap canvasBitmap; 187 SkBitmap canvasBitmap;
188 canvasBitmap.allocN32Pixels(100, 100); 188 canvasBitmap.allocN32Pixels(100, 100);
189 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); 189 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0));
190 SkAutoLockPixels autoLock(canvasBitmap); 190 SkAutoLockPixels autoLock(canvasBitmap);
191 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 191 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
192 } 192 }
193 193
194 static void rasterizeMain(PaintCanvas* canvas, PaintRecord* record) { 194 static void rasterizeMain(PaintCanvas* canvas, PaintRecord* record) {
195 canvas->drawPicture(record); 195 canvas->drawPicture(record);
196 } 196 }
197 197
198 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { 198 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) {
199 m_lazyDecoder->setData(m_data, true); 199 m_lazyDecoder->setData(m_data, true);
200 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); 200 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
201 ASSERT_TRUE(image); 201 ASSERT_TRUE(image);
202 EXPECT_EQ(1, image->width()); 202 EXPECT_EQ(1, image->width());
203 EXPECT_EQ(1, image->height()); 203 EXPECT_EQ(1, image->height());
204 204
205 PaintRecorder recorder; 205 PaintRecorder recorder;
206 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 206 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100);
207 tempCanvas->drawImage(image.get(), 0, 0); 207 tempCanvas->drawImage(image.get(), 0, 0);
208 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); 208 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture();
209 EXPECT_EQ(0, m_decodeRequestCount); 209 EXPECT_EQ(0, m_decodeRequestCount);
210 210
211 // Create a thread to rasterize PaintRecord. 211 // Create a thread to rasterize PaintRecord.
212 std::unique_ptr<WebThread> thread = 212 std::unique_ptr<WebThread> thread =
213 WTF::wrapUnique(Platform::current()->createThread("RasterThread")); 213 WTF::wrapUnique(Platform::current()->createThread("RasterThread"));
214 thread->getWebTaskRunner()->postTask( 214 thread->getWebTaskRunner()->postTask(
215 BLINK_FROM_HERE, 215 BLINK_FROM_HERE,
216 crossThreadBind(&rasterizeMain, 216 crossThreadBind(&rasterizeMain,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 m_lazyDecoder->setData(m_data, true); 296 m_lazyDecoder->setData(m_data, true);
297 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); 297 sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0);
298 ASSERT_TRUE(image); 298 ASSERT_TRUE(image);
299 EXPECT_EQ(m_decodedSize.width(), image->width()); 299 EXPECT_EQ(m_decodedSize.width(), image->width());
300 EXPECT_EQ(m_decodedSize.height(), image->height()); 300 EXPECT_EQ(m_decodedSize.height(), image->height());
301 301
302 useMockImageDecoderFactory(); 302 useMockImageDecoderFactory();
303 303
304 // The following code should not fail any assert. 304 // The following code should not fail any assert.
305 PaintRecorder recorder; 305 PaintRecorder recorder;
306 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); 306 PaintCanvas* tempCanvas = recorder.beginRecording(100, 100);
307 tempCanvas->drawImage(image.get(), 0, 0); 307 tempCanvas->drawImage(image.get(), 0, 0);
308 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); 308 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture();
309 EXPECT_EQ(0, m_decodeRequestCount); 309 EXPECT_EQ(0, m_decodeRequestCount);
310 m_surface->getCanvas()->drawPicture(record); 310 m_surface->getCanvas()->drawPicture(record);
311 EXPECT_EQ(1, m_decodeRequestCount); 311 EXPECT_EQ(1, m_decodeRequestCount);
312 } 312 }
313 313
314 TEST_F(DeferredImageDecoderTest, smallerFrameCount) { 314 TEST_F(DeferredImageDecoderTest, smallerFrameCount) {
315 m_frameCount = 1; 315 m_frameCount = 1;
316 m_lazyDecoder->setData(m_data, false); 316 m_lazyDecoder->setData(m_data, false);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 SharedBuffer::create(m_data->data(), m_data->size()); 376 SharedBuffer::create(m_data->data(), m_data->size());
377 EXPECT_EQ(originalData->size(), m_data->size()); 377 EXPECT_EQ(originalData->size(), m_data->size());
378 m_lazyDecoder->setData(originalData, false); 378 m_lazyDecoder->setData(originalData, false);
379 RefPtr<SharedBuffer> newData = m_lazyDecoder->data(); 379 RefPtr<SharedBuffer> newData = m_lazyDecoder->data();
380 EXPECT_EQ(originalData->size(), newData->size()); 380 EXPECT_EQ(originalData->size(), newData->size());
381 EXPECT_EQ( 381 EXPECT_EQ(
382 0, std::memcmp(originalData->data(), newData->data(), newData->size())); 382 0, std::memcmp(originalData->data(), newData->data(), newData->size()));
383 } 383 }
384 384
385 } // namespace blink 385 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698