Title: [93777] trunk/Source/WebCore
Revision
93777
Author
[email protected]
Date
2011-08-25 05:31:19 -0700 (Thu, 25 Aug 2011)

Log Message

TiledBackingStore: Untie the tile implementation from the platform.
https://bugs.webkit.org/show_bug.cgi?id=66760

Reviewed by Kenneth Rohde Christiansen.

Make the Tile class polymorphic and introduce TiledBackingStoreBackend as a Tile factory.

* platform/graphics/Tile.h:
(WebCore::Tile::~Tile):
* platform/graphics/TiledBackingStore.cpp:
(WebCore::TiledBackingStore::TiledBackingStore):
(WebCore::TiledBackingStore::paint):
(WebCore::TiledBackingStore::createTiles):
* platform/graphics/TiledBackingStore.h:
(WebCore::TiledBackingStore::client):
* platform/graphics/TiledBackingStoreBackend.h: Added.
(WebCore::TiledBackingStoreBackend::create):
(WebCore::TiledBackingStoreBackend::~TiledBackingStoreBackend):
(WebCore::TiledBackingStoreBackend::TiledBackingStoreBackend):
* platform/graphics/qt/TileQt.cpp:
(WebCore::TileQt::TileQt):
(WebCore::TileQt::~TileQt):
(WebCore::TileQt::isDirty):
(WebCore::TileQt::isReadyToPaint):
(WebCore::TileQt::invalidate):
(WebCore::TileQt::updateBackBuffer):
(WebCore::TileQt::swapBackBufferToFront):
(WebCore::TileQt::paint):
(WebCore::TiledBackingStoreBackend::paintCheckerPattern):
(WebCore::TiledBackingStoreBackend::createTile):
* platform/graphics/qt/TileQt.h: Copied from Source/WebCore/platform/graphics/Tile.h.
(WebCore::TileQt::create):
(WebCore::TileQt::coordinate):
(WebCore::TileQt::rect):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (93776 => 93777)


--- trunk/Source/WebCore/ChangeLog	2011-08-25 12:30:33 UTC (rev 93776)
+++ trunk/Source/WebCore/ChangeLog	2011-08-25 12:31:19 UTC (rev 93777)
@@ -1,3 +1,40 @@
+2011-08-23  Jocelyn Turcotte  <[email protected]>
+
+        TiledBackingStore: Untie the tile implementation from the platform.
+        https://bugs.webkit.org/show_bug.cgi?id=66760
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Make the Tile class polymorphic and introduce TiledBackingStoreBackend as a Tile factory.
+
+        * platform/graphics/Tile.h:
+        (WebCore::Tile::~Tile):
+        * platform/graphics/TiledBackingStore.cpp:
+        (WebCore::TiledBackingStore::TiledBackingStore):
+        (WebCore::TiledBackingStore::paint):
+        (WebCore::TiledBackingStore::createTiles):
+        * platform/graphics/TiledBackingStore.h:
+        (WebCore::TiledBackingStore::client):
+        * platform/graphics/TiledBackingStoreBackend.h: Added.
+        (WebCore::TiledBackingStoreBackend::create):
+        (WebCore::TiledBackingStoreBackend::~TiledBackingStoreBackend):
+        (WebCore::TiledBackingStoreBackend::TiledBackingStoreBackend):
+        * platform/graphics/qt/TileQt.cpp:
+        (WebCore::TileQt::TileQt):
+        (WebCore::TileQt::~TileQt):
+        (WebCore::TileQt::isDirty):
+        (WebCore::TileQt::isReadyToPaint):
+        (WebCore::TileQt::invalidate):
+        (WebCore::TileQt::updateBackBuffer):
+        (WebCore::TileQt::swapBackBufferToFront):
+        (WebCore::TileQt::paint):
+        (WebCore::TiledBackingStoreBackend::paintCheckerPattern):
+        (WebCore::TiledBackingStoreBackend::createTile):
+        * platform/graphics/qt/TileQt.h: Copied from Source/WebCore/platform/graphics/Tile.h.
+        (WebCore::TileQt::create):
+        (WebCore::TileQt::coordinate):
+        (WebCore::TileQt::rect):
+
 2011-08-25  Andreas Kling  <[email protected]>
 
         [Qt] Path::boundingRect() is unnecessarily slow.

