| 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 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "platform/graphics/DeferredImageDecoder.h" | 26 #include "platform/graphics/DeferredImageDecoder.h" |
| 27 | 27 |
| 28 #include "platform/SharedBuffer.h" | 28 #include "platform/SharedBuffer.h" |
| 29 #include "platform/Task.h" | 29 #include "platform/Task.h" |
| 30 #include "platform/ThreadSafeFunctional.h" | 30 #include "platform/ThreadSafeFunctional.h" |
| 31 #include "platform/graphics/ImageDecodingStore.h" | 31 #include "platform/graphics/ImageDecodingStore.h" |
| 32 #include "platform/graphics/ImageFrameGenerator.h" | 32 #include "platform/graphics/ImageFrameGenerator.h" |
| 33 #include "platform/graphics/test/MockImageDecoder.h" | 33 #include "platform/graphics/test/MockImageDecoder.h" |
| 34 #include "platform/image-decoders/SharedBufferSegmentReader.h" |
| 34 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 35 #include "public/platform/WebThread.h" | 36 #include "public/platform/WebThread.h" |
| 36 #include "public/platform/WebTraceLocation.h" | 37 #include "public/platform/WebTraceLocation.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 38 #include "third_party/skia/include/core/SkCanvas.h" | 39 #include "third_party/skia/include/core/SkCanvas.h" |
| 39 #include "third_party/skia/include/core/SkImage.h" | 40 #include "third_party/skia/include/core/SkImage.h" |
| 40 #include "third_party/skia/include/core/SkPicture.h" | 41 #include "third_party/skia/include/core/SkPicture.h" |
| 41 #include "third_party/skia/include/core/SkPictureRecorder.h" | 42 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 42 #include "third_party/skia/include/core/SkPixmap.h" | 43 #include "third_party/skia/include/core/SkPixmap.h" |
| 43 #include "third_party/skia/include/core/SkSurface.h" | 44 #include "third_party/skia/include/core/SkSurface.h" |
| 45 #include "third_party/skia/src/core/SkRWBuffer.h" |
| 44 #include "wtf/PassRefPtr.h" | 46 #include "wtf/PassRefPtr.h" |
| 45 #include "wtf/RefPtr.h" | 47 #include "wtf/RefPtr.h" |
| 46 | 48 |
| 47 namespace blink { | 49 namespace blink { |
| 48 | 50 |
| 49 namespace { | 51 namespace { |
| 50 | 52 |
| 51 // Raw data for a PNG file with 1x1 white pixels. | 53 // Raw data for a PNG file with 1x1 white pixels. |
| 52 const unsigned char whitePNG[] = { | 54 const unsigned char whitePNG[] = { |
| 53 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, | 55 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 m_frameCount = 2; | 334 m_frameCount = 2; |
| 333 m_lazyDecoder->setData(*m_data, false); | 335 m_lazyDecoder->setData(*m_data, false); |
| 334 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 336 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
| 335 m_frameCount = 0; | 337 m_frameCount = 0; |
| 336 m_lazyDecoder->setData(*m_data, true); | 338 m_lazyDecoder->setData(*m_data, true); |
| 337 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); | 339 EXPECT_EQ(m_frameCount, m_lazyDecoder->frameCount()); |
| 338 } | 340 } |
| 339 | 341 |
| 340 TEST_F(DeferredImageDecoderTest, frameOpacity) | 342 TEST_F(DeferredImageDecoderTest, frameOpacity) |
| 341 { | 343 { |
| 342 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(*m_data, | 344 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(*m_data.get(), |
| 343 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl
ied); | 345 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl
ied); |
| 344 OwnPtr<DeferredImageDecoder> decoder = DeferredImageDecoder::createForTestin
g(actualDecoder.release()); | 346 OwnPtr<DeferredImageDecoder> decoder = DeferredImageDecoder::createForTestin
g(actualDecoder.release()); |
| 345 decoder->setData(*m_data, true); | 347 decoder->setData(*m_data, true); |
| 346 | 348 |
| 347 SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1); | 349 SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1); |
| 348 SkAutoPixmapStorage pixels; | 350 SkAutoPixmapStorage pixels; |
| 349 pixels.alloc(pixInfo); | 351 pixels.alloc(pixInfo); |
| 350 | 352 |
| 351 // Before decoding, the frame is not known to be opaque. | 353 // Before decoding, the frame is not known to be opaque. |
| 352 RefPtr<SkImage> frame = decoder->createFrameAtIndex(0); | 354 RefPtr<SkImage> frame = decoder->createFrameAtIndex(0); |
| 353 ASSERT_TRUE(frame); | 355 ASSERT_TRUE(frame); |
| 354 EXPECT_FALSE(frame->isOpaque()); | 356 EXPECT_FALSE(frame->isOpaque()); |
| 355 | 357 |
| 356 // Force a lazy decode by reading pixels. | 358 // Force a lazy decode by reading pixels. |
| 357 EXPECT_TRUE(frame->readPixels(pixels, 0, 0)); | 359 EXPECT_TRUE(frame->readPixels(pixels, 0, 0)); |
| 358 | 360 |
| 359 // After decoding, the frame is known to be opaque. | 361 // After decoding, the frame is known to be opaque. |
| 360 frame = decoder->createFrameAtIndex(0); | 362 frame = decoder->createFrameAtIndex(0); |
| 361 ASSERT_TRUE(frame); | 363 ASSERT_TRUE(frame); |
| 362 EXPECT_TRUE(frame->isOpaque()); | 364 EXPECT_TRUE(frame->isOpaque()); |
| 363 | 365 |
| 364 // Re-generating the opaque-marked frame should not fail. | 366 // Re-generating the opaque-marked frame should not fail. |
| 365 EXPECT_TRUE(frame->readPixels(pixels, 0, 0)); | 367 EXPECT_TRUE(frame->readPixels(pixels, 0, 0)); |
| 366 } | 368 } |
| 367 | 369 |
| 368 } // namespace blink | 370 } // namespace blink |
| OLD | NEW |