Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp |
| diff --git a/third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp b/third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp |
| index c227f47b8ebb341cdb2628e2f5ab8eab2e1c1dfe..2c32bb56998e658e68d608bbfe12e7b3f0f1cf25 100644 |
| --- a/third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp |
| +++ b/third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp |
| @@ -4,6 +4,9 @@ |
| #include "core/html/canvas/OffscreenCanvas.h" |
| +#include "core/html/canvas/CanvasContextCreationAttributes.h" |
| +#include "core/html/canvas/OffscreenCanvasRenderingContext.h" |
| +#include "core/html/canvas/OffscreenCanvasRenderingContextFactory.h" |
| #include "wtf/MathExtras.h" |
| namespace blink { |
| @@ -28,8 +31,56 @@ OffscreenCanvas::OffscreenCanvas(const IntSize& size) |
| { |
| } |
| +OffscreenCanvasRenderingContext* OffscreenCanvas::getContext(const String& id, const CanvasContextCreationAttributes& attributes) |
| +{ |
| + OffscreenCanvasRenderingContext::ContextType contextType = OffscreenCanvasRenderingContext::contextTypeFromId(id); |
| + |
| + // Unknown type. |
| + if (contextType == OffscreenCanvasRenderingContext::ContextTypeCount) |
| + return nullptr; |
| + |
| + OffscreenCanvasRenderingContextFactory* factory = getRenderingContextFactory(contextType); |
| + if (!factory) |
| + return nullptr; |
|
Justin Novosad
2016/03/02 15:41:50
This is correct, but it needs to be tested in a la
xlai (Olivia)
2016/03/03 22:50:06
Done for here and elsewhere.
|
| + |
| + if (m_context) { |
| + if (m_context->contextType() == contextType) |
| + return m_context.get(); |
|
Justin Novosad
2016/03/02 15:41:50
This case needs to be covered in a layout test.
|
| + |
| + factory->onError(this, "OffscreenCanvas has an existing context of a different type"); |
| + return nullptr; |
|
Justin Novosad
2016/03/02 15:41:50
This case need to be covered in a layout test.
|
| + } |
| + |
| + m_context = factory->create(this, attributes); |
| + if (!m_context) |
| + return nullptr; |
|
Justin Novosad
2016/03/02 15:41:50
This is not necessary. The return statement below
|
| + |
| + return m_context.get(); |
| +} |
| + |
| +OffscreenCanvas::ContextFactoryVector& OffscreenCanvas::renderingContextFactories() |
| +{ |
| + DEFINE_STATIC_LOCAL(ContextFactoryVector, s_contextFactories, (OffscreenCanvasRenderingContext::ContextTypeCount)); |
| + return s_contextFactories; |
| +} |
| + |
| +OffscreenCanvasRenderingContextFactory* OffscreenCanvas::getRenderingContextFactory(int type) |
| +{ |
| + ASSERT(type < OffscreenCanvasRenderingContext::ContextTypeCount); |
| + return renderingContextFactories()[type].get(); |
| +} |
| + |
| +void OffscreenCanvas::registerRenderingContextFactory(PassOwnPtr<OffscreenCanvasRenderingContextFactory> renderingContextFactory) |
| +{ |
| + OffscreenCanvasRenderingContext::ContextType type = renderingContextFactory->contextType(); |
| + ASSERT(type < OffscreenCanvasRenderingContext::ContextTypeCount); |
| + ASSERT(!renderingContextFactories()[type]); |
| + renderingContextFactories()[type] = renderingContextFactory; |
| +} |
| + |
| DEFINE_TRACE(OffscreenCanvas) |
| { |
| + visitor->trace(m_context); |
| } |
| } // namespace blink |