Modified: trunk/Source/WebCore/platform/graphics/Tile.h (93776 => 93777)


--- trunk/Source/WebCore/platform/graphics/Tile.h	2011-08-25 12:30:33 UTC (rev 93776)
+++ trunk/Source/WebCore/platform/graphics/Tile.h	2011-08-25 12:31:19 UTC (rev 93777)
@@ -25,52 +25,27 @@
 #include "IntPoint.h"
 #include "IntPointHash.h"
 #include "IntRect.h"
-#include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 
-#if PLATFORM(QT)
-QT_BEGIN_NAMESPACE
-class QPixmap;
-class QRegion;
-QT_END_NAMESPACE
-#endif
-
 namespace WebCore {
-    
+
 class GraphicsContext;
-class TiledBackingStore;
 
 class Tile : public RefCounted<Tile> {
 public:
     typedef IntPoint Coordinate;
 
-    static PassRefPtr<Tile> create(TiledBackingStore* backingStore, const Coordinate& tileCoordinate) { return adoptRef(new Tile(backingStore, tileCoordinate)); }
-    ~Tile();
-    
-    bool isDirty() const;
-    void invalidate(const IntRect&);
-    Vector<IntRect> updateBackBuffer();
-    void swapBackBufferToFront();
-    bool isReadyToPaint() const;
-    void paint(GraphicsContext*, const IntRect&);
+    virtual ~Tile() { }
 
-    const Tile::Coordinate& coordinate() const { return m_coordinate; }
-    const IntRect& rect() const { return m_rect; }
-    
-    static void paintCheckerPattern(GraphicsContext*, const FloatRect&);
+    virtual bool isDirty() const = 0;
+    virtual void invalidate(const IntRect&) = 0;
+    virtual Vector<IntRect> updateBackBuffer() = 0;
+    virtual void swapBackBufferToFront() = 0;
+    virtual bool isReadyToPaint() const = 0;
+    virtual void paint(GraphicsContext*, const IntRect&) = 0;
 
-private:
-    Tile(TiledBackingStore*, const Coordinate&);
-    
-    TiledBackingStore* m_backingStore;
-    Coordinate m_coordinate;
-    IntRect m_rect;
-
-#if PLATFORM(QT)
-    QPixmap* m_buffer;
-    QPixmap* m_backBuffer;
-    QRegion* m_dirtyRegion;
-#endif
+    virtual const Tile::Coordinate& coordinate() const = 0;
+    virtual const IntRect& rect() const = 0;
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/TiledBackingStore.cpp (93776 => 93777)


--- trunk/Source/WebCore/platform/graphics/TiledBackingStore.cpp	2011-08-25 12:30:33 UTC (rev 93776)
+++ trunk/Source/WebCore/platform/graphics/TiledBackingStore.cpp	2011-08-25 12:31:19 UTC (rev 93777)
@@ -36,9 +36,9 @@
     return IntPoint(rect.maxX() - 1, rect.maxY() - 1);
 }
 
-
-TiledBackingStore::TiledBackingStore(TiledBackingStoreClient* client)
+TiledBackingStore::TiledBackingStore(TiledBackingStoreClient* client, PassOwnPtr<TiledBackingStoreBackend> backend)
     : m_client(client)
+    , m_backend(backend)
     , m_tileBufferUpdateTimer(new TileTimer(this, &TiledBackingStore::tileBufferUpdateTimerFired))
     , m_tileCreationTimer(new TileTimer(this, &TiledBackingStore::tileCreationTimerFired))
     , m_tileSize(defaultTileWidth, defaultTileHeight)
@@ -153,7 +153,7 @@
                 IntRect target = intersection(tileRect, dirtyRect);
                 if (target.isEmpty())
                     continue;
-                Tile::paintCheckerPattern(context, FloatRect(target));
+                m_backend->paintCheckerPattern(context, FloatRect(target));
             }
         }
     }
