| 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/html/canvas/CanvasContextCreationAttributes.h" | 8 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
| 9 #include "core/html/canvas/CanvasRenderingContext.h" | 9 #include "core/html/canvas/CanvasRenderingContext.h" |
| 10 #include "core/html/canvas/CanvasRenderingContextFactory.h" | 10 #include "core/html/canvas/CanvasRenderingContextFactory.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 return nullptr; | 39 return nullptr; |
| 40 } | 40 } |
| 41 ImageBitmap* image = m_context->transferToImageBitmap(exceptionState); | 41 ImageBitmap* image = m_context->transferToImageBitmap(exceptionState); |
| 42 if (!image) { | 42 if (!image) { |
| 43 // Undocumented exception (not in spec) | 43 // Undocumented exception (not in spec) |
| 44 exceptionState.throwDOMException(V8GeneralError, "Out of memory"); | 44 exceptionState.throwDOMException(V8GeneralError, "Out of memory"); |
| 45 } | 45 } |
| 46 return image; | 46 return image; |
| 47 } | 47 } |
| 48 | 48 |
| 49 CanvasRenderingContext* OffscreenCanvas::getCanvasRenderingContext(const String&
id, const CanvasContextCreationAttributes& attributes) | 49 CanvasRenderingContext* OffscreenCanvas::getCanvasRenderingContext(ScriptState*
scriptState, const String& id, const CanvasContextCreationAttributes& attributes
) |
| 50 { | 50 { |
| 51 CanvasRenderingContext::ContextType contextType = CanvasRenderingContext::co
ntextTypeFromId(id); | 51 CanvasRenderingContext::ContextType contextType = CanvasRenderingContext::co
ntextTypeFromId(id); |
| 52 | 52 |
| 53 // Unknown type. | 53 // Unknown type. |
| 54 if (contextType == CanvasRenderingContext::ContextTypeCount) | 54 if (contextType == CanvasRenderingContext::ContextTypeCount) |
| 55 return nullptr; | 55 return nullptr; |
| 56 | 56 |
| 57 CanvasRenderingContextFactory* factory = getRenderingContextFactory(contextT
ype); | 57 CanvasRenderingContextFactory* factory = getRenderingContextFactory(contextT
ype); |
| 58 if (!factory) | 58 if (!factory) |
| 59 return nullptr; | 59 return nullptr; |
| 60 | 60 |
| 61 if (m_context) { | 61 if (m_context) { |
| 62 if (m_context->getContextType() != contextType) { | 62 if (m_context->getContextType() != contextType) { |
| 63 factory->onError(this, "OffscreenCanvas has an existing context of a
different type"); | 63 factory->onError(this, "OffscreenCanvas has an existing context of a
different type"); |
| 64 return nullptr; | 64 return nullptr; |
| 65 } | 65 } |
| 66 } else { | 66 } else { |
| 67 m_context = factory->create(this, attributes); | 67 m_context = factory->create(scriptState, this, attributes); |
| 68 } | 68 } |
| 69 | 69 |
| 70 return m_context.get(); | 70 return m_context.get(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 OffscreenCanvas::ContextFactoryVector& OffscreenCanvas::renderingContextFactorie
s() | 73 OffscreenCanvas::ContextFactoryVector& OffscreenCanvas::renderingContextFactorie
s() |
| 74 { | 74 { |
| 75 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (CanvasRenderi
ngContext::ContextTypeCount)); | 75 DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (CanvasRenderi
ngContext::ContextTypeCount)); |
| 76 return s_contextFactories; | 76 return s_contextFactories; |
| 77 } | 77 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 90 renderingContextFactories()[type] = renderingContextFactory; | 90 renderingContextFactories()[type] = renderingContextFactory; |
| 91 } | 91 } |
| 92 | 92 |
| 93 DEFINE_TRACE(OffscreenCanvas) | 93 DEFINE_TRACE(OffscreenCanvas) |
| 94 { | 94 { |
| 95 visitor->trace(m_context); | 95 visitor->trace(m_context); |
| 96 visitor->trace(m_canvas); | 96 visitor->trace(m_canvas); |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |