Title: [92376] trunk/Source/WebKit2
Revision
92376
Author
[email protected]
Date
2011-08-04 08:41:49 -0700 (Thu, 04 Aug 2011)

Log Message

[Qt][WK2] Create scene graph nodes for tiles in QTouchWebView instead of using imperative painting.
https://bugs.webkit.org/show_bug.cgi?id=65528

Reviewed by Benjamin Poulain.

Converts QTouchWebPage from QSGPaintedItem to a straight QSGItem.
- A SGTileNode is created and added to the scene graph for each tile,
  positioning them relatively to the page.
  It's basically a QSGSimpleTextureNode with support for specifying a
  source rect plus for owning the QSGTexture for proper destruction on
  shutdown by the rendering thread.
- Scale nodes are used as parent of tile nodes to revert the scaling set on the
  QTouchWebPage and allow us to keep using integer coordinates.
- The SGAgent class is introduced to carry scene graph update request up to the
  updatePaintNode call of the item, which may be on the scene graph rendering thread.

* UIProcess/API/qt/qtouchwebpage.cpp:
(QTouchWebPage::QTouchWebPage):
(QTouchWebPage::updatePaintNode):
Delegate scene graph updates to the SGAgent which received update requests from the tiled drawing area.
(QTouchWebPage::event):
(QTouchWebPage::geometryChanged):
(QTouchWebPagePrivate::QTouchWebPagePrivate):
* UIProcess/API/qt/qtouchwebpage.h:
* UIProcess/API/qt/qtouchwebpage_p.h:
* UIProcess/TiledDrawingAreaProxy.cpp:
Manage the scale node in the TileSet, it will be the parent node of Tile nodes.
(WebKit::TiledDrawingAreaTileSet::sgNodeID):
(WebKit::TiledDrawingAreaTileSet::TiledDrawingAreaTileSet):
(WebKit::TiledDrawingAreaTileSet::~TiledDrawingAreaTileSet):
(WebKit::TiledDrawingAreaProxy::TiledDrawingAreaProxy):
(WebKit::TiledDrawingAreaProxy::setContentsScale):
(WebKit::TiledDrawingAreaProxy::createTiles):
(WebKit::TiledDrawingAreaProxy::removeAllTiles):
* UIProcess/TiledDrawingAreaTile.h:
(WebKit::TiledDrawingAreaTile::create):
* UIProcess/qt/SGAgent.cpp: Added.
* UIProcess/qt/SGAgent.h: Added.
* UIProcess/qt/SGTileNode.cpp: Added.
* UIProcess/qt/SGTileNode.h: Added.
* UIProcess/qt/TiledDrawingAreaProxyQt.cpp:
Disable the paint call and update the scene graph on incorporateUpdate through the SGAgent.
(WebKit::TiledDrawingAreaProxy::updateWebView):
* UIProcess/qt/TiledDrawingAreaTileQt.cpp:
(WebKit::TiledDrawingAreaTile::TiledDrawingAreaTile):
(WebKit::TiledDrawingAreaTile::~TiledDrawingAreaTile):
(WebKit::TiledDrawingAreaTile::isReadyToPaint):
(WebKit::TiledDrawingAreaTile::swapBackBufferToFront):
(WebKit::TiledDrawingAreaTile::paint):
(WebKit::TiledDrawingAreaTile::incorporateUpdate):
(WebKit::TiledDrawingAreaTile::disableUpdates):
(WebKit::TiledDrawingAreaTile::setParentNodeID):
* UIProcess/qt/TouchViewInterface.cpp:
(WebKit::TouchViewInterface::sceneGraphAgent):
(WebKit::TouchViewInterface::setViewNeedsDisplay):
* UIProcess/qt/TouchViewInterface.h:
* WebKit2.pro:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (92375 => 92376)


