Title: [109748] trunk
Revision
109748
Author
noam.rosent...@nokia.com
Date
2012-03-05 07:52:16 -0800 (Mon, 05 Mar 2012)

Log Message

[Qt] [WK2] Support threaded renderer in WK2
https://bugs.webkit.org/show_bug.cgi?id=76661

Source/WebKit2:

Made the appropriate fixes in the UI process code to make rendering thread-safe.
- Separated the scenegraph node code to QtWebPageSGNode. QtWebPageSGNode has direct access
  to LayerTreeHostProxy.

- Each function in LayerTreeHostProxy can be either called from the main thread (handling
  messages from the web process), or from the renderer thread (handling the GL context).
  The render-queue is locked with a mutex, and messages back to the web process are sent
  via callOnMainThread.

- LayerTreeHostProxy is now ThreadSafeRefCounted. That is done to make sure that the GL
  resources it creates are only freed when the QtWebPageSGNode is deleted, which can be
  before or after the owning DrawingAreaProxy is deleted. This ensures that the class is
  deleted only after its GL resources are freed, otherwise those resources may leak.

Based on a patch by Viatcheslav Ostapenko.

Reviewed by Kenneth Rohde Christiansen.

* Target.pri: Added new files.
* UIProcess/API/qt/qquickwebpage.cpp: Moved QtWebPageSGNode out.
(QQuickWebPage::updatePaintNode): Call QtWebPageSGNode
(QQuickWebPagePrivate::updateSize): Call QtWebPageSGNode
(QQuickWebPagePrivate::didDeleteSGWebPageNode): Override QtWebPageSGNode::Client
(QQuickWebPagePrivate::~QQuickWebPagePrivate):
* UIProcess/API/qt/qquickwebpage_p_p.h:
(QQuickWebPagePrivate):
* UIProcess/DrawingAreaProxy.h:
(WebKit):
(WebKit::DrawingAreaProxy::layerTreeHostProxy): Made LayerTreeHostProxy ref-counted.
(DrawingAreaProxy):
* UIProcess/DrawingAreaProxyImpl.cpp:
(WebKit::DrawingAreaProxyImpl::DrawingAreaProxyImpl):
(WebKit::DrawingAreaProxyImpl::enterAcceleratedCompositingMode):
* UIProcess/LayerTreeHostProxy.h:
(WebKit):
(WebKit::LayerTreeHostProxy::create):
(LayerTreeHostProxy):
* UIProcess/qt/LayerTreeHostProxyQt.cpp:
(WebKit::LayerTreeHostProxy::paintToCurrentGLContext):
(WebKit):
(MainThreadGuardedInvoker):
    A class that allows invoking functions in the main thread, while guarding a ref-
    counted object.

(WebKit::MainThreadGuardedInvoker::call):
(WebKit::MainThreadGuardedInvoker::MainThreadGuardedInvoker):
(WebKit::MainThreadGuardedInvoker::invoke):
(WebKit::LayerTreeHostProxy::syncAnimations):
(WebKit::LayerTreeHostProxy::updateViewport):
(WebKit::LayerTreeHostProxy::detachDrawingArea):
(WebKit::LayerTreeHostProxy::syncLayerParameters):
(WebKit::LayerTreeHostProxy::setShouldRenderNextFrame):
(WebKit::LayerTreeHostProxy::flushLayerChanges):
(WebKit::LayerTreeHostProxy::ensureRootLayer):
(WebKit::LayerTreeHostProxy::syncRemoteContent):
(WebKit::LayerTreeHostProxy::dispatchUpdate):
(WebKit::LayerTreeHostProxy::createDirectlyCompositedImage):
(WebKit::LayerTreeHostProxy::purgeGLResources):
* UIProcess/qt/QtWebPageSGNode.cpp: Added.
* UIProcess/qt/QtWebPageSGNode.h: Added.

Tools:

Remove the QML_NO_THREADED_RENDERER environment variable from MiniBrowser.

