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

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

Issue 2137973002: Thread-Safety: Fix ImageBitmapLoader::decodeImageOnDecoderThread() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 void ImageBitmapFactories::ImageBitmapLoader::scheduleAsyncImageBitmapDecoding(D OMArrayBuffer* arrayBuffer) 213 void ImageBitmapFactories::ImageBitmapLoader::scheduleAsyncImageBitmapDecoding(D OMArrayBuffer* arrayBuffer)
214 { 214 {
215 // For a 4000*4000 png image where each 10*10 tile is filled in by a random RGBA value, 215 // For a 4000*4000 png image where each 10*10 tile is filled in by a random RGBA value,
216 // the byteLength is around 2M, and it typically takes around 4.5ms to decod e on a 216 // the byteLength is around 2M, and it typically takes around 4.5ms to decod e on a
217 // current model of Linux desktop. 217 // current model of Linux desktop.
218 const int longTaskByteLengthThreshold = 2000000; 218 const int longTaskByteLengthThreshold = 2000000;
219 BackgroundTaskRunner::TaskSize taskSize = BackgroundTaskRunner::TaskSizeShor tRunningTask; 219 BackgroundTaskRunner::TaskSize taskSize = BackgroundTaskRunner::TaskSizeShor tRunningTask;
220 if (arrayBuffer->byteLength() >= longTaskByteLengthThreshold) 220 if (arrayBuffer->byteLength() >= longTaskByteLengthThreshold)
221 taskSize = BackgroundTaskRunner::TaskSizeLongRunningTask; 221 taskSize = BackgroundTaskRunner::TaskSizeLongRunningTask;
222 WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWebTask Runner(); 222 WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWebTask Runner();
223 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, crossThreadBin d(&ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread, wrapCros sThreadPersistent(this), crossThreadUnretained(taskRunner), wrapCrossThreadPersi stent(arrayBuffer)), taskSize); 223 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, crossThreadBin d(&ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread, wrapCros sThreadPersistent(this), crossThreadUnretained(taskRunner), wrapCrossThreadPersi stent(arrayBuffer), m_options.premultiplyAlpha(), m_options.colorSpaceConversion ()), taskSize);
224 } 224 }
225 225
226 void ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread(WebTask Runner* taskRunner, DOMArrayBuffer* arrayBuffer) 226 void ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread(WebTask Runner* taskRunner, DOMArrayBuffer* arrayBuffer, const String& premultiplyAlphaO ption, const String& colorSpaceConversionOption)
227 { 227 {
228 ASSERT(!isMainThread()); 228 ASSERT(!isMainThread());
229 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(static_cast<char*>( arrayBuffer->data()), static_cast<size_t>(arrayBuffer->byteLength())); 229 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(static_cast<char*>( arrayBuffer->data()), static_cast<size_t>(arrayBuffer->byteLength()));
230 230
231 ImageDecoder::AlphaOption alphaOp = ImageDecoder::AlphaPremultiplied; 231 ImageDecoder::AlphaOption alphaOp = ImageDecoder::AlphaPremultiplied;
232 if (m_options.premultiplyAlpha() == "none") 232 if (premultiplyAlphaOption == "none")
233 alphaOp = ImageDecoder::AlphaNotPremultiplied; 233 alphaOp = ImageDecoder::AlphaNotPremultiplied;
234 ImageDecoder::GammaAndColorProfileOption colorSpaceOp = ImageDecoder::GammaA ndColorProfileApplied; 234 ImageDecoder::GammaAndColorProfileOption colorSpaceOp = ImageDecoder::GammaA ndColorProfileApplied;
235 if (m_options.colorSpaceConversion() == "none") 235 if (colorSpaceConversionOption == "none")
236 colorSpaceOp = ImageDecoder::GammaAndColorProfileIgnored; 236 colorSpaceOp = ImageDecoder::GammaAndColorProfileIgnored;
237 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*sharedBuffer, al phaOp, colorSpaceOp)); 237 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*sharedBuffer, al phaOp, colorSpaceOp));
238 RefPtr<SkImage> frame; 238 RefPtr<SkImage> frame;
239 if (decoder) { 239 if (decoder) {
240 decoder->setData(sharedBuffer.get(), true); 240 decoder->setData(sharedBuffer.get(), true);
241 frame = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); 241 frame = ImageBitmap::getSkImageFromDecoder(std::move(decoder));
242 } 242 }
243 taskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(&ImageBitmapFactories: :ImageBitmapLoader::resolvePromiseOnOriginalThread, wrapCrossThreadPersistent(th is), frame.release())); 243 taskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(&ImageBitmapFactories: :ImageBitmapLoader::resolvePromiseOnOriginalThread, wrapCrossThreadPersistent(th is), frame.release()));
244 } 244 }
245 245
(...skipping 22 matching lines...) Expand all
268 m_factory->didFinishLoading(this); 268 m_factory->didFinishLoading(this);
269 } 269 }
270 270
271 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) 271 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader)
272 { 272 {
273 visitor->trace(m_factory); 273 visitor->trace(m_factory);
274 visitor->trace(m_resolver); 274 visitor->trace(m_resolver);
275 } 275 }
276 276
277 } // namespace blink 277 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/imagebitmap/ImageBitmapFactories.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698