--- trunk/Source/WebKit2/ChangeLog	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/ChangeLog	2011-08-04 15:41:49 UTC (rev 92376)
@@ -1,3 +1,63 @@
+2011-08-02  Jocelyn Turcotte  <[email protected]>
+
+        [Qt][WK2] Create scene graph nodes for tiles in QTouchWebView instead of using imperative painting.
+        https://bugs.webkit.org/show_bug.cgi?id=65528
+
+        Reviewed by Benjamin Poulain.
+
+        Converts QTouchWebPage from QSGPaintedItem to a straight QSGItem.
+        - A SGTileNode is created and added to the scene graph for each tile,
+          positioning them relatively to the page.
+          It's basically a QSGSimpleTextureNode with support for specifying a
+          source rect plus for owning the QSGTexture for proper destruction on
+          shutdown by the rendering thread.
+        - Scale nodes are used as parent of tile nodes to revert the scaling set on the
+          QTouchWebPage and allow us to keep using integer coordinates.
+        - The SGAgent class is introduced to carry scene graph update request up to the
+          updatePaintNode call of the item, which may be on the scene graph rendering thread.
+
+        * UIProcess/API/qt/qtouchwebpage.cpp:
+        (QTouchWebPage::QTouchWebPage):
+        (QTouchWebPage::updatePaintNode):
+        Delegate scene graph updates to the SGAgent which received update requests from the tiled drawing area.
+        (QTouchWebPage::event):
+        (QTouchWebPage::geometryChanged):
+        (QTouchWebPagePrivate::QTouchWebPagePrivate):
+        * UIProcess/API/qt/qtouchwebpage.h:
+        * UIProcess/API/qt/qtouchwebpage_p.h:
+        * UIProcess/TiledDrawingAreaProxy.cpp:
+        Manage the scale node in the TileSet, it will be the parent node of Tile nodes.
+        (WebKit::TiledDrawingAreaTileSet::sgNodeID):
+        (WebKit::TiledDrawingAreaTileSet::TiledDrawingAreaTileSet):
+        (WebKit::TiledDrawingAreaTileSet::~TiledDrawingAreaTileSet):
+        (WebKit::TiledDrawingAreaProxy::TiledDrawingAreaProxy):
+        (WebKit::TiledDrawingAreaProxy::setContentsScale):
+        (WebKit::TiledDrawingAreaProxy::createTiles):
+        (WebKit::TiledDrawingAreaProxy::removeAllTiles):
+        * UIProcess/TiledDrawingAreaTile.h:
+        (WebKit::TiledDrawingAreaTile::create):
+        * UIProcess/qt/SGAgent.cpp: Added.
+        * UIProcess/qt/SGAgent.h: Added.
+        * UIProcess/qt/SGTileNode.cpp: Added.
+        * UIProcess/qt/SGTileNode.h: Added.
+        * UIProcess/qt/TiledDrawingAreaProxyQt.cpp:
+        Disable the paint call and update the scene graph on incorporateUpdate through the SGAgent.
+        (WebKit::TiledDrawingAreaProxy::updateWebView):
+        * UIProcess/qt/TiledDrawingAreaTileQt.cpp:
+        (WebKit::TiledDrawingAreaTile::TiledDrawingAreaTile):
+        (WebKit::TiledDrawingAreaTile::~TiledDrawingAreaTile):
+        (WebKit::TiledDrawingAreaTile::isReadyToPaint):
+        (WebKit::TiledDrawingAreaTile::swapBackBufferToFront):
+        (WebKit::TiledDrawingAreaTile::paint):
+        (WebKit::TiledDrawingAreaTile::incorporateUpdate):
+        (WebKit::TiledDrawingAreaTile::disableUpdates):
+        (WebKit::TiledDrawingAreaTile::setParentNodeID):
+        * UIProcess/qt/TouchViewInterface.cpp:
+        (WebKit::TouchViewInterface::sceneGraphAgent):
+        (WebKit::TouchViewInterface::setViewNeedsDisplay):
+        * UIProcess/qt/TouchViewInterface.h:
+        * WebKit2.pro:
+
 2011-08-04  Alexis Menard  <[email protected]>
 
         [Qt] Make navigation actions properly usable in QML.

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage.cpp (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage.cpp	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage.cpp	2011-08-04 15:41:49 UTC (rev 92376)
@@ -21,18 +21,19 @@
 #include "config.h"
 #include "qtouchwebpage.h"
 #include "qtouchwebpage_p.h"
+
 #include "qtouchwebpageproxy.h"
-
 #include <QApplication>
 #include <QGraphicsSceneMouseEvent>
 #include <QPainter>
+#include <QSGNode>
 #include <QUrl>
-#include <QtDebug>
 
 QTouchWebPage::QTouchWebPage(QSGItem* parent)
-    : QSGPaintedItem(parent)
+    : QSGItem(parent)
     , d(new QTouchWebPagePrivate(this))
 {
+    setFlag(ItemHasContents);
 }
 
 QTouchWebPage::~QTouchWebPage()
@@ -40,11 +41,6 @@
     delete d;
 }
 
-void QTouchWebPage::paint(QPainter* painter)
-{
-    d->page->paint(painter, boundingRect().toAlignedRect());
-}
-
 void QTouchWebPage::load(const QUrl& url)
 {
     d->page->load(url);
@@ -67,6 +63,18 @@
 
 /*! \reimp
 */
+QSGNode* QTouchWebPage::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*)
+{
+    if (!oldNode)
+        oldNode = new QSGNode;
+    d->sgAgent.updatePaintNode(oldNode);
+
+    // QSGItem takes ownership of this return value and it's children between and after updatePaintNode calls.
+    return oldNode;
+}
+
+/*! \reimp
+*/
 bool QTouchWebPage::event(QEvent* ev)
 {
     switch (ev->type()) {
@@ -82,7 +90,7 @@
 
     if (d->page->handleEvent(ev))
         return true;
-    return QSGPaintedItem::event(ev);
+    return QSGItem::event(ev);
 }
 
 void QTouchWebPage::keyPressEvent(QKeyEvent* event)
@@ -117,7 +125,7 @@
 
 void QTouchWebPage::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry)
 {
-    QSGPaintedItem::geometryChanged(newGeometry, oldGeometry);
+    QSGItem::geometryChanged(newGeometry, oldGeometry);
     if (newGeometry.size() != oldGeometry.size())
         d->page->setDrawingAreaSize(newGeometry.size().toSize());
 }