@@ -190,7 +190,7 @@
     createTiles();
 }
 
-double TiledBackingStore::tileDistance(const IntRect& viewport, const Tile::Coordinate& tileCoordinate)
+double TiledBackingStore::tileDistance(const IntRect& viewport, const Tile::Coordinate& tileCoordinate) const
 {
     if (viewport.intersects(tileRectForCoordinate(tileCoordinate)))
         return 0;
@@ -260,7 +260,7 @@
     unsigned tilesToCreateCount = tilesToCreate.size();
     for (unsigned n = 0; n < tilesToCreateCount; ++n) {
         Tile::Coordinate coordinate = tilesToCreate[n];
-        setTile(coordinate, Tile::create(this, coordinate));
+        setTile(coordinate, m_backend->createTile(this, coordinate));
     }
     requiredTileCount -= tilesToCreateCount;
     

Modified: trunk/Source/WebCore/platform/graphics/TiledBackingStore.h (93776 => 93777)


--- trunk/Source/WebCore/platform/graphics/TiledBackingStore.h	2011-08-25 12:30:33 UTC (rev 93776)
+++ trunk/Source/WebCore/platform/graphics/TiledBackingStore.h	2011-08-25 12:31:19 UTC (rev 93777)
@@ -26,6 +26,7 @@
 #include "IntPoint.h"
 #include "IntRect.h"
 #include "Tile.h"
+#include "TiledBackingStoreBackend.h"
 #include "Timer.h"
 #include <wtf/Assertions.h>
 #include <wtf/HashMap.h>
@@ -34,16 +35,18 @@
 namespace WebCore {
 
 class GraphicsContext;
+class TiledBackingStore;
 class TiledBackingStoreClient;
 
 class TiledBackingStore {
     WTF_MAKE_NONCOPYABLE(TiledBackingStore); WTF_MAKE_FAST_ALLOCATED;
 public:
-    TiledBackingStore(TiledBackingStoreClient*);
+    TiledBackingStore(TiledBackingStoreClient*, PassOwnPtr<TiledBackingStoreBackend> = TiledBackingStoreBackend::create());
     ~TiledBackingStore();
 
     void adjustVisibleRect();
     
+    TiledBackingStoreClient* client() { return m_client; }
     float contentsScale() { return m_contentsScale; }
     void setContentsScale(float);
     
@@ -67,6 +70,13 @@
     }
     void setKeepAndCoverAreaMultipliers(const FloatSize& keepMultiplier, const FloatSize& coverMultiplier);    
 
+    IntRect mapToContents(const IntRect&) const;
+    IntRect mapFromContents(const IntRect&) const;
+
+    IntRect tileRectForCoordinate(const Tile::Coordinate&) const;
+    Tile::Coordinate tileCoordinateForPoint(const IntPoint&) const;
+    double tileDistance(const IntRect& viewport, const Tile::Coordinate&) const;
+
 private:
     void startTileBufferUpdateTimer();
     void startTileCreationTimer();
@@ -88,19 +98,13 @@
     void setTile(const Tile::Coordinate& coordinate, PassRefPtr<Tile> tile);
     void removeTile(const Tile::Coordinate& coordinate);
 
-    IntRect mapToContents(const IntRect&) const;
-    IntRect mapFromContents(const IntRect&) const;
-    
     IntRect contentsRect() const;
     
-    IntRect tileRectForCoordinate(const Tile::Coordinate&) const;
-    Tile::Coordinate tileCoordinateForPoint(const IntPoint&) const;
-    double tileDistance(const IntRect& viewport, const Tile::Coordinate&);
-    
     void paintCheckerPattern(GraphicsContext*, const IntRect&, const Tile::Coordinate&);
 
 private:
     TiledBackingStoreClient* m_client;
+    OwnPtr<TiledBackingStoreBackend> m_backend;
 
     typedef HashMap<Tile::Coordinate, RefPtr<Tile> > TileMap;
     TileMap m_tiles;

Added: trunk/Source/WebCore/platform/graphics/TiledBackingStoreBackend.h (0 => 93777)


--- trunk/Source/WebCore/platform/graphics/TiledBackingStoreBackend.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/TiledBackingStoreBackend.h	2011-08-25 12:31:19 UTC (rev 93777)
@@ -0,0 +1,48 @@
+/*
+ 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 library 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 library; 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 TiledBackingStoreBackend_h
+#define TiledBackingStoreBackend_h
+
+#if ENABLE(TILED_BACKING_STORE)
+
+#include "PassOwnPtr.h"
+#include "Tile.h"
+
+namespace WebCore {
+
+class TiledBackingStore;
+class TiledBackingStoreBackend;
+
+class TiledBackingStoreBackend {
+public:
+    static PassOwnPtr<TiledBackingStoreBackend> create() { return adoptPtr(new TiledBackingStoreBackend); }
+    virtual ~TiledBackingStoreBackend() { }
+    virtual PassRefPtr<Tile> createTile(TiledBackingStore*, const Tile::Coordinate&);
+    virtual void paintCheckerPattern(GraphicsContext*, const FloatRect&);
+
+protected:
+    TiledBackingStoreBackend() { }
+};
+
+}
+
+#endif
+
+#endif

Modified: trunk/Source/WebCore/platform/graphics/qt/TileQt.cpp (93776 => 93777)


--- trunk/Source/WebCore/platform/graphics/qt/TileQt.cpp	2011-08-25 12:30:33 UTC (rev 93776)
+++ trunk/Source/WebCore/platform/graphics/qt/TileQt.cpp	2011-08-25 12:31:19 UTC (rev 93777)
@@ -18,7 +18,7 @@
  */
 
 #include "config.h"
-#include "Tile.h"
+#include "TileQt.h"
 
 #if ENABLE(TILED_BACKING_STORE)
 
@@ -55,7 +55,7 @@
     return *pixmap;
 }
     
-Tile::Tile(TiledBackingStore* backingStore, const Coordinate& tileCoordinate)
+TileQt::TileQt(TiledBackingStore* backingStore, const Coordinate& tileCoordinate)
     : m_backingStore(backingStore)
     , m_coordinate(tileCoordinate)
     , m_rect(m_backingStore->tileRectForCoordinate(tileCoordinate))
@@ -65,24 +65,24 @@
 {
 }
 
-Tile::~Tile()
+TileQt::~TileQt()
 {
     delete m_buffer;
     delete m_backBuffer;
     delete m_dirtyRegion;
 }
 
-bool Tile::isDirty() const 
+bool TileQt::isDirty() const
 { 
     return !m_dirtyRegion->isEmpty(); 
 }
 
-bool Tile::isReadyToPaint() const
+bool TileQt::isReadyToPaint() const
 { 
     return m_buffer; 
 }
 
-void Tile::invalidate(const IntRect& dirtyRect)
+void TileQt::invalidate(const IntRect& dirtyRect)
 {
     IntRect tileDirtyRect = intersection(dirtyRect, m_rect);
     if (tileDirtyRect.isEmpty())
@@ -91,15 +91,15 @@
     *m_dirtyRegion += tileDirtyRect;
 }
     
-Vector<IntRect> Tile::updateBackBuffer()
+Vector<IntRect> TileQt::updateBackBuffer()
 {
     if (m_buffer && !isDirty())
         return Vector<IntRect>();
 
     if (!m_backBuffer) {
         if (!m_buffer) {
-            m_backBuffer = new QPixmap(m_backingStore->m_tileSize.width(), m_backingStore->m_tileSize.height());
-            m_backBuffer->fill(m_backingStore->m_client->tiledBackingStoreBackgroundColor());
+            m_backBuffer = new QPixmap(m_backingStore->tileSize().width(), m_backingStore->tileSize().height());
+            m_backBuffer->fill(m_backingStore->client()->tiledBackingStoreBackgroundColor());
         } else {
             // Currently all buffers are updated synchronously at the same time so there is no real need
             // to have separate back and front buffers. Just use the existing buffer.
@@ -122,15 +122,15 @@
         IntRect rect = dirtyRects[n];
         updatedRects.append(rect);
         context.clip(FloatRect(rect));
-        context.scale(FloatSize(m_backingStore->m_contentsScale, m_backingStore->m_contentsScale));
-        m_backingStore->m_client->tiledBackingStorePaint(&context, m_backingStore->mapToContents(rect));
+        context.scale(FloatSize(m_backingStore->contentsScale(), m_backingStore->contentsScale()));
+        m_backingStore->client()->tiledBackingStorePaint(&context, m_backingStore->mapToContents(rect));
         context.restore();
     }
 
     return updatedRects;
 }
 
-void Tile::swapBackBufferToFront()
+void TileQt::swapBackBufferToFront()
 {
     if (!m_backBuffer)
         return;
@@ -139,7 +139,7 @@
     m_backBuffer = 0;
 }
 
-void Tile::paint(GraphicsContext* context, const IntRect& rect)
+void TileQt::paint(GraphicsContext* context, const IntRect& rect)
 {
     if (!m_buffer)
         return;
@@ -153,7 +153,7 @@
     context->platformContext()->drawPixmap(target, *m_buffer, source);
 }
     
-void Tile::paintCheckerPattern(GraphicsContext* context, const FloatRect& target)
+void TiledBackingStoreBackend::paintCheckerPattern(GraphicsContext* context, const FloatRect& target)
 {
     QPainter* painter = context->platformContext();
     QTransform worldTransform = painter->worldTransform();
@@ -178,6 +178,11 @@
     painter->setWorldTransform(worldTransform);
 }
 
+PassRefPtr<Tile> TiledBackingStoreBackend::createTile(TiledBackingStore* backingStore, const Tile::Coordinate& tileCoordinate)
+{
+    return TileQt::create(backingStore, tileCoordinate);
 }
 
+}
+
 #endif

Copied: trunk/Source/WebCore/platform/graphics/qt/TileQt.h (from rev 93775, trunk/Source/WebCore/platform/graphics/Tile.h) (0 => 93777)


--- trunk/Source/WebCore/platform/graphics/qt/TileQt.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/qt/TileQt.h	2011-08-25 12:31:19 UTC (rev 93777)
@@ -0,0 +1,71 @@
+/*
+ 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 library 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 library; 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 TileQt_h
+#define TileQt_h
+
+#if ENABLE(TILED_BACKING_STORE)
+
+#include "IntPoint.h"
+#include "IntRect.h"
+#include "Tile.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+QT_BEGIN_NAMESPACE
+class QPixmap;
+class QRegion;
+QT_END_NAMESPACE
+
+namespace WebCore {
+
+class TiledBackingStore;
+
+class TileQt : public Tile {
+public:
+    typedef IntPoint Coordinate;
+
+    static PassRefPtr<Tile> create(TiledBackingStore* backingStore, const Coordinate& tileCoordinate) { return adoptRef(new TileQt(backingStore, tileCoordinate)); }
+    ~TileQt();
+
+    bool isDirty() const;
+    void invalidate(const IntRect&);
+    Vector<IntRect> updateBackBuffer();
+    void swapBackBufferToFront();
+    bool isReadyToPaint() const;
+    void paint(GraphicsContext*, const IntRect&);
+
+    const Tile::Coordinate& coordinate() const { return m_coordinate; }
+    const IntRect& rect() const { return m_rect; }
+
+private:
+    TileQt(TiledBackingStore*, const Coordinate&);
+
+    TiledBackingStore* m_backingStore;
+    Coordinate m_coordinate;
+    IntRect m_rect;
+
+    QPixmap* m_buffer;
+    QPixmap* m_backBuffer;
+    QRegion* m_dirtyRegion;
+};
+
+}
+#endif
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to