Chromium Code Reviews| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 { | 154 { |
| 155 m_lazyDecoder->setData(*m_data, true); | 155 m_lazyDecoder->setData(*m_data, true); |
| 156 RefPtr<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); | 156 RefPtr<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); |
| 157 ASSERT_TRUE(image); | 157 ASSERT_TRUE(image); |
| 158 EXPECT_EQ(1, image->width()); | 158 EXPECT_EQ(1, image->width()); |
| 159 EXPECT_EQ(1, image->height()); | 159 EXPECT_EQ(1, image->height()); |
| 160 | 160 |
| 161 SkPictureRecorder recorder; | 161 SkPictureRecorder recorder; |
| 162 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 162 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
| 163 tempCanvas->drawImage(image.get(), 0, 0); | 163 tempCanvas->drawImage(image.get(), 0, 0); |
| 164 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); | 164 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
| 165 EXPECT_EQ(0, m_decodeRequestCount); | 165 EXPECT_EQ(0, m_decodeRequestCount); |
| 166 | 166 |
| 167 m_surface->getCanvas()->drawPicture(picture.get()); | 167 m_surface->getCanvas()->drawPicture(picture); |
| 168 EXPECT_EQ(0, m_decodeRequestCount); | 168 EXPECT_EQ(0, m_decodeRequestCount); |
| 169 | 169 |
| 170 SkBitmap canvasBitmap; | 170 SkBitmap canvasBitmap; |
| 171 canvasBitmap.allocN32Pixels(100, 100); | 171 canvasBitmap.allocN32Pixels(100, 100); |
| 172 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); | 172 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); |
| 173 SkAutoLockPixels autoLock(canvasBitmap); | 173 SkAutoLockPixels autoLock(canvasBitmap); |
| 174 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); | 174 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) | 177 TEST_F(DeferredImageDecoderTest, drawIntoSkPictureProgressive) |
| 178 { | 178 { |
| 179 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10); | 179 RefPtr<SharedBuffer> partialData = SharedBuffer::create(m_data->data(), m_da ta->size() - 10); |
| 180 | 180 |
| 181 // Received only half the file. | 181 // Received only half the file. |
| 182 m_lazyDecoder->setData(*partialData, false); | 182 m_lazyDecoder->setData(*partialData, false); |
| 183 RefPtr<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); | 183 RefPtr<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); |
| 184 ASSERT_TRUE(image); | 184 ASSERT_TRUE(image); |
| 185 SkPictureRecorder recorder; | 185 SkPictureRecorder recorder; |
| 186 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 186 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
| 187 tempCanvas->drawImage(image.get(), 0, 0); | 187 tempCanvas->drawImage(image.get(), 0, 0); |
| 188 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); | 188 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
|
tomhudson
2016/03/24 19:52:40
We can fold these (two) calls into the drawPicture
f(malita)
2016/03/24 20:22:41
Right, that's the optimal pattern - but with tests
| |
| 189 m_surface->getCanvas()->drawPicture(picture.get()); | 189 m_surface->getCanvas()->drawPicture(picture); |
| 190 | 190 |
| 191 // Fully received the file and draw the SkPicture again. | 191 // Fully received the file and draw the SkPicture again. |
| 192 m_lazyDecoder->setData(*m_data, true); | 192 m_lazyDecoder->setData(*m_data, true); |
| 193 image = m_lazyDecoder->createFrameAtIndex(0); | 193 image = m_lazyDecoder->createFrameAtIndex(0); |
| 194 ASSERT_TRUE(image); | 194 ASSERT_TRUE(image); |
| 195 tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 195 tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
| 196 tempCanvas->drawImage(image.get(), 0, 0); | 196 tempCanvas->drawImage(image.get(), 0, 0); |
| 197 picture = adoptRef(recorder.endRecording()); | 197 picture = recorder.finishRecordingAsPicture(); |
| 198 m_surface->getCanvas()->drawPicture(picture.get()); | 198 m_surface->getCanvas()->drawPicture(picture); |
| 199 | 199 |
| 200 SkBitmap canvasBitmap; | 200 SkBitmap canvasBitmap; |
| 201 canvasBitmap.allocN32Pixels(100, 100); | 201 canvasBitmap.allocN32Pixels(100, 100); |
| 202 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); | 202 ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); |
| 203 SkAutoLockPixels autoLock(canvasBitmap); | 203 SkAutoLockPixels autoLock(canvasBitmap); |
| 204 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); | 204 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) | 207 static void rasterizeMain(SkCanvas* canvas, SkPicture* picture) |
| 208 { | 208 { |
| 209 canvas->drawPicture(picture); | 209 canvas->drawPicture(picture); |
| 210 } | 210 } |
| 211 | 211 |
| 212 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) | 212 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) |
| 213 { | 213 { |
| 214 m_lazyDecoder->setData(*m_data, true); | 214 m_lazyDecoder->setData(*m_data, true); |
| 215 RefPtr<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); | 215 RefPtr<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); |
| 216 ASSERT_TRUE(image); | 216 ASSERT_TRUE(image); |
| 217 EXPECT_EQ(1, image->width()); | 217 EXPECT_EQ(1, image->width()); |
| 218 EXPECT_EQ(1, image->height()); | 218 EXPECT_EQ(1, image->height()); |
| 219 | 219 |
| 220 SkPictureRecorder recorder; | 220 SkPictureRecorder recorder; |
| 221 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 221 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
| 222 tempCanvas->drawImage(image.get(), 0, 0); | 222 tempCanvas->drawImage(image.get(), 0, 0); |
| 223 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); | 223 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
| 224 EXPECT_EQ(0, m_decodeRequestCount); | 224 EXPECT_EQ(0, m_decodeRequestCount); |
| 225 | 225 |
| 226 // Create a thread to rasterize SkPicture. | 226 // Create a thread to rasterize SkPicture. |
| 227 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Raste rThread")); | 227 OwnPtr<WebThread> thread = adoptPtr(Platform::current()->createThread("Raste rThread")); |
| 228 thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&raster izeMain, AllowCrossThreadAccess(m_surface->getCanvas()), AllowCrossThreadAccess( picture.get()))); | 228 thread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, threadSafeBind(&raster izeMain, AllowCrossThreadAccess(m_surface->getCanvas()), AllowCrossThreadAccess( picture.get()))); |
| 229 thread.clear(); | 229 thread.clear(); |
| 230 EXPECT_EQ(0, m_decodeRequestCount); | 230 EXPECT_EQ(0, m_decodeRequestCount); |
| 231 | 231 |
| 232 SkBitmap canvasBitmap; | 232 SkBitmap canvasBitmap; |
| 233 canvasBitmap.allocN32Pixels(100, 100); | 233 canvasBitmap.allocN32Pixels(100, 100); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 ASSERT_TRUE(image); | 311 ASSERT_TRUE(image); |
| 312 EXPECT_EQ(m_decodedSize.width(), image->width()); | 312 EXPECT_EQ(m_decodedSize.width(), image->width()); |
| 313 EXPECT_EQ(m_decodedSize.height(), image->height()); | 313 EXPECT_EQ(m_decodedSize.height(), image->height()); |
| 314 | 314 |
| 315 useMockImageDecoderFactory(); | 315 useMockImageDecoderFactory(); |
| 316 | 316 |
| 317 // The following code should not fail any assert. | 317 // The following code should not fail any assert. |
| 318 SkPictureRecorder recorder; | 318 SkPictureRecorder recorder; |
| 319 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); | 319 SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); |
| 320 tempCanvas->drawImage(image.get(), 0, 0); | 320 tempCanvas->drawImage(image.get(), 0, 0); |
| 321 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); | 321 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); |
| 322 EXPECT_EQ(0, m_decodeRequestCount); | 322 EXPECT_EQ(0, m_decodeRequestCount); |
| 323 m_surface->getCanvas()->drawPicture(picture.get()); | 323 m_surface->getCanvas()->drawPicture(picture); |
| 324 EXPECT_EQ(1, m_decodeRequestCount); | 324 EXPECT_EQ(1, m_decodeRequestCount); |
| 325 } | 325 } |
| 326 | 326 |
| 327 TEST_F(DeferredImageDecoderTest, smallerFrameCount) | 327 TEST_F(DeferredImageDecoderTest, smallerFrameCount) |
| 328 { | 328 { |
| 329 m_frameCount = 1; | 329 m_frameCount = 1; |
| 330 m_lazyDecoder->setData(*m_data, false); | 330 m_lazyDecoder->setData(*m_data, false); |
| 331 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 331 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
| 332 m_frameCount = 2; | 332 m_frameCount = 2; |
| 333 m_lazyDecoder->setData(*m_data, false); | 333 m_lazyDecoder->setData(*m_data, false); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 363 // After decoding, the frame is known to be opaque. | 363 // After decoding, the frame is known to be opaque. |
| 364 frame = decoder->createFrameAtIndex(0); | 364 frame = decoder->createFrameAtIndex(0); |
| 365 ASSERT_TRUE(frame); | 365 ASSERT_TRUE(frame); |
| 366 EXPECT_TRUE(frame->isOpaque()); | 366 EXPECT_TRUE(frame->isOpaque()); |
| 367 | 367 |
| 368 // Re-generating the opaque-marked frame should not fail. | 368 // Re-generating the opaque-marked frame should not fail. |
| 369 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 369 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); |
| 370 } | 370 } |
| 371 | 371 |
| 372 } // namespace blink | 372 } // namespace blink |
| OLD | NEW |