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

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

Issue 2104913002: Rename threadSafeBind() to crossThreadBind() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@TRV_CTCPointer
Patch Set: Rebase 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
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 25 matching lines...) Expand all
36 #include "core/frame/ImageBitmap.h" 36 #include "core/frame/ImageBitmap.h"
37 #include "core/frame/LocalDOMWindow.h" 37 #include "core/frame/LocalDOMWindow.h"
38 #include "core/frame/UseCounter.h" 38 #include "core/frame/UseCounter.h"
39 #include "core/html/HTMLCanvasElement.h" 39 #include "core/html/HTMLCanvasElement.h"
40 #include "core/html/HTMLImageElement.h" 40 #include "core/html/HTMLImageElement.h"
41 #include "core/html/HTMLVideoElement.h" 41 #include "core/html/HTMLVideoElement.h"
42 #include "core/html/ImageData.h" 42 #include "core/html/ImageData.h"
43 #include "core/imagebitmap/ImageBitmapOptions.h" 43 #include "core/imagebitmap/ImageBitmapOptions.h"
44 #include "core/svg/graphics/SVGImage.h" 44 #include "core/svg/graphics/SVGImage.h"
45 #include "core/workers/WorkerGlobalScope.h" 45 #include "core/workers/WorkerGlobalScope.h"
46 #include "platform/CrossThreadFunctional.h"
46 #include "platform/SharedBuffer.h" 47 #include "platform/SharedBuffer.h"
47 #include "platform/ThreadSafeFunctional.h"
48 #include "platform/image-decoders/ImageDecoder.h" 48 #include "platform/image-decoders/ImageDecoder.h"
49 #include "platform/threading/BackgroundTaskRunner.h" 49 #include "platform/threading/BackgroundTaskRunner.h"
50 #include "public/platform/Platform.h" 50 #include "public/platform/Platform.h"
51 #include "public/platform/WebThread.h" 51 #include "public/platform/WebThread.h"
52 #include "public/platform/WebTraceLocation.h" 52 #include "public/platform/WebTraceLocation.h"
53 #include <memory> 53 #include <memory>
54 #include <v8.h> 54 #include <v8.h>
55 55
56 namespace blink { 56 namespace blink {
57 57
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 void ImageBitmapFactories::ImageBitmapLoader::scheduleAsyncImageBitmapDecoding(D OMArrayBuffer* arrayBuffer) 214 void ImageBitmapFactories::ImageBitmapLoader::scheduleAsyncImageBitmapDecoding(D OMArrayBuffer* arrayBuffer)
215 { 215 {
216 // For a 4000*4000 png image where each 10*10 tile is filled in by a random RGBA value, 216 // For a 4000*4000 png image where each 10*10 tile is filled in by a random RGBA value,
217 // the byteLength is around 2M, and it typically takes around 4.5ms to decod e on a 217 // the byteLength is around 2M, and it typically takes around 4.5ms to decod e on a
218 // current model of Linux desktop. 218 // current model of Linux desktop.
219 const int longTaskByteLengthThreshold = 2000000; 219 const int longTaskByteLengthThreshold = 2000000;
220 BackgroundTaskRunner::TaskSize taskSize = BackgroundTaskRunner::TaskSizeShor tRunningTask; 220 BackgroundTaskRunner::TaskSize taskSize = BackgroundTaskRunner::TaskSizeShor tRunningTask;
221 if (arrayBuffer->byteLength() >= longTaskByteLengthThreshold) 221 if (arrayBuffer->byteLength() >= longTaskByteLengthThreshold)
222 taskSize = BackgroundTaskRunner::TaskSizeLongRunningTask; 222 taskSize = BackgroundTaskRunner::TaskSizeLongRunningTask;
223 WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWebTask Runner(); 223 WebTaskRunner* taskRunner = Platform::current()->currentThread()->getWebTask Runner();
224 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind (&ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread, wrapCross ThreadPersistent(this), crossThreadUnretained(taskRunner), wrapCrossThreadPersis tent(arrayBuffer)), taskSize); 224 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, crossThreadBin d(&ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread, wrapCros sThreadPersistent(this), crossThreadUnretained(taskRunner), wrapCrossThreadPersi stent(arrayBuffer)), taskSize);
225 } 225 }
226 226
227 void ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread(WebTask Runner* taskRunner, DOMArrayBuffer* arrayBuffer) 227 void ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread(WebTask Runner* taskRunner, DOMArrayBuffer* arrayBuffer)
228 { 228 {
229 ASSERT(!isMainThread()); 229 ASSERT(!isMainThread());
230 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(static_cast<char*>( arrayBuffer->data()), static_cast<size_t>(arrayBuffer->byteLength())); 230 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(static_cast<char*>( arrayBuffer->data()), static_cast<size_t>(arrayBuffer->byteLength()));
231 231
232 ImageDecoder::AlphaOption alphaOp = ImageDecoder::AlphaPremultiplied; 232 ImageDecoder::AlphaOption alphaOp = ImageDecoder::AlphaPremultiplied;
233 if (m_options.premultiplyAlpha() == "none") 233 if (m_options.premultiplyAlpha() == "none")
234 alphaOp = ImageDecoder::AlphaNotPremultiplied; 234 alphaOp = ImageDecoder::AlphaNotPremultiplied;
235 ImageDecoder::GammaAndColorProfileOption colorSpaceOp = ImageDecoder::GammaA ndColorProfileApplied; 235 ImageDecoder::GammaAndColorProfileOption colorSpaceOp = ImageDecoder::GammaA ndColorProfileApplied;
236 if (m_options.colorSpaceConversion() == "none") 236 if (m_options.colorSpaceConversion() == "none")
237 colorSpaceOp = ImageDecoder::GammaAndColorProfileIgnored; 237 colorSpaceOp = ImageDecoder::GammaAndColorProfileIgnored;
238 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*sharedBuffer, al phaOp, colorSpaceOp)); 238 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(*sharedBuffer, al phaOp, colorSpaceOp));
239 RefPtr<SkImage> frame; 239 RefPtr<SkImage> frame;
240 if (decoder) { 240 if (decoder) {
241 decoder->setData(sharedBuffer.get(), true); 241 decoder->setData(sharedBuffer.get(), true);
242 frame = ImageBitmap::getSkImageFromDecoder(std::move(decoder)); 242 frame = ImageBitmap::getSkImageFromDecoder(std::move(decoder));
243 } 243 }
244 taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&ImageBitmapFactories:: ImageBitmapLoader::resolvePromiseOnOriginalThread, wrapCrossThreadPersistent(thi s), frame.release())); 244 taskRunner->postTask(BLINK_FROM_HERE, crossThreadBind(&ImageBitmapFactories: :ImageBitmapLoader::resolvePromiseOnOriginalThread, wrapCrossThreadPersistent(th is), frame.release()));
245 } 245 }
246 246
247 void ImageBitmapFactories::ImageBitmapLoader::resolvePromiseOnOriginalThread(Pas sRefPtr<SkImage> frame) 247 void ImageBitmapFactories::ImageBitmapLoader::resolvePromiseOnOriginalThread(Pas sRefPtr<SkImage> frame)
248 { 248 {
249 if (!frame) { 249 if (!frame) {
250 rejectPromise(); 250 rejectPromise();
251 return; 251 return;
252 } 252 }
253 ASSERT(frame->width() && frame->height()); 253 ASSERT(frame->width() && frame->height());
254 254
(...skipping 14 matching lines...) Expand all
269 m_factory->didFinishLoading(this); 269 m_factory->didFinishLoading(this);
270 } 270 }
271 271
272 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) 272 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader)
273 { 273 {
274 visitor->trace(m_factory); 274 visitor->trace(m_factory);
275 visitor->trace(m_resolver); 275 visitor->trace(m_resolver);
276 } 276 }
277 277
278 } // namespace blink 278 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698