Reviewed by Kenneth Rohde Christiansen.

* MiniBrowser/qt/main.cpp:
(main):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (109747 => 109748)


--- trunk/Source/WebKit2/ChangeLog	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Source/WebKit2/ChangeLog	2012-03-05 15:52:16 UTC (rev 109748)
@@ -1,3 +1,69 @@
+2012-03-05  No'am Rosenthal  <noam.rosent...@nokia.com>
+
+        [Qt] [WK2] Support threaded renderer in WK2
+        https://bugs.webkit.org/show_bug.cgi?id=76661
+
+        Made the appropriate fixes in the UI process code to make rendering thread-safe.
+        - Separated the scenegraph node code to QtWebPageSGNode. QtWebPageSGNode has direct access
+          to LayerTreeHostProxy.
+
+        - Each function in LayerTreeHostProxy can be either called from the main thread (handling
+          messages from the web process), or from the renderer thread (handling the GL context).
+          The render-queue is locked with a mutex, and messages back to the web process are sent
+          via callOnMainThread.
+
+        - LayerTreeHostProxy is now ThreadSafeRefCounted. That is done to make sure that the GL
+          resources it creates are only freed when the QtWebPageSGNode is deleted, which can be
+          before or after the owning DrawingAreaProxy is deleted. This ensures that the class is
+          deleted only after its GL resources are freed, otherwise those resources may leak.
+
+        Based on a patch by Viatcheslav Ostapenko.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * Target.pri: Added new files.
+        * UIProcess/API/qt/qquickwebpage.cpp: Moved QtWebPageSGNode out.
+        (QQuickWebPage::updatePaintNode): Call QtWebPageSGNode
+        (QQuickWebPagePrivate::updateSize): Call QtWebPageSGNode
+        (QQuickWebPagePrivate::didDeleteSGWebPageNode): Override QtWebPageSGNode::Client
+        (QQuickWebPagePrivate::~QQuickWebPagePrivate):
+        * UIProcess/API/qt/qquickwebpage_p_p.h:
+        (QQuickWebPagePrivate):
+        * UIProcess/DrawingAreaProxy.h:
+        (WebKit):
+        (WebKit::DrawingAreaProxy::layerTreeHostProxy): Made LayerTreeHostProxy ref-counted.
+        (DrawingAreaProxy):
+        * UIProcess/DrawingAreaProxyImpl.cpp:
+        (WebKit::DrawingAreaProxyImpl::DrawingAreaProxyImpl):
+        (WebKit::DrawingAreaProxyImpl::enterAcceleratedCompositingMode):
+        * UIProcess/LayerTreeHostProxy.h:
+        (WebKit):
+        (WebKit::LayerTreeHostProxy::create):
+        (LayerTreeHostProxy):
+        * UIProcess/qt/LayerTreeHostProxyQt.cpp:
+        (WebKit::LayerTreeHostProxy::paintToCurrentGLContext):
+        (WebKit):
+        (MainThreadGuardedInvoker):
+            A class that allows invoking functions in the main thread, while guarding a ref-
+            counted object.
+
+        (WebKit::MainThreadGuardedInvoker::call):
+        (WebKit::MainThreadGuardedInvoker::MainThreadGuardedInvoker):
+        (WebKit::MainThreadGuardedInvoker::invoke):
+        (WebKit::LayerTreeHostProxy::syncAnimations):
+        (WebKit::LayerTreeHostProxy::updateViewport):
+        (WebKit::LayerTreeHostProxy::detachDrawingArea):
+        (WebKit::LayerTreeHostProxy::syncLayerParameters):
+        (WebKit::LayerTreeHostProxy::setShouldRenderNextFrame):
+        (WebKit::LayerTreeHostProxy::flushLayerChanges):
+        (WebKit::LayerTreeHostProxy::ensureRootLayer):
+        (WebKit::LayerTreeHostProxy::syncRemoteContent):
+        (WebKit::LayerTreeHostProxy::dispatchUpdate):
+        (WebKit::LayerTreeHostProxy::createDirectlyCompositedImage):
+        (WebKit::LayerTreeHostProxy::purgeGLResources):
+        * UIProcess/qt/QtWebPageSGNode.cpp: Added.
+        * UIProcess/qt/QtWebPageSGNode.h: Added.
+
 2012-03-04  Raphael Kubo da Costa  <k...@profusion.mobi>
 
         [CMake] Libraries are installed to /usr/lib and not /usr/lib64 on x86_64

