LayerTreeHost should be created with a WebPage reference instead of a pointer
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Jun 2016 12:13:11 +0000 (12:13 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Jun 2016 12:13:11 +0000 (12:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158520

Reviewed by Žan Doberšek.

We are indeed creating the LayerTreeHost always from a WebPage reference but getting its address to pass it to
the LayerTreeHost create() function.

* WebProcess/WebPage/CoordinatedGraphics/CoordinatedDrawingArea.cpp:
(WebKit::CoordinatedDrawingArea::enterAcceleratedCompositingMode):
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
(WebKit::CoordinatedLayerTreeHost::create):
(WebKit::CoordinatedLayerTreeHost::CoordinatedLayerTreeHost):
(WebKit::CoordinatedLayerTreeHost::didFlushRootLayer):
(WebKit::CoordinatedLayerTreeHost::performScheduledLayerFlush):
(WebKit::CoordinatedLayerTreeHost::commitSceneState):
(WebKit::CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged):
* WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
* WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp:
(WebKit::ThreadedCoordinatedLayerTreeHost::create):
(WebKit::ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost):
(WebKit::ThreadedCoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged):
(WebKit::ThreadedCoordinatedLayerTreeHost::compositorDidFlushLayers):
(WebKit::ThreadedCoordinatedLayerTreeHost::didScaleFactorChanged):
(WebKit::ThreadedCoordinatedLayerTreeHost::setVisibleContentsRect):
* WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:
* WebProcess/WebPage/DrawingAreaImpl.cpp:
(WebKit::DrawingAreaImpl::enterAcceleratedCompositingMode):
* WebProcess/WebPage/LayerTreeHost.cpp:
(WebKit::LayerTreeHost::create):
(WebKit::LayerTreeHost::LayerTreeHost):
* WebProcess/WebPage/LayerTreeHost.h:
* WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
(WebKit::LayerTreeHostGtk::create):
(WebKit::LayerTreeHostGtk::LayerTreeHostGtk):
(WebKit::LayerTreeHostGtk::makeContextCurrent):
(WebKit::LayerTreeHostGtk::deviceOrPageScaleFactorChanged):
(WebKit::LayerTreeHostGtk::paintContents):
(WebKit::LayerTreeHostGtk::deviceScaleFactor):
(WebKit::LayerTreeHostGtk::pageScaleFactor):
(WebKit::LayerTreeHostGtk::flushPendingLayerChanges):
(WebKit::LayerTreeHostGtk::flushAndRenderLayers):
(WebKit::LayerTreeHostGtk::pageBackgroundTransparencyChanged):
(WebKit::LayerTreeHostGtk::initialize): Deleted.
* WebProcess/WebPage/gtk/LayerTreeHostGtk.h:

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedDrawingArea.cpp
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp
Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h
Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp
Source/WebKit2/WebProcess/WebPage/LayerTreeHost.cpp
Source/WebKit2/WebProcess/WebPage/LayerTreeHost.h
Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp
Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h

index 4c5ea03..2a19b9d 100644 (file)
@@ -1,3 +1,51 @@
+2016-06-08  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        LayerTreeHost should be created with a WebPage reference instead of a pointer
+        https://bugs.webkit.org/show_bug.cgi?id=158520
+
+        Reviewed by Žan Doberšek.
+
+        We are indeed creating the LayerTreeHost always from a WebPage reference but getting its address to pass it to
+        the LayerTreeHost create() function.
+
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedDrawingArea.cpp:
+        (WebKit::CoordinatedDrawingArea::enterAcceleratedCompositingMode):
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.cpp:
+        (WebKit::CoordinatedLayerTreeHost::create):
+        (WebKit::CoordinatedLayerTreeHost::CoordinatedLayerTreeHost):
+        (WebKit::CoordinatedLayerTreeHost::didFlushRootLayer):
+        (WebKit::CoordinatedLayerTreeHost::performScheduledLayerFlush):
+        (WebKit::CoordinatedLayerTreeHost::commitSceneState):
+        (WebKit::CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged):
+        * WebProcess/WebPage/CoordinatedGraphics/CoordinatedLayerTreeHost.h:
+        * WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp:
+        (WebKit::ThreadedCoordinatedLayerTreeHost::create):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::compositorDidFlushLayers):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::didScaleFactorChanged):
+        (WebKit::ThreadedCoordinatedLayerTreeHost::setVisibleContentsRect):
+        * WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:
+        * WebProcess/WebPage/DrawingAreaImpl.cpp:
+        (WebKit::DrawingAreaImpl::enterAcceleratedCompositingMode):
+        * WebProcess/WebPage/LayerTreeHost.cpp:
+        (WebKit::LayerTreeHost::create):
+        (WebKit::LayerTreeHost::LayerTreeHost):
+        * WebProcess/WebPage/LayerTreeHost.h:
+        * WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
+        (WebKit::LayerTreeHostGtk::create):
+        (WebKit::LayerTreeHostGtk::LayerTreeHostGtk):
+        (WebKit::LayerTreeHostGtk::makeContextCurrent):
+        (WebKit::LayerTreeHostGtk::deviceOrPageScaleFactorChanged):
+        (WebKit::LayerTreeHostGtk::paintContents):
+        (WebKit::LayerTreeHostGtk::deviceScaleFactor):
+        (WebKit::LayerTreeHostGtk::pageScaleFactor):
+        (WebKit::LayerTreeHostGtk::flushPendingLayerChanges):
+        (WebKit::LayerTreeHostGtk::flushAndRenderLayers):
+        (WebKit::LayerTreeHostGtk::pageBackgroundTransparencyChanged):
+        (WebKit::LayerTreeHostGtk::initialize): Deleted.
+        * WebProcess/WebPage/gtk/LayerTreeHostGtk.h:
+
 2016-06-07  Sam Weinig  <sam@webkit.org>
 
         Fix 10.10 build.
