Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) { | 43 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) { |
| 44 CanvasRenderingContext::trace(visitor); | 44 CanvasRenderingContext::trace(visitor); |
| 45 BaseRenderingContext2D::trace(visitor); | 45 BaseRenderingContext2D::trace(visitor); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void OffscreenCanvasRenderingContext2D::commit(ExceptionState& exceptionState) { | 48 void OffscreenCanvasRenderingContext2D::commit(ExceptionState& exceptionState) { |
| 49 if (getOffscreenCanvas()->getAssociatedCanvasId() < 0) { | 49 if (getOffscreenCanvas()->getAssociatedCanvasId() < 0) { |
| 50 // If an OffscreenCanvas has no associated canvas Id, it indicates that | 50 // If an OffscreenCanvas has no associated canvas Id, it indicates that |
| 51 // it is not an OffscreenCanvas created by transfering control from html | 51 // it is not an OffscreenCanvas created by transfering control from html |
| 52 // canvas. | 52 // canvas. |
| 53 exceptionState.throwDOMException(InvalidStateError, | 53 exceptionState.throwDOMException( |
| 54 "Commit() was called on a context whose " | 54 InvalidStateError, |
| 55 "OffscreenCanvas is not associated with a " | 55 "Commit() was called on a context whose OffscreenCanvas is not " |
| 56 "canvas element."); | 56 "associated with a canvas element."); |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 double commitStartTime = WTF::monotonicallyIncreasingTime(); | 59 double commitStartTime = WTF::monotonicallyIncreasingTime(); |
| 60 RefPtr<StaticBitmapImage> image = this->transferToStaticBitmapImage(); | 60 RefPtr<StaticBitmapImage> image = this->transferToStaticBitmapImage(); |
| 61 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame( | 61 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame( |
| 62 std::move(image), commitStartTime); | 62 std::move(image), commitStartTime); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // BaseRenderingContext2D implementation | 65 // BaseRenderingContext2D implementation |
| 66 bool OffscreenCanvasRenderingContext2D::originClean() const { | 66 bool OffscreenCanvasRenderingContext2D::originClean() const { |
| 67 return getOffscreenCanvas()->originClean(); | 67 return getOffscreenCanvas()->originClean(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void OffscreenCanvasRenderingContext2D::setOriginTainted() { | 70 void OffscreenCanvasRenderingContext2D::setOriginTainted() { |
| 71 return getOffscreenCanvas()->setOriginTainted(); | 71 return getOffscreenCanvas()->setOriginTainted(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin( | 74 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin( |
| 75 CanvasImageSource* source, | 75 CanvasImageSource* source, |
| 76 ExecutionContext* executionContext) { | 76 ExecutionContext* executionContext) { |
| 77 if (executionContext->isWorkerGlobalScope()) { | 77 if (executionContext->isWorkerGlobalScope()) { |
| 78 // We only support passing in ImageBitmap and OffscreenCanvases as source | 78 // We only support passing in ImageBitmap and OffscreenCanvases as |
| 79 // images in drawImage() or createPattern() in a OffscreenCanvas2d in | 79 // source images in drawImage() or createPattern() in a |
| 80 // worker. | 80 // OffscreenCanvas2d in worker. |
| 81 DCHECK(source->isImageBitmap() || source->isOffscreenCanvas()); | 81 DCHECK(source->isImageBitmap() || source->isOffscreenCanvas()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 return CanvasRenderingContext::wouldTaintOrigin( | 84 return CanvasRenderingContext::wouldTaintOrigin( |
| 85 source, executionContext->getSecurityOrigin()); | 85 source, executionContext->getSecurityOrigin()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 int OffscreenCanvasRenderingContext2D::width() const { | 88 int OffscreenCanvasRenderingContext2D::width() const { |
| 89 return getOffscreenCanvas()->width(); | 89 return getOffscreenCanvas()->width(); |
| 90 } | 90 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 | 187 |
| 188 AffineTransform OffscreenCanvasRenderingContext2D::baseTransform() const { | 188 AffineTransform OffscreenCanvasRenderingContext2D::baseTransform() const { |
| 189 if (!m_imageBuffer) | 189 if (!m_imageBuffer) |
| 190 return AffineTransform(); // identity | 190 return AffineTransform(); // identity |
| 191 return m_imageBuffer->baseTransform(); | 191 return m_imageBuffer->baseTransform(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void OffscreenCanvasRenderingContext2D::didDraw(const SkIRect& dirtyRect) {} | 194 void OffscreenCanvasRenderingContext2D::didDraw(const SkIRect& dirtyRect) {} |
| 195 | 195 |
| 196 bool OffscreenCanvasRenderingContext2D::stateHasFilter() { | 196 bool OffscreenCanvasRenderingContext2D::stateHasFilter() { |
| 197 // TODO: crbug.com/593838 make hasFilter accept nullptr | 197 return state().hasFilterWithoutDocument(getOffscreenCanvas()->size()); |
| 198 // return state().hasFilter(nullptr, nullptr, IntSize(width(), height()), | |
| 199 // this); | |
| 200 return false; | |
| 201 } | 198 } |
| 202 | 199 |
| 203 SkImageFilter* OffscreenCanvasRenderingContext2D::stateGetFilter() { | 200 SkImageFilter* OffscreenCanvasRenderingContext2D::stateGetFilter() { |
| 204 // TODO: make getFilter accept nullptr | 201 SkImageFilter* f = |
| 205 // return state().getFilter(nullptr, nullptr, IntSize(width(), height()), | 202 state().getFilterWithoutDocument(getOffscreenCanvas()->size()); |
| 206 // this); | 203 return f; |
|
meade_UTC10
2016/10/26 06:57:34
Nit: This could just be
return state().getFilterW
fserb
2016/10/26 19:08:26
done.
| |
| 207 return nullptr; | 204 } |
| 205 | |
| 206 void OffscreenCanvasRenderingContext2D::setFilter(const String& filterString) { | |
| 207 BaseRenderingContext2D::setFilter(filterString); | |
| 208 } | 208 } |
| 209 | 209 |
| 210 void OffscreenCanvasRenderingContext2D::validateStateStack() const { | 210 void OffscreenCanvasRenderingContext2D::validateStateStack() const { |
| 211 #if DCHECK_IS_ON() | 211 #if DCHECK_IS_ON() |
| 212 if (SkCanvas* skCanvas = existingDrawingCanvas()) { | 212 if (SkCanvas* skCanvas = existingDrawingCanvas()) { |
| 213 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), | 213 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), |
| 214 m_stateStack.size() + 1); | 214 m_stateStack.size() + 1); |
| 215 } | 215 } |
| 216 #endif | 216 #endif |
| 217 } | 217 } |
| 218 | 218 |
| 219 bool OffscreenCanvasRenderingContext2D::isContextLost() const { | 219 bool OffscreenCanvasRenderingContext2D::isContextLost() const { |
| 220 return false; | 220 return false; |
| 221 } | 221 } |
| 222 | 222 |
| 223 bool OffscreenCanvasRenderingContext2D::isPaintable() const { | 223 bool OffscreenCanvasRenderingContext2D::isPaintable() const { |
| 224 return this->imageBuffer(); | 224 return this->imageBuffer(); |
| 225 } | 225 } |
| 226 } | 226 } |
| OLD | NEW |