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

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

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

Powered by Google App Engine
This is Rietveld 408576698