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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 0x6d, 0x6d, 0x61, 0x3d, 0x30, 0x2e, 0x34, 0x35, 0x34, 0x35, 0x35, 0x00, | 76 0x6d, 0x6d, 0x61, 0x3d, 0x30, 0x2e, 0x34, 0x35, 0x34, 0x35, 0x35, 0x00, |
77 0x21, 0xf9, 0x04, 0x00, 0x14, 0x00, 0xff, 0x00, 0x21, 0xfe, 0x20, 0x43, | 77 0x21, 0xf9, 0x04, 0x00, 0x14, 0x00, 0xff, 0x00, 0x21, 0xfe, 0x20, 0x43, |
78 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, | 78 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, |
79 0x65, 0x7a, 0x67, 0x69, 0x66, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x67, 0x69, | 79 0x65, 0x7a, 0x67, 0x69, 0x66, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x67, 0x69, |
80 0x66, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x72, 0x00, 0x2c, 0x00, 0x00, 0x00, | 80 0x66, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x72, 0x00, 0x2c, 0x00, 0x00, 0x00, |
81 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x21, | 81 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x21, |
82 0xf9, 0x04, 0x00, 0x14, 0x00, 0xff, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, | 82 0xf9, 0x04, 0x00, 0x14, 0x00, 0xff, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, |
83 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4c, 0x01, 0x00, 0x3b, | 83 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4c, 0x01, 0x00, 0x3b, |
84 }; | 84 }; |
85 | 85 |
| 86 // Raw data for a GIF file with 1x1 white pixels. Modified from animatedGIF. |
| 87 const unsigned char whiteGIF[] = { |
| 88 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0xf0, 0x00, |
| 89 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x21, 0xff, 0x0b, 0x4e, 0x45, |
| 90 0x54, 0x53, 0x43, 0x41, 0x50, 0x45, 0x32, 0x2e, 0x30, 0x03, 0x01, 0x00, |
| 91 0x00, 0x00, 0x21, 0xff, 0x0b, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x4d, 0x61, |
| 92 0x67, 0x69, 0x63, 0x6b, 0x0d, 0x67, 0x61, 0x6d, 0x6d, 0x61, 0x3d, 0x30, |
| 93 0x2e, 0x34, 0x35, 0x34, 0x35, 0x35, 0x00, 0x21, 0xff, 0x0b, 0x49, 0x6d, |
| 94 0x61, 0x67, 0x65, 0x4d, 0x61, 0x67, 0x69, 0x63, 0x6b, 0x0d, 0x67, 0x61, |
| 95 0x6d, 0x6d, 0x61, 0x3d, 0x30, 0x2e, 0x34, 0x35, 0x34, 0x35, 0x35, 0x00, |
| 96 0x21, 0xf9, 0x04, 0x00, 0x00, 0x00, 0xff, 0x00, 0x2c, 0x00, 0x00, 0x00, |
| 97 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x4c, 0x01, 0x00, 0x3b}; |
| 98 |
86 } // namespace | 99 } // namespace |
87 | 100 |
88 class DeferredImageDecoderTest : public ::testing::Test, | 101 class DeferredImageDecoderTest : public ::testing::Test, |
89 public MockImageDecoderClient { | 102 public MockImageDecoderClient { |
90 public: | 103 public: |
91 void SetUp() override { | 104 void SetUp() override { |
92 ImageDecodingStore::instance().setCacheLimitInBytes(1024 * 1024); | 105 ImageDecodingStore::instance().setCacheLimitInBytes(1024 * 1024); |
93 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG)); | 106 m_data = SharedBuffer::create(whitePNG, sizeof(whitePNG)); |
94 m_frameCount = 1; | 107 m_frameCount = 1; |
95 std::unique_ptr<MockImageDecoder> decoder = MockImageDecoder::create(this); | 108 std::unique_ptr<MockImageDecoder> decoder = MockImageDecoder::create(this); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 330 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
318 m_frameCount = 2; | 331 m_frameCount = 2; |
319 m_lazyDecoder->setData(m_data, false); | 332 m_lazyDecoder->setData(m_data, false); |
320 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 333 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
321 m_frameCount = 0; | 334 m_frameCount = 0; |
322 m_lazyDecoder->setData(m_data, true); | 335 m_lazyDecoder->setData(m_data, true); |
323 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 336 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
324 } | 337 } |
325 | 338 |
326 TEST_F(DeferredImageDecoderTest, frameOpacity) { | 339 TEST_F(DeferredImageDecoderTest, frameOpacity) { |
327 std::unique_ptr<DeferredImageDecoder> decoder = DeferredImageDecoder::create( | 340 for (bool testGIF : {false, true}) { |
328 m_data, true, ImageDecoder::AlphaPremultiplied, | 341 if (testGIF) |
329 ColorBehavior::transformToTargetForTesting()); | 342 m_data = SharedBuffer::create(whiteGIF, sizeof(whiteGIF)); |
330 | 343 |
331 SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1); | 344 std::unique_ptr<DeferredImageDecoder> decoder = |
| 345 DeferredImageDecoder::create( |
| 346 m_data, true, ImageDecoder::AlphaPremultiplied, |
| 347 ColorBehavior::transformToTargetForTesting()); |
332 | 348 |
333 size_t rowBytes = pixInfo.minRowBytes(); | 349 SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1); |
334 size_t size = pixInfo.getSafeSize(rowBytes); | |
335 | 350 |
336 Vector<char> storage(size); | 351 size_t rowBytes = pixInfo.minRowBytes(); |
337 SkPixmap pixmap(pixInfo, storage.data(), rowBytes); | 352 size_t size = pixInfo.getSafeSize(rowBytes); |
338 | 353 |
339 // Before decoding, the frame is not known to be opaque. | 354 Vector<char> storage(size); |
340 sk_sp<SkImage> frame = decoder->createFrameAtIndex(0); | 355 SkPixmap pixmap(pixInfo, storage.data(), rowBytes); |
341 ASSERT_TRUE(frame); | |
342 EXPECT_FALSE(frame->isOpaque()); | |
343 | 356 |
344 // Force a lazy decode by reading pixels. | 357 // Before decoding, the frame is not known to be opaque. |
345 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 358 sk_sp<SkImage> frame = decoder->createFrameAtIndex(0); |
| 359 ASSERT_TRUE(frame); |
| 360 EXPECT_FALSE(frame->isOpaque()); |
346 | 361 |
347 // After decoding, the frame is known to be opaque. | 362 // Force a lazy decode by reading pixels. |
348 frame = decoder->createFrameAtIndex(0); | 363 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); |
349 ASSERT_TRUE(frame); | |
350 EXPECT_TRUE(frame->isOpaque()); | |
351 | 364 |
352 // Re-generating the opaque-marked frame should not fail. | 365 // After decoding, the frame is known to be opaque. |
353 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 366 frame = decoder->createFrameAtIndex(0); |
| 367 ASSERT_TRUE(frame); |
| 368 EXPECT_TRUE(frame->isOpaque()); |
| 369 |
| 370 // Re-generating the opaque-marked frame should not fail. |
| 371 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); |
| 372 } |
354 } | 373 } |
355 | 374 |
356 // The DeferredImageDecoder would sometimes assume that a frame was a certain | 375 // The DeferredImageDecoder would sometimes assume that a frame was a certain |
357 // size even if the actual decoder reported it had a size of 0 bytes. This test | 376 // size even if the actual decoder reported it had a size of 0 bytes. This test |
358 // verifies that it's fixed by always checking with the actual decoder when | 377 // verifies that it's fixed by always checking with the actual decoder when |
359 // creating a frame. | 378 // creating a frame. |
360 TEST_F(DeferredImageDecoderTest, respectActualDecoderSizeOnCreate) { | 379 TEST_F(DeferredImageDecoderTest, respectActualDecoderSizeOnCreate) { |
361 m_data = SharedBuffer::create(animatedGIF, sizeof(animatedGIF)); | 380 m_data = SharedBuffer::create(animatedGIF, sizeof(animatedGIF)); |
362 m_frameCount = 2; | 381 m_frameCount = 2; |
363 forceFirstFrameToBeEmpty(); | 382 forceFirstFrameToBeEmpty(); |
(...skipping 12 matching lines...) Expand all Loading... |
376 SharedBuffer::create(m_data->data(), m_data->size()); | 395 SharedBuffer::create(m_data->data(), m_data->size()); |
377 EXPECT_EQ(originalData->size(), m_data->size()); | 396 EXPECT_EQ(originalData->size(), m_data->size()); |
378 m_lazyDecoder->setData(originalData, false); | 397 m_lazyDecoder->setData(originalData, false); |
379 RefPtr<SharedBuffer> newData = m_lazyDecoder->data(); | 398 RefPtr<SharedBuffer> newData = m_lazyDecoder->data(); |
380 EXPECT_EQ(originalData->size(), newData->size()); | 399 EXPECT_EQ(originalData->size(), newData->size()); |
381 EXPECT_EQ( | 400 EXPECT_EQ( |
382 0, std::memcmp(originalData->data(), newData->data(), newData->size())); | 401 0, std::memcmp(originalData->data(), newData->data(), newData->size())); |
383 } | 402 } |
384 | 403 |
385 } // namespace blink | 404 } // namespace blink |
OLD | NEW |