Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Unified Diff: third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp

Issue 1748163003: Add rendering context and rendering 2D context to OffscreenCanvas (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove CanvasRenderingContextBase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698