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

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: schenney comments 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
« no previous file with comments | « Source/platform/DragImage.cpp ('k') | Source/platform/graphics/GraphicsContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 0x77, 0x53, 0xde, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, 52 0x77, 0x53, 0xde, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47,
53 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, 0x00, 0x09, 53 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, 0x00, 0x09,
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)
63 {
64 SkAutoTUnref<SkBaseDevice> device(new SkBitmapDevice(SkBitmap::kARGB_8888_Co nfig, width, height));
65 return new SkCanvas(device);
66 }
67
68 struct Rasterizer { 62 struct Rasterizer {
69 SkCanvas* canvas; 63 SkCanvas* canvas;
70 SkPicture* picture; 64 SkPicture* picture;
71 }; 65 };
72 66
73 } // namespace 67 } // namespace
74 68
75 class DeferredImageDecoderTest : public ::testing::Test, public MockImageDecoder Client { 69 class DeferredImageDecoderTest : public ::testing::Test, public MockImageDecoder Client {
76 public: 70 public:
77 virtual void SetUp() OVERRIDE 71 virtual void SetUp() OVERRIDE
78 { 72 {
79 ImageDecodingStore::initializeOnce(); 73 ImageDecodingStore::initializeOnce();
80 DeferredImageDecoder::setEnabled(true); 74 DeferredImageDecoder::setEnabled(true);
81 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG)); 75 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG));
82 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(this); 76 OwnPtr<MockImageDecoder> decoder = MockImageDecoder::create(this);
83 m_actualDecoder = decoder.get(); 77 m_actualDecoder = decoder.get();
84 m_actualDecoder->setSize(1, 1); 78 m_actualDecoder->setSize(1, 1);
85 m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release() ); 79 m_lazyDecoder = DeferredImageDecoder::createForTesting(decoder.release() );
86 m_canvas.reset(createRasterCanvas(100, 100)); 80 m_canvas.reset(SkCanvas::NewRasterN32(100, 100));
81 ASSERT_TRUE(m_canvas);
87 m_frameBufferRequestCount = 0; 82 m_frameBufferRequestCount = 0;
88 m_frameCount = 1; 83 m_frameCount = 1;
89 m_repetitionCount = cAnimationNone; 84 m_repetitionCount = cAnimationNone;
90 m_status = ImageFrame::FrameComplete; 85 m_status = ImageFrame::FrameComplete;
91 m_frameDuration = 0; 86 m_frameDuration = 0;
92 m_decodedSize = m_actualDecoder->size(); 87 m_decodedSize = m_actualDecoder->size();
93 } 88 }
94 89
95 virtual void TearDown() OVERRIDE 90 virtual void TearDown() OVERRIDE
96 { 91 {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 158
164 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 159 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
165 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 160 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
166 m_picture.endRecording(); 161 m_picture.endRecording();
167 EXPECT_EQ(0, m_frameBufferRequestCount); 162 EXPECT_EQ(0, m_frameBufferRequestCount);
168 163
169 m_canvas->drawPicture(m_picture); 164 m_canvas->drawPicture(m_picture);
170 EXPECT_EQ(0, m_frameBufferRequestCount); 165 EXPECT_EQ(0, m_frameBufferRequestCount);
171 166
172 SkBitmap canvasBitmap; 167 SkBitmap canvasBitmap;
173 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 168 ASSERT_TRUE(canvasBitmap.allocN32Pixels(100, 100));
174 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 169 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0));
175 SkAutoLockPixels autoLock(canvasBitmap); 170 SkAutoLockPixels autoLock(canvasBitmap);
176 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 171 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
177 } 172 }
178 173
179 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) 174 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive)
180 { 175 {
181 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10); 176 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10);
182 177
183 // Received only half the file. 178 // Received only half the file.
184 m_lazyDecoder->setData(partialData.get(), false); 179 m_lazyDecoder->setData(partialData.get(), false);
185 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage(); 180 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN ativeImage();
186 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 181 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
187 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 182 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
188 m_picture.endRecording(); 183 m_picture.endRecording();
189 m_canvas->drawPicture(m_picture); 184 m_canvas->drawPicture(m_picture);
190 185
191 // Fully received the file and draw the SkPicture again. 186 // Fully received the file and draw the SkPicture again.
192 m_lazyDecoder->setData(m_data.get(), true); 187 m_lazyDecoder->setData(m_data.get(), true);
193 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); 188 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage();
194 tempCanvas = m_picture.beginRecording(100, 100); 189 tempCanvas = m_picture.beginRecording(100, 100);
195 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 190 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
196 m_picture.endRecording(); 191 m_picture.endRecording();
197 m_canvas->drawPicture(m_picture); 192 m_canvas->drawPicture(m_picture);
198 193
199 SkBitmap canvasBitmap; 194 SkBitmap canvasBitmap;
200 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 195 ASSERT_TRUE(canvasBitmap.allocN32Pixels(100, 100));
201 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 196 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0));
202 SkAutoLockPixels autoLock(canvasBitmap); 197 SkAutoLockPixels autoLock(canvasBitmap);
203 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 198 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
204 } 199 }
205 200
206 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) 201 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture)
207 { 202 {
208 canvas->drawPicture(*picture); 203 canvas->drawPicture(*picture);
209 } 204 }
210 205
(...skipping 11 matching lines...) Expand all
222 m_picture.endRecording(); 217 m_picture.endRecording();
223 EXPECT_EQ(0, m_frameBufferRequestCount); 218 EXPECT_EQ(0, m_frameBufferRequestCount);
224 219
225 // Create a thread to rasterize SkPicture. 220 // Create a thread to rasterize SkPicture.
226 OwnPtr<blink::WebThread> thread = adoptPtr(blink::Platform::current()->creat eThread("RasterThread")); 221 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))); 222 thread->postTask(new Task(WTF::bind(&rasterizeMain, m_canvas.get(), &m_pictu re)));
228 thread.clear(); 223 thread.clear();
229 EXPECT_EQ(0, m_frameBufferRequestCount); 224 EXPECT_EQ(0, m_frameBufferRequestCount);
230 225
231 SkBitmap canvasBitmap; 226 SkBitmap canvasBitmap;
232 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); 227 ASSERT_TRUE(canvasBitmap.allocN32Pixels(100, 100));
233 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); 228 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0));
234 SkAutoLockPixels autoLock(canvasBitmap); 229 SkAutoLockPixels autoLock(canvasBitmap);
235 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); 230 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0));
236 } 231 }
237 232
238 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading) 233 TEST_F(DeferredImageDecoderTest, singleFrameImageLoading)
239 { 234 {
240 m_status = ImageFrame::FramePartial; 235 m_status = ImageFrame::FramePartial;
241 m_lazyDecoder->setData(m_data.get(), false); 236 m_lazyDecoder->setData(m_data.get(), false);
242 EXPECT_FALSE(m_lazyDecoder->frameIsCompleteAtIndex(0)); 237 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. 319 // The following code should not fail any assert.
325 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); 320 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100);
326 tempCanvas->drawBitmap(image->bitmap(), 0, 0); 321 tempCanvas->drawBitmap(image->bitmap(), 0, 0);
327 m_picture.endRecording(); 322 m_picture.endRecording();
328 EXPECT_EQ(0, m_frameBufferRequestCount); 323 EXPECT_EQ(0, m_frameBufferRequestCount);
329 m_canvas->drawPicture(m_picture); 324 m_canvas->drawPicture(m_picture);
330 EXPECT_EQ(1, m_frameBufferRequestCount); 325 EXPECT_EQ(1, m_frameBufferRequestCount);
331 } 326 }
332 327
333 } // namespace WebCore 328 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/DragImage.cpp ('k') | Source/platform/graphics/GraphicsContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698