Modified: trunk/Source/WebKit2/Target.pri (109747 => 109748)


--- trunk/Source/WebKit2/Target.pri	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Source/WebKit2/Target.pri	2012-03-05 15:52:16 UTC (rev 109748)
@@ -261,6 +261,7 @@
     UIProcess/qt/QtGestureRecognizer.h \
     UIProcess/qt/QtPanGestureRecognizer.h \
     UIProcess/qt/QtPinchGestureRecognizer.h \
+    UIProcess/qt/QtWebPageSGNode.h \
     UIProcess/qt/QtTapGestureRecognizer.h \
     UIProcess/qt/QtWebError.h \
     UIProcess/qt/QtDialogRunner.h \
@@ -592,6 +593,7 @@
     UIProcess/qt/QtGestureRecognizer.cpp \
     UIProcess/qt/QtPanGestureRecognizer.cpp \
     UIProcess/qt/QtPinchGestureRecognizer.cpp \
+    UIProcess/qt/QtWebPageSGNode.cpp \
     UIProcess/qt/QtTapGestureRecognizer.cpp \
     UIProcess/qt/QtWebError.cpp \
     UIProcess/qt/QtDialogRunner.cpp \

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp (109747 => 109748)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp	2012-03-05 15:52:16 UTC (rev 109748)
@@ -23,13 +23,10 @@
 
 #include "LayerTreeHostProxy.h"
 #include "QtWebPageEventHandler.h"
+#include "QtWebPageSGNode.h"
 #include "TransformationMatrix.h"
 #include "qquickwebpage_p_p.h"
 #include "qquickwebview_p.h"
-#include <QtQuick/QQuickCanvas>
-#include <QtQuick/QSGGeometryNode>
-#include <QtQuick/QSGMaterial>
-#include <private/qsgrendernode_p.h>
 
 QQuickWebPage::QQuickWebPage(QQuickWebView* viewportItem)
     : QQuickItem(viewportItem)
@@ -77,51 +74,7 @@
         webPageProxy->drawingArea()->paintLayerTree(painter);
 }
 
