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

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

Issue 1484853003: Ganesh: images upload to GPU performance fix (skip copying encoded data) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 27
28 #include "platform/graphics/ImageFrameGenerator.h" 28 #include "platform/graphics/ImageFrameGenerator.h"
29 29
30 #include "SkData.h"
30 #include "platform/SharedBuffer.h" 31 #include "platform/SharedBuffer.h"
31 #include "platform/TraceEvent.h" 32 #include "platform/TraceEvent.h"
32 #include "platform/graphics/ImageDecodingStore.h" 33 #include "platform/graphics/ImageDecodingStore.h"
33 #include "platform/image-decoders/ImageDecoder.h" 34 #include "platform/image-decoders/ImageDecoder.h"
34 35
35 namespace blink { 36 namespace blink {
36 37
37 static bool compatibleInfo(const SkImageInfo& src, const SkImageInfo& dst) 38 static bool compatibleInfo(const SkImageInfo& src, const SkImageInfo& dst)
38 { 39 {
39 if (src == dst) 40 if (src == dst)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 componentSizes[0].set(size.width(), size.height()); 95 componentSizes[0].set(size.width(), size.height());
95 size = decoder->decodedYUVSize(1, sizeType); 96 size = decoder->decodedYUVSize(1, sizeType);
96 componentSizes[1].set(size.width(), size.height()); 97 componentSizes[1].set(size.width(), size.height());
97 size = decoder->decodedYUVSize(2, sizeType); 98 size = decoder->decodedYUVSize(2, sizeType);
98 componentSizes[2].set(size.width(), size.height()); 99 componentSizes[2].set(size.width(), size.height());
99 return true; 100 return true;
100 } 101 }
101 102
102 ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha redBuffer> data, bool allDataReceived, bool isMultiFrame) 103 ImageFrameGenerator::ImageFrameGenerator(const SkISize& fullSize, PassRefPtr<Sha redBuffer> data, bool allDataReceived, bool isMultiFrame)
103 : m_fullSize(fullSize) 104 : m_fullSize(fullSize)
105 , m_data(new ThreadSafeDataTransport())
Noel Gordon 2015/12/04 03:28:03 Shouldn't this be using adoptRef?
aleksandar.stojiljkovic 2015/12/04 11:11:43 Done.
104 , m_isMultiFrame(isMultiFrame) 106 , m_isMultiFrame(isMultiFrame)
105 , m_decodeFailedAndEmpty(false) 107 , m_decodeFailedAndEmpty(false)
106 , m_decodeCount(0) 108 , m_decodeCount(0)
107 , m_frameCount(0) 109 , m_frameCount(0)
108 { 110 {
109 setData(data.get(), allDataReceived); 111 setData(data.get(), allDataReceived);
110 } 112 }
111 113
112 ImageFrameGenerator::~ImageFrameGenerator() 114 ImageFrameGenerator::~ImageFrameGenerator()
113 { 115 {
114 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this); 116 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this);
115 } 117 }
116 118
117 void ImageFrameGenerator::setData(PassRefPtr<SharedBuffer> data, bool allDataRec eived) 119 void ImageFrameGenerator::setData(PassRefPtr<SharedBuffer> data, bool allDataRec eived)
118 { 120 {
119 m_data.setData(data.get(), allDataReceived); 121 m_data->setData(data.get(), allDataReceived);
120 } 122 }
121 123
122 void ImageFrameGenerator::copyData(RefPtr<SharedBuffer>* data, bool* allDataRece ived) 124 static void sharedBufSkDataReleaseProc(const void* addr, void* ctx)
Noel Gordon 2015/12/04 03:28:03 What value does "Buf" add here? sharedSkDataRelea
aleksandar.stojiljkovic 2015/12/04 11:11:43 Using address now in assert bellow. abbrv resolved
123 { 125 {
126 ThreadSafeDataTransport* someonesMData = static_cast<ThreadSafeDataTransport *>(ctx);
Noel Gordon 2015/12/04 03:28:03 someonesMData, is actually someone's dataTransport
aleksandar.stojiljkovic 2015/12/04 11:11:43 Done.
127 ASSERT(someonesMData);
Noel Gordon 2015/12/04 03:28:03 Is there a stronger assertion you could make here?
aleksandar.stojiljkovic 2015/12/04 11:11:43 There is release_assert covering the situation in
128 // Deref m_data now.
129 someonesMData->deref();
130 }
131
132 SkData* ImageFrameGenerator::refEncodedData() const
133 {
134 // Every SkData instance and SharedBuffer need to keep buffer->data() refcou nted.
135 // Both SkData and m_data.m_readBuffer are having separate ref counting impl ementations.
136 //
137 // SkData's SkData::NewWithProc is designed with similar use case in mind,
138 // unmapping wrapped shmem data once all SkData instances are disposed.
139 // in this case, sharedBufSkDataReleaseProc would just need to deref (since m_data.m_readBuffer
140 // might still hold a reference) and that is happening in sharedBufSkDataRel easeProc.
141 //
142 // Preventing m_data disposal if ImageFrameGenerator is thread safe - SkData could get disposed
143 // in any thread, and SkData would still need to hold the ref to SharedBuffe r if ImageFrameGenerator
144 // is deleted. This is why full m_data (ThreadSafeRefCounted) is passed to c lient - to hold the
145 // reference to SharedBuffer (accompanying returned SkData). By contract in Skia's SkData,
146 // client needs to call SkData unref that would end up in sharedBufSkDataRel easeProc
147 // releasing the ref to ThreadSafeDataTransport (in thread safe way) and und erlying SharedBuffer.
148 //
149 // A note about allDataReceived:
150 // Client side use case is valid only for full image (encoded) data download ed,
Noel Gordon 2015/12/04 03:28:03 What is "Client side use case"? I have no clue wh
aleksandar.stojiljkovic 2015/12/04 11:11:43 Done. It is irrelevant sentence since this code is
Noel Gordon 2015/12/04 12:40:30 Thanks, and feel free to remove any other "irrelev
aleksandar.stojiljkovic 2015/12/04 14:31:15 Done.
151 // but, incidentally, this is in line with current Chromium implementation, where
152 // DeferredImageDecoder::setData is called only once with allDataReceived an d after
153 // that m_data.m_readBuffer.data() is not changed. For the sake of not leavi ng loose ends,
154 // ThreadSafeDataTransport::data is checking if there is new data added afte r AllDataReceived
155 // was set to true.
124 SharedBuffer* buffer = 0; 156 SharedBuffer* buffer = 0;
125 m_data.data(&buffer, allDataReceived); 157 bool allDataReceived = false;
126 if (buffer) 158 m_data->data(&buffer, &allDataReceived);
127 *data = buffer->copy(); 159 if (!allDataReceived)
160 return nullptr;
161
162 // While SkData is holding reference to underlying data, prevent disposing m _data and its content.
163 m_data->ref();
164 return SkData::NewWithProc(buffer->data(), buffer->size(), sharedBufSkDataRe leaseProc, m_data.get());
128 } 165 }
129 166
130 bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index, void* pixels, size_t rowBytes) 167 bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index, void* pixels, size_t rowBytes)
131 { 168 {
132 // This method is called to populate a discardable memory owned by Skia. 169 // This method is called to populate a discardable memory owned by Skia.
133 170
134 // Prevents concurrent decode or scale operations on the same image data. 171 // Prevents concurrent decode or scale operations on the same image data.
135 MutexLocker lock(m_decodeMutex); 172 MutexLocker lock(m_decodeMutex);
136 173
137 // This implementation does not support scaling so check the requested size. 174 // This implementation does not support scaling so check the requested size.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 214
178 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeToYUV", "generator", this, "decodeCount", static_cast<int>(m_decodeCount)); 215 TRACE_EVENT2("blink", "ImageFrameGenerator::decodeToYUV", "generator", this, "decodeCount", static_cast<int>(m_decodeCount));
179 216
180 if (!planes || !planes[0] || !planes[1] || !planes[2] 217 if (!planes || !planes[0] || !planes[1] || !planes[2]
181 || !rowBytes || !rowBytes[0] || !rowBytes[1] || !rowBytes[2]) { 218 || !rowBytes || !rowBytes[0] || !rowBytes[1] || !rowBytes[2]) {
182 return false; 219 return false;
183 } 220 }
184 221
185 SharedBuffer* data = 0; 222 SharedBuffer* data = 0;
186 bool allDataReceived = false; 223 bool allDataReceived = false;
187 m_data.data(&data, &allDataReceived); 224 m_data->data(&data, &allDataReceived);
188 225
189 // FIXME: YUV decoding does not currently support progressive decoding. 226 // FIXME: YUV decoding does not currently support progressive decoding.
190 ASSERT(allDataReceived); 227 ASSERT(allDataReceived);
191 228
192 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp haPremultiplied, ImageDecoder::GammaAndColorProfileApplied); 229 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp haPremultiplied, ImageDecoder::GammaAndColorProfileApplied);
193 if (!decoder) 230 if (!decoder)
194 return false; 231 return false;
195 232
196 decoder->setData(data, allDataReceived); 233 decoder->setData(data, allDataReceived);
197 234
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 320 }
284 321
285 bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap* bitmap) 322 bool ImageFrameGenerator::decode(size_t index, ImageDecoder** decoder, SkBitmap* bitmap)
286 { 323 {
287 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.wid th(), "height", m_fullSize.height()); 324 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.wid th(), "height", m_fullSize.height());
288 325
289 ASSERT(decoder); 326 ASSERT(decoder);
290 SharedBuffer* data = 0; 327 SharedBuffer* data = 0;
291 bool allDataReceived = false; 328 bool allDataReceived = false;
292 bool newDecoder = false; 329 bool newDecoder = false;
293 m_data.data(&data, &allDataReceived); 330 m_data->data(&data, &allDataReceived);
294 331
295 // Try to create an ImageDecoder if we are not given one. 332 // Try to create an ImageDecoder if we are not given one.
296 if (!*decoder) { 333 if (!*decoder) {
297 newDecoder = true; 334 newDecoder = true;
298 if (m_imageDecoderFactory) 335 if (m_imageDecoderFactory)
299 *decoder = m_imageDecoderFactory->create().leakPtr(); 336 *decoder = m_imageDecoderFactory->create().leakPtr();
300 337
301 if (!*decoder) 338 if (!*decoder)
302 *decoder = ImageDecoder::create(*data, ImageDecoder::AlphaPremultipl ied, ImageDecoder::GammaAndColorProfileApplied).leakPtr(); 339 *decoder = ImageDecoder::create(*data, ImageDecoder::AlphaPremultipl ied, ImageDecoder::GammaAndColorProfileApplied).leakPtr();
303 340
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 388 }
352 389
353 bool ImageFrameGenerator::getYUVComponentSizes(SkISize componentSizes[3]) 390 bool ImageFrameGenerator::getYUVComponentSizes(SkISize componentSizes[3])
354 { 391 {
355 ASSERT(componentSizes); 392 ASSERT(componentSizes);
356 393
357 TRACE_EVENT2("webkit", "ImageFrameGenerator::getYUVComponentSizes", "width", m_fullSize.width(), "height", m_fullSize.height()); 394 TRACE_EVENT2("webkit", "ImageFrameGenerator::getYUVComponentSizes", "width", m_fullSize.width(), "height", m_fullSize.height());
358 395
359 SharedBuffer* data = 0; 396 SharedBuffer* data = 0;
360 bool allDataReceived = false; 397 bool allDataReceived = false;
361 m_data.data(&data, &allDataReceived); 398 m_data->data(&data, &allDataReceived);
362 399
363 // FIXME: YUV decoding does not currently support progressive decoding. 400 // FIXME: YUV decoding does not currently support progressive decoding.
364 if (!allDataReceived) 401 if (!allDataReceived)
365 return false; 402 return false;
366 403
367 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp haPremultiplied, ImageDecoder::GammaAndColorProfileApplied); 404 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp haPremultiplied, ImageDecoder::GammaAndColorProfileApplied);
368 if (!decoder) 405 if (!decoder)
369 return false; 406 return false;
370 407
371 // JPEG images support YUV decoding: other decoders do not. So don't pump da ta into decoders 408 // JPEG images support YUV decoding: other decoders do not. So don't pump da ta into decoders
372 // that always return false to updateYUVComponentSizes() requests. 409 // that always return false to updateYUVComponentSizes() requests.
373 if (decoder->filenameExtension() != "jpg") 410 if (decoder->filenameExtension() != "jpg")
374 return false; 411 return false;
375 412
376 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. 413 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding.
377 decoder->setData(data, allDataReceived); 414 decoder->setData(data, allDataReceived);
378 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); 415 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes);
379 decoder->setImagePlanes(dummyImagePlanes.release()); 416 decoder->setImagePlanes(dummyImagePlanes.release());
380 417
381 return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder:: SizeForMemoryAllocation); 418 return updateYUVComponentSizes(decoder.get(), componentSizes, ImageDecoder:: SizeForMemoryAllocation);
382 } 419 }
383 420
384 } // namespace blink 421 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698