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

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: 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "public/platform/WebImage.h" 31 #include "public/platform/WebImage.h"
32 32
33 #include "platform/SharedBuffer.h" 33 #include "platform/SharedBuffer.h"
34 #include "platform/graphics/Image.h" 34 #include "platform/graphics/Image.h"
35 #include "platform/image-decoders/ImageDecoder.h" 35 #include "platform/image-decoders/ImageDecoder.h"
36 #include "platform/image-decoders/SharedBufferSegmentReader.h"
36 #include "public/platform/WebData.h" 37 #include "public/platform/WebData.h"
37 #include "public/platform/WebSize.h" 38 #include "public/platform/WebSize.h"
38 #include "third_party/skia/include/core/SkImage.h" 39 #include "third_party/skia/include/core/SkImage.h"
39 #include "wtf/OwnPtr.h" 40 #include "wtf/OwnPtr.h"
40 #include "wtf/PassOwnPtr.h" 41 #include "wtf/PassOwnPtr.h"
41 #include "wtf/PassRefPtr.h" 42 #include "wtf/PassRefPtr.h"
42 #include "wtf/Vector.h" 43 #include "wtf/Vector.h"
43 #include <algorithm> 44 #include <algorithm>
44 45
45 namespace blink { 46 namespace blink {
46 47
47 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize) 48 WebImage WebImage::fromData(const WebData& data, const WebSize& desiredSize)
48 { 49 {
49 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 50 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
50 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); 51 RefPtr<SharedBufferSegmentReader> segmentReader = adoptRef(new SharedBufferS egmentReader(buffer));
52 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*segmentReader.get(), Imag eDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored));
51 if (!decoder) 53 if (!decoder)
52 return WebImage(); 54 return WebImage();
53 55
54 decoder->setData(buffer.get(), true); 56 decoder->setData(segmentReader.get(), true);
55 if (!decoder->isSizeAvailable()) 57 if (!decoder->isSizeAvailable())
56 return WebImage(); 58 return WebImage();
57 59
58 // Frames are arranged by decreasing size, then decreasing bit depth. 60 // Frames are arranged by decreasing size, then decreasing bit depth.
59 // Pick the frame closest to |desiredSize|'s area without being smaller, 61 // Pick the frame closest to |desiredSize|'s area without being smaller,
60 // which has the highest bit depth. 62 // which has the highest bit depth.
61 const size_t frameCount = decoder->frameCount(); 63 const size_t frameCount = decoder->frameCount();
62 size_t index = 0; // Default to first frame if none are large enough. 64 size_t index = 0; // Default to first frame if none are large enough.
63 int frameAreaAtIndex = 0; 65 int frameAreaAtIndex = 0;
64 for (size_t i = 0; i < frameCount; ++i) { 66 for (size_t i = 0; i < frameCount; ++i) {
(...skipping 19 matching lines...) Expand all
84 86
85 return WebImage(frame->bitmap()); 87 return WebImage(frame->bitmap());
86 } 88 }
87 89
88 WebVector<WebImage> WebImage::framesFromData(const WebData& data) 90 WebVector<WebImage> WebImage::framesFromData(const WebData& data)
89 { 91 {
90 // This is to protect from malicious images. It should be big enough that it 's never hit in pracice. 92 // 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; 93 const size_t maxFrameCount = 8;
92 94
93 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 95 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
94 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*buffer.get(), ImageDecode r::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored)); 96 RefPtr<SharedBufferSegmentReader> segmentReader = adoptRef(new SharedBufferS egmentReader(buffer));
97 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*segmentReader.get(), Imag eDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileIgnored));
95 if (!decoder) 98 if (!decoder)
96 return WebVector<WebImage>(); 99 return WebVector<WebImage>();
97 100
98 decoder->setData(buffer.get(), true); 101 decoder->setData(segmentReader.get(), true);
99 if (!decoder->isSizeAvailable()) 102 if (!decoder->isSizeAvailable())
100 return WebVector<WebImage>(); 103 return WebVector<WebImage>();
101 104
102 // Frames are arranged by decreasing size, then decreasing bit depth. 105 // Frames are arranged by decreasing size, then decreasing bit depth.
103 // Keep the first frame at every size, has the highest bit depth. 106 // Keep the first frame at every size, has the highest bit depth.
104 const size_t frameCount = decoder->frameCount(); 107 const size_t frameCount = decoder->frameCount();
105 IntSize lastSize; 108 IntSize lastSize;
106 109
107 Vector<WebImage> frames; 110 Vector<WebImage> frames;
108 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { 111 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) 149 WebImage::WebImage(const PassRefPtr<Image>& image)
147 { 150 {
148 if (!image) 151 if (!image)
149 return; 152 return;
150 153
151 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) 154 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame())
152 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); 155 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode);
153 } 156 }
154 157
155 } // namespace blink 158 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698