Create the SharedGraphicsContext3D through its own method.
authordanakj@chromium.org <danakj@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2013 18:35:26 +0000 (18:35 +0000)
committerdanakj@chromium.org <danakj@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2013 18:35:26 +0000 (18:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109345

Reviewed by James Robinson.

Source/Platform:

Add Platform API methods to get shared contexts from the embedder.

* chromium/public/Platform.h:
(Platform):
(WebKit::Platform::sharedOffscreenGraphicsContext3D):
(WebKit::Platform::sharedOffscreenGrContext):

Source/WebCore:

Allow creating a GraphicsContext3DPrivate from an externally owned
WebGraphicsContext3D and GrContext. Then create the shared graphics
context from these provided by the embedder.

This falls back to the old path if the new methods return NULL to
let us land this immediately and then transition the chromium side
over to this path.

* platform/chromium/support/GraphicsContext3DPrivate.cpp:
(WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
(WebCore):
(WebCore::GraphicsContext3DPrivate::createGraphicsContextFromExternalWebContextAndGrContext):
(WebCore::GraphicsContext3DPrivate::grContext):
* platform/chromium/support/GraphicsContext3DPrivate.h:
(GraphicsContext3DPrivate):
(WebCore::GraphicsContext3DPrivate::webContext):
* platform/graphics/gpu/SharedGraphicsContext3D.cpp:
(WebCore::SharedGraphicsContext3DImpl::getOrCreateContext):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@144072 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/Platform/ChangeLog
Source/Platform/chromium/public/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.cpp
Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.h
Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp

index fa5e30c..858d8bf 100644 (file)
@@ -1,3 +1,17 @@
+2013-02-26  Dana Jansens  <danakj@chromium.org>
+
+        Create the SharedGraphicsContext3D through its own method.
+        https://bugs.webkit.org/show_bug.cgi?id=109345
+
+        Reviewed by James Robinson.
+
+        Add Platform API methods to get shared contexts from the embedder.
+
+        * chromium/public/Platform.h:
+        (Platform):
+        (WebKit::Platform::sharedOffscreenGraphicsContext3D):
+        (WebKit::Platform::sharedOffscreenGrContext):
+
 2013-02-22  Ali Juma  <ajuma@chromium.org>
 
         [chromium] Register newly-created layers for animation
index ee180cb..d36a0fc 100644 (file)
@@ -44,6 +44,8 @@
 #include "WebString.h"
 #include "WebVector.h"
 
+class GrContext;
+
 namespace WebKit {
 
 class WebAudioBus;
@@ -451,6 +453,20 @@ public:
     // Returns newly allocated and initialized offscreen WebGraphicsContext3D instance.
     virtual WebGraphicsContext3D* createOffscreenGraphicsContext3D(const WebGraphicsContext3D::Attributes&) { return 0; }
 
+    // May return null if GPU is not supported.
+    // Returns the shared WebGraphicsContext3D. This is a singleton object for
+    // the entire process. Calling this function may destroy both the shared
+    // offscreen WebGraphicsContext3D and GrContext pointers last returned, so
+    // it should only be called from a single site. The implementor should
+    // create a new context before destroying its current context, if required,
+    // to ensure the same pointer can not be returned twice in a row for two
+    // different contexts.
+    virtual WebGraphicsContext3D* sharedOffscreenGraphicsContext3D() { return 0; }
+
+    // May return null if GPU is not supported.
+    // Returns the shared GrContext. This is a singleton object for the entire process.
+    virtual GrContext* sharedOffscreenGrContext() { return 0; }
+
     // Returns true if the platform is capable of producing an offscreen context suitable for accelerating 2d canvas.
     // This will return false if the platform cannot promise that contexts will be preserved across operations like
     // locking the screen or if the platform cannot provide a context with suitable performance characteristics.
index 8562849..1ff467b 100644 (file)
@@ -1,3 +1,29 @@
+2013-02-26  Dana Jansens  <danakj@chromium.org>
+
+        Create the SharedGraphicsContext3D through its own method.
+        https://bugs.webkit.org/show_bug.cgi?id=109345
+
+        Reviewed by James Robinson.
+
+        Allow creating a GraphicsContext3DPrivate from an externally owned
+        WebGraphicsContext3D and GrContext. Then create the shared graphics
+        context from these provided by the embedder.
+
+        This falls back to the old path if the new methods return NULL to
+        let us land this immediately and then transition the chromium side
+        over to this path.
+
+        * platform/chromium/support/GraphicsContext3DPrivate.cpp:
+        (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
+        (WebCore):
+        (WebCore::GraphicsContext3DPrivate::createGraphicsContextFromExternalWebContextAndGrContext):
+        (WebCore::GraphicsContext3DPrivate::grContext):
+        * platform/chromium/support/GraphicsContext3DPrivate.h:
+        (GraphicsContext3DPrivate):
+        (WebCore::GraphicsContext3DPrivate::webContext):
+        * platform/graphics/gpu/SharedGraphicsContext3D.cpp:
+        (WebCore::SharedGraphicsContext3DImpl::getOrCreateContext):
+
 2013-02-26  Antti Koivisto  <antti@apple.com>
 
         REGRESSION(r143986): fast/files/revoke-blob-url.html asserts
index a230483..09c0663 100644 (file)
@@ -57,7 +57,8 @@ namespace WebCore {
 // GraphicsContext3DPrivate
 
 GraphicsContext3DPrivate::GraphicsContext3DPrivate(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, bool preserveDrawingBuffer)
-    : m_impl(webContext)
+    : m_impl(webContext.get())
+    , m_ownedWebContext(webContext)
     , m_initializedAvailableExtensions(false)
     , m_layerComposited(false)
     , m_preserveDrawingBuffer(preserveDrawingBuffer)
@@ -66,6 +67,17 @@ GraphicsContext3DPrivate::GraphicsContext3DPrivate(PassOwnPtr<WebKit::WebGraphic
 {
 }
 
+GraphicsContext3DPrivate::GraphicsContext3DPrivate(WebKit::WebGraphicsContext3D* webContext, GrContext* grContext, bool preserveDrawingBuffer)
+    : m_impl(webContext)
+    , m_initializedAvailableExtensions(false)
+    , m_layerComposited(false)
+    , m_preserveDrawingBuffer(preserveDrawingBuffer)
+    , m_resourceSafety(ResourceSafetyUnknown)
+    , m_grContext(grContext)
+{
+}
+
+
 GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
 {
     if (m_grContext) {
@@ -83,6 +95,15 @@ PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextFro
     return context.release();
 }
 
+PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextFromExternalWebContextAndGrContext(WebKit::WebGraphicsContext3D* webContext, GrContext* grContext, bool preserveDrawingBuffer)
+{
+    RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(GraphicsContext3D::Attributes(), 0));
+
+    OwnPtr<GraphicsContext3DPrivate> priv = adoptPtr(new GraphicsContext3DPrivate(webContext, grContext, preserveDrawingBuffer));
+    context->m_private = priv.release();
+    return context.release();
+}
+
 WebKit::WebGraphicsContext3D* GraphicsContext3DPrivate::extractWebGraphicsContext3D(GraphicsContext3D* context)
 {
     if (!context)
@@ -130,9 +151,10 @@ GrContext* GraphicsContext3DPrivate::grContext()
         return 0;
 
     interface->fCallback = bindWebGraphicsContext3DGLContextCallback;
-    interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(m_impl.get());
+    interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(m_impl);
 
-    m_grContext.reset(GrContext::Create(kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
+    m_ownedGrContext.reset(GrContext::Create(kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
+    m_grContext = m_ownedGrContext;
     if (!m_grContext)
         return 0;
 
index d193a6c..a441b06 100644 (file)
@@ -54,6 +54,8 @@ public:
     // be used on any other thread.
     static PassRefPtr<GraphicsContext3D> createGraphicsContextFromWebContext(PassOwnPtr<WebKit::WebGraphicsContext3D>, bool preserveDrawingBuffer = false);
 
+    static PassRefPtr<GraphicsContext3D> createGraphicsContextFromExternalWebContextAndGrContext(WebKit::WebGraphicsContext3D*, GrContext*, bool preserveDrawingBuffer = false);
+
     // Helper function to provide access to the lower-level WebGraphicsContext3D,
     // which is needed for subordinate contexts like WebGL's to share resources
     // with the compositor's context.
@@ -61,7 +63,7 @@ public:
 
     virtual ~GraphicsContext3DPrivate();
 
-    WebKit::WebGraphicsContext3D* webContext() const { return m_impl.get(); }
+    WebKit::WebGraphicsContext3D* webContext() const { return m_impl; }
 
     GrContext* grContext();
 
@@ -86,10 +88,12 @@ public:
 
 private:
     GraphicsContext3DPrivate(PassOwnPtr<WebKit::WebGraphicsContext3D>, bool preserveDrawingBuffer);
+    GraphicsContext3DPrivate(WebKit::WebGraphicsContext3D*, GrContext*, bool preserveDrawingBuffer);
 
     void initializeExtensions();
 
-    OwnPtr<WebKit::WebGraphicsContext3D> m_impl;
+    WebKit::WebGraphicsContext3D* m_impl;
+    OwnPtr<WebKit::WebGraphicsContext3D> m_ownedWebContext;
     OwnPtr<Extensions3DChromium> m_extensions;
     OwnPtr<GraphicsContext3DContextLostCallbackAdapter> m_contextLostCallbackAdapter;
     OwnPtr<GraphicsContext3DErrorMessageCallbackAdapter> m_errorMessageCallbackAdapter;
@@ -114,7 +118,8 @@ private:
     // used to resize the Canvas.
     SkBitmap m_resizingBitmap;
 
-    SkAutoTUnref<GrContext> m_grContext;
+    GrContext* m_grContext;
+    SkAutoTUnref<GrContext> m_ownedGrContext;
 };
 
 } // namespace WebCore
index a7074b7..3fdb335 100644 (file)
 #include "SharedGraphicsContext3D.h"
 
 #include "Extensions3D.h"
+#if PLATFORM(CHROMIUM)
+#include "GraphicsContext3DPrivate.h"
+#include <public/Platform.h>
+#include <public/WebGraphicsContext3D.h>
+#endif
 #include <wtf/MainThread.h>
 
 namespace WebCore {
@@ -38,23 +43,42 @@ public:
     SharedGraphicsContext3DImpl() : m_context(0) { }
     PassRefPtr<GraphicsContext3D> getOrCreateContext()
     {
-        // If we lost the context, or can't make it current, create a new one.
-        if (m_context && (!m_context->makeContextCurrent() || (m_context->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR)))
-            m_context.clear();
-
         bool wasCreated = false;
 
-        if (!m_context) {
-            createContext();
-            wasCreated = true;
+#if PLATFORM(CHROMIUM)
+        WebKit::WebGraphicsContext3D* webContext = WebKit::Platform::current()->sharedOffscreenGraphicsContext3D();
+        GrContext* grContext = WebKit::Platform::current()->sharedOffscreenGrContext();
+
+        if (webContext && grContext) {
+            WebKit::WebGraphicsContext3D* oldWebContext = m_context ? GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_context.get()) : 0;
+            GrContext* oldGrContext = m_context ? m_context->grContext() : 0;
+            if (webContext != oldWebContext || grContext != oldGrContext)
+                m_context.clear();
+
+            if (!m_context) {
+                m_context = GraphicsContext3DPrivate::createGraphicsContextFromExternalWebContextAndGrContext(webContext, grContext);
+                wasCreated = true;
+            }
+
+            // FIXME: Don't fallback to the legacy path when chromium supports the new offscreen methods.
+        } else
+#endif
+        {
+            // If we lost the context, or can't make it current, create a new one.
+            if (m_context && (!m_context->makeContextCurrent() || (m_context->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR)))
+                m_context.clear();
+
+            if (!m_context) {
+                createContext();
+                wasCreated = true;
+            }
+
+            if (m_context && !m_context->makeContextCurrent())
+                m_context.clear();
         }
 
-        if (m_context && !m_context->makeContextCurrent())
-            m_context.clear();
-
         if (m_context && wasCreated)
             m_context->getExtensions()->pushGroupMarkerEXT("SharedGraphicsContext");
-
         return m_context;
     }