| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" | 5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" |
| 6 | 6 |
| 7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC
ontextOrWebGL2RenderingContext.h" | 7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC
ontextOrWebGL2RenderingContext.h" |
| 8 #include "core/frame/ImageBitmap.h" | 8 #include "core/frame/ImageBitmap.h" |
| 9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
| 10 #include "core/workers/WorkerGlobalScope.h" | 10 #include "core/workers/WorkerGlobalScope.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 toWorkerGlobalScope(executionContext)->workerSettings(); | 36 toWorkerGlobalScope(executionContext)->workerSettings(); |
| 37 if (workerSettings && workerSettings->disableReadingFromCanvas()) | 37 if (workerSettings && workerSettings->disableReadingFromCanvas()) |
| 38 canvas->setDisableReadingFromCanvasTrue(); | 38 canvas->setDisableReadingFromCanvasTrue(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) { | 41 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) { |
| 42 CanvasRenderingContext::trace(visitor); | 42 CanvasRenderingContext::trace(visitor); |
| 43 BaseRenderingContext2D::trace(visitor); | 43 BaseRenderingContext2D::trace(visitor); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void OffscreenCanvasRenderingContext2D::commit(ScriptState* scriptState, | 46 ScriptPromise OffscreenCanvasRenderingContext2D::commit( |
| 47 ExceptionState& exceptionState) { | 47 ScriptState* scriptState, |
| 48 ExceptionState& exceptionState) { |
| 48 UseCounter::Feature feature = UseCounter::OffscreenCanvasCommit2D; | 49 UseCounter::Feature feature = UseCounter::OffscreenCanvasCommit2D; |
| 49 UseCounter::count(scriptState->getExecutionContext(), feature); | 50 UseCounter::count(scriptState->getExecutionContext(), feature); |
| 50 if (!getOffscreenCanvas()->hasPlaceholderCanvas()) { | 51 if (!offscreenCanvas()->hasPlaceholderCanvas()) { |
| 51 // If an OffscreenCanvas has no associated canvas Id, it indicates that | 52 // If an OffscreenCanvas has no associated canvas Id, it indicates that |
| 52 // it is not an OffscreenCanvas created by transfering control from html | 53 // it is not an OffscreenCanvas created by transfering control from html |
| 53 // canvas. | 54 // canvas. |
| 54 exceptionState.throwDOMException(InvalidStateError, | 55 exceptionState.throwDOMException(InvalidStateError, |
| 55 "Commit() was called on a context whose " | 56 "Commit() was called on a context whose " |
| 56 "OffscreenCanvas is not associated with a " | 57 "OffscreenCanvas is not associated with a " |
| 57 "canvas element."); | 58 "canvas element."); |
| 58 return; | 59 return exceptionState.reject(scriptState); |
| 59 } | 60 } |
| 60 double commitStartTime = WTF::monotonicallyIncreasingTime(); | 61 |
| 61 RefPtr<StaticBitmapImage> image = transferToStaticBitmapImage(); | 62 bool isWebGLSoftwareRendering = false; |
| 62 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame( | 63 return offscreenCanvas()->commit(transferToStaticBitmapImage(), |
| 63 std::move(image), commitStartTime); | 64 isWebGLSoftwareRendering, scriptState); |
| 64 } | 65 } |
| 65 | 66 |
| 66 // BaseRenderingContext2D implementation | 67 // BaseRenderingContext2D implementation |
| 67 bool OffscreenCanvasRenderingContext2D::originClean() const { | 68 bool OffscreenCanvasRenderingContext2D::originClean() const { |
| 68 return getOffscreenCanvas()->originClean(); | 69 return offscreenCanvas()->originClean(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void OffscreenCanvasRenderingContext2D::setOriginTainted() { | 72 void OffscreenCanvasRenderingContext2D::setOriginTainted() { |
| 72 return getOffscreenCanvas()->setOriginTainted(); | 73 return offscreenCanvas()->setOriginTainted(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin( | 76 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin( |
| 76 CanvasImageSource* source, | 77 CanvasImageSource* source, |
| 77 ExecutionContext* executionContext) { | 78 ExecutionContext* executionContext) { |
| 78 if (executionContext->isWorkerGlobalScope()) { | 79 if (executionContext->isWorkerGlobalScope()) { |
| 79 // We only support passing in ImageBitmap and OffscreenCanvases as source | 80 // We only support passing in ImageBitmap and OffscreenCanvases as source |
| 80 // images in drawImage() or createPattern() in a OffscreenCanvas2d in | 81 // images in drawImage() or createPattern() in a OffscreenCanvas2d in |
| 81 // worker. | 82 // worker. |
| 82 DCHECK(source->isImageBitmap() || source->isOffscreenCanvas()); | 83 DCHECK(source->isImageBitmap() || source->isOffscreenCanvas()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 return CanvasRenderingContext::wouldTaintOrigin( | 86 return CanvasRenderingContext::wouldTaintOrigin( |
| 86 source, executionContext->getSecurityOrigin()); | 87 source, executionContext->getSecurityOrigin()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 int OffscreenCanvasRenderingContext2D::width() const { | 90 int OffscreenCanvasRenderingContext2D::width() const { |
| 90 return getOffscreenCanvas()->width(); | 91 return offscreenCanvas()->width(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 int OffscreenCanvasRenderingContext2D::height() const { | 94 int OffscreenCanvasRenderingContext2D::height() const { |
| 94 return getOffscreenCanvas()->height(); | 95 return offscreenCanvas()->height(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const { | 98 bool OffscreenCanvasRenderingContext2D::hasImageBuffer() const { |
| 98 return !!m_imageBuffer; | 99 return !!m_imageBuffer; |
| 99 } | 100 } |
| 100 | 101 |
| 101 void OffscreenCanvasRenderingContext2D::reset() { | 102 void OffscreenCanvasRenderingContext2D::reset() { |
| 102 m_imageBuffer = nullptr; | 103 m_imageBuffer = nullptr; |
| 103 BaseRenderingContext2D::reset(); | 104 BaseRenderingContext2D::reset(); |
| 104 } | 105 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 174 } |
| 174 | 175 |
| 175 ImageData* OffscreenCanvasRenderingContext2D::toImageData( | 176 ImageData* OffscreenCanvasRenderingContext2D::toImageData( |
| 176 SnapshotReason reason) const { | 177 SnapshotReason reason) const { |
| 177 if (!imageBuffer()) | 178 if (!imageBuffer()) |
| 178 return nullptr; | 179 return nullptr; |
| 179 sk_sp<SkImage> snapshot = | 180 sk_sp<SkImage> snapshot = |
| 180 m_imageBuffer->newSkImageSnapshot(PreferNoAcceleration, reason); | 181 m_imageBuffer->newSkImageSnapshot(PreferNoAcceleration, reason); |
| 181 ImageData* imageData = nullptr; | 182 ImageData* imageData = nullptr; |
| 182 if (snapshot) { | 183 if (snapshot) { |
| 183 imageData = ImageData::create(this->getOffscreenCanvas()->size()); | 184 imageData = ImageData::create(offscreenCanvas()->size()); |
| 184 SkImageInfo imageInfo = | 185 SkImageInfo imageInfo = |
| 185 SkImageInfo::Make(this->width(), this->height(), kRGBA_8888_SkColorType, | 186 SkImageInfo::Make(this->width(), this->height(), kRGBA_8888_SkColorType, |
| 186 kUnpremul_SkAlphaType); | 187 kUnpremul_SkAlphaType); |
| 187 snapshot->readPixels(imageInfo, imageData->data()->data(), | 188 snapshot->readPixels(imageInfo, imageData->data()->data(), |
| 188 imageInfo.minRowBytes(), 0, 0); | 189 imageInfo.minRowBytes(), 0, 0); |
| 189 } | 190 } |
| 190 return imageData; | 191 return imageData; |
| 191 } | 192 } |
| 192 | 193 |
| 193 void OffscreenCanvasRenderingContext2D::setOffscreenCanvasGetContextResult( | 194 void OffscreenCanvasRenderingContext2D::setOffscreenCanvasGetContextResult( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 250 } |
| 250 | 251 |
| 251 bool OffscreenCanvasRenderingContext2D::isContextLost() const { | 252 bool OffscreenCanvasRenderingContext2D::isContextLost() const { |
| 252 return false; | 253 return false; |
| 253 } | 254 } |
| 254 | 255 |
| 255 bool OffscreenCanvasRenderingContext2D::isPaintable() const { | 256 bool OffscreenCanvasRenderingContext2D::isPaintable() const { |
| 256 return this->imageBuffer(); | 257 return this->imageBuffer(); |
| 257 } | 258 } |
| 258 } | 259 } |
| OLD | NEW |