-void QQuickWebPagePrivate::paintToCurrentGLContext(const QTransform& transform, float opacity)
-{
-    if (!q->isVisible())
-        return;
 
-    QRectF clipRect = viewportItem->mapRectToScene(viewportItem->boundingRect());
-
-    if (!clipRect.isValid())
-        return;
-
-    DrawingAreaProxy* drawingArea = webPageProxy->drawingArea();
-    if (!drawingArea)
-        return;
-
-    drawingArea->paintToCurrentGLContext(QTransform(transform).scale(contentsScale, contentsScale), opacity, clipRect);
-}
-
-struct PageProxyNode : public QSGRenderNode {
-    PageProxyNode(QQuickWebPagePrivate* page)
-        : m_pagePrivate(page)
-    {
-    }
-
-    virtual StateFlags changedStates()
-    {
-        return StateFlags(StencilState) | ColorState | BlendState;
-    }
-
-    virtual void render(const RenderState&)
-    {
-        if (!m_pagePrivate)
-            return;
-        QTransform transform = matrix() ? matrix()->toTransform() : QTransform();
-        m_pagePrivate->paintToCurrentGLContext(transform, inheritedOpacity());
-    }
-
-    ~PageProxyNode()
-    {
-        if (m_pagePrivate)
-            m_pagePrivate->resetPaintNode();
-    }
-
-    QQuickWebPagePrivate* m_pagePrivate;
-};
-
 QSGNode* QQuickWebPage::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*)
 {
     if (!(flags() & ItemHasContents)) {
@@ -130,13 +83,16 @@
         return 0;
     }
 
-    PageProxyNode* proxyNode = static_cast<PageProxyNode*>(oldNode);
-    if (!proxyNode) {
-        proxyNode = new PageProxyNode(d);
-        d->m_paintNode = proxyNode;
+    QtWebPageSGNode* sceneNode = static_cast<QtWebPageSGNode*>(oldNode);
+    if (sceneNode)
+        return sceneNode;
+    sceneNode = new QtWebPageSGNode(d->webPageProxy->drawingArea()->layerTreeHostProxy(), d);
+    {
+        MutexLocker lock(d->m_paintNodeMutex);
+        d->m_paintNode = sceneNode;
     }
-
-    return proxyNode;
+    d->updateSize();
+    return sceneNode;
 }
 
 QtWebPageEventHandler* QQuickWebPage::eventHandler() const
@@ -188,20 +144,23 @@
     QSizeF scaledSize = contentsSize * contentsScale;
     q->setSize(scaledSize);
     viewportItem->updateContentsSize(scaledSize);
+    QRectF clipRect = viewportItem->mapRectToScene(viewportItem->boundingRect());
+
+    MutexLocker lock(m_paintNodeMutex);
+    if (!m_paintNode)
+        return;
+    m_paintNode->setClipRect(clipRect);
+    m_paintNode->setContentsScale(contentsScale);
 }
 
-void QQuickWebPagePrivate::resetPaintNode()
+void QQuickWebPagePrivate::willDeleteScenegraphNode()
 {
+    MutexLocker lock(m_paintNodeMutex);
     m_paintNode = 0;
-    DrawingAreaProxy* drawingArea = webPageProxy->drawingArea();
-    if (drawingArea && drawingArea->layerTreeHostProxy())
-        drawingArea->layerTreeHostProxy()->purgeGLResources();
 }
 
 QQuickWebPagePrivate::~QQuickWebPagePrivate()
 {
-    if (m_paintNode)
-        static_cast<PageProxyNode*>(m_paintNode)->m_pagePrivate = 0;
 }
 
 #include "moc_qquickwebpage_p.cpp"

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h (109747 => 109748)


--- trunk/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h	2012-03-05 15:52:16 UTC (rev 109748)
@@ -21,6 +21,7 @@
 #ifndef qquickwebpage_p_p_h
 #define qquickwebpage_p_p_h
 
+#include "QtWebPageSGNode.h"
 #include "qquickwebpage_p.h"
 #include <QTransform>
 
@@ -31,17 +32,16 @@
 
 class QtWebPageEventHandler;
 
