Title: [144072] trunk/Source
Revision
144072
Author
[email protected]
Date
2013-02-26 10:35:26 -0800 (Tue, 26 Feb 2013)

Log Message

Create the SharedGraphicsContext3D through its own method.
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):

Modified Paths

Diff

Modified: trunk/Source/Platform/ChangeLog (144071 => 144072)


--- trunk/Source/Platform/ChangeLog	2013-02-26 18:32:09 UTC (rev 144071)
+++ trunk/Source/Platform/ChangeLog	2013-02-26 18:35:26 UTC (rev 144072)
@@ -1,3 +1,17 @@
+2013-02-26  Dana Jansens  <[email protected]>
+
+        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  <[email protected]>
 
         [chromium] Register newly-created layers for animation

Modified: trunk/Source/Platform/chromium/public/Platform.h (144071 => 144072)


--- trunk/Source/Platform/chromium/public/Platform.h	2013-02-26 18:32:09 UTC (rev 144071)
+++ trunk/Source/Platform/chromium/public/Platform.h	2013-02-26 18:35:26 UTC (rev 144072)
@@ -44,6 +44,8 @@
 #include "WebString.h"
 #include "WebVector.h"
 
+class GrContext;
+
 namespace WebKit {
 
 class WebAudioBus;
@@ -451,6 +453,20 @@
     // 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.

Modified: trunk/Source/WebCore/ChangeLog (144071 => 144072)


--- trunk/Source/WebCore/ChangeLog	2013-02-26 18:32:09 UTC (rev 144071)
+++ trunk/Source/WebCore/ChangeLog	2013-02-26 18:35:26 UTC (rev 144072)
@@ -1,3 +1,29 @@
+2013-02-26  Dana Jansens  <[email protected]>
+
+        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  <[email protected]>
 
         REGRESSION(r143986): fast/files/revoke-blob-url.html asserts

Modified: trunk/Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.cpp (144071 => 144072)


--- trunk/Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.cpp	2013-02-26 18:32:09 UTC (rev 144071)
+++ trunk/Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.cpp	2013-02-26 18:35:26 UTC (rev 144072)
@@ -57,7 +57,8 @@
 // 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(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 @@
     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 @@
         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;
 

Modified: trunk/Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.h (144071 => 144072)


--- trunk/Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.h	2013-02-26 18:32:09 UTC (rev 144071)
+++ trunk/Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.h	2013-02-26 18:35:26 UTC (rev 144072)
@@ -54,6 +54,8 @@
     // 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 @@
 
     virtual ~GraphicsContext3DPrivate();
 
-    WebKit::WebGraphicsContext3D* webContext() const { return m_impl.get(); }
+    WebKit::WebGraphicsContext3D* webContext() const { return m_impl; }
 
     GrContext* grContext();
 
@@ -86,10 +88,12 @@
 
 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 @@
     // used to resize the Canvas.
     SkBitmap m_resizingBitmap;
 
-    SkAutoTUnref<GrContext> m_grContext;
+    GrContext* m_grContext;
+    SkAutoTUnref<GrContext> m_ownedGrContext;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp (144071 => 144072)


--- trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp	2013-02-26 18:32:09 UTC (rev 144071)
+++ trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp	2013-02-26 18:35:26 UTC (rev 144072)
@@ -29,6 +29,11 @@
 #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 @@
     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;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to