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

Side by Side Diff: third_party/WebKit/Source/platform/exported/WebImage.cpp

Issue 1812273003: Eliminate copies of encoded image data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small cleanups; remove unneeded changes 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 namespace blink { 45 namespace blink {
46 46
47 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) 47 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize)
48 { 48 {
49 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 49 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
50 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); 50 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored));
51 if (!decoder) 51 if (!decoder)
52 return WebImage(); 52 return WebImage();
53 53
54 decoder->setData(buffer.get(), true); 54 decoder->setData(buffer.release(), true);
55 if (!decoder->isSizeAvailable()) 55 if (!decoder->isSizeAvailable())
56 return WebImage(); 56 return WebImage();
57 57
58 // Frames are arranged by decreasing size, then decreasing bit depth. 58 // Frames are arranged by decreasing size, then decreasing bit depth.
59 // Pick the frame closest to |desiredSize|'s area without being smaller, 59 // Pick the frame closest to |desiredSize|'s area without being smaller,
60 // which has the highest bit depth. 60 // which has the highest bit depth.
61 const size_t frameCount = decoder->frameCount(); 61 const size_t frameCount = decoder->frameCount();
62 size_t index = 0; // Default to first frame if none are large enough. 62 size_t index = 0; // Default to first frame if none are large enough.
63 int frameAreaAtIndex = 0; 63 int frameAreaAtIndex = 0;
64 for (size_t i = 0; i < frameCount; ++i) { 64 for (size_t i = 0; i < frameCount; ++i) {
(...skipping 23 matching lines...) Expand all
88 WebVector<WebImage> WebImage::framesFromData(const WebData& data) 88 WebVector<WebImage> WebImage::framesFromData(const WebData& data)
89 { 89 {
90 // This is to protect from malicious images. It should be big enough that it 's never hit in pracice. 90 // This is to protect from malicious images. It should be big enough that it 's never hit in pracice.
91 const size_t maxFrameCount = 8; 91 const size_t maxFrameCount = 8;
92 92
93 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 93 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
94 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); 94 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored));
95 if (!decoder) 95 if (!decoder)
96 return WebVector<WebImage>(); 96 return WebVector<WebImage>();
97 97
98 decoder->setData(buffer.get(), true); 98 decoder->setData(buffer.release(), true);
99 if (!decoder->isSizeAvailable()) 99 if (!decoder->isSizeAvailable())
100 return WebVector<WebImage>(); 100 return WebVector<WebImage>();
101 101
102 // Frames are arranged by decreasing size, then decreasing bit depth. 102 // Frames are arranged by decreasing size, then decreasing bit depth.
103 // Keep the first frame at every size, has the highest bit depth. 103 // Keep the first frame at every size, has the highest bit depth.
104 const size_t frameCount = decoder->frameCount(); 104 const size_t frameCount = decoder->frameCount();
105 IntSize lastSize; 105 IntSize lastSize;
106 106
107 Vector<WebImage> frames; 107 Vector<WebImage> frames;
108 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { 108 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 WebImage::WebImage(const PassRefPtr<Image>& image) 146 WebImage::WebImage(const PassRefPtr<Image>& image)
147 { 147 {
148 if (!image) 148 if (!image)
149 return; 149 return;
150 150
151 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) 151 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame())
152 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); 152 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode);
153 } 153 }
154 154
155 } // namespace blink 155 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698