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

Side by Side Diff: third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.cpp

Issue 1878463002: Move DOMArrayBuffer, DOMArrayBufferViews and DataView to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tidy 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) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 184 }
185 185
186 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise() 186 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise()
187 { 187 {
188 m_resolver->reject(DOMException::create(InvalidStateError, "The source image cannot be decoded.")); 188 m_resolver->reject(DOMException::create(InvalidStateError, "The source image cannot be decoded."));
189 m_factory->didFinishLoading(this); 189 m_factory->didFinishLoading(this);
190 } 190 }
191 191
192 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() 192 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading()
193 { 193 {
194 if (!m_loader.arrayBufferResult()) { 194 DOMArrayBuffer* arrayBuffer = m_loader.arrayBufferResult();
sof 2016/04/10 17:32:28 As FileReaderLoader re-creates a DOMArrayBuffer ea
195 if (!arrayBuffer) {
195 rejectPromise(); 196 rejectPromise();
196 return; 197 return;
197 } 198 }
198 scheduleAsyncImageBitmapDecoding(); 199 scheduleAsyncImageBitmapDecoding(arrayBuffer);
199 } 200 }
200 201
201 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode) 202 void ImageBitmapFactories::ImageBitmapLoader::didFail(FileError::ErrorCode)
202 { 203 {
203 rejectPromise(); 204 rejectPromise();
204 } 205 }
205 206
206 void ImageBitmapFactories::ImageBitmapLoader::scheduleAsyncImageBitmapDecoding() 207 void ImageBitmapFactories::ImageBitmapLoader::scheduleAsyncImageBitmapDecoding(D OMArrayBuffer* arrayBuffer)
207 { 208 {
208 // For a 4000*4000 png image where each 10*10 tile is filled in by a random RGBA value, 209 // For a 4000*4000 png image where each 10*10 tile is filled in by a random RGBA value,
209 // the byteLength is around 2M, and it typically takes around 4.5ms to decod e on a 210 // the byteLength is around 2M, and it typically takes around 4.5ms to decod e on a
210 // current model of Linux desktop. 211 // current model of Linux desktop.
211 const int longTaskByteLengthThreshold = 2000000; 212 const int longTaskByteLengthThreshold = 2000000;
212 BackgroundTaskRunner::TaskSize taskSize = (m_loader.arrayBufferResult()->byt eLength() >= longTaskByteLengthThreshold) ? BackgroundTaskRunner::TaskSizeLongRu nningTask : BackgroundTaskRunner::TaskSizeShortRunningTask; 213 BackgroundTaskRunner::TaskSize taskSize = BackgroundTaskRunner::TaskSizeShor tRunningTask;
214 if (arrayBuffer->byteLength() >= longTaskByteLengthThreshold)
215 taskSize = BackgroundTaskRunner::TaskSizeLongRunningTask;
213 WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWebTask Runner(); 216 WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWebTask Runner();
214 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind (&ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread, AllowCros sThreadAccess(this), AllowCrossThreadAccess(taskRunner)), taskSize); 217 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind (&ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread, AllowCros sThreadAccess(this), AllowCrossThreadAccess(taskRunner), AllowCrossThreadAccess( arrayBuffer)), taskSize);
215 } 218 }
216 219
217 void ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread(WebTask Runner* taskRunner) 220 void ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread(WebTask Runner* taskRunner, DOMArrayBuffer* arrayBuffer)
218 { 221 {
219 ASSERT(!isMainThread()); 222 ASSERT(!isMainThread());
220 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create((char*)m_loader.arr ayBufferResult()->data(), static_cast<size_t>(m_loader.arrayBufferResult()->byte Length())); 223 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(static_cast<char*>( arrayBuffer->data()), static_cast<size_t>(arrayBuffer->byteLength()));
221 224
222 ImageDecoder::AlphaOption alphaOp = ImageDecoder::AlphaPremultiplied; 225 ImageDecoder::AlphaOption alphaOp = ImageDecoder::AlphaPremultiplied;
223 if (m_options.premultiplyAlpha() == "none") 226 if (m_options.premultiplyAlpha() == "none")
224 alphaOp = ImageDecoder::AlphaNotPremultiplied; 227 alphaOp = ImageDecoder::AlphaNotPremultiplied;
225 ImageDecoder::GammaAndColorProfileOption colorspaceOp = ImageDecoder::GammaA ndColorProfileApplied; 228 ImageDecoder::GammaAndColorProfileOption colorspaceOp = ImageDecoder::GammaA ndColorProfileApplied;
226 if (m_options.colorspaceConversion() == "none") 229 if (m_options.colorspaceConversion() == "none")
227 colorspaceOp = ImageDecoder::GammaAndColorProfileIgnored; 230 colorspaceOp = ImageDecoder::GammaAndColorProfileIgnored;
228 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*sharedBuffer, alphaOp, co lorspaceOp)); 231 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*sharedBuffer, alphaOp, co lorspaceOp));
229 RefPtr<SkImage> frame; 232 RefPtr<SkImage> frame;
230 if (decoder) { 233 if (decoder) {
(...skipping 28 matching lines...) Expand all
259 m_factory->didFinishLoading(this); 262 m_factory->didFinishLoading(this);
260 } 263 }
261 264
262 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) 265 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader)
263 { 266 {
264 visitor->trace(m_factory); 267 visitor->trace(m_factory);
265 visitor->trace(m_resolver); 268 visitor->trace(m_resolver);
266 } 269 }
267 270
268 } // namespace blink 271 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698