OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/html/canvas/CanvasAsyncBlobCreator.h" | 5 #include "core/html/canvas/CanvasAsyncBlobCreator.h" |
6 | 6 |
7 #include "core/fileapi/Blob.h" | 7 #include "core/fileapi/Blob.h" |
8 #include "platform/ThreadSafeFunctional.h" | 8 #include "platform/ThreadSafeFunctional.h" |
9 #include "platform/graphics/ImageBuffer.h" | 9 #include "platform/graphics/ImageBuffer.h" |
10 #include "platform/image-encoders/JPEGImageEncoder.h" | 10 #include "platform/image-encoders/JPEGImageEncoder.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } else if (m_mimeType == MimeTypeJpeg) { | 111 } else if (m_mimeType == MimeTypeJpeg) { |
112 this->scheduleInitiateJpegEncoding(quality); | 112 this->scheduleInitiateJpegEncoding(quality); |
113 } else { | 113 } else { |
114 // Progressive encoding is only applicable to png and jpeg image for
mat, | 114 // Progressive encoding is only applicable to png and jpeg image for
mat, |
115 // and thus idle tasks scheduling can only be applied to these image
formats. | 115 // and thus idle tasks scheduling can only be applied to these image
formats. |
116 // TODO(xlai): Progressive encoding on webp image formats (crbug.com
/571399) | 116 // TODO(xlai): Progressive encoding on webp image formats (crbug.com
/571399) |
117 ASSERT_NOT_REACHED(); | 117 ASSERT_NOT_REACHED(); |
118 } | 118 } |
119 // We post the below task to check if the above idle task isn't late. | 119 // We post the below task to check if the above idle task isn't late. |
120 // There's no risk of concurrency as both tasks are on main thread. | 120 // There's no risk of concurrency as both tasks are on main thread. |
121 this->postDelayedTaskToMainThread(BLINK_FROM_HERE, bind(&CanvasAsyncBlob
Creator::idleTaskStartTimeoutEvent, this, quality), IdleTaskStartTimeoutDelay); | 121 this->postDelayedTaskToMainThread(BLINK_FROM_HERE, bind(&CanvasAsyncBlob
Creator::idleTaskStartTimeoutEvent, WeakPersistentThisPointer<CanvasAsyncBlobCre
ator>(this), quality), IdleTaskStartTimeoutDelay); |
122 } else if (m_mimeType == MimeTypeWebp) { | 122 } else if (m_mimeType == MimeTypeWebp) { |
123 BackgroundTaskRunner::TaskSize taskSize = (m_size.height() * m_size.widt
h() >= LongTaskImageSizeThreshold) ? BackgroundTaskRunner::TaskSizeLongRunningTa
sk : BackgroundTaskRunner::TaskSizeShortRunningTask; | 123 BackgroundTaskRunner::TaskSize taskSize = (m_size.height() * m_size.widt
h() >= LongTaskImageSizeThreshold) ? BackgroundTaskRunner::TaskSizeLongRunningTa
sk : BackgroundTaskRunner::TaskSizeShortRunningTask; |
124 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafe
Bind(&CanvasAsyncBlobCreator::encodeImageOnEncoderThread, wrapCrossThreadPersist
ent(this), quality), taskSize); | 124 BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafe
Bind(&CanvasAsyncBlobCreator::encodeImageOnEncoderThread, wrapCrossThreadPersist
ent(this), quality), taskSize); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 void CanvasAsyncBlobCreator::scheduleInitiateJpegEncoding(const double& quality) | 128 void CanvasAsyncBlobCreator::scheduleInitiateJpegEncoding(const double& quality) |
129 { | 129 { |
130 Platform::current()->mainThread()->scheduler()->postIdleTask(BLINK_FROM_HERE
, bind<double>(&CanvasAsyncBlobCreator::initiateJpegEncoding, WeakPersistentThis
Pointer<CanvasAsyncBlobCreator>(this), quality)); | 130 Platform::current()->mainThread()->scheduler()->postIdleTask(BLINK_FROM_HERE
, bind<double>(&CanvasAsyncBlobCreator::initiateJpegEncoding, WeakPersistentThis
Pointer<CanvasAsyncBlobCreator>(this), quality)); |
131 } | 131 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 353 } |
354 } | 354 } |
355 | 355 |
356 void CanvasAsyncBlobCreator::postDelayedTaskToMainThread(const WebTraceLocation&
location, std::unique_ptr<SameThreadClosure> task, double delayMs) | 356 void CanvasAsyncBlobCreator::postDelayedTaskToMainThread(const WebTraceLocation&
location, std::unique_ptr<SameThreadClosure> task, double delayMs) |
357 { | 357 { |
358 DCHECK(isMainThread()); | 358 DCHECK(isMainThread()); |
359 Platform::current()->mainThread()->getWebTaskRunner()->postDelayedTask(locat
ion, std::move(task), delayMs); | 359 Platform::current()->mainThread()->getWebTaskRunner()->postDelayedTask(locat
ion, std::move(task), delayMs); |
360 } | 360 } |
361 | 361 |
362 } // namespace blink | 362 } // namespace blink |
OLD | NEW |