Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/DeferredImageDecoderTest.cpp

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 RefPtr<SharedBufferSegmentReader> segmentReader = adoptRef(new SharedBufferS egmentReader(m_data));
345 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(*segmentReader.get (),
343 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl ied); 346 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl ied);
344 OwnPtr<DeferredImageDecoder> decoder = DeferredImageDecoder::createForTestin g(actualDecoder.release()); 347 OwnPtr<DeferredImageDecoder> decoder = DeferredImageDecoder::createForTestin g(actualDecoder.release());
345 decoder->setData(*m_data, true); 348 decoder->setData(*m_data, true);
346 349
347 SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1); 350 SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1);
348 SkAutoPixmapStorage pixels; 351 SkAutoPixmapStorage pixels;
349 pixels.alloc(pixInfo); 352 pixels.alloc(pixInfo);
350 353
351 // Before decoding, the frame is not known to be opaque. 354 // Before decoding, the frame is not known to be opaque.
352 RefPtr<SkImage> frame = decoder->createFrameAtIndex(0); 355 RefPtr<SkImage> frame = decoder->createFrameAtIndex(0);
353 ASSERT_TRUE(frame); 356 ASSERT_TRUE(frame);
354 EXPECT_FALSE(frame->isOpaque()); 357 EXPECT_FALSE(frame->isOpaque());
355 358
356 // Force a lazy decode by reading pixels. 359 // Force a lazy decode by reading pixels.
357 EXPECT_TRUE(frame->readPixels(pixels, 0, 0)); 360 EXPECT_TRUE(frame->readPixels(pixels, 0, 0));
358 361
359 // After decoding, the frame is known to be opaque. 362 // After decoding, the frame is known to be opaque.
360 frame = decoder->createFrameAtIndex(0); 363 frame = decoder->createFrameAtIndex(0);
361 ASSERT_TRUE(frame); 364 ASSERT_TRUE(frame);
362 EXPECT_TRUE(frame->isOpaque()); 365 EXPECT_TRUE(frame->isOpaque());
363 366
364 // Re-generating the opaque-marked frame should not fail. 367 // Re-generating the opaque-marked frame should not fail.
365 EXPECT_TRUE(frame->readPixels(pixels, 0, 0)); 368 EXPECT_TRUE(frame->readPixels(pixels, 0, 0));
366 } 369 }
367 370
368 } // namespace blink 371 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698