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

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

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/graphics/DeferredImageDecoder.h"
6
7 #include "platform/SharedBuffer.h"
8 #include "platform/image-decoders/ImageDecoderTestHelpers.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/skia/include/core/SkImage.h"
11 #include "wtf/RefPtr.h"
12
13 namespace blink {
14
15 /**
16 * Used to test decoding SkImages out of order.
17 * e.g.
18 * SkImage* imageA = decoder.createFrameAtIndex(0);
19 * // supply more (but not all) data to the decoder
20 * SkImage* imageB = decoder.createFrameAtIndex(laterFrame);
21 * imageB->preroll();
22 * imageA->preroll();
23 *
24 * This results in using the same ImageDecoder (in the ImageDecodingStore) to
25 * decode less data the second time. This test ensures that it is safe to do
26 * so.
27 *
28 * @param fileName File to decode
29 * @param bytesForFirstFrame Number of bytes needed to return an SkImage
30 * @param laterFrame Frame to decode with almost complete data. Can be 0.
31 */
32 static void mixImages(const char* fileName, size_t bytesForFirstFrame, size_t la terFrame)
33 {
34 RefPtr<SharedBuffer> file = readFile(fileName);
35 ASSERT_NE(file, nullptr);
36
37 OwnPtr<DeferredImageDecoder> decoder = DeferredImageDecoder::create(*file.ge t(), ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored );
38 ASSERT_TRUE(decoder.get());
39
40 RefPtr<SharedBuffer> partialFile = SharedBuffer::create(file->data(), bytesF orFirstFrame);
41 decoder->setData(*partialFile.get(), false);
42 RefPtr<SkImage> partialImage = decoder->createFrameAtIndex(0);
43
44 RefPtr<SharedBuffer> almostCompleteFile = SharedBuffer::create(file->data(), file->size() - 1);
45 decoder->setData(*almostCompleteFile.get(), false);
46 RefPtr<SkImage> imageWithMoreData = decoder->createFrameAtIndex(laterFrame);
47
48 imageWithMoreData->preroll();
49 partialImage->preroll();
50 }
51
52 TEST(DeferredImageDecoderTestWoPlatform, mixImagesGif)
53 {
54 mixImages("/LayoutTests/fast/images/resources/animated.gif", 818u, 1u);
55 }
56
57 TEST(DeferredImageDecoderTestWoPlatform, mixImagesPng)
58 {
59 mixImages("/LayoutTests/fast/images/resources/mu.png", 910u, 0u);
60 }
61
62 TEST(DeferredImageDecoderTestWoPlatform, mixImagesJpg)
63 {
64 mixImages("/LayoutTests/fast/images/resources/2-dht.jpg", 177u, 0u);
65 }
66
67 TEST(DeferredImageDecoderTestWoPlatform, mixImagesWebp)
68 {
69 mixImages("/LayoutTests/fast/images/resources/webp-animated.webp", 142u, 1u) ;
70 }
71
72 TEST(DeferredImageDecoderTestWoPlatform, mixImagesBmp)
73 {
74 mixImages("/LayoutTests/fast/images/resources/lenna.bmp", 122u, 0u);
75 }
76
77 TEST(DeferredImageDecoderTestWoPlatform, mixImagesIco)
78 {
79 mixImages("/LayoutTests/fast/images/resources/1bit.ico", 70u, 0u);
80 }
81
82 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698