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

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: 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 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/SkDataSegmentReader.h"
33 #include "third_party/skia/include/core/SkData.h" 34 #include "third_party/skia/include/core/SkData.h"
35 #include "third_party/skia/src/core/SkRWBuffer.h"
34 36
35 namespace blink { 37 namespace blink {
36 38
37 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f rameGenerator, const SkImageInfo& info, size_t index) 39 DecodingImageGenerator::DecodingImageGenerator(PassRefPtr<ImageFrameGenerator> f rameGenerator, const SkImageInfo& info, PassRefPtr<SegmentReader> data, bool all DataReceived, size_t index)
38 : SkImageGenerator(info) 40 : SkImageGenerator(info)
39 , m_frameGenerator(frameGenerator) 41 , m_frameGenerator(frameGenerator)
42 , m_data(data)
43 , m_allDataReceived(allDataReceived)
40 , m_frameIndex(index) 44 , m_frameIndex(index)
41 , m_generationId(0) 45 , m_generationId(0)
42 , m_canYUVDecode(false) 46 , m_canYUVDecode(false)
43 { 47 {
44 } 48 }
45 49
46 DecodingImageGenerator::~DecodingImageGenerator() 50 DecodingImageGenerator::~DecodingImageGenerator()
47 { 51 {
48 } 52 }
49 53
50 SkData* DecodingImageGenerator::onRefEncodedData() 54 SkData* DecodingImageGenerator::onRefEncodedData()
51 { 55 {
52 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); 56 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData");
53 57
54 return m_frameGenerator->refEncodedData(); 58 if (!m_allDataReceived)
59 return nullptr;
60
61 return m_data->getAsSkData().leakRef();
scroggo_chromium 2016/03/22 20:18:41 When combined with crrev.com/1567623002 (which fir
Peter Kasting 2016/03/23 02:42:57 Can we pass this out as a smart object and thus av
f(malita) 2016/03/23 16:41:57 This is part of the SkImageGenerator interface (ca
55 } 62 }
56 63
57 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount) 64 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor table[], int* tableCount)
58 { 65 {
59 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st atic_cast<int>(m_frameIndex)); 66 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", st atic_cast<int>(m_frameIndex));
60 67
61 // Implementation doesn't support scaling yet so make sure we're not given a different size. 68 // Implementation doesn't support scaling yet so make sure we're not given a different size.
62 if (info.width() != getInfo().width() || info.height() != getInfo().height() ) 69 if (info.width() != getInfo().width() || info.height() != getInfo().height() )
63 return false; 70 return false;
64 71
65 if (info.colorType() != getInfo().colorType()) { 72 if (info.colorType() != getInfo().colorType()) {
66 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkA lphaType after fully decoding the image frame, 73 // blink::ImageFrame may have changed the owning SkBitmap to kOpaque_SkA lphaType after fully decoding the image frame,
67 // so if we see a request for opaque, that is ok even if our initial alp ha type was not opaque. 74 // so if we see a request for opaque, that is ok even if our initial alp ha type was not opaque.
68 return false; 75 return false;
69 } 76 }
70 77
71 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); 78 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId);
72 bool decoded = m_frameGenerator->decodeAndScale(m_frameIndex, getInfo(), pix els, rowBytes); 79 bool decoded = m_frameGenerator->decodeAndScale(m_data.get(), m_allDataRecei ved, m_frameIndex, getInfo(), pixels, rowBytes);
73 PlatformInstrumentation::didDecodeLazyPixelRef(); 80 PlatformInstrumentation::didDecodeLazyPixelRef();
74 81
75 return decoded; 82 return decoded;
76 } 83 }
77 84
78 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], SkYUVColorSpace* colorSpace) 85 bool DecodingImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], SkYUVColorSpace* colorSpace)
79 { 86 {
80 if (!m_canYUVDecode) 87 if (!m_canYUVDecode || !m_allDataReceived)
Peter Kasting 2016/03/23 02:42:58 Why is it important to not YUV decode when we don'
scroggo_chromium 2016/03/24 13:59:44 I'm not very familiar with the YUV code, but there
Peter Kasting 2016/03/24 22:05:43 Ah. Maybe it makes sense to have a comment here s
scroggo_chromium 2016/03/25 01:05:10 Done.
81 return false; 88 return false;
82 89
83 bool requestingYUVSizes = !planes || !planes[0]; 90 bool requestingYUVSizes = !planes || !planes[0];
84 91
85 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", requestingYUV Sizes ? "sizes" : "frame index", static_cast<int>(m_frameIndex)); 92 TRACE_EVENT1("blink", "DecodingImageGenerator::getYUV8Planes", requestingYUV Sizes ? "sizes" : "frame index", static_cast<int>(m_frameIndex));
86 93
87 if (requestingYUVSizes) 94 if (requestingYUVSizes)
88 return m_frameGenerator->getYUVComponentSizes(sizes); 95 return m_frameGenerator->getYUVComponentSizes(m_data.get(), sizes);
89 96
90 if (colorSpace) 97 if (colorSpace)
91 *colorSpace = kJPEG_SkYUVColorSpace; 98 *colorSpace = kJPEG_SkYUVColorSpace;
92 99
93 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId); 100 PlatformInstrumentation::willDecodeLazyPixelRef(m_generationId);
94 bool decoded = m_frameGenerator->decodeToYUV(m_frameIndex, sizes, planes, ro wBytes); 101 bool decoded = m_frameGenerator->decodeToYUV(m_data.get(), m_frameIndex, siz es, planes, rowBytes);
95 PlatformInstrumentation::didDecodeLazyPixelRef(); 102 PlatformInstrumentation::didDecodeLazyPixelRef();
96 103
97 return decoded; 104 return decoded;
98 } 105 }
99 106
100 SkImageGenerator* DecodingImageGenerator::create(SkData* data) 107 SkImageGenerator* DecodingImageGenerator::create(SkData* data)
f(malita) 2016/03/23 16:41:57 Not new to this CL, but I think this factory is tr
scroggo_chromium 2016/03/24 13:59:44 That's correct. This method gets passed to SetImag
101 { 108 {
102 RefPtr<SharedBuffer> buffer = SharedBuffer::create(data->bytes(), data->size ()); 109 if (!data)
110 return 0;
Peter Kasting 2016/03/23 02:42:57 Is there a particular reason this explicit check n
scroggo_chromium 2016/03/24 13:59:44 I have not added any calls that might pass null, s
103 111
112 RefPtr<SegmentReader> segmentReader = adoptRef(new SkDataSegmentReader(data) );
104 // We just need the size of the image, so we have to temporarily create an I mageDecoder. Since 113 // We just need the size of the image, so we have to temporarily create an I mageDecoder. Since
105 // we only need the size, it doesn't really matter about premul or not, or g amma settings. 114 // we only need the size, it doesn't really matter about premul or not, or g amma settings.
106 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*buffer.get(), ImageDeco der::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); 115 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*segmentReader.get(), Im ageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied);
107 if (!decoder) 116 if (!decoder)
108 return 0; 117 return 0;
109 118
110 decoder->setData(buffer.get(), true); 119 decoder->setData(segmentReader.get(), true);
111 if (!decoder->isSizeAvailable()) 120 if (!decoder->isSizeAvailable())
112 return 0; 121 return 0;
113 122
114 const IntSize size = decoder->size(); 123 const IntSize size = decoder->size();
115 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t()); 124 const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.heigh t());
116 125
117 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), buffer, true, false); 126 RefPtr<ImageFrameGenerator> frame = ImageFrameGenerator::create(SkISize::Mak e(size.width(), size.height()), false);
118 if (!frame) 127 if (!frame)
119 return 0; 128 return 0;
120 129
121 return new DecodingImageGenerator(frame, info, 0); 130 return new DecodingImageGenerator(frame, info, segmentReader, true, 0);
f(malita) 2016/03/23 16:41:57 segmentReader.release() (to minimize refcount chu
scroggo_chromium 2016/03/24 13:59:44 Done.
122 } 131 }
123 132
124 } // namespace blink 133 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698