-class QQuickWebPagePrivate {
+class QQuickWebPagePrivate : public QtWebPageSGNode::Client {
 public:
     QQuickWebPagePrivate(QQuickWebPage* q, QQuickWebView* viewportItem);
     ~QQuickWebPagePrivate();
+    virtual void willDeleteScenegraphNode();
 
     void initialize(WebKit::WebPageProxy*);
     void setDrawingAreaSize(const QSize&);
 
     void updateSize();
-
-    void paintToCurrentGLContext(const QTransform&, float opacity);
     void paint(QPainter*);
     void resetPaintNode();
 
@@ -50,7 +50,8 @@
     QQuickWebView* const viewportItem;
     WebKit::WebPageProxy* webPageProxy;
     bool paintingIsInitialized;
-    QSGNode* m_paintNode;
+    QtWebPageSGNode* m_paintNode;
+    Mutex m_paintNodeMutex;
 
     QSizeF contentsSize;
     qreal contentsScale;

Modified: trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h (109747 => 109748)


--- trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Source/WebKit2/UIProcess/DrawingAreaProxy.h	2012-03-05 15:52:16 UTC (rev 109748)
@@ -29,6 +29,7 @@
 
 #include "BackingStore.h"
 #include "DrawingAreaInfo.h"
+#include "LayerTreeHostProxy.h"
 #include <WebCore/IntRect.h>
 #include <WebCore/IntSize.h>
 #include <stdint.h>
@@ -54,7 +55,6 @@
 namespace WebKit {
 
 class LayerTreeContext;
-class LayerTreeHostProxy;
 class UpdateInfo;
 class WebLayerTreeInfo;
 class WebLayerUpdateInfo;
@@ -90,7 +90,7 @@
     virtual bool isBackingStoreReady() const { return true; }
     virtual void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&) { }
     virtual void paintLayerTree(BackingStore::PlatformGraphicsContext) { }
-    LayerTreeHostProxy* layerTreeHostProxy() const { return m_layerTreeHostProxy.get(); }
+    PassRefPtr<LayerTreeHostProxy> layerTreeHostProxy() const { return m_layerTreeHostProxy; }
     virtual void setVisibleContentsRectForScaling(const WebCore::IntRect& visibleContentsRect, float scale) { }
     virtual void setVisibleContentsRectForPanning(const WebCore::IntRect& visibleContentsRect, const WebCore::FloatPoint& trajectoryVector) { }
     virtual void createTileForLayer(int layerID, int tileID, const WebKit::UpdateInfo&) { }
@@ -110,7 +110,7 @@
     WebCore::IntSize m_scrollOffset;
 
 #if USE(UI_SIDE_COMPOSITING)
-    OwnPtr<LayerTreeHostProxy> m_layerTreeHostProxy;
+    RefPtr<LayerTreeHostProxy> m_layerTreeHostProxy;
 #endif
 
 private:

Modified: trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp (109747 => 109748)


--- trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Source/WebKit2/UIProcess/DrawingAreaProxyImpl.cpp	2012-03-05 15:52:16 UTC (rev 109748)
@@ -61,7 +61,7 @@
 #if USE(UI_SIDE_COMPOSITING)
     // Construct the proxy early to allow messages to be sent to the web process while AC is entered there.
     if (webPageProxy->pageGroup()->preferences()->forceCompositingMode())
-        m_layerTreeHostProxy = adoptPtr(new LayerTreeHostProxy(this));
+        m_layerTreeHostProxy = LayerTreeHostProxy::create(this);
 #endif
 }
 
@@ -337,7 +337,7 @@
     m_webPageProxy->enterAcceleratedCompositingMode(layerTreeContext);
 #if USE(UI_SIDE_COMPOSITING)
     if (!m_layerTreeHostProxy)
-        m_layerTreeHostProxy = adoptPtr(new LayerTreeHostProxy(this));
+        m_layerTreeHostProxy = LayerTreeHostProxy::create(this);
 #endif
 }
 

Modified: trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h (109747 => 109748)


--- trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Source/WebKit2/UIProcess/LayerTreeHostProxy.h	2012-03-05 15:52:16 UTC (rev 109748)
@@ -23,7 +23,7 @@
 #if USE(UI_SIDE_COMPOSITING)
 
 #include "BackingStore.h"
-#include "DrawingAreaProxy.h"
+#include "Connection.h"
 #include "Region.h"
 #include "TextureMapper.h"
 #include "TextureMapperBackingStore.h"
@@ -36,17 +36,17 @@
 #include <WebCore/Timer.h>
 #include <wtf/Functional.h>
 #include <wtf/HashSet.h>
+#include <wtf/ThreadingPrimitives.h>
 
