OLD | NEW |
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 EXPECT_EQ(1, image->bitmap().height()); | 155 EXPECT_EQ(1, image->bitmap().height()); |
156 EXPECT_FALSE(image->bitmap().isNull()); | 156 EXPECT_FALSE(image->bitmap().isNull()); |
157 EXPECT_TRUE(image->bitmap().isImmutable()); | 157 EXPECT_TRUE(image->bitmap().isImmutable()); |
158 | 158 |
159 SkPictureRecorder recorder; | 159 SkPictureRecorder recorder; |
160 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 160 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
161 tempCanvas->drawBitmap(image->bitmap(), 0, 0); | 161 tempCanvas->drawBitmap(image->bitmap(), 0, 0); |
162 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); | 162 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); |
163 EXPECT_EQ(0, m_frameBufferRequestCount); | 163 EXPECT_EQ(0, m_frameBufferRequestCount); |
164 | 164 |
165 m_canvas->drawPicture(*picture); | 165 m_canvas->drawPicture(picture.get()); |
166 EXPECT_EQ(0, m_frameBufferRequestCount); | 166 EXPECT_EQ(0, m_frameBufferRequestCount); |
167 | 167 |
168 SkBitmap canvasBitmap; | 168 SkBitmap canvasBitmap; |
169 ASSERT_TRUE(canvasBitmap.allocN32Pixels(100, 100)); | 169 ASSERT_TRUE(canvasBitmap.allocN32Pixels(100, 100)); |
170 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); | 170 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); |
171 SkAutoLockPixels autoLock(canvasBitmap); | 171 SkAutoLockPixels autoLock(canvasBitmap); |
172 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); | 172 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); |
173 } | 173 } |
174 | 174 |
175 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) | 175 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) |
176 { | 176 { |
177 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da
ta->size() - 10); | 177 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da
ta->size() - 10); |
178 | 178 |
179 // Received only half the file. | 179 // Received only half the file. |
180 m_lazyDecoder->setData(*partialData, false); | 180 m_lazyDecoder->setData(*partialData, false); |
181 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN
ativeImage(); | 181 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN
ativeImage(); |
182 SkPictureRecorder recorder; | 182 SkPictureRecorder recorder; |
183 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 183 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
184 tempCanvas->drawBitmap(image->bitmap(), 0, 0); | 184 tempCanvas->drawBitmap(image->bitmap(), 0, 0); |
185 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); | 185 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); |
186 m_canvas->drawPicture(*picture); | 186 m_canvas->drawPicture(picture.get()); |
187 | 187 |
188 // Fully received the file and draw the SkPicture again. | 188 // Fully received the file and draw the SkPicture again. |
189 m_lazyDecoder->setData(*m_data, true); | 189 m_lazyDecoder->setData(*m_data, true); |
190 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); | 190 image = m_lazyDecoder->frameBufferAtIndex(0)->asNewNativeImage(); |
191 tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 191 tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
192 tempCanvas->drawBitmap(image->bitmap(), 0, 0); | 192 tempCanvas->drawBitmap(image->bitmap(), 0, 0); |
193 picture = adoptRef(recorder.endRecording()); | 193 picture = adoptRef(recorder.endRecording()); |
194 m_canvas->drawPicture(*picture); | 194 m_canvas->drawPicture(picture.get()); |
195 | 195 |
196 SkBitmap canvasBitmap; | 196 SkBitmap canvasBitmap; |
197 ASSERT_TRUE(canvasBitmap.allocN32Pixels(100, 100)); | 197 ASSERT_TRUE(canvasBitmap.allocN32Pixels(100, 100)); |
198 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); | 198 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); |
199 SkAutoLockPixels autoLock(canvasBitmap); | 199 SkAutoLockPixels autoLock(canvasBitmap); |
200 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); | 200 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); |
201 } | 201 } |
202 | 202 |
203 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) | 203 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) |
204 { | 204 { |
205 canvas->drawPicture(*picture); | 205 canvas->drawPicture(picture); |
206 } | 206 } |
207 | 207 |
208 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) | 208 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) |
209 { | 209 { |
210 m_lazyDecoder->setData(*m_data, true); | 210 m_lazyDecoder->setData(*m_data, true); |
211 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN
ativeImage(); | 211 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN
ativeImage(); |
212 EXPECT_EQ(1, image->bitmap().width()); | 212 EXPECT_EQ(1, image->bitmap().width()); |
213 EXPECT_EQ(1, image->bitmap().height()); | 213 EXPECT_EQ(1, image->bitmap().height()); |
214 EXPECT_FALSE(image->bitmap().isNull()); | 214 EXPECT_FALSE(image->bitmap().isNull()); |
215 EXPECT_TRUE(image->bitmap().isImmutable()); | 215 EXPECT_TRUE(image->bitmap().isImmutable()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 EXPECT_TRUE(image->bitmap().isImmutable()); | 318 EXPECT_TRUE(image->bitmap().isImmutable()); |
319 | 319 |
320 useMockImageDecoderFactory(); | 320 useMockImageDecoderFactory(); |
321 | 321 |
322 // The following code should not fail any assert. | 322 // The following code should not fail any assert. |
323 SkPictureRecorder recorder; | 323 SkPictureRecorder recorder; |
324 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 324 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
325 tempCanvas->drawBitmap(image->bitmap(), 0, 0); | 325 tempCanvas->drawBitmap(image->bitmap(), 0, 0); |
326 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); | 326 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); |
327 EXPECT_EQ(0, m_frameBufferRequestCount); | 327 EXPECT_EQ(0, m_frameBufferRequestCount); |
328 m_canvas->drawPicture(*picture); | 328 m_canvas->drawPicture(picture.get()); |
329 EXPECT_EQ(1, m_frameBufferRequestCount); | 329 EXPECT_EQ(1, m_frameBufferRequestCount); |
330 } | 330 } |
331 | 331 |
332 TEST_F(DeferredImageDecoderTest, smallerFrameCount) | 332 TEST_F(DeferredImageDecoderTest, smallerFrameCount) |
333 { | 333 { |
334 m_frameCount = 1; | 334 m_frameCount = 1; |
335 m_lazyDecoder->setData(*m_data, false); | 335 m_lazyDecoder->setData(*m_data, false); |
336 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 336 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
337 m_frameCount = 2; | 337 m_frameCount = 2; |
338 m_lazyDecoder->setData(*m_data, false); | 338 m_lazyDecoder->setData(*m_data, false); |
339 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 339 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
340 m_frameCount = 0; | 340 m_frameCount = 0; |
341 m_lazyDecoder->setData(*m_data, true); | 341 m_lazyDecoder->setData(*m_data, true); |
342 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 342 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
343 } | 343 } |
344 | 344 |
345 } // namespace WebCore | 345 } // namespace WebCore |
OLD | NEW |