@@ -133,6 +141,7 @@
     : q(view)
     , page(0)
     , navigationController(0)
+    , sgAgent(view)
 {
 }
 

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage.h (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage.h	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage.h	2011-08-04 15:41:49 UTC (rev 92376)
@@ -24,7 +24,7 @@
 #include "qwebkitglobal.h"
 #include "qwebkittypes.h"
 
-#include <QtDeclarative/qsgpainteditem.h>
+#include <QtDeclarative/qsgitem.h>
 #include <QSharedPointer>
 
 class QTouchWebPagePrivate;
@@ -36,7 +36,7 @@
     class TouchViewInterface;
 }
 
-class QWEBKIT_EXPORT QTouchWebPage : public QSGPaintedItem {
+class QWEBKIT_EXPORT QTouchWebPage : public QSGItem {
     Q_OBJECT
     Q_PROPERTY(QString title READ title NOTIFY titleChanged)
     Q_PROPERTY(QUrl url READ url NOTIFY urlChanged)
@@ -56,7 +56,7 @@
 
     QWebNavigationController* navigationController() const;
 
-    virtual void paint(QPainter*);
+    virtual QSGNode* updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData*);
     virtual bool event(QEvent*);
 
 Q_SIGNALS:

Modified: trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage_p.h (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage_p.h	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage_p.h	2011-08-04 15:41:49 UTC (rev 92376)
@@ -21,11 +21,13 @@
 #ifndef qtouchwebpage_p_h
 #define qtouchwebpage_p_h
 
-#include <QMenu>
+#include "SGAgent.h"
 #include "qtouchwebpage.h"
 #include "qwebnavigationcontroller.h"
+#include <QMenu>
 
 class QRectF;
+class QSGNode;
 class QString;
 class QTouchWebPage;
 class QTouchWebPageProxy;
@@ -44,6 +46,7 @@
     QTouchWebPage* const q;
     QTouchWebPageProxy* page;
     QWebNavigationController* navigationController;
+    WebKit::SGAgent sgAgent;
 };
 
 #endif /* qtouchwebpage_p_h */

Modified: trunk/Source/WebKit2/UIProcess/TiledDrawingAreaProxy.cpp (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/TiledDrawingAreaProxy.cpp	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/TiledDrawingAreaProxy.cpp	2011-08-04 15:41:49 UTC (rev 92376)
@@ -35,6 +35,11 @@
 #include "WebPageProxy.h"
 #include "WebProcessProxy.h"
 
+#if PLATFORM(QT)
+#include "SGAgent.h"
+#include "TouchViewInterface.h"
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -48,24 +53,45 @@
 public:
     typedef HashMap<TiledDrawingAreaTile::Coordinate, RefPtr<TiledDrawingAreaTile> > TileMap;
 
-    TiledDrawingAreaTileSet(float contentsScale = 1.0f);
+    TiledDrawingAreaTileSet(PlatformWebView*, float contentsScale = 1.0f);
+    ~TiledDrawingAreaTileSet();
 
     WebCore::IntRect mapToContents(const WebCore::IntRect&) const;
     WebCore::IntRect mapFromContents(const WebCore::IntRect&) const;
 
     TileMap& tiles() { return m_tiles; }
     float contentsScale() const { return m_contentsScale; }
+#if PLATFORM(QT)
+    int sgNodeID() const { return m_sgNodeID; }
+#endif
 
 private:
     TileMap m_tiles;
     float m_contentsScale;
+#if PLATFORM(QT)
+    SGAgent* m_sgAgent;
+    int m_sgNodeID;
+#endif
 };
 
-TiledDrawingAreaTileSet::TiledDrawingAreaTileSet(float contentsScale)
+TiledDrawingAreaTileSet::TiledDrawingAreaTileSet(PlatformWebView* webView, float contentsScale)
     : m_contentsScale(contentsScale)
+#if PLATFORM(QT)
+    , m_sgAgent(webView->sceneGraphAgent())
+    , m_sgNodeID(m_sgAgent->createScaleNode(0, 1 / contentsScale))
+#endif
 {
 }
 
+TiledDrawingAreaTileSet::~TiledDrawingAreaTileSet()
+{
+#if PLATFORM(QT)
+    // Forcing the tiles destruction to remove their sg node before removing their parent node.
+    m_tiles.clear();
+    m_sgAgent->removeNode(m_sgNodeID);
+#endif
+}
+
 IntRect TiledDrawingAreaTileSet::mapToContents(const IntRect& rect) const
 {
     return enclosingIntRect(FloatRect(rect.x() / m_contentsScale,
@@ -99,7 +125,7 @@
     , m_isWaitingForDidSetFrameNotification(false)
     , m_isVisible(true)
     , m_webView(webView)
-    , m_currentTileSet(adoptPtr(new TiledDrawingAreaTileSet))
+    , m_currentTileSet(adoptPtr(new TiledDrawingAreaTileSet(webView)))
     , m_tileBufferUpdateTimer(RunLoop::main(), this, &TiledDrawingAreaProxy::tileBufferUpdateTimerFired)
     , m_tileCreationTimer(RunLoop::main(), this, &TiledDrawingAreaProxy::tileCreationTimerFired)
     , m_tileSize(defaultTileWidth, defaultTileHeight)
@@ -408,7 +434,7 @@
         m_previousTileSet = m_currentTileSet.release();
         disableTileSetUpdates(m_previousTileSet.get());
     }
-    m_currentTileSet = adoptPtr(new TiledDrawingAreaTileSet(scale));
+    m_currentTileSet = adoptPtr(new TiledDrawingAreaTileSet(m_webView, scale));
     createTiles();
 }
 
@@ -496,7 +522,11 @@
     unsigned tilesToCreateCount = tilesToCreate.size();
     for (unsigned n = 0; n < tilesToCreateCount; ++n) {
         TiledDrawingAreaTile::Coordinate coordinate = tilesToCreate[n];
-        RefPtr<TiledDrawingAreaTile> tile = TiledDrawingAreaTile::create(this, coordinate);
+        RefPtr<TiledDrawingAreaTile> tile = TiledDrawingAreaTile::create(this, m_webView, coordinate);
+#if PLATFORM(QT)
+        ASSERT(m_currentTileSet->sgNodeID());
+        tile->setParentNodeID(m_currentTileSet->sgNodeID());
+#endif
         m_currentTileSet->tiles().set(coordinate, tile);
     }
 
@@ -561,7 +591,7 @@
 
 void TiledDrawingAreaProxy::removeAllTiles()
 {
-    m_currentTileSet = adoptPtr(new TiledDrawingAreaTileSet(m_currentTileSet->contentsScale()));
+    m_currentTileSet = adoptPtr(new TiledDrawingAreaTileSet(m_webView, m_currentTileSet->contentsScale()));
 }
 
 

Modified: trunk/Source/WebKit2/UIProcess/TiledDrawingAreaTile.h (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/TiledDrawingAreaTile.h	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/TiledDrawingAreaTile.h	2011-08-04 15:41:49 UTC (rev 92376)
@@ -43,11 +43,22 @@
 class TiledDrawingAreaProxy;
 class UpdateInfo;
 
+#if PLATFORM(MAC)
+typedef WKView PlatformWebView;
+#elif PLATFORM(WIN)
+class WebView;
+typedef WebView PlatformWebView;
+#elif PLATFORM(QT)
+class SGAgent;
+class TouchViewInterface;
+typedef TouchViewInterface PlatformWebView;
+#endif
+
 class TiledDrawingAreaTile : public RefCounted<TiledDrawingAreaTile> {
 public:
     typedef WebCore::IntPoint Coordinate;
 
-    static PassRefPtr<TiledDrawingAreaTile> create(TiledDrawingAreaProxy* proxy, const Coordinate& tileCoordinate) { return adoptRef(new TiledDrawingAreaTile(proxy, tileCoordinate)); }
+    static PassRefPtr<TiledDrawingAreaTile> create(TiledDrawingAreaProxy* proxy, PlatformWebView* webView, const Coordinate& tileCoordinate) { return adoptRef(new TiledDrawingAreaTile(proxy, webView, tileCoordinate)); }
     ~TiledDrawingAreaTile();
 
     bool isDirty() const;
@@ -67,9 +78,12 @@
     void disableUpdates();
 
     int ID() const { return m_ID; }
+#if PLATFORM(QT)
+    void setParentNodeID(int);
+#endif
 
 private:
-    TiledDrawingAreaTile(TiledDrawingAreaProxy* proxy, const TiledDrawingAreaTile::Coordinate& tileCoordinate);
+    TiledDrawingAreaTile(TiledDrawingAreaProxy*, PlatformWebView*, const TiledDrawingAreaTile::Coordinate& tileCoordinate);
 
     TiledDrawingAreaProxy* m_proxy;
     Coordinate m_coordinate;
@@ -79,10 +93,11 @@
     bool m_hasUpdatePending;
 
 #if PLATFORM(QT)
-    QPixmap m_buffer;
-    QPixmap m_backBuffer;
+    QImage m_backBuffer;
+    SGAgent* m_sgAgent;
+    int m_nodeID;
+    int m_parentNodeID;
     bool m_isBackBufferValid;
-    bool m_isFrontBufferValid;
     QRegion m_dirtyRegion;
 #endif
 };

Added: trunk/Source/WebKit2/UIProcess/qt/SGAgent.cpp (0 => 92376)


--- trunk/Source/WebKit2/UIProcess/qt/SGAgent.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/SGAgent.cpp	2011-08-04 15:41:49 UTC (rev 92376)
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2010, 2011 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 "SGAgent.h"
+
+#include "PassOwnPtr.h"
+#include "SGTileNode.h"
+#include <QSGEngine>
+#include <QSGItem>
+#include <QSGTexture>
+
+namespace WebKit {
+
+struct NodeUpdateCreateTile : public NodeUpdate {
+    NodeUpdateCreateTile(int nodeID, int parentNodeID)
+        : NodeUpdate(CreateTile)
+        , nodeID(nodeID)
+        , parentNodeID(parentNodeID)
+    { }
+    int nodeID;
+    int parentNodeID;
+};
+
+struct NodeUpdateCreateScale : public NodeUpdate {
+    NodeUpdateCreateScale(int nodeID, int parentNodeID, float scale)
+        : NodeUpdate(CreateScale)
+        , nodeID(nodeID)
+        , parentNodeID(parentNodeID)
+        , scale(scale)
+    { }
+    int nodeID;
+    int parentNodeID;
+    float scale;
+};
+
+struct NodeUpdateRemove : public NodeUpdate {
+    NodeUpdateRemove(int nodeID)
+        : NodeUpdate(Remove)
+        , nodeID(nodeID)
+    { }
+    int nodeID;
+};
+
+struct NodeUpdateSetTexture : public NodeUpdate {
+    NodeUpdateSetTexture(int nodeID, const QImage& texture, const QRect& sourceRect, const QRect& targetRect)
+        : NodeUpdate(SetTexture)
+        , nodeID(nodeID)
+        , texture(texture)
+        , sourceRect(sourceRect)
+        , targetRect(targetRect)
+    { }
+    int nodeID;
+    QImage texture;
+    QRect sourceRect;
+    QRect targetRect;
+};
+
+
+SGAgent::SGAgent(QSGItem* item)
+    : item(item)
+    , nextNodeID(1)
+{
+}
+
+int SGAgent::createTileNode(int parentNodeID)
+{
+    int nodeID = nextNodeID++;
+    nodeUpdatesQueue.append(adoptPtr(new NodeUpdateCreateTile(nodeID, parentNodeID)));
+    item->update();
+    return nodeID;
+}
+
+int SGAgent::createScaleNode(int parentNodeID, float scale)
+{
+    int nodeID = nextNodeID++;
+    nodeUpdatesQueue.append(adoptPtr(new NodeUpdateCreateScale(nodeID, parentNodeID, scale)));
+    item->update();
+    return nodeID;
+}
+
+void SGAgent::removeNode(int nodeID)
+{
+    nodeUpdatesQueue.append(adoptPtr(new NodeUpdateRemove(nodeID)));
+    item->update();
+}
+
+void SGAgent::setNodeTexture(int nodeID, const QImage& texture, const QRect& sourceRect, const QRect& targetRect)
+{
+    nodeUpdatesQueue.append(adoptPtr(new NodeUpdateSetTexture(nodeID, texture, sourceRect, targetRect)));
+    item->update();
+}
+
+void SGAgent::updatePaintNode(QSGNode* itemNode)
+{
+    while (!nodeUpdatesQueue.isEmpty()) {
+        OwnPtr<NodeUpdate> nodeUpdate(nodeUpdatesQueue.takeFirst());
+        switch (nodeUpdate->type) {
+        case NodeUpdate::CreateTile: {
+            NodeUpdateCreateTile* createTileUpdate = static_cast<NodeUpdateCreateTile*>(nodeUpdate.get());
+            SGTileNode* tileNode = new SGTileNode;
+            QSGNode* parentNode = createTileUpdate->parentNodeID ? nodes.get(createTileUpdate->parentNodeID) : itemNode;
+            parentNode->prependChildNode(tileNode);
+            nodes.set(createTileUpdate->nodeID, tileNode);
+            break;
+        }
+        case NodeUpdate::CreateScale: {
+            NodeUpdateCreateScale* createScaleUpdate = static_cast<NodeUpdateCreateScale*>(nodeUpdate.get());
+            QSGTransformNode* scaleNode = new QSGTransformNode;
+            QMatrix4x4 scaleMatrix;
+            // Use scale(float,float) to prevent scaling the Z component.
+            scaleMatrix.scale(createScaleUpdate->scale, createScaleUpdate->scale);
+            scaleNode->setMatrix(scaleMatrix);
+            QSGNode* parentNode = createScaleUpdate->parentNodeID ? nodes.get(createScaleUpdate->parentNodeID) : itemNode;
+            // Prepend instead of append to paint the new, incomplete, tileset before/behind the previous one.
+            parentNode->prependChildNode(scaleNode);
+            nodes.set(createScaleUpdate->nodeID, scaleNode);
+            break;
+        }
+        case NodeUpdate::Remove: {
+            NodeUpdateRemove* removeUpdate = static_cast<NodeUpdateRemove*>(nodeUpdate.get());
+            delete nodes.take(removeUpdate->nodeID);
+            break;
+        }
+        case NodeUpdate::SetTexture: {
+            NodeUpdateSetTexture* setTextureUpdate = static_cast<NodeUpdateSetTexture*>(nodeUpdate.get());
+            SGTileNode* tileNode = static_cast<SGTileNode*>(nodes.get(setTextureUpdate->nodeID));
+            if (tileNode) {
+                QSGTexture* texture = item->sceneGraphEngine()->createTextureFromImage(setTextureUpdate->texture);
+                tileNode->setTexture(texture);
+                tileNode->setTargetRect(setTextureUpdate->targetRect);
+                tileNode->setSourceRect(texture->convertToNormalizedSourceRect(setTextureUpdate->sourceRect));
+            }
+            break;
+        }
+        default:
+            ASSERT_NOT_REACHED();
+        }
+    }
+}
+
+}

Added: trunk/Source/WebKit2/UIProcess/qt/SGAgent.h (0 => 92376)


--- trunk/Source/WebKit2/UIProcess/qt/SGAgent.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/SGAgent.h	2011-08-04 15:41:49 UTC (rev 92376)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2011 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 SGAgent_h
+#define SGAgent_h
+
+#include "Deque.h"
+#include "OwnPtr.h"
+#include "HashMap.h"
+
+class QImage;
+class QRect;
+class QSGItem;
+class QSGNode;
+class QSize;
+
+namespace WebKit {
+
+class NodeUpdate;
+class PageNode;
+
+// Takes care of taking update requests then fulfilling them asynchronously on the scene graph thread.
+class SGAgent {
+public:
+    SGAgent(QSGItem*);
+
+    int createTileNode(int parentNodeID);
+    int createScaleNode(int parentNodeID, float scale);
+    void removeNode(int nodeID);
+    void setNodeTexture(int nodeID, const QImage& texture, const QRect& sourceRect, const QRect& targetRect);
+
+    // Called by the QSGItem.
+    void updatePaintNode(QSGNode* itemNode);
+
+private:
+    QSGItem* item;
+    Deque<OwnPtr<NodeUpdate> > nodeUpdatesQueue;
+    HashMap<int, QSGNode*> nodes;
+    int nextNodeID;
+};
+
+struct NodeUpdate {
+    enum Type {
+        CreateTile,
+        CreateScale,
+        Remove,
+        SetTexture
+    };
+    NodeUpdate(Type type)
+        : type(type)
+    { }
+    Type type;
+};
+
+}
+
+#endif /* SGAgent_h */

Added: trunk/Source/WebKit2/UIProcess/qt/SGTileNode.cpp (0 => 92376)


--- trunk/Source/WebKit2/UIProcess/qt/SGTileNode.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/SGTileNode.cpp	2011-08-04 15:41:49 UTC (rev 92376)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010, 2011 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 "SGTileNode.h"
+
+namespace WebKit {
+
+SGTileNode::SGTileNode()
+    : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
+{
+    setGeometry(&m_geometry);
+    setMaterial(&m_material);
+    setOpaqueMaterial(&m_opaqueMaterial);
+}
+
+void SGTileNode::setTargetRect(const QRectF& r)
+{
+    if (m_targetRect == r)
+        return;
+    m_targetRect = r;
+    QSGGeometry::updateTexturedRectGeometry(&m_geometry, m_targetRect, m_sourceRect);
+    markDirty(DirtyGeometry);
+}
+
+void SGTileNode::setSourceRect(const QRectF& r)
+{
+    if (m_sourceRect == r)
+        return;
+    m_sourceRect = r;
+    QSGGeometry::updateTexturedRectGeometry(&m_geometry, m_targetRect, m_sourceRect);
+    markDirty(DirtyGeometry);
+}
+
+void SGTileNode::setTexture(QSGTexture* texture)
+{
+    if (m_material.texture() == texture)
+        return;
+    m_material.setTexture(texture);
+    m_opaqueMaterial.setTexture(texture);
+    m_texture.reset(texture);
+    markDirty(DirtyMaterial);
+}
+
+}

Copied: trunk/Source/WebKit2/UIProcess/qt/SGTileNode.h (from rev 92375, trunk/Source/WebKit2/UIProcess/API/qt/qtouchwebpage_p.h) (0 => 92376)


--- trunk/Source/WebKit2/UIProcess/qt/SGTileNode.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/SGTileNode.h	2011-08-04 15:41:49 UTC (rev 92376)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 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 SGTileNode_h
+#define SGTileNode_h
+
+#include <QSGGeometryNode>
+#include <QSGOpaqueTextureMaterial>
+#include <QSGTextureMaterial>
+
+QT_BEGIN_NAMESPACE
+class QSGTexture;
+QT_END_NAMESPACE
+
+namespace WebKit {
+
+class SGTileNode : public QSGGeometryNode {
+public:
+    SGTileNode();
+
+    void setTargetRect(const QRectF&);
+    void setSourceRect(const QRectF&);
+    // This takes ownership of the texture.
+    void setTexture(QSGTexture*);
+
+private:
+    QSGGeometry m_geometry;
+    QSGOpaqueTextureMaterial m_opaqueMaterial;
+    QSGTextureMaterial m_material;
+    QScopedPointer<QSGTexture> m_texture;
+
+    QRectF m_targetRect;
+    QRectF m_sourceRect;
+};
+
+}
+
+#endif /* SGTileNode_h */

Modified: trunk/Source/WebKit2/UIProcess/qt/TiledDrawingAreaProxyQt.cpp (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/qt/TiledDrawingAreaProxyQt.cpp	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/qt/TiledDrawingAreaProxyQt.cpp	2011-08-04 15:41:49 UTC (rev 92376)
@@ -39,12 +39,7 @@
 
 void TiledDrawingAreaProxy::updateWebView(const Vector<IntRect>& paintedArea)
 {
-    if (!page() || !page()->isValid())
-        return;
-
-    unsigned size = paintedArea.size();
-    for (unsigned n = 0; n < size; ++n)
-        static_cast<ViewInterface*>(m_webView)->setViewNeedsDisplay(QRect(paintedArea[n]));
+    // SG updates are triggered through SGAgent.
 }
 
 WebPageProxy* TiledDrawingAreaProxy::page()

Modified: trunk/Source/WebKit2/UIProcess/qt/TiledDrawingAreaTileQt.cpp (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/qt/TiledDrawingAreaTileQt.cpp	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/qt/TiledDrawingAreaTileQt.cpp	2011-08-04 15:41:49 UTC (rev 92376)
@@ -27,8 +27,10 @@
 #include "TiledDrawingAreaTile.h"
 
 #include "GraphicsContext.h"
+#include "SGAgent.h"
 #include "ShareableBitmap.h"
 #include "TiledDrawingAreaProxy.h"
+#include "TouchViewInterface.h"
 #include "UpdateInfo.h"
 #include "WebPageProxy.h"
 #include "WebProcessProxy.h"
@@ -40,13 +42,15 @@
 
 namespace WebKit {
 
-TiledDrawingAreaTile::TiledDrawingAreaTile(TiledDrawingAreaProxy* proxy, const Coordinate& tileCoordinate)
+TiledDrawingAreaTile::TiledDrawingAreaTile(TiledDrawingAreaProxy* proxy, PlatformWebView* webView, const Coordinate& tileCoordinate)
     : m_proxy(proxy)
     , m_coordinate(tileCoordinate)
     , m_rect(proxy->tileRectForCoordinate(tileCoordinate))
     , m_hasUpdatePending(false)
+    , m_sgAgent(webView->sceneGraphAgent())
+    , m_nodeID(0)
+    , m_parentNodeID(0)
     , m_isBackBufferValid(false)
-    , m_isFrontBufferValid(false)
     , m_dirtyRegion(m_rect)
 {
     static int id = 0;
@@ -63,6 +67,8 @@
     qDebug() << "deleting tile id=" << m_ID;
 #endif
     disableUpdates();
+    if (m_nodeID)
+        m_sgAgent->removeNode(m_nodeID);
 }
 
 bool TiledDrawingAreaTile::isDirty() const
@@ -72,7 +78,7 @@
 
 bool TiledDrawingAreaTile::isReadyToPaint() const
 {
-    return m_isFrontBufferValid;
+    return !!m_nodeID;
 }
 
 bool TiledDrawingAreaTile::hasReadyBackBuffer() const
@@ -101,26 +107,12 @@
 
 void TiledDrawingAreaTile::swapBackBufferToFront()
 {
-    ASSERT(!m_backBuffer.isNull());
-
-    const QPixmap swap = m_buffer;
-    m_buffer = m_backBuffer;
-    m_isFrontBufferValid = m_isBackBufferValid;
-    m_isBackBufferValid = false;
-    m_backBuffer = swap;
+    // FIXME: Implement once we can tight invalidated tile updates together.
 }
 
 void TiledDrawingAreaTile::paint(GraphicsContext* context, const IntRect& rect)
 {
-    ASSERT(!m_buffer.isNull());
-
-    IntRect target = intersection(rect, m_rect);
-    IntRect source((target.x() - m_rect.x()),
-                   (target.y() - m_rect.y()),
-                   target.width(),
-                   target.height());
-
-    context->platformContext()->drawPixmap(target, m_buffer, source);
+    ASSERT_NOT_REACHED();
 }
 
 void TiledDrawingAreaTile::incorporateUpdate(const UpdateInfo& updateInfo, float)
@@ -136,14 +128,21 @@
     const QSize tileSize = m_proxy->tileSize();
 
     if (m_backBuffer.size() != tileSize) {
-        m_backBuffer = QPixmap(tileSize);
+        m_backBuffer = QImage(tileSize, image.format());
         m_backBuffer.fill(Qt::transparent);
     }
 
-    QPainter painter(&m_backBuffer);
-    painter.drawPixmap(0, 0, m_buffer);
-    IntSize drawPoint = updateChunkRect.location() - m_rect.location();
-    painter.drawImage(QPoint(drawPoint.width(), drawPoint.height()), image);
+    {
+        QPainter painter(&m_backBuffer);
+        IntSize drawPoint = updateChunkRect.location() - m_rect.location();
+        painter.drawImage(QPoint(drawPoint.width(), drawPoint.height()), image);
+    }
+
+    if (!m_nodeID)
+        m_nodeID = m_sgAgent->createTileNode(m_parentNodeID);
+    ASSERT(m_nodeID);
+    QRect sourceRect(0, 0, m_rect.width(), m_rect.height());
+    m_sgAgent->setNodeTexture(m_nodeID, m_backBuffer, sourceRect, m_rect);
 }
 
 void TiledDrawingAreaTile::disableUpdates()
@@ -157,11 +156,17 @@
     }
 
     m_proxy->unregisterTile(m_ID);
-    m_backBuffer = QPixmap();
+    m_backBuffer = QImage();
     m_isBackBufferValid = false;
     m_proxy = 0;
 }
 
+void TiledDrawingAreaTile::setParentNodeID(int nodeID)
+{
+    ASSERT(!m_nodeID);
+    m_parentNodeID = nodeID;
+}
+
 void TiledDrawingAreaTile::updateBackBuffer()
 {
     ASSERT(m_proxy);

Modified: trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.cpp (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.cpp	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.cpp	2011-08-04 15:41:49 UTC (rev 92376)
@@ -91,11 +91,15 @@
     m_viewportView->d->viewportRectUpdated();
 }
 
-void TouchViewInterface::setViewNeedsDisplay(const QRect& invalidatedRect)
+SGAgent* TouchViewInterface::sceneGraphAgent() const
 {
-    m_pageView->update(invalidatedRect);
+    return &m_pageView->d->sgAgent;
 }
 
+void TouchViewInterface::setViewNeedsDisplay(const QRect&)
+{
+}
+
 QSize TouchViewInterface::drawingAreaSize()
 {
     return QSize(m_pageView->width(), m_pageView->height());

Modified: trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h (92375 => 92376)


--- trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/UIProcess/qt/TouchViewInterface.h	2011-08-04 15:41:49 UTC (rev 92376)
@@ -29,6 +29,8 @@
 
 namespace WebKit {
 
+class SGAgent;
+
 class TouchViewInterface : public ViewInterface
 {
 public:
@@ -43,6 +45,8 @@
     void pinchGestureRequestUpdate(const QPointF&, qreal);
     void pinchGestureEnded();
 
+    SGAgent* sceneGraphAgent() const;
+
 private:
     /* Implementation of ViewInterface */
     virtual void setViewNeedsDisplay(const QRect&);

Modified: trunk/Source/WebKit2/WebKit2.pro (92375 => 92376)


--- trunk/Source/WebKit2/WebKit2.pro	2011-08-04 15:22:05 UTC (rev 92375)
+++ trunk/Source/WebKit2/WebKit2.pro	2011-08-04 15:41:49 UTC (rev 92376)
@@ -249,6 +249,8 @@
     UIProcess/qt/qwkhistory_p.h \
     UIProcess/qt/qwkpreferences.h \
     UIProcess/qt/qwkpreferences_p.h \
+    UIProcess/qt/SGAgent.h \
+    UIProcess/qt/SGTileNode.h \
     UIProcess/qt/ViewInterface.h \
     UIProcess/qt/WebUndoCommandQt.h \
     UIProcess/qt/WebContextMenuProxyQt.h \
@@ -476,6 +478,8 @@
     UIProcess/qt/qwkcontext.cpp \
     UIProcess/qt/qwkhistory.cpp \
     UIProcess/qt/qwkpreferences.cpp \
+    UIProcess/qt/SGAgent.cpp \
+    UIProcess/qt/SGTileNode.cpp \
     UIProcess/qt/TiledDrawingAreaProxyQt.cpp \
     UIProcess/qt/TiledDrawingAreaTileQt.cpp \
     UIProcess/qt/TextCheckerQt.cpp \
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to