-
 namespace WebKit {
 
+class DrawingAreaProxy;
 class LayerBackingStore;
 class WebLayerInfo;
 class WebLayerUpdateInfo;
 
-class LayerTreeHostProxy : public WebCore::GraphicsLayerClient {
+class LayerTreeHostProxy : public ThreadSafeRefCounted<LayerTreeHostProxy>, public WebCore::GraphicsLayerClient {
 public:
-    LayerTreeHostProxy(DrawingAreaProxy*);
     virtual ~LayerTreeHostProxy();
     void syncCompositingLayerState(const WebLayerInfo&);
     void deleteCompositingLayer(WebLayerID);
@@ -68,6 +68,8 @@
     void didReceiveLayerTreeHostProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     void updateViewport();
 
+    static PassRefPtr<LayerTreeHostProxy> create(DrawingAreaProxy* drawingArea) { return adoptRef(new LayerTreeHostProxy(drawingArea)); }
+
 protected:
     PassOwnPtr<WebCore::GraphicsLayer> createLayer(WebLayerID);
 
@@ -88,7 +90,10 @@
     float m_contentsScale;
 
     Vector<Function<void()> > m_renderQueue;
+    WTF::Mutex m_renderQueueMutex;
     void dispatchUpdate(const Function<void()>&);
+    void detachDrawingArea();
+    void setShouldRenderNextFrame();
 
 #if USE(TEXTURE_MAPPER)
     OwnPtr<WebCore::TextureMapper> m_textureMapper;
@@ -113,13 +118,14 @@
     void ensureLayer(WebLayerID);
     void swapBuffers();
     void syncAnimations();
+    void updateViewportOnMainThread();
+    LayerTreeHostProxy(DrawingAreaProxy*);
 
     OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
     Vector<WebLayerID> m_layersToDelete;
 
     LayerMap m_layers;
     WebLayerID m_rootLayerID;
-    int m_id;
 };
 
 }

Modified: trunk/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp (109747 => 109748)


--- trunk/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp	2012-03-05 15:52:16 UTC (rev 109748)
@@ -95,6 +95,32 @@
     syncAnimations();
 }
 
+template<class T>
+class MainThreadGuardedInvoker {
+public:
+    static void call(PassRefPtr<T> objectToGuard, const Function<void()>& function)
+    {
+        MainThreadGuardedInvoker<T>* invoker = new MainThreadGuardedInvoker<T>(objectToGuard, function);
+        callOnMainThread(invoke, invoker);
+    }
+
+private:
+    MainThreadGuardedInvoker(PassRefPtr<T> object, const Function<void()>& newFunction)
+        : objectToGuard(object)
+        , function(newFunction)
+    {
+    }
+
+    RefPtr<T> objectToGuard;
+    Function<void()> function;
+    static void invoke(void* data)
+    {
+        MainThreadGuardedInvoker<T>* invoker = static_cast<MainThreadGuardedInvoker<T>*>(data);
+        invoker->function();
+        delete invoker;
+    }
+};
+
 void LayerTreeHostProxy::syncAnimations()
 {
     TextureMapperLayer* layer = toTextureMapperLayer(rootLayer());
@@ -102,7 +128,7 @@
 
     layer->syncAnimationsRecursively();
     if (layer->descendantsOrSelfHaveRunningAnimations())
-        updateViewport();
+        MainThreadGuardedInvoker<LayerTreeHostProxy>::call(this, bind(&LayerTreeHostProxy::updateViewport, this));
 }
 
 void LayerTreeHostProxy::paintToGraphicsContext(QPainter* painter)
@@ -127,9 +153,15 @@
 
 void LayerTreeHostProxy::updateViewport()
 {
-    m_drawingAreaProxy->updateViewport();
+    if (m_drawingAreaProxy)
+        m_drawingAreaProxy->updateViewport();
 }
 
