⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 144072 in webkit


Ignore:
Timestamp:
Feb 26, 2013, 10:35:26 AM (14 years ago)
Author:
danakj@chromium.org
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):

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/Platform/ChangeLog

    r143803 r144072  
     12013-02-26  Dana Jansens  <danakj@chromium.org>
     2
     3        Create the SharedGraphicsContext3D through its own method.
     4        https://bugs.webkit.org/show_bug.cgi?id=109345
     5
     6        Reviewed by James Robinson.
     7
     8        Add Platform API methods to get shared contexts from the embedder.
     9
     10        * chromium/public/Platform.h:
     11        (Platform):
     12        (WebKit::Platform::sharedOffscreenGraphicsContext3D):
     13        (WebKit::Platform::sharedOffscreenGrContext):
     14
    1152013-02-22  Ali Juma  <ajuma@chromium.org>
    216
  • trunk/Source/Platform/chromium/public/Platform.h

    r143496 r144072  
    4444#include "WebString.h"
    4545#include "WebVector.h"
     46
     47class GrContext;
    4648
    4749namespace WebKit {
     
    452454    virtual WebGraphicsContext3D* createOffscreenGraphicsContext3D(const WebGraphicsContext3D::Attributes&) { return 0; }
    453455
     456    // May return null if GPU is not supported.
     457    // Returns the shared WebGraphicsContext3D. This is a singleton object for
     458    // the entire process. Calling this function may destroy both the shared
     459    // offscreen WebGraphicsContext3D and GrContext pointers last returned, so
     460    // it should only be called from a single site. The implementor should
     461    // create a new context before destroying its current context, if required,
     462    // to ensure the same pointer can not be returned twice in a row for two
     463    // different contexts.
     464    virtual WebGraphicsContext3D* sharedOffscreenGraphicsContext3D() { return 0; }
     465
     466    // May return null if GPU is not supported.
     467    // Returns the shared GrContext. This is a singleton object for the entire process.
     468    virtual GrContext* sharedOffscreenGrContext() { return 0; }
     469
    454470    // Returns true if the platform is capable of producing an offscreen context suitable for accelerating 2d canvas.
    455471    // This will return false if the platform cannot promise that contexts will be preserved across operations like
  • trunk/Source/WebCore/ChangeLog

    r144068 r144072  
     12013-02-26  Dana Jansens  <danakj@chromium.org>
     2
     3        Create the SharedGraphicsContext3D through its own method.
     4        https://bugs.webkit.org/show_bug.cgi?id=109345
     5
     6        Reviewed by James Robinson.
     7
     8        Allow creating a GraphicsContext3DPrivate from an externally owned
     9        WebGraphicsContext3D and GrContext. Then create the shared graphics
     10        context from these provided by the embedder.
     11
     12        This falls back to the old path if the new methods return NULL to
     13        let us land this immediately and then transition the chromium side
     14        over to this path.
     15
     16        * platform/chromium/support/GraphicsContext3DPrivate.cpp:
     17        (WebCore::GraphicsContext3DPrivate::GraphicsContext3DPrivate):
     18        (WebCore):
     19        (WebCore::GraphicsContext3DPrivate::createGraphicsContextFromExternalWebContextAndGrContext):
     20        (WebCore::GraphicsContext3DPrivate::grContext):
     21        * platform/chromium/support/GraphicsContext3DPrivate.h:
     22        (GraphicsContext3DPrivate):
     23        (WebCore::GraphicsContext3DPrivate::webContext):
     24        * platform/graphics/gpu/SharedGraphicsContext3D.cpp:
     25        (WebCore::SharedGraphicsContext3DImpl::getOrCreateContext):
     26
    1272013-02-26  Antti Koivisto  <antti@apple.com>
    228
  • trunk/Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.cpp

    r142028 r144072  
    5858
    5959GraphicsContext3DPrivate::GraphicsContext3DPrivate(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, bool preserveDrawingBuffer)
     60    : m_impl(webContext.get())
     61    , m_ownedWebContext(webContext)
     62    , m_initializedAvailableExtensions(false)
     63    , m_layerComposited(false)
     64    , m_preserveDrawingBuffer(preserveDrawingBuffer)
     65    , m_resourceSafety(ResourceSafetyUnknown)
     66    , m_grContext(0)
     67{
     68}
     69
     70GraphicsContext3DPrivate::GraphicsContext3DPrivate(WebKit::WebGraphicsContext3D* webContext, GrContext* grContext, bool preserveDrawingBuffer)
    6071    : m_impl(webContext)
    6172    , m_initializedAvailableExtensions(false)
     
    6374    , m_preserveDrawingBuffer(preserveDrawingBuffer)
    6475    , m_resourceSafety(ResourceSafetyUnknown)
    65     , m_grContext(0)
    66 {
    67 }
     76    , m_grContext(grContext)
     77{
     78}
     79
    6880
    6981GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
     
    8092
    8193    OwnPtr<GraphicsContext3DPrivate> priv = adoptPtr(new GraphicsContext3DPrivate(webContext, preserveDrawingBuffer));
     94    context->m_private = priv.release();
     95    return context.release();
     96}
     97
     98PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextFromExternalWebContextAndGrContext(WebKit::WebGraphicsContext3D* webContext, GrContext* grContext, bool preserveDrawingBuffer)
     99{
     100    RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(GraphicsContext3D::Attributes(), 0));
     101
     102    OwnPtr<GraphicsContext3DPrivate> priv = adoptPtr(new GraphicsContext3DPrivate(webContext, grContext, preserveDrawingBuffer));
    82103    context->m_private = priv.release();
    83104    return context.release();
     
    131152
    132153    interface->fCallback = bindWebGraphicsContext3DGLContextCallback;
    133     interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(m_impl.get());
    134 
    135     m_grContext.reset(GrContext::Create(kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
     154    interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(m_impl);
     155
     156    m_ownedGrContext.reset(GrContext::Create(kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
     157    m_grContext = m_ownedGrContext;
    136158    if (!m_grContext)
    137159        return 0;
  • trunk/Source/WebCore/platform/chromium/support/GraphicsContext3DPrivate.h

    r141943 r144072  
    5555    static PassRefPtr<GraphicsContext3D> createGraphicsContextFromWebContext(PassOwnPtr<WebKit::WebGraphicsContext3D>, bool preserveDrawingBuffer = false);
    5656
     57    static PassRefPtr<GraphicsContext3D> createGraphicsContextFromExternalWebContextAndGrContext(WebKit::WebGraphicsContext3D*, GrContext*, bool preserveDrawingBuffer = false);
     58
    5759    // Helper function to provide access to the lower-level WebGraphicsContext3D,
    5860    // which is needed for subordinate contexts like WebGL's to share resources
     
    6264    virtual ~GraphicsContext3DPrivate();
    6365
    64     WebKit::WebGraphicsContext3D* webContext() const { return m_impl.get(); }
     66    WebKit::WebGraphicsContext3D* webContext() const { return m_impl; }
    6567
    6668    GrContext* grContext();
     
    8789private:
    8890    GraphicsContext3DPrivate(PassOwnPtr<WebKit::WebGraphicsContext3D>, bool preserveDrawingBuffer);
     91    GraphicsContext3DPrivate(WebKit::WebGraphicsContext3D*, GrContext*, bool preserveDrawingBuffer);
    8992
    9093    void initializeExtensions();
    9194
    92     OwnPtr<WebKit::WebGraphicsContext3D> m_impl;
     95    WebKit::WebGraphicsContext3D* m_impl;
     96    OwnPtr<WebKit::WebGraphicsContext3D> m_ownedWebContext;
    9397    OwnPtr<Extensions3DChromium> m_extensions;
    9498    OwnPtr<GraphicsContext3DContextLostCallbackAdapter> m_contextLostCallbackAdapter;
     
    115119    SkBitmap m_resizingBitmap;
    116120
    117     SkAutoTUnref<GrContext> m_grContext;
     121    GrContext* m_grContext;
     122    SkAutoTUnref<GrContext> m_ownedGrContext;
    118123};
    119124
  • trunk/Source/WebCore/platform/graphics/gpu/SharedGraphicsContext3D.cpp

    r141943 r144072  
    3030
    3131#include "Extensions3D.h"
     32#if PLATFORM(CHROMIUM)
     33#include "GraphicsContext3DPrivate.h"
     34#include <public/Platform.h>
     35#include <public/WebGraphicsContext3D.h>
     36#endif
    3237#include <wtf/MainThread.h>
    3338
     
    3944    PassRefPtr<GraphicsContext3D> getOrCreateContext()
    4045    {
    41         // If we lost the context, or can't make it current, create a new one.
    42         if (m_context && (!m_context->makeContextCurrent() || (m_context->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR)))
    43             m_context.clear();
    44 
    4546        bool wasCreated = false;
    4647
    47         if (!m_context) {
    48             createContext();
    49             wasCreated = true;
     48#if PLATFORM(CHROMIUM)
     49        WebKit::WebGraphicsContext3D* webContext = WebKit::Platform::current()->sharedOffscreenGraphicsContext3D();
     50        GrContext* grContext = WebKit::Platform::current()->sharedOffscreenGrContext();
     51
     52        if (webContext && grContext) {
     53            WebKit::WebGraphicsContext3D* oldWebContext = m_context ? GraphicsContext3DPrivate::extractWebGraphicsContext3D(m_context.get()) : 0;
     54            GrContext* oldGrContext = m_context ? m_context->grContext() : 0;
     55            if (webContext != oldWebContext || grContext != oldGrContext)
     56                m_context.clear();
     57
     58            if (!m_context) {
     59                m_context = GraphicsContext3DPrivate::createGraphicsContextFromExternalWebContextAndGrContext(webContext, grContext);
     60                wasCreated = true;
     61            }
     62
     63            // FIXME: Don't fallback to the legacy path when chromium supports the new offscreen methods.
     64        } else
     65#endif
     66        {
     67            // If we lost the context, or can't make it current, create a new one.
     68            if (m_context && (!m_context->makeContextCurrent() || (m_context->getExtensions()->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR)))
     69                m_context.clear();
     70
     71            if (!m_context) {
     72                createContext();
     73                wasCreated = true;
     74            }
     75
     76            if (m_context && !m_context->makeContextCurrent())
     77                m_context.clear();
    5078        }
    51 
    52         if (m_context && !m_context->makeContextCurrent())
    53             m_context.clear();
    5479
    5580        if (m_context && wasCreated)
    5681            m_context->getExtensions()->pushGroupMarkerEXT("SharedGraphicsContext");
    57 
    5882        return m_context;
    5983    }
Note: See TracChangeset for help on using the changeset viewer.