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

Unified Diff: third_party/WebKit/Source/modules/offscreencanvas/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: Make OffscreenCanvasRenderingContext Modules exportable" Created 4 years, 9 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/modules/offscreencanvas/OffscreenCanvas.cpp
diff --git a/third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp b/third_party/WebKit/Source/modules/offscreencanvas/OffscreenCanvas.cpp
similarity index 21%
rename from third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp
rename to third_party/WebKit/Source/modules/offscreencanvas/OffscreenCanvas.cpp
index c227f47b8ebb341cdb2628e2f5ab8eab2e1c1dfe..1a00c5b7d8fd715632282ad437351edcc7c04d80 100644
--- a/third_party/WebKit/Source/core/html/canvas/OffscreenCanvas.cpp
+++ b/third_party/WebKit/Source/modules/offscreencanvas/OffscreenCanvas.cpp
@@ -2,8 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/html/canvas/OffscreenCanvas.h"
+#include "modules/offscreencanvas/OffscreenCanvas.h"
+#include "core/html/canvas/CanvasContextCreationAttributes.h"
+#include "modules/offscreencanvas/OffscreenCanvasRenderingContext.h"
+#include "modules/offscreencanvas/OffscreenCanvasRenderingContextFactory.h"
+#include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h"
#include "wtf/MathExtras.h"
namespace blink {
@@ -28,8 +32,64 @@ OffscreenCanvas::OffscreenCanvas(const IntSize& size)
{
}
+OffscreenCanvasRenderingContext2D* 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;
+
+ if (m_context) {
+ if (m_context->contextType() != contextType) {
+ factory->onError(this, "OffscreenCanvas has an existing context of a different type");
+ return nullptr;
+ }
+ } else {
+ m_context = factory->create(this, attributes);
+ }
+
+ // TODO: When there're more than one context type implemented in the future,
+ // the return type here should be changed to base class of all Offscreen
+ // context types.
+ return static_cast<OffscreenCanvasRenderingContext2D*>(m_context.get());
+}
+
+OffscreenCanvasRenderingContext2D* OffscreenCanvas::renderingContext() const
+{
+ // TODO: When there're more than one context type implemented in the future,
+ // the return type here should be changed to base class of all Offscreen
+ // context types.
+ return static_cast<OffscreenCanvasRenderingContext2D*>(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