+void LayerTreeHostProxy::detachDrawingArea()
+{
+    m_drawingAreaProxy = 0;
+}
+
 void LayerTreeHostProxy::syncLayerParameters(const WebLayerInfo& layerInfo)
 {
     WebLayerID id = layerInfo.id;
@@ -185,11 +217,14 @@
         case WebKit::WebLayerAnimation::RemoveAnimation:
             layer->removeAnimation(anim.name);
             break;
-        case WebKit::WebLayerAnimation::PauseAnimation:
+        case WebKit::WebLayerAnimation::PauseAnimation: {
             double offset = WTF::currentTime() - anim.startTime;
             layer->pauseAnimation(anim.name, offset);
             break;
         }
+        default:
+            break;
+        }
     }
 
     if (layerInfo.isRootLayer && m_rootLayerID != id)
@@ -295,13 +330,17 @@
     m_backingStoresWithPendingBuffers.clear();
 }
 
+void LayerTreeHostProxy::setShouldRenderNextFrame()
+{
+    // The pending tiles state is on its way to the screen, tell the web process to render the next one.
+    m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
+}
+
 void LayerTreeHostProxy::flushLayerChanges()
 {
     m_rootLayer->syncCompositingState(FloatRect());
     swapBuffers();
-
-    // The pending tiles state is on its way for the screen, tell the web process to render the next one.
-    m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
+    MainThreadGuardedInvoker<LayerTreeHostProxy>::call(this, bind(&LayerTreeHostProxy::setShouldRenderNextFrame, this));
 }
 
 void LayerTreeHostProxy::ensureRootLayer()
@@ -315,14 +354,13 @@
 
     // The root layer should not have zero size, or it would be optimized out.
     m_rootLayer->setSize(FloatSize(1.0, 1.0));
-    if (!m_textureMapper)
-        m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode);
     toTextureMapperLayer(m_rootLayer.get())->setTextureMapper(m_textureMapper.get());
 }
 
 void LayerTreeHostProxy::syncRemoteContent()
 {
     // We enqueue messages and execute them during paint, as they require an active GL context.
+    MutexLocker locker(m_renderQueueMutex);
     ensureRootLayer();
 
     for (size_t i = 0; i < m_renderQueue.size(); ++i)
@@ -333,6 +371,7 @@
 
 void LayerTreeHostProxy::dispatchUpdate(const Function<void()>& function)
 {
+    MutexLocker locker(m_renderQueueMutex);
     m_renderQueue.append(function);
     updateViewport();
 }
@@ -357,7 +396,6 @@
     dispatchUpdate(bind(&LayerTreeHostProxy::removeTile, this, layerID, tileID));
 }
 
