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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 249 } |
250 | 250 |
251 this->signalAlternativeCodePathFinishedForTesting(); | 251 this->signalAlternativeCodePathFinishedForTesting(); |
252 } | 252 } |
253 | 253 |
254 void CanvasAsyncBlobCreator::createBlobAndInvokeCallback() | 254 void CanvasAsyncBlobCreator::createBlobAndInvokeCallback() |
255 { | 255 { |
256 ASSERT(isMainThread()); | 256 ASSERT(isMainThread()); |
257 Blob* resultBlob = Blob::create(m_encodedImage->data(), m_encodedImage->size
(), convertMimeTypeEnumToString(m_mimeType)); | 257 Blob* resultBlob = Blob::create(m_encodedImage->data(), m_encodedImage->size
(), convertMimeTypeEnumToString(m_mimeType)); |
258 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, bind(&BlobCallback::handleEvent, m_callback, resultBlob)); | 258 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, bind(&BlobCallback::handleEvent, m_callback, resultBlob)); |
| 259 // Since toBlob is done, timeout events are no longer needed. So we clear |
| 260 // non-GC members to allow teardown of CanvasAsyncBlobCreator. |
| 261 m_data.clear(); |
| 262 m_callback.clear(); |
259 } | 263 } |
260 | 264 |
261 void CanvasAsyncBlobCreator::createNullAndInvokeCallback() | 265 void CanvasAsyncBlobCreator::createNullAndInvokeCallback() |
262 { | 266 { |
263 ASSERT(isMainThread()); | 267 ASSERT(isMainThread()); |
264 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, bind(&BlobCallback::handleEvent, m_callback, nullptr)); | 268 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FROM_H
ERE, bind(&BlobCallback::handleEvent, m_callback, nullptr)); |
| 269 // Since toBlob is done (failed), timeout events are no longer needed. So we |
| 270 // clear non-GC members to allow teardown of CanvasAsyncBlobCreator. |
| 271 m_data.clear(); |
| 272 m_callback.clear(); |
265 } | 273 } |
266 | 274 |
267 void CanvasAsyncBlobCreator::encodeImageOnEncoderThread(double quality) | 275 void CanvasAsyncBlobCreator::encodeImageOnEncoderThread(double quality) |
268 { | 276 { |
269 ASSERT(!isMainThread()); | 277 ASSERT(!isMainThread()); |
270 ASSERT(m_mimeType == MimeTypeWebp); | 278 ASSERT(m_mimeType == MimeTypeWebp); |
271 | 279 |
272 if (!ImageDataBuffer(m_size, m_data->data()).encodeImage("image/webp", quali
ty, m_encodedImage.get())) { | 280 if (!ImageDataBuffer(m_size, m_data->data()).encodeImage("image/webp", quali
ty, m_encodedImage.get())) { |
273 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&BlobCallback::handleEvent, wrapCrossThreadPersistent(m_
callback.get()), nullptr)); | 281 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR
OM_HERE, threadSafeBind(&BlobCallback::handleEvent, wrapCrossThreadPersistent(m_
callback.get()), nullptr)); |
274 return; | 282 return; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 361 } |
354 } | 362 } |
355 | 363 |
356 void CanvasAsyncBlobCreator::postDelayedTaskToMainThread(const WebTraceLocation&
location, std::unique_ptr<SameThreadClosure> task, double delayMs) | 364 void CanvasAsyncBlobCreator::postDelayedTaskToMainThread(const WebTraceLocation&
location, std::unique_ptr<SameThreadClosure> task, double delayMs) |
357 { | 365 { |
358 DCHECK(isMainThread()); | 366 DCHECK(isMainThread()); |
359 Platform::current()->mainThread()->getWebTaskRunner()->postDelayedTask(locat
ion, std::move(task), delayMs); | 367 Platform::current()->mainThread()->getWebTaskRunner()->postDelayedTask(locat
ion, std::move(task), delayMs); |
360 } | 368 } |
361 | 369 |
362 } // namespace blink | 370 } // namespace blink |
OLD | NEW |