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

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

Issue 201213002: Remove uses of SkBitmap::Config (deprecated) from core/ and platform/. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00, 54 0x70, 0x48, 0x59, 0x73, 0x00, 0x00, 0x0b, 0x13, 0x00, 0x00,
55 0x0b, 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00, 55 0x0b, 0x13, 0x01, 0x00, 0x9a, 0x9c, 0x18, 0x00, 0x00, 0x00,
56 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0xff, 56 0x0c, 0x49, 0x44, 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0xff,
57 0xff, 0x3f, 0x00, 0x05, 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59, 57 0xff, 0x3f, 0x00, 0x05, 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59,
58 0xe7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 58 0xe7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae,
59 0x42, 0x60, 0x82, 59 0x42, 0x60, 0x82,
60 }; 60 };
61 61
62 static SkCanvas* createRasterCanvas(int width, int height) 62 static SkCanvas* createRasterCanvas(int width, int height)
63 { 63 {
64 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(SkBitmap::kARGB_8888_Co nfig, width, height)); 64 SkBitmap bitmap;
65 return new SkCanvas(device); 65 bitmap.allocN32Pixels(width, height);
66 return new SkCanvas(bitmap);
reed1 2014/03/17 13:25:18 There is an even nicer way to to this... return S
jbroman 2014/03/17 16:46:38 Done, and inlined at the call site.
66 } 67 }
67 68
68 struct Rasterizer { 69 struct Rasterizer {
69 SkCanvas* canvas; 70 SkCanvas* canvas;
70 SkPicture* picture; 71 SkPicture* picture;
71 }; 72 };
72 73
73 } // namespace 74 } // namespace
74 75
75 class DeferredImageDecoderTest : public ::testing::Test, public MockImageDecoder Client { 76 class DeferredImageDecoderTest : public ::testing::Test, public MockImageDecoder Client {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 164
164 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 165 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
165 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 166 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
166 m_picture.endRecording(); 167 m_picture.endRecording();
167 EXPECT_EQ(0, m_frameBufferRequestCount); 168 EXPECT_EQ(0, m_frameBufferRequestCount);
168 169
169 m_canvas->drawPicture(m_picture); 170 m_canvas->drawPicture(m_picture);
170 EXPECT_EQ(0, m_frameBufferRequestCount); 171 EXPECT_EQ(0, m_frameBufferRequestCount);
171 172
172 SkBitmap canvasBitmap; 173 SkBitmap canvasBitmap;
173 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 174 canvasBitmap.allocN32Pixels(100, 100);
174 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 175 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0));
175 SkAutoLockPixels autoLock(canvasBitmap); 176 SkAutoLockPixels autoLock(canvasBitmap);
176 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 177 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
177 } 178 }
178 179
179 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) 180 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive)
180 { 181 {
181 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10); 182 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10);
182 183
183 // Received only half the file. 184 // Received only half the file.
184 m_lazyDecoder->setData(partialData.get(), false); 185 m_lazyDecoder->setData(partialData.get(), false);
185 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 186 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage();
186 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 187 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
187 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 188 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
188 m_picture.endRecording(); 189 m_picture.endRecording();
189 m_canvas->drawPicture(m_picture); 190 m_canvas->drawPicture(m_picture);
190 191
191 // Fully received the file and draw the SkPicture again. 192 // Fully received the file and draw the SkPicture again.
192 m_lazyDecoder->setData(m_data.get(), true); 193 m_lazyDecoder->setData(m_data.get(), true);
193 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); 194 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
194 tempCanvas = m_picture.beginRecording(100, 100); 195 tempCanvas = m_picture.beginRecording(100, 100);
195 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 196 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
196 m_picture.endRecording(); 197 m_picture.endRecording();
197 m_canvas->drawPicture(m_picture); 198 m_canvas->drawPicture(m_picture);
198 199
199 SkBitmap canvasBitmap; 200 SkBitmap canvasBitmap;
200 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 201 canvasBitmap.allocN32Pixels(100, 100);
201 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 202 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0));
202 SkAutoLockPixels autoLock(canvasBitmap); 203 SkAutoLockPixels autoLock(canvasBitmap);
203 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 204 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
204 } 205 }
205 206
206 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) 207 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture)
207 { 208 {
208 canvas->drawPicture(*picture); 209 canvas->drawPicture(*picture);
209 } 210 }
210 211
(...skipping 11 matching lines...) Expand all
222 m_picture.endRecording(); 223 m_picture.endRecording();
223 EXPECT_EQ(0, m_frameBufferRequestCount); 224 EXPECT_EQ(0, m_frameBufferRequestCount);
224 225
225 // Create a thread to rasterize SkPicture. 226 // Create a thread to rasterize SkPicture.
226 OwnPtr<blink::WebThread> thread = adoptPtr(blink::Platform::current()->creat eThread("RasterThread")); 227 OwnPtr<blink::WebThread> thread = adoptPtr(blink::Platform::current()->creat eThread("RasterThread"));
227 thread->postTask(new Task(WTF::bind(&rasterizeMain, m_canvas.get(), &m_pictu re))); 228 thread->postTask(new Task(WTF::bind(&rasterizeMain, m_canvas.get(), &m_pictu re)));
228 thread.clear(); 229 thread.clear();
229 EXPECT_EQ(0, m_frameBufferRequestCount); 230 EXPECT_EQ(0, m_frameBufferRequestCount);
230 231
231 SkBitmap canvasBitmap; 232 SkBitmap canvasBitmap;
232 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 233 canvasBitmap.allocN32Pixels(100, 100);
233 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 234 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0));
234 SkAutoLockPixels autoLock(canvasBitmap); 235 SkAutoLockPixels autoLock(canvasBitmap);
235 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 236 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
236 } 237 }
237 238
238 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading) 239 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading)
239 { 240 {
240 m_status = ImageFrame::FramePartial; 241 m_status = ImageFrame::FramePartial;
241 m_lazyDecoder->setData(m_data.get(), false); 242 m_lazyDecoder->setData(m_data.get(), false);
242 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); 243 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // The following code should not fail any assert. 325 // The following code should not fail any assert.
325 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 326 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
326 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 327 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
327 m_picture.endRecording(); 328 m_picture.endRecording();
328 EXPECT_EQ(0, m_frameBufferRequestCount); 329 EXPECT_EQ(0, m_frameBufferRequestCount);
329 m_canvas->drawPicture(m_picture); 330 m_canvas->drawPicture(m_picture);
330 EXPECT_EQ(1, m_frameBufferRequestCount); 331 EXPECT_EQ(1, m_frameBufferRequestCount);
331 } 332 }
332 333
333 } // namespace WebCore 334 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698