-
 void LayerTreeHostProxy::deleteCompositingLayer(WebLayerID id)
 {
     dispatchUpdate(bind(&LayerTreeHostProxy::deleteLayer, this, id));
@@ -380,6 +418,7 @@
 
 void LayerTreeHostProxy::createDirectlyCompositedImage(int64_t key, const WebKit::ShareableBitmap::Handle& handle)
 {
+    // Even though ShareableBitmap is not ThreadSafeRefCounted, we can safely move it to the renderer thread as the main thread will not touch it anymore.
     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
     dispatchUpdate(bind(&LayerTreeHostProxy::createImage, this, key, bitmap));
 }
@@ -403,6 +442,8 @@
 
 void LayerTreeHostProxy::purgeGLResources()
 {
+    MutexLocker locker(m_renderQueueMutex);
+    m_renderQueue.clear();
     TextureMapperLayer* layer = toTextureMapperLayer(rootLayer());
 
     if (layer)

Added: trunk/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.cpp (0 => 109748)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.cpp	2012-03-05 15:52:16 UTC (rev 109748)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "QtWebPageSGNode.h"
+
+namespace WebKit {
+
+QtWebPageSGNode::QtWebPageSGNode(PassRefPtr<LayerTreeHostProxy> layerTreeHost, Client* client)
+    : m_layerTreeHost(layerTreeHost)
+    , m_client(client)
+    , m_contentsScale(1)
+{
+}
+
+QSGRenderNode::StateFlags QtWebPageSGNode::changedStates()
+{
+    return StateFlags(StencilState) | ColorState | BlendState;
+}
+
+void QtWebPageSGNode::render(const RenderState& state)
+{
+    QTransform transform = matrix() ? matrix()->toTransform() : QTransform();
+    float scale = contentsScale();
+    m_layerTreeHost->paintToCurrentGLContext(QTransform(transform).scale(scale, scale), inheritedOpacity(), clipRect());
+}
+
+void QtWebPageSGNode::setContentsScale(float scale)
+{
+    MutexLocker lock(m_mutex);
+    m_contentsScale = scale;
+}
+
+float QtWebPageSGNode::contentsScale()
+{
+    MutexLocker lock(m_mutex);
+    return m_contentsScale;
+}
+
+void QtWebPageSGNode::setClipRect(const QRectF& rect)
+{
+    MutexLocker lock(m_mutex);
+    m_clipRect = rect;
+}
+
+QRectF QtWebPageSGNode::clipRect()
+{
+    MutexLocker lock(m_mutex);
+    return m_clipRect;
+}
+
+QtWebPageSGNode::~QtWebPageSGNode()
+{
+    if (m_layerTreeHost)
+        m_layerTreeHost->purgeGLResources();
+
+    if (m_client)
+        m_client->willDeleteScenegraphNode();
+}
+
+}

Added: trunk/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.h (0 => 109748)


--- trunk/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/QtWebPageSGNode.h	2012-03-05 15:52:16 UTC (rev 109748)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef QtWebPageSGNode_h
+#define QtWebPageSGNode_h
+
+#include "LayerTreeHostProxy.h"
+#include <private/qsgrendernode_p.h>
+
+namespace WebKit {
+
+struct QtWebPageSGNode : public QSGRenderNode {
+public:
+    struct Client {
+        virtual void willDeleteScenegraphNode() { }
+    };
+
+    QtWebPageSGNode(PassRefPtr<LayerTreeHostProxy>, Client*);
+    ~QtWebPageSGNode();
+    virtual StateFlags changedStates();
+    virtual void render(const RenderState&);
+    void setContentsScale(float);
+    float contentsScale();
+    void setClipRect(const QRectF&);
+    QRectF clipRect();
+
+private:
+    RefPtr<LayerTreeHostProxy> m_layerTreeHost;
+    Client* m_client;
+    float m_contentsScale;
+    QRectF m_clipRect;
+    Mutex m_mutex;
+};
+
+}
+#endif /* QtWebPageSGNode_h */

Modified: trunk/Tools/ChangeLog (109747 => 109748)


--- trunk/Tools/ChangeLog	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Tools/ChangeLog	2012-03-05 15:52:16 UTC (rev 109748)
@@ -1,3 +1,15 @@
+2012-03-05  No'am Rosenthal  <noam.rosent...@nokia.com>
+
+        [Qt] [WK2] Support threaded renderer in WK2
+        https://bugs.webkit.org/show_bug.cgi?id=76661
+
+        Remove the QML_NO_THREADED_RENDERER environment variable from MiniBrowser.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * MiniBrowser/qt/main.cpp:
+        (main):
+
 2012-03-05  Alexander Færøy  <alexander.fae...@nokia.com>
 
         Unreviewed. Add myself to committer list.

Modified: trunk/Tools/MiniBrowser/qt/main.cpp (109747 => 109748)


--- trunk/Tools/MiniBrowser/qt/main.cpp	2012-03-05 15:37:19 UTC (rev 109747)
+++ trunk/Tools/MiniBrowser/qt/main.cpp	2012-03-05 15:52:16 UTC (rev 109748)
@@ -39,9 +39,6 @@
 
 int main(int argc, char** argv)
 {
-    // FIXME: We must add support for the threaded rendering as it is the default.
-    qputenv("QML_NO_THREADED_RENDERER", QByteArray("1"));
-
     MiniBrowserApplication app(argc, argv);
 
     if (app.isRobotized()) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to