| 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/offscreencanvas/OffscreenCanvas.h" | 5 #include "core/offscreencanvas/OffscreenCanvas.h" |
| 6 | 6 |
| 7 #include "core/dom/ExceptionCode.h" | 7 #include "core/dom/ExceptionCode.h" |
| 8 #include "core/fileapi/Blob.h" | 8 #include "core/fileapi/Blob.h" |
| 9 #include "core/frame/ImageBitmap.h" | 9 #include "core/frame/ImageBitmap.h" |
| 10 #include "core/html/ImageData.h" | 10 #include "core/html/ImageData.h" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 double startTime = WTF::monotonicallyIncreasingTime(); | 299 double startTime = WTF::monotonicallyIncreasingTime(); |
| 300 String encodingMimeType = ImageEncoderUtils::toEncodingMimeType( | 300 String encodingMimeType = ImageEncoderUtils::toEncodingMimeType( |
| 301 options.type(), ImageEncoderUtils::EncodeReasonConvertToBlobPromise); | 301 options.type(), ImageEncoderUtils::EncodeReasonConvertToBlobPromise); |
| 302 | 302 |
| 303 ImageData* imageData = nullptr; | 303 ImageData* imageData = nullptr; |
| 304 if (this->renderingContext()) { | 304 if (this->renderingContext()) { |
| 305 imageData = this->renderingContext()->toImageData(SnapshotReasonUnknown); | 305 imageData = this->renderingContext()->toImageData(SnapshotReasonUnknown); |
| 306 } | 306 } |
| 307 if (!imageData) { | 307 if (!imageData) { |
| 308 return ScriptPromise(); | 308 exceptionState.throwDOMException( |
| 309 InvalidStateError, "OffscreenCanvas object has no rendering contexts"); |
| 310 return exceptionState.reject(scriptState); |
| 309 } | 311 } |
| 310 | 312 |
| 311 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 313 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 312 | 314 |
| 313 Document* document = | 315 Document* document = |
| 314 scriptState->getExecutionContext()->isDocument() | 316 scriptState->getExecutionContext()->isDocument() |
| 315 ? static_cast<Document*>(scriptState->getExecutionContext()) | 317 ? static_cast<Document*>(scriptState->getExecutionContext()) |
| 316 : nullptr; | 318 : nullptr; |
| 317 | 319 |
| 318 CanvasAsyncBlobCreator* asyncCreator = CanvasAsyncBlobCreator::create( | 320 CanvasAsyncBlobCreator* asyncCreator = CanvasAsyncBlobCreator::create( |
| 319 imageData->data(), encodingMimeType, imageData->size(), startTime, | 321 imageData->data(), encodingMimeType, imageData->size(), startTime, |
| 320 document, resolver); | 322 document, resolver); |
| 321 | 323 |
| 322 asyncCreator->scheduleAsyncBlobCreation(options.quality()); | 324 asyncCreator->scheduleAsyncBlobCreation(options.quality()); |
| 323 | 325 |
| 324 return resolver->promise(); | 326 return resolver->promise(); |
| 325 } | 327 } |
| 326 | 328 |
| 327 DEFINE_TRACE(OffscreenCanvas) { | 329 DEFINE_TRACE(OffscreenCanvas) { |
| 328 visitor->trace(m_context); | 330 visitor->trace(m_context); |
| 329 visitor->trace(m_executionContext); | 331 visitor->trace(m_executionContext); |
| 330 visitor->trace(m_commitPromiseResolver); | 332 visitor->trace(m_commitPromiseResolver); |
| 331 EventTargetWithInlineData::trace(visitor); | 333 EventTargetWithInlineData::trace(visitor); |
| 332 } | 334 } |
| 333 | 335 |
| 334 } // namespace blink | 336 } // namespace blink |
| OLD | NEW |