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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 ColorBehavior::TransformToTargetForTesting()); | 339 ColorBehavior::TransformToTargetForTesting()); |
340 | 340 |
341 SkImageInfo pix_info = SkImageInfo::MakeN32Premul(1, 1); | 341 SkImageInfo pix_info = SkImageInfo::MakeN32Premul(1, 1); |
342 | 342 |
343 size_t row_bytes = pix_info.minRowBytes(); | 343 size_t row_bytes = pix_info.minRowBytes(); |
344 size_t size = pix_info.getSafeSize(row_bytes); | 344 size_t size = pix_info.getSafeSize(row_bytes); |
345 | 345 |
346 Vector<char> storage(size); | 346 Vector<char> storage(size); |
347 SkPixmap pixmap(pix_info, storage.data(), row_bytes); | 347 SkPixmap pixmap(pix_info, storage.data(), row_bytes); |
348 | 348 |
349 // Before decoding, the frame is not known to be opaque. | 349 // Before decoding, the frame's alpha is unknown and assumed to be |
| 350 // transparent. This works well with partial decoding, which will be |
| 351 // transparent until the full first frame is decoded. |
350 sk_sp<SkImage> frame = decoder->CreateFrameAtIndex(0); | 352 sk_sp<SkImage> frame = decoder->CreateFrameAtIndex(0); |
351 ASSERT_TRUE(frame); | 353 ASSERT_TRUE(frame); |
352 EXPECT_FALSE(frame->isOpaque()); | 354 EXPECT_FALSE(frame->isOpaque()); |
353 | 355 |
354 // Force a lazy decode by reading pixels. | 356 // Force a lazy decode by reading pixels. |
355 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 357 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); |
356 | 358 |
357 // After decoding, the frame is known to be opaque. | |
358 frame = decoder->CreateFrameAtIndex(0); | 359 frame = decoder->CreateFrameAtIndex(0); |
359 ASSERT_TRUE(frame); | 360 ASSERT_TRUE(frame); |
360 EXPECT_TRUE(frame->isOpaque()); | 361 // When test_gif is true, we use a GIF file which is opaque. |
| 362 // When test_gif is false we use a PNG file instead. |
| 363 // Our PNG handling does not check if an image may be opaque, so it is |
| 364 // treated as transparent. |
| 365 EXPECT_EQ(test_gif, frame->isOpaque()); |
361 | 366 |
362 // Re-generating the opaque-marked frame should not fail. | 367 // Re-generating the opaque-marked frame should not fail. |
363 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); | 368 EXPECT_TRUE(frame->readPixels(pixmap, 0, 0)); |
364 } | 369 } |
365 } | 370 } |
366 | 371 |
367 // The DeferredImageDecoder would sometimes assume that a frame was a certain | 372 // The DeferredImageDecoder would sometimes assume that a frame was a certain |
368 // size even if the actual decoder reported it had a size of 0 bytes. This test | 373 // size even if the actual decoder reported it had a size of 0 bytes. This test |
369 // verifies that it's fixed by always checking with the actual decoder when | 374 // verifies that it's fixed by always checking with the actual decoder when |
370 // creating a frame. | 375 // creating a frame. |
(...skipping 16 matching lines...) Expand all Loading... |
387 SharedBuffer::Create(data_->Data(), data_->size()); | 392 SharedBuffer::Create(data_->Data(), data_->size()); |
388 EXPECT_EQ(original_data->size(), data_->size()); | 393 EXPECT_EQ(original_data->size(), data_->size()); |
389 lazy_decoder_->SetData(original_data, false); | 394 lazy_decoder_->SetData(original_data, false); |
390 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); | 395 RefPtr<SharedBuffer> new_data = lazy_decoder_->Data(); |
391 EXPECT_EQ(original_data->size(), new_data->size()); | 396 EXPECT_EQ(original_data->size(), new_data->size()); |
392 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), | 397 EXPECT_EQ(0, std::memcmp(original_data->Data(), new_data->Data(), |
393 new_data->size())); | 398 new_data->size())); |
394 } | 399 } |
395 | 400 |
396 } // namespace blink | 401 } // namespace blink |
OLD | NEW |