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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.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
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 12 matching lines...) Expand all
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "platform/graphics/DecodingImageGenerator.h" 26 #include "platform/graphics/DecodingImageGenerator.h"
27 27
28 #include "platform/PlatformInstrumentation.h" 28 #include "platform/PlatformInstrumentation.h"
29 #include "platform/SharedBuffer.h" 29 #include "platform/SharedBuffer.h"
30 #include "platform/TraceEvent.h" 30 #include "platform/TraceEvent.h"
31 #include "platform/graphics/ImageFrameGenerator.h" 31 #include "platform/graphics/ImageFrameGenerator.h"
32 #include "platform/image-decoders/ImageDecoder.h" 32 #include "platform/image-decoders/ImageDecoder.h"
33 #include "platform/image-decoders/SegmentReader.h"
33 #include "third_party/skia/include/core/SkData.h" 34 #include "third_party/skia/include/core/SkData.h"
34 35
35 namespace blink { 36 namespace blink {
36 37
37 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f rameGenerator, const SkImageInfo& info, size_t index) 38 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f rameGenerator, const SkImageInfo& info, PassRefPtr<SegmentReader> data, bool all DataReceived, size_t index)
38 : SkImageGenerator(info) 39 : SkImageGenerator(info)
39 , m_frameGenerator(frameGenerator) 40 , m_frameGenerator(frameGenerator)
41 , m_data(data)
42 , m_allDataReceived(allDataReceived)
40 , m_frameIndex(index) 43 , m_frameIndex(index)
41 , m_canYUVDecode(false) 44 , m_canYUVDecode(false)
42 { 45 {
43 } 46 }
44 47
45 DecodingImageGenerator::~DecodingImageGenerator() 48 DecodingImageGenerator::~DecodingImageGenerator()
46 { 49 {
47 } 50 }
48 51
49 SkData* DecodingImageGenerator::onRefEncodedData() 52 SkData* DecodingImageGenerator::onRefEncodedData()
50 { 53 {
51 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); 54 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData");
52 55
53 return m_frameGenerator->refEncodedData(); 56 return m_allDataReceived ? m_data->getAsSkData().leakRef() : nullptr;
54 } 57 }
55 58
56 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount) 59 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount)
57 { 60 {
58 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st atic_cast<int>(m_frameIndex)); 61 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st atic_cast<int>(m_frameIndex));
59 62
60 // Implementation doesn't support scaling yet so make sure we're not given a different size. 63 // Implementation doesn't support scaling yet so make sure we're not given a different size.
61 if (info.width() != getInfo().width() || info.height() != getInfo().height() ) 64 if (info.width() != getInfo().width() || info.height() != getInfo().height() )
62 return false; 65 return false;
63 66
64 if (info.colorType() != getInfo().colorType()) { 67 if (info.colorType() != getInfo().colorType()) {
65 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkA lphaType after fully decoding the image frame, 68 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkA lphaType after fully decoding the image frame,
66 // so if we see a request for opaque, that is ok even if our initial alp ha type was not opaque. 69 // so if we see a request for opaque, that is ok even if our initial alp ha type was not opaque.
67 return false; 70 return false;
68 } 71 }
69 72
70 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); 73 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID());
71 bool decoded = m_frameGenerator->decodeAndScale(m_frameIndex, getInfo(), pix els, rowBytes); 74 bool decoded = m_frameGenerator->decodeAndScale(m_data.get(), m_allDataRecei ved, m_frameIndex, getInfo(), pixels, rowBytes);
72 PlatformInstrumentation::didDecodeLazyPixelRef(); 75 PlatformInstrumentation::didDecodeLazyPixelRef();
73 76
74 return decoded; 77 return decoded;
75 } 78 }
76 79
77 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpac e* colorSpace) const 80 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpac e* colorSpace) const
78 { 81 {
79 if (!m_canYUVDecode) 82 // YUV decoding does not currently support progressive decoding. See comment in ImageFrameGenerator.h.
83 if (!m_canYUVDecode || !m_allDataReceived)
80 return false; 84 return false;
81 85
82 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", static_c ast<int>(m_frameIndex)); 86 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", static_c ast<int>(m_frameIndex));
83 87
84 if (colorSpace) 88 if (colorSpace)
85 *colorSpace = kJPEG_SkYUVColorSpace; 89 *colorSpace = kJPEG_SkYUVColorSpace;
86 90
87 return m_frameGenerator->getYUVComponentSizes(sizeInfo); 91 return m_frameGenerator->getYUVComponentSizes(m_data.get(), sizeInfo);
88 } 92 }
89 93
90 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void * planes[3]) 94 bool DecodingImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void * planes[3])
91 { 95 {
92 ASSERT(m_canYUVDecode); 96 // YUV decoding does not currently support progressive decoding. See comment in ImageFrameGenerator.h.
97 ASSERT(m_canYUVDecode && m_allDataReceived);
93 98
94 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index" , static_cast<int>(m_frameIndex)); 99 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", "frame index" , static_cast<int>(m_frameIndex));
95 100
96 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); 101 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID());
97 bool decoded = m_frameGenerator->decodeToYUV(m_frameIndex, sizeInfo.fSizes, planes, sizeInfo.fWidthBytes); 102 bool decoded = m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, siz eInfo.fSizes, planes, sizeInfo.fWidthBytes);
98 PlatformInstrumentation::didDecodeLazyPixelRef(); 103 PlatformInstrumentation::didDecodeLazyPixelRef();
99 104
100 return decoded; 105 return decoded;
101 } 106 }
102 107
103 SkImageGenerator* DecodingImageGenerator::create(SkData* data) 108 SkImageGenerator* DecodingImageGenerator::create(SkData* data)
104 { 109 {
105 RefPtr<SharedBuffer> buffer = SharedBuffer::create(data->bytes(), data->size ());
106
107 // We just need the size of the image, so we have to temporarily create an I mageDecoder. Since 110 // We just need the size of the image, so we have to temporarily create an I mageDecoder. Since
108 // we only need the size, it doesn't really matter about premul or not, or g amma settings. 111 // we only need the size, it doesn't really matter about premul or not, or g amma settings.
109 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*buffer.get(), ImageDeco der::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); 112 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(static_cast<const char*> (data->data()), data->size(),
113 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl ied);
110 if (!decoder) 114 if (!decoder)
111 return 0; 115 return 0;
112 116
113 decoder->setData(buffer.get(), true); 117 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkData(data);
118 decoder->setData(segmentReader.get(), true);
114 if (!decoder->isSizeAvailable()) 119 if (!decoder->isSizeAvailable())
115 return 0; 120 return 0;
116 121
117 const IntSize size = decoder->size(); 122 const IntSize size = decoder->size();
118 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t()); 123 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t());
119 124
120 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), buffer, true, false); 125 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), false);
121 if (!frame) 126 if (!frame)
122 return 0; 127 return 0;
123 128
124 return new DecodingImageGenerator(frame, info, 0); 129 return new DecodingImageGenerator(frame, info, segmentReader.release(), true , 0);
125 } 130 }
126 131
127 } // namespace blink 132 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698