index 9da31d6..cdf2fab 100644 (file)
@@ -306,7 +306,7 @@ void CoordinatedDrawingArea::enterAcceleratedCompositingMode(GraphicsLayer* grap
     m_exitCompositingTimer.stop();
     m_wantsToExitAcceleratedCompositingMode = false;
 
-    m_layerTreeHost = LayerTreeHost::create(&m_webPage);
+    m_layerTreeHost = LayerTreeHost::create(m_webPage);
     if (!m_inUpdateBackingStoreState)
         m_layerTreeHost->setShouldNotifyAfterNextScheduledLayerFlush(true);
 
index 492e67d..b68dc40 100644 (file)
@@ -49,7 +49,7 @@ using namespace WebCore;
 
 namespace WebKit {
 
-Ref<CoordinatedLayerTreeHost> CoordinatedLayerTreeHost::create(WebPage* webPage)
+Ref<CoordinatedLayerTreeHost> CoordinatedLayerTreeHost::create(WebPage& webPage)
 {
     return adoptRef(*new CoordinatedLayerTreeHost(webPage));
 }
@@ -58,7 +58,7 @@ CoordinatedLayerTreeHost::~CoordinatedLayerTreeHost()
 {
 }
 
-CoordinatedLayerTreeHost::CoordinatedLayerTreeHost(WebPage* webPage)
+CoordinatedLayerTreeHost::CoordinatedLayerTreeHost(WebPage& webPage)
     : LayerTreeHost(webPage)
     , m_notifyAfterScheduledLayerFlush(false)
     , m_isValid(true)
@@ -69,9 +69,9 @@ CoordinatedLayerTreeHost::CoordinatedLayerTreeHost(WebPage* webPage)
     , m_forceRepaintAsyncCallbackID(0)
     , m_viewOverlayRootLayer(nullptr)
 {
-    m_coordinator = std::make_unique<CompositingCoordinator>(webPage->corePage(), this);
+    m_coordinator = std::make_unique<CompositingCoordinator>(m_webPage.corePage(), this);
 
-    m_coordinator->createRootLayer(webPage->size());
+    m_coordinator->createRootLayer(m_webPage.size());
     m_layerTreeContext.contextID = toCoordinatedGraphicsLayer(m_coordinator->rootLayer())->id();
 
     CoordinatedSurface::setFactory(createCoordinatedSurface);
@@ -186,7 +186,7 @@ void CoordinatedLayerTreeHost::didFlushRootLayer(const FloatRect& visibleContent
 {
     // Because our view-relative overlay root layer is not attached to the FrameView's GraphicsLayer tree, we need to flush it manually.
     if (m_viewOverlayRootLayer)
-        m_viewOverlayRootLayer->flushCompositingState(visibleContentRect,  m_webPage->mainFrame()->view()->viewportIsStable());
+        m_viewOverlayRootLayer->flushCompositingState(visibleContentRect,  m_webPage.mainFrame()->view()->viewportIsStable());
 }
 
 void CoordinatedLayerTreeHost::performScheduledLayerFlush()
@@ -202,12 +202,12 @@ void CoordinatedLayerTreeHost::performScheduledLayerFlush()
     bool didSync = m_coordinator->flushPendingLayerChanges();
 
     if (m_forceRepaintAsyncCallbackID) {
-        m_webPage->send(Messages::WebPageProxy::VoidCallback(m_forceRepaintAsyncCallbackID));
+        m_webPage.send(Messages::WebPageProxy::VoidCallback(m_forceRepaintAsyncCallbackID));
         m_forceRepaintAsyncCallbackID = 0;
     }
 
     if (m_notifyAfterScheduledLayerFlush && didSync) {
-        static_cast<CoordinatedDrawingArea*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
+        static_cast<CoordinatedDrawingArea*>(m_webPage.drawingArea())->layerHostDidFlushLayers();
         m_notifyAfterScheduledLayerFlush = false;
     }
 }
@@ -223,7 +223,7 @@ void CoordinatedLayerTreeHost::paintLayerContents(const GraphicsLayer*, Graphics
 
 void CoordinatedLayerTreeHost::commitSceneState(const WebCore::CoordinatedGraphicsState& state)
 {
-    m_webPage->send(Messages::CoordinatedLayerTreeHostProxy::CommitCoordinatedGraphicsState(state));
+    m_webPage.send(Messages::CoordinatedLayerTreeHostProxy::CommitCoordinatedGraphicsState(state));
     m_isWaitingForRenderer = true;
 }
 
@@ -235,7 +235,7 @@ RefPtr<CoordinatedSurface> CoordinatedLayerTreeHost::createCoordinatedSurface(co
 void CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged()
 {
     m_coordinator->deviceOrPageScaleFactorChanged();
-    m_webPage->mainFrame()->pageOverlayController().didChangeDeviceScaleFactor();
+    m_webPage.mainFrame()->pageOverlayController().didChangeDeviceScaleFactor();
 }
 
 void CoordinatedLayerTreeHost::pageBackgroundTransparencyChanged()
index fc88412..4d88599 100644 (file)
@@ -40,7 +40,7 @@ class WebPage;
 class CoordinatedLayerTreeHost : public LayerTreeHost, public WebCore::CompositingCoordinator::Client
 {
 public:
-    static Ref<CoordinatedLayerTreeHost> create(WebPage*);
+    static Ref<CoordinatedLayerTreeHost> create(WebPage&);
     virtual ~CoordinatedLayerTreeHost();
 
     const LayerTreeContext& layerTreeContext() override { return m_layerTreeContext; }
@@ -75,7 +75,7 @@ public:
     static RefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
 
 protected:
-    explicit CoordinatedLayerTreeHost(WebPage*);
+    explicit CoordinatedLayerTreeHost(WebPage&);
 
 private:
     // CoordinatedLayerTreeHost
index 6970122..2d954b9 100644 (file)
@@ -48,7 +48,7 @@ using namespace WebCore;
 
 namespace WebKit {
 
-Ref<ThreadedCoordinatedLayerTreeHost> ThreadedCoordinatedLayerTreeHost::create(WebPage* webPage)
+Ref<ThreadedCoordinatedLayerTreeHost> ThreadedCoordinatedLayerTreeHost::create(WebPage webPage)
 {
     return adoptRef(*new ThreadedCoordinatedLayerTreeHost(webPage));
 }
@@ -57,7 +57,7 @@ ThreadedCoordinatedLayerTreeHost::~ThreadedCoordinatedLayerTreeHost()
 {
 }
 
-ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost(WebPage* webPage)
+ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost(WebPage& webPage)
     : LayerTreeHost(webPage)
     , m_forceRepaintAsyncCallbackID(0)
     , m_notifyAfterScheduledLayerFlush(false)
@@ -66,9 +66,9 @@ ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost(WebPage* webP
     , m_layerFlushTimer(RunLoop::main(), this, &ThreadedCoordinatedLayerTreeHost::performScheduledLayerFlush)
     , m_layerFlushSchedulingEnabled(true)
 {
-    m_coordinator = std::make_unique<CompositingCoordinator>(m_webPage->corePage(), this);
+    m_coordinator = std::make_unique<CompositingCoordinator>(m_webPage.corePage(), this);
 
-    m_coordinator->createRootLayer(m_webPage->size());
+    m_coordinator->createRootLayer(m_webPage.size());
 
     CoordinatedSurface::setFactory(createCoordinatedSurface);
 
@@ -149,7 +149,7 @@ void ThreadedCoordinatedLayerTreeHost::sizeDidChange(const WebCore::IntSize& new
 void ThreadedCoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged()
 {
     m_coordinator->deviceOrPageScaleFactorChanged();
-    m_compositor->setDeviceScaleFactor(m_webPage->deviceScaleFactor());
+    m_compositor->setDeviceScaleFactor(m_webPage.deviceScaleFactor());
 }
 
 void ThreadedCoordinatedLayerTreeHost::pauseRendering()
@@ -180,12 +180,12 @@ void ThreadedCoordinatedLayerTreeHost::didChangeViewportProperties(const WebCore
 
 void ThreadedCoordinatedLayerTreeHost::compositorDidFlushLayers()
 {
-    static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
+    static_cast<DrawingAreaImpl*>(m_webPage.drawingArea())->layerHostDidFlushLayers();
 }
 
 void ThreadedCoordinatedLayerTreeHost::didScaleFactorChanged(float scale, const IntPoint& origin)
 {
-    m_webPage->scalePage(scale, origin);
+    m_webPage.scalePage(scale, origin);
 }
 
 void ThreadedCoordinatedLayerTreeHost::setViewOverlayRootLayer(GraphicsLayer* graphicsLayer)
@@ -221,8 +221,8 @@ void ThreadedCoordinatedLayerTreeHost::setVisibleContentsRect(const FloatRect& r
     if (m_lastScrollPosition != roundedIntPoint(rect.location())) {
         m_lastScrollPosition = roundedIntPoint(rect.location());
 
-        if (!m_webPage->corePage()->mainFrame().view()->useFixedLayout())
-            m_webPage->corePage()->mainFrame().view()->notifyScrollPositionChanged(m_lastScrollPosition);
+        if (!m_webPage.corePage()->mainFrame().view()->useFixedLayout())
+            m_webPage.corePage()->mainFrame().view()->notifyScrollPositionChanged(m_lastScrollPosition);
     }
 
     if (m_lastScaleFactor != scale) {
index 3579a3a..ced8328 100644 (file)
@@ -61,7 +61,7 @@ class WebPage;
 class ThreadedCoordinatedLayerTreeHost : public LayerTreeHost, public WebCore::CompositingCoordinator::Client, public ThreadedCompositor::Client {
     WTF_MAKE_NONCOPYABLE(ThreadedCoordinatedLayerTreeHost); WTF_MAKE_FAST_ALLOCATED;
 public:
-    static Ref<ThreadedCoordinatedLayerTreeHost> create(WebPage*);
+    static Ref<ThreadedCoordinatedLayerTreeHost> create(WebPage&);
     virtual ~ThreadedCoordinatedLayerTreeHost();
 
     const LayerTreeContext& layerTreeContext() override { return m_layerTreeContext; };
@@ -101,7 +101,7 @@ public:
     static RefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
 
 protected:
-    explicit ThreadedCoordinatedLayerTreeHost(WebPage*);
+    explicit ThreadedCoordinatedLayerTreeHost(WebPage&);
 
 private:
 
index 825c765..d47dfb3 100644 (file)
@@ -471,7 +471,7 @@ void DrawingAreaImpl::enterAcceleratedCompositingMode(GraphicsLayer* graphicsLay
 
     ASSERT(!m_layerTreeHost);
 
-    m_layerTreeHost = LayerTreeHost::create(&m_webPage);
+    m_layerTreeHost = LayerTreeHost::create(m_webPage);
 #if USE(TEXTURE_MAPPER) && PLATFORM(GTK)
     if (m_nativeSurfaceHandleForCompositing)
         m_layerTreeHost->setNativeSurfaceHandleForCompositing(m_nativeSurfaceHandleForCompositing);
index e50b008..d2a14f8 100644 (file)
@@ -41,7 +41,7 @@ using namespace WebCore;
 
 namespace WebKit {
 
-PassRefPtr<LayerTreeHost> LayerTreeHost::create(WebPage* webPage)
+RefPtr<LayerTreeHost> LayerTreeHost::create(WebPage& webPage)
 {
 #if USE(COORDINATED_GRAPHICS_THREADED)
     return ThreadedCoordinatedLayerTreeHost::create(webPage);
@@ -51,11 +51,11 @@ PassRefPtr<LayerTreeHost> LayerTreeHost::create(WebPage* webPage)
     return LayerTreeHostGtk::create(webPage);
 #else
     UNUSED_PARAM(webPage);
-    return 0;
+    return nullptr;
 #endif
 }
 
-LayerTreeHost::LayerTreeHost(WebPage* webPage)
+LayerTreeHost::LayerTreeHost(WebPage& webPage)
     : m_webPage(webPage)
 {
 }
index 4864540..73bd91e 100644 (file)
@@ -57,7 +57,7 @@ class WebPage;
 
 class LayerTreeHost : public RefCounted<LayerTreeHost> {
 public:
-    static PassRefPtr<LayerTreeHost> create(WebPage*);
+    static RefPtr<LayerTreeHost> create(WebPage&);
     virtual ~LayerTreeHost();
 
     virtual const LayerTreeContext& layerTreeContext() = 0;
@@ -101,9 +101,9 @@ public:
     virtual void setViewOverlayRootLayer(WebCore::GraphicsLayer*) = 0;
 
 protected:
-    explicit LayerTreeHost(WebPage*);
+    explicit LayerTreeHost(WebPage&);
 
-    WebPage* m_webPage;
+    WebPage& m_webPage;
 };
 
 } // namespace WebKit
index 5b83c72..552a762 100644 (file)
@@ -126,14 +126,12 @@ void LayerTreeHostGtk::RenderFrameScheduler::renderFrame()
     nextFrame();
 }
 
-PassRefPtr<LayerTreeHostGtk> LayerTreeHostGtk::create(WebPage* webPage)
+Ref<LayerTreeHostGtk> LayerTreeHostGtk::create(WebPage& webPage)
 {
-    RefPtr<LayerTreeHostGtk> host = adoptRef(new LayerTreeHostGtk(webPage));
-    host->initialize();
-    return host.release();
+    return adoptRef(*new LayerTreeHostGtk(webPage));
 }
 
-LayerTreeHostGtk::LayerTreeHostGtk(WebPage* webPage)
+LayerTreeHostGtk::LayerTreeHostGtk(WebPage& webPage)
     : LayerTreeHost(webPage)
     , m_isValid(true)
     , m_notifyAfterScheduledLayerFlush(false)
@@ -141,41 +139,21 @@ LayerTreeHostGtk::LayerTreeHostGtk(WebPage* webPage)
     , m_viewOverlayRootLayer(nullptr)
     , m_renderFrameScheduler(std::bind(&LayerTreeHostGtk::renderFrame, this))
 {
-}
-
-bool LayerTreeHostGtk::makeContextCurrent()
-{
-    if (!m_layerTreeContext.contextID) {
-        m_context = nullptr;
-        return false;
-    }
-
-    if (!m_context) {
-        m_context = GLContext::createContextForWindow(reinterpret_cast<GLNativeWindowType>(m_layerTreeContext.contextID), GLContext::sharingContext());
-        if (!m_context)
-            return false;
-    }
-
-    return m_context->makeContextCurrent();
-}
-
-void LayerTreeHostGtk::initialize()
-{
     m_rootLayer = GraphicsLayer::create(graphicsLayerFactory(), *this);
     m_rootLayer->setDrawsContent(false);
-    m_rootLayer->setSize(m_webPage->size());
+    m_rootLayer->setSize(m_webPage.size());
 
     m_scaleMatrix.makeIdentity();
-    m_scaleMatrix.scale(m_webPage->deviceScaleFactor() * m_webPage->pageScaleFactor());
+    m_scaleMatrix.scale(m_webPage.deviceScaleFactor() * m_webPage.pageScaleFactor());
     downcast<GraphicsLayerTextureMapper>(*m_rootLayer).layer().setAnchorPoint(FloatPoint3D());
     downcast<GraphicsLayerTextureMapper>(*m_rootLayer).layer().setTransform(m_scaleMatrix);
 
     // The non-composited contents are a child of the root layer.
     m_nonCompositedContentLayer = GraphicsLayer::create(graphicsLayerFactory(), *this);
     m_nonCompositedContentLayer->setDrawsContent(true);
-    m_nonCompositedContentLayer->setContentsOpaque(m_webPage->drawsBackground());
-    m_nonCompositedContentLayer->setSize(m_webPage->size());
-    if (m_webPage->corePage()->settings().acceleratedDrawingEnabled())
+    m_nonCompositedContentLayer->setContentsOpaque(m_webPage.drawsBackground());
+    m_nonCompositedContentLayer->setSize(m_webPage.size());
+    if (m_webPage.corePage()->settings().acceleratedDrawingEnabled())
         m_nonCompositedContentLayer->setAcceleratesDrawing(true);
 
 #ifndef NDEBUG
@@ -187,6 +165,22 @@ void LayerTreeHostGtk::initialize()
     m_nonCompositedContentLayer->setNeedsDisplay();
 }
 
+bool LayerTreeHostGtk::makeContextCurrent()
+{
+    if (!m_layerTreeContext.contextID) {
+        m_context = nullptr;
+        return false;
+    }
+
+    if (!m_context) {
+        m_context = GLContext::createContextForWindow(reinterpret_cast<GLNativeWindowType>(m_layerTreeContext.contextID), GLContext::sharingContext());
+        if (!m_context)
+            return false;
+    }
+
+    return m_context->makeContextCurrent();
+}
+
 LayerTreeHostGtk::~LayerTreeHostGtk()
 {
     ASSERT(!m_isValid);
@@ -279,7 +273,7 @@ void LayerTreeHostGtk::deviceOrPageScaleFactorChanged()
     m_nonCompositedContentLayer->deviceOrPageScaleFactorChanged();
 
     m_scaleMatrix.makeIdentity();
-    m_scaleMatrix.scale(m_webPage->deviceScaleFactor() * m_webPage->pageScaleFactor());
+    m_scaleMatrix.scale(m_webPage.deviceScaleFactor() * m_webPage.pageScaleFactor());
     downcast<GraphicsLayerTextureMapper>(*m_rootLayer).layer().setTransform(m_scaleMatrix);
 }
 
@@ -291,17 +285,17 @@ void LayerTreeHostGtk::forceRepaint()
 void LayerTreeHostGtk::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const FloatRect& clipRect)
 {
     if (graphicsLayer == m_nonCompositedContentLayer.get())
-        m_webPage->drawRect(graphicsContext, enclosingIntRect(clipRect));
+        m_webPage.drawRect(graphicsContext, enclosingIntRect(clipRect));
 }
 
 float LayerTreeHostGtk::deviceScaleFactor() const
 {
-    return m_webPage->deviceScaleFactor();
+    return m_webPage.deviceScaleFactor();
 }
 
 float LayerTreeHostGtk::pageScaleFactor() const
 {
-    return m_webPage->pageScaleFactor();
+    return m_webPage.pageScaleFactor();
 }
 
 bool LayerTreeHostGtk::renderFrame()
@@ -312,11 +306,11 @@ bool LayerTreeHostGtk::renderFrame()
 
 bool LayerTreeHostGtk::flushPendingLayerChanges()
 {
-    bool viewportIsStable = m_webPage->corePage()->mainFrame().view()->viewportIsStable();
+    bool viewportIsStable = m_webPage.corePage()->mainFrame().view()->viewportIsStable();
     m_rootLayer->flushCompositingStateForThisLayerOnly(viewportIsStable);
     m_nonCompositedContentLayer->flushCompositingStateForThisLayerOnly(viewportIsStable);
 
-    if (!m_webPage->corePage()->mainFrame().view()->flushCompositingStateIncludingSubframes())
+    if (!m_webPage.corePage()->mainFrame().view()->flushCompositingStateIncludingSubframes())
         return false;
 
     if (m_viewOverlayRootLayer)
@@ -354,7 +348,7 @@ void LayerTreeHostGtk::flushAndRenderLayers()
 {
     {
         RefPtr<LayerTreeHostGtk> protect(this);
-        m_webPage->layoutIfNeeded();
+        m_webPage.layoutIfNeeded();
 
         if (!m_isValid)
             return;
@@ -371,7 +365,7 @@ void LayerTreeHostGtk::flushAndRenderLayers()
 
     if (m_notifyAfterScheduledLayerFlush) {
         // Let the drawing area know that we've done a flush of the layer changes.
-        static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
+        static_cast<DrawingAreaImpl*>(m_webPage.drawingArea())->layerHostDidFlushLayers();
         m_notifyAfterScheduledLayerFlush = false;
     }
 }
@@ -401,7 +395,7 @@ void LayerTreeHostGtk::setLayerFlushSchedulingEnabled(bool layerFlushingEnabled)
 
 void LayerTreeHostGtk::pageBackgroundTransparencyChanged()
 {
-    m_nonCompositedContentLayer->setContentsOpaque(m_webPage->drawsBackground());
+    m_nonCompositedContentLayer->setContentsOpaque(m_webPage.drawsBackground());
 }
 
 void LayerTreeHostGtk::cancelPendingLayerFlush()
index 11aea22..bbfb321 100644 (file)
@@ -41,16 +41,14 @@ namespace WebKit {
 
 class LayerTreeHostGtk final : public LayerTreeHost, WebCore::GraphicsLayerClient {
 public:
-    static PassRefPtr<LayerTreeHostGtk> create(WebPage*);
+    static Ref<LayerTreeHostGtk> create(WebPage&);
     virtual ~LayerTreeHostGtk();
 
-protected:
-    explicit LayerTreeHostGtk(WebPage*);
+private:
+    explicit LayerTreeHostGtk(WebPage&);
 
     WebCore::GraphicsLayer* rootLayer() const { return m_rootLayer.get(); }
 
-    void initialize();
-
     // LayerTreeHost
     void scheduleLayerFlush() override;
     void setLayerFlushSchedulingEnabled(bool layerFlushingEnabled) override;
@@ -64,8 +62,6 @@ protected:
 
     void setNativeSurfaceHandleForCompositing(uint64_t) override;
 
-private:
-
     class RenderFrameScheduler {
     public:
         RenderFrameScheduler(std::function<bool()>);