OLD | NEW |
---|---|
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 Loading... | |
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, threadSafeBind (&ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread, AllowCros sThreadAccess(this), AllowCrossThreadAccess(taskRunner), AllowCrossThreadAccess( arrayBuffer)), taskSize); | 223 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind (&ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread, wrapCross ThreadPersistent(this), AllowCrossThreadAccess(taskRunner), wrapCrossThreadPersi stent(arrayBuffer)), taskSize); |
sof
2016/05/17 05:44:46
Clarifying Q: why is it considered preferable to h
hiroshige
2016/05/17 05:57:12
|AllowCrossThreadAccess(taskRunner)| will be repla
sof
2016/05/17 06:05:24
ok, we'll arrive at names that work better iterati
| |
224 } | 224 } |
225 | 225 |
226 void ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread(WebTask Runner* taskRunner, DOMArrayBuffer* arrayBuffer) | 226 void ImageBitmapFactories::ImageBitmapLoader::decodeImageOnDecoderThread(WebTask Runner* taskRunner, DOMArrayBuffer* arrayBuffer) |
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 (m_options.premultiplyAlpha() == "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 (m_options.colorSpaceConversion() == "none") |
236 colorSpaceOp = ImageDecoder::GammaAndColorProfileIgnored; | 236 colorSpaceOp = ImageDecoder::GammaAndColorProfileIgnored; |
237 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*sharedBuffer, alphaOp, co lorSpaceOp)); | 237 OwnPtr<ImageDecoder> decoder(ImageDecoder::create(*sharedBuffer, alphaOp, co lorSpaceOp)); |
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, threadSafeBind(&ImageBitmapFactories:: ImageBitmapLoader::resolvePromiseOnOriginalThread, AllowCrossThreadAccess(this), frame.release())); | 243 taskRunner->postTask(BLINK_FROM_HERE, threadSafeBind(&ImageBitmapFactories:: ImageBitmapLoader::resolvePromiseOnOriginalThread, wrapCrossThreadPersistent(thi s), frame.release())); |
244 } | 244 } |
245 | 245 |
246 void ImageBitmapFactories::ImageBitmapLoader::resolvePromiseOnOriginalThread(Pas sRefPtr<SkImage> frame) | 246 void ImageBitmapFactories::ImageBitmapLoader::resolvePromiseOnOriginalThread(Pas sRefPtr<SkImage> frame) |
247 { | 247 { |
248 if (!frame) { | 248 if (!frame) { |
249 rejectPromise(); | 249 rejectPromise(); |
250 return; | 250 return; |
251 } | 251 } |
252 ASSERT(frame->width() && frame->height()); | 252 ASSERT(frame->width() && frame->height()); |
253 | 253 |
(...skipping 14 matching lines...) Expand all Loading... | |
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 |
OLD | NEW |