Title: [291048] trunk/Source
Revision
291048
Author
[email protected]
Date
2022-03-09 06:30:14 -0800 (Wed, 09 Mar 2022)

Log Message

[WinCairo] Improve WCTiledBacking and TextureMapperSparseBackingStore
https://bugs.webkit.org/show_bug.cgi?id=237355

Reviewed by Don Olmstead.

Source/WebCore:

* platform/graphics/texmap/TextureMapperSparseBackingStore.cpp:
(WebCore::TextureMapperSparseBackingStore::setSize):
(WebCore::TextureMapperSparseBackingStore::paintToTextureMapper):
(WebCore::TextureMapperSparseBackingStore::drawBorder):
(WebCore::TextureMapperSparseBackingStore::drawRepaintCounter):
(WebCore::TextureMapperSparseBackingStore::updateContents):
(WebCore::TextureMapperSparseBackingStore::removeTile):
(WebCore::TextureMapperSparseBackingStore::TextureMapperSparseBackingStore): Deleted.
(WebCore::TextureMapperSparseBackingStore::removeUncoveredTiles): Deleted.
(WebCore::TextureMapperSparseBackingStore::tileDimension const): Deleted.
* platform/graphics/texmap/TextureMapperSparseBackingStore.h:
* platform/graphics/texmap/TextureMapperTile.h:

Source/WebKit:

TextureMapperSparseBackingStore simply had a Vector to have all
tiles. If a web page had a very large layer, the vector was
extended to be able to keep all tiles, and it performed poorly.
Use a HashMap to keep tiles only in the coverage rect.

GraphicsLayerWC had only one dirty rect, and created a
ImageBuffer for all tiles to update. Change it to have one dirty
rect for one tile, and create a ImageBuffer for every dirty tile.

* GPUProcess/graphics/wc/WCScene.cpp:
(WebKit::WCScene::update):
* PlatformWin.cmake:
* WebProcess/WebPage/wc/DrawingAreaWC.cpp:
(WebKit::flushLayerImageBuffers):
* WebProcess/WebPage/wc/GraphicsLayerWC.cpp:
(WebKit::GraphicsLayerWC::setSize):
(WebKit::GraphicsLayerWC::recursiveCommitChanges):
* WebProcess/WebPage/wc/WCTileGrid.cpp: Added.
(WebKit::WCTileGrid::Tile::Tile):
(WebKit::WCTileGrid::Tile::addDirtyRect):
(WebKit::WCTileGrid::Tile::clearDirtyRect):
(WebKit::WCTileGrid::Tile::hasDirtyRect const):
(WebKit::WCTileGrid::setSize):
(WebKit::WCTileGrid::tileRectFromPixelRect):
(WebKit::WCTileGrid::tileSizeFromPixelSize):
(WebKit::WCTileGrid::tilePixelSize const):
(WebKit::WCTileGrid::addDirtyRect):
(WebKit::WCTileGrid::clearDirtyRects):
(WebKit::WCTileGrid::ensureTile):
(WebKit::WCTileGrid::setCoverageRect):
* WebProcess/WebPage/wc/WCTileGrid.h: Added.
(WebKit::WCTileGrid::Tile::willRemove const):
(WebKit::WCTileGrid::Tile::setWillRemove):
(WebKit::WCTileGrid::Tile::dirtyRect):
(WebKit::WCTileGrid::tiles):
* WebProcess/WebPage/wc/WCUpateInfo.h:
(WebKit::WCTileUpdate::encode const):
(WebKit::WCTileUpdate::decode):
(WebKit::WCLayerUpateInfo::encode const):
(WebKit::WCLayerUpateInfo::decode):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291047 => 291048)


--- trunk/Source/WebCore/ChangeLog	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebCore/ChangeLog	2022-03-09 14:30:14 UTC (rev 291048)
@@ -1,3 +1,23 @@
+2022-03-09  Fujii Hironori  <[email protected]>
+
+        [WinCairo] Improve WCTiledBacking and TextureMapperSparseBackingStore
+        https://bugs.webkit.org/show_bug.cgi?id=237355
+
+        Reviewed by Don Olmstead.
+
+        * platform/graphics/texmap/TextureMapperSparseBackingStore.cpp:
+        (WebCore::TextureMapperSparseBackingStore::setSize):
+        (WebCore::TextureMapperSparseBackingStore::paintToTextureMapper):
+        (WebCore::TextureMapperSparseBackingStore::drawBorder):
+        (WebCore::TextureMapperSparseBackingStore::drawRepaintCounter):
+        (WebCore::TextureMapperSparseBackingStore::updateContents):
+        (WebCore::TextureMapperSparseBackingStore::removeTile):
+        (WebCore::TextureMapperSparseBackingStore::TextureMapperSparseBackingStore): Deleted.
+        (WebCore::TextureMapperSparseBackingStore::removeUncoveredTiles): Deleted.
+        (WebCore::TextureMapperSparseBackingStore::tileDimension const): Deleted.
+        * platform/graphics/texmap/TextureMapperSparseBackingStore.h:
+        * platform/graphics/texmap/TextureMapperTile.h:
+
 2022-03-09  Antoine Quint  <[email protected]>
 
         [web-animations] increase the max number of animatable properties

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperSparseBackingStore.cpp (291047 => 291048)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperSparseBackingStore.cpp	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperSparseBackingStore.cpp	2022-03-09 14:30:14 UTC (rev 291048)
@@ -32,44 +32,14 @@
 
 namespace WebCore {
 
-TextureMapperSparseBackingStore::TextureMapperSparseBackingStore(int tileSize)
-    : m_tileSize(tileSize)
-{
-}
-
 void TextureMapperSparseBackingStore::setSize(const IntSize& size)
 {
     if (m_size == size)
         return;
+    m_size = size;
     m_tiles.clear();
-    m_size = size;
-    auto tiles = tileDimension();
-    for (int y = 0; y < tiles.height(); y++) {
-        for (int x = 0; x < tiles.width(); x++) {
-            IntRect rect = { x * m_tileSize, y * m_tileSize, m_tileSize, m_tileSize };
-            rect.intersect({ { }, m_size });
-            m_tiles.append(TextureMapperTile(rect));
-        }
-    }
 }
 
-void TextureMapperSparseBackingStore::removeUncoveredTiles(const IntRect& coverage)
-{
-    auto minCoveredX = coverage.x() / m_tileSize;
-    auto maxCoveredX = (coverage.maxX() + m_tileSize - 1) / m_tileSize;
-    auto minCoveredY = coverage.y() / m_tileSize;
-    auto maxCoveredY = (coverage.maxY() + m_tileSize - 1) / m_tileSize;
-    auto tiles = tileDimension();
-    for (int y = 0; y < tiles.height(); y++) {
-        bool coveredY = minCoveredY <= y && y < maxCoveredY;
-        for (int x = 0; x < tiles.width(); x++) {
-            bool covered = coveredY && minCoveredX <= x && x < maxCoveredX;
-            if (!covered)
-                m_tiles[x + y * tiles.width()].setTexture(nullptr);
-        }
-    }
-}
-
 TransformationMatrix TextureMapperSparseBackingStore::adjustedTransformForRect(const FloatRect& targetRect)
 {
     return TransformationMatrix::rectToRect({ { }, m_size }, targetRect);
@@ -79,33 +49,35 @@
 {
     IntRect rect = { { }, m_size };
     TransformationMatrix adjustedTransform = transform * adjustedTransformForRect(targetRect);
-    for (auto& tile : m_tiles)
-        tile.paint(textureMapper, adjustedTransform, opacity, calculateExposedTileEdges(rect, tile.rect()));
+    for (auto& iterator : m_tiles)
+        iterator.value->paint(textureMapper, adjustedTransform, opacity, calculateExposedTileEdges(rect, iterator.value->rect()));
 }
 
 void TextureMapperSparseBackingStore::drawBorder(TextureMapper& textureMapper, const Color& borderColor, float borderWidth, const FloatRect& targetRect, const TransformationMatrix& transform)
 {
     TransformationMatrix adjustedTransform = transform * adjustedTransformForRect(targetRect);
-    for (auto& tile : m_tiles)
-        textureMapper.drawBorder(borderColor, borderWidth, tile.rect(), adjustedTransform);
+    for (auto& iterator : m_tiles)
+        textureMapper.drawBorder(borderColor, borderWidth, iterator.value->rect(), adjustedTransform);
 }
 
 void TextureMapperSparseBackingStore::drawRepaintCounter(TextureMapper& textureMapper, int repaintCount, const Color& borderColor, const FloatRect& targetRect, const TransformationMatrix& transform)
 {
     TransformationMatrix adjustedTransform = transform * adjustedTransformForRect(targetRect);
-    for (auto& tile : m_tiles)
-        textureMapper.drawNumber(repaintCount, borderColor, tile.rect().location(), adjustedTransform);
+    for (auto& iterator : m_tiles)
+        textureMapper.drawNumber(repaintCount, borderColor, iterator.value->rect().location(), adjustedTransform);
 }
 
-IntSize TextureMapperSparseBackingStore::tileDimension() const
+void TextureMapperSparseBackingStore::updateContents(TextureMapper& textureMapper, const TileIndex& index, Image& image, const IntRect& dirtyRect)
 {
-    return { (m_size.width() + m_tileSize - 1) / m_tileSize,  (m_size.height() + m_tileSize - 1) / m_tileSize };
+    auto addResult = m_tiles.ensure(index, [&]() {
+        return makeUnique<TextureMapperTile>(dirtyRect);
+    });
+    addResult.iterator->value->updateContents(textureMapper, &image, dirtyRect);
 }
 
-void TextureMapperSparseBackingStore::updateContents(TextureMapper& textureMapper, Image& image, const IntRect& dirtyRect)
+void TextureMapperSparseBackingStore::removeTile(const TileIndex& index)
 {
-    for (auto& tile : m_tiles)
-        tile.updateContents(textureMapper, &image, dirtyRect);
+    m_tiles.remove(index);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperSparseBackingStore.h (291047 => 291048)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperSparseBackingStore.h	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperSparseBackingStore.h	2022-03-09 14:30:14 UTC (rev 291048)
@@ -29,8 +29,10 @@
 
 #if USE(GRAPHICS_LAYER_WC)
 
+#include "IntPointHash.h"
 #include "TextureMapperBackingStore.h"
 #include "TextureMapperTile.h"
+#include <wtf/HashMap.h>
 
 namespace WebCore {
 
@@ -37,21 +39,20 @@
 class TextureMapperSparseBackingStore final : public TextureMapperBackingStore {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    TextureMapperSparseBackingStore(int tileSize);
+    using TileIndex = WebCore::IntPoint;
+
     void setSize(const IntSize&);
-    void removeUncoveredTiles(const IntRect& coverage);
     void paintToTextureMapper(TextureMapper&, const FloatRect&, const TransformationMatrix&, float) override;
     void drawBorder(TextureMapper&, const Color&, float borderWidth, const FloatRect&, const TransformationMatrix&) override;
     void drawRepaintCounter(TextureMapper&, int repaintCount, const Color&, const FloatRect&, const TransformationMatrix&) override;
-    void updateContents(TextureMapper&, Image&, const IntRect& dirtyRect);
+    void updateContents(TextureMapper&, const TileIndex&, Image&, const IntRect& dirtyRect);
+    void removeTile(const TileIndex&);
 
 private:
-    IntSize tileDimension() const;
     TransformationMatrix adjustedTransformForRect(const FloatRect&);
 
-    int m_tileSize;
-    Vector<TextureMapperTile> m_tiles;
     IntSize m_size;
+    HashMap<TileIndex, std::unique_ptr<TextureMapperTile>> m_tiles;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperTile.h (291047 => 291048)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperTile.h	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperTile.h	2022-03-09 14:30:14 UTC (rev 291048)
@@ -30,6 +30,7 @@
 class GraphicsLayer;
 
 class TextureMapperTile {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
     inline RefPtr<BitmapTexture> texture() const { return m_texture; }
     inline FloatRect rect() const { return m_rect; }

Modified: trunk/Source/WebKit/ChangeLog (291047 => 291048)


--- trunk/Source/WebKit/ChangeLog	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebKit/ChangeLog	2022-03-09 14:30:14 UTC (rev 291048)
@@ -1,3 +1,51 @@
+2022-03-09  Fujii Hironori  <[email protected]>
+
+        [WinCairo] Improve WCTiledBacking and TextureMapperSparseBackingStore
+        https://bugs.webkit.org/show_bug.cgi?id=237355
+
+        Reviewed by Don Olmstead.
+
+        TextureMapperSparseBackingStore simply had a Vector to have all
+        tiles. If a web page had a very large layer, the vector was
+        extended to be able to keep all tiles, and it performed poorly.
+        Use a HashMap to keep tiles only in the coverage rect.
+
+        GraphicsLayerWC had only one dirty rect, and created a
+        ImageBuffer for all tiles to update. Change it to have one dirty
+        rect for one tile, and create a ImageBuffer for every dirty tile.
+
+        * GPUProcess/graphics/wc/WCScene.cpp:
+        (WebKit::WCScene::update):
+        * PlatformWin.cmake:
+        * WebProcess/WebPage/wc/DrawingAreaWC.cpp:
+        (WebKit::flushLayerImageBuffers):
+        * WebProcess/WebPage/wc/GraphicsLayerWC.cpp:
+        (WebKit::GraphicsLayerWC::setSize):
+        (WebKit::GraphicsLayerWC::recursiveCommitChanges):
+        * WebProcess/WebPage/wc/WCTileGrid.cpp: Added.
+        (WebKit::WCTileGrid::Tile::Tile):
+        (WebKit::WCTileGrid::Tile::addDirtyRect):
+        (WebKit::WCTileGrid::Tile::clearDirtyRect):
+        (WebKit::WCTileGrid::Tile::hasDirtyRect const):
+        (WebKit::WCTileGrid::setSize):
+        (WebKit::WCTileGrid::tileRectFromPixelRect):
+        (WebKit::WCTileGrid::tileSizeFromPixelSize):
+        (WebKit::WCTileGrid::tilePixelSize const):
+        (WebKit::WCTileGrid::addDirtyRect):
+        (WebKit::WCTileGrid::clearDirtyRects):
+        (WebKit::WCTileGrid::ensureTile):
+        (WebKit::WCTileGrid::setCoverageRect):
+        * WebProcess/WebPage/wc/WCTileGrid.h: Added.
+        (WebKit::WCTileGrid::Tile::willRemove const):
+        (WebKit::WCTileGrid::Tile::setWillRemove):
+        (WebKit::WCTileGrid::Tile::dirtyRect):
+        (WebKit::WCTileGrid::tiles):
+        * WebProcess/WebPage/wc/WCUpateInfo.h:
+        (WebKit::WCTileUpdate::encode const):
+        (WebKit::WCTileUpdate::decode):
+        (WebKit::WCLayerUpateInfo::encode const):
+        (WebKit::WCLayerUpateInfo::decode):
+
 2022-03-09  Carlos Garcia Campos  <[email protected]>
 
         [GTK][WPE] Stop using the env var WEBKIT_INSPECTOR_SERVER to connect to the inspector

Modified: trunk/Source/WebKit/GPUProcess/graphics/wc/WCScene.cpp (291047 => 291048)


--- trunk/Source/WebKit/GPUProcess/graphics/wc/WCScene.cpp	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebKit/GPUProcess/graphics/wc/WCScene.cpp	2022-03-09 14:30:14 UTC (rev 291048)
@@ -53,7 +53,7 @@
     }
 
     WebCore::TextureMapperLayer texmapLayer;
-    std::optional<WebCore::TextureMapperSparseBackingStore> backingStore;
+    std::unique_ptr<WebCore::TextureMapperSparseBackingStore> backingStore;
     std::unique_ptr<WebCore::TextureMapperLayer> backdropLayer;
 };
 
@@ -127,8 +127,7 @@
         if (layerUpdate.changes & WCLayerChange::Background) {
             if (layerUpdate.hasBackingStore) {
                 if (!layer->backingStore) {
-                    const int tileSize = 512;
-                    layer->backingStore.emplace<WebCore::TextureMapperSparseBackingStore>(tileSize);
+                    layer->backingStore = makeUnique<WebCore::TextureMapperSparseBackingStore>();
                     auto& backingStore = *layer->backingStore;
                     layer->texmapLayer.setBackgroundColor({ });
                     layer->texmapLayer.setBackingStore(&backingStore);
@@ -135,16 +134,21 @@
                 }
                 auto& backingStore = *layer->backingStore;
                 backingStore.setSize(WebCore::IntSize(layer->texmapLayer.size()));
-                backingStore.removeUncoveredTiles(layerUpdate.coverageRect);
-                auto bitmap = layerUpdate.backingStore.bitmap();
-                if (bitmap) {
-                    auto image = bitmap->createImage();
-                    backingStore.updateContents(*m_textureMapper, *image, layerUpdate.dirtyRect);
+                for (auto& tileUpdate : layerUpdate.tileUpdate) {
+                    if (tileUpdate.willRemove)
+                        backingStore.removeTile(tileUpdate.index);
+                    else {
+                        auto bitmap = tileUpdate.backingStore.bitmap();
+                        if (bitmap) {
+                            auto image = bitmap->createImage();
+                            backingStore.updateContents(*m_textureMapper, tileUpdate.index, *image, tileUpdate.dirtyRect);
+                        }
+                    }
                 }
             } else {
                 layer->texmapLayer.setBackgroundColor(layerUpdate.backgroundColor);
                 layer->texmapLayer.setBackingStore(nullptr);
-                layer->backingStore = std::nullopt;
+                layer->backingStore = nullptr;
             }
         }
         if (layerUpdate.changes & WCLayerChange::SolidColor)

Modified: trunk/Source/WebKit/PlatformWin.cmake (291047 => 291048)


--- trunk/Source/WebKit/PlatformWin.cmake	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebKit/PlatformWin.cmake	2022-03-09 14:30:14 UTC (rev 291048)
@@ -105,6 +105,7 @@
     WebProcess/WebPage/wc/DrawingAreaWC.cpp
     WebProcess/WebPage/wc/GraphicsLayerWC.cpp
     WebProcess/WebPage/wc/WCLayerFactory.cpp
+    WebProcess/WebPage/wc/WCTileGrid.cpp
 
     WebProcess/WebPage/win/WebPageWin.cpp
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/wc/DrawingAreaWC.cpp (291047 => 291048)


--- trunk/Source/WebKit/WebProcess/WebPage/wc/DrawingAreaWC.cpp	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebKit/WebProcess/WebPage/wc/DrawingAreaWC.cpp	2022-03-09 14:30:14 UTC (rev 291048)
@@ -193,9 +193,11 @@
 {
     for (auto& layerInfo : info.changedLayers) {
         if (layerInfo.changes & WCLayerChange::Background) {
-            if (auto image = layerInfo.backingStore.imageBuffer()) {
-                if (auto flusher = image->createFlusher())
-                    flusher->flush();
+            for (auto& tileUpdate : layerInfo.tileUpdate) {
+                if (auto image = tileUpdate.backingStore.imageBuffer()) {
+                    if (auto flusher = image->createFlusher())
+                        flusher->flush();
+                }
             }
         }
     }

Modified: trunk/Source/WebKit/WebProcess/WebPage/wc/GraphicsLayerWC.cpp (291047 => 291048)


--- trunk/Source/WebKit/WebProcess/WebPage/wc/GraphicsLayerWC.cpp	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebKit/WebProcess/WebPage/wc/GraphicsLayerWC.cpp	2022-03-09 14:30:14 UTC (rev 291048)
@@ -28,6 +28,7 @@
 #include "GraphicsLayerWC.h"
 
 #include "WCPlatformLayerGCGL.h"
+#include "WCTileGrid.h"
 #include <WebCore/TransformState.h>
 
 namespace WebKit {
@@ -41,57 +42,55 @@
 
     bool paintAndFlush(WCLayerUpateInfo& update)
     {
-        update.dirtyRect = enclosingIntRect(m_dirtyRect);
-        update.coverageRect = m_coverageRect;
-        m_dirtyRect = { };
-        auto& imageRect = update.dirtyRect;
-        if (imageRect.isEmpty())
-            return false;
-        auto image = m_owner.createImageBuffer(imageRect.size());
-        auto& context = image->context();
-        context.translate(-imageRect.x(), -imageRect.y());
-        m_owner.paintGraphicsLayerContents(context, update.dirtyRect);
-        image->flushDrawingContextAsync();
-        update.backingStore.setImageBuffer(WTFMove(image));
-        return true;
+        bool repainted = false;
+        for (auto& entry : m_tileGrid.tiles()) {
+            auto& tile = *entry.value;
+            WCTileUpdate tileUpdate;
+            tileUpdate.index = entry.key;
+            tileUpdate.willRemove = tile.willRemove();
+            if (tileUpdate.willRemove) {
+                update.tileUpdate.append(WTFMove(tileUpdate));
+                continue;
+            }
+            if (!tile.hasDirtyRect())
+                continue;
+            repainted = true;
+            auto& dirtyRect = tile.dirtyRect();
+            tileUpdate.dirtyRect = dirtyRect;
+            auto image = m_owner.createImageBuffer(dirtyRect.size());
+            auto& context = image->context();
+            context.translate(-dirtyRect.x(), -dirtyRect.y());
+            m_owner.paintGraphicsLayerContents(context, dirtyRect);
+            image->flushDrawingContextAsync();
+            tileUpdate.backingStore.setImageBuffer(WTFMove(image));
+            update.tileUpdate.append(WTFMove(tileUpdate));
+        }
+        m_tileGrid.clearDirtyRects();
+        return repainted;
     }
 
+    void setSize(const FloatSize& size)
+    {
+        m_tileGrid.setSize(expandedIntSize(size));
+    }
+
     void setDirtyRect(const WebCore::FloatRect& rect)
     {
-        m_dirtyRect.unite(rect);
+        m_tileGrid.addDirtyRect(enclosingIntRect(rect));
     }
 
-    bool hasDirtyRect()
+    bool updateCoverageRect(const FloatRect& rect)
     {
-        return !m_dirtyRect.isEmpty();
+        return m_tileGrid.setCoverageRect(enclosingIntRect(rect));
     }
 
     TiledBacking* tiledBacking() const { return const_cast<WCTiledBacking*>(this); };
 
-    IntRect adjustCoverageRect(IntRect coverage)
-    {
-        int x = coverage.x() / tileSize().width() * tileSize().width();
-        int y = coverage.y() / tileSize().height() * tileSize().height();
-        int maxX = (coverage.maxX() + tileSize().width() - 1) / tileSize().width() * tileSize().width();
-        int maxY = (coverage.maxY() + tileSize().height() - 1) / tileSize().height() * tileSize().height();
-        IntRect newCoverage { x, y, maxX - x, maxY - y };
-        newCoverage.intersect(bounds());
-        return newCoverage;
-    }
-
     // TiledBacking override
     void setVisibleRect(const FloatRect&) final { }
     FloatRect visibleRect() const final { return { }; };
     void setLayoutViewportRect(std::optional<FloatRect>) final { }
-    void setCoverageRect(const FloatRect& rect) final
-    {
-        auto newCoverage = adjustCoverageRect(enclosingIntRect(rect));
-        WebCore::Region region(newCoverage);
-        region.subtract(m_coverageRect);
-        setDirtyRect(region.bounds());
-        m_coverageRect = newCoverage;
-        m_dirtyRect.intersect(m_coverageRect);
-    }
+    void setCoverageRect(const FloatRect& rect) final { }
     FloatRect coverageRect() const final { return { }; };
     bool tilesWouldChangeForCoverageRect(const FloatRect&) const final { return false; }
     void setTiledScrollingIndicatorPosition(const FloatPoint&) final { }
@@ -108,7 +107,7 @@
     FloatRect adjustTileCoverageRectForScrolling(const FloatRect& coverageRect, const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& currentVisibleRect, float contentsScale) final { return { }; };
     void willStartLiveResize() final { };
     void didEndLiveResize() final { };
-    IntSize tileSize() const final { return { 512, 512 }; };
+    IntSize tileSize() const final { return m_tileGrid.tilePixelSize(); }
     void revalidateTiles() final { }
     void forceRepaint() final { }
     IntRect tileGridExtent() const final { return { }; }
@@ -133,9 +132,8 @@
 
 private:
     bool m_isInWindow { false };
-    WebCore::IntRect m_coverageRect;
-    WebCore::FloatRect m_dirtyRect;
     GraphicsLayerWC& m_owner;
+    WCTileGrid m_tileGrid;
 };
 
 
@@ -282,6 +280,7 @@
     if (size == m_size)
         return;
     GraphicsLayer::setSize(size);
+    m_tiledBacking->setSize(size);
     noteLayerPropertyChanged(WCLayerChange::Geometry);
 }
 
@@ -695,8 +694,8 @@
 
     bool accumulateTransform = accumulatesTransform(*this);
     VisibleAndCoverageRects rects = computeVisibleAndCoverageRect(localState, accumulateTransform);
-    m_tiledBacking->setCoverageRect(rects.coverageRect);
-    if (m_tiledBacking->hasDirtyRect())
+    bool needsToPaint = m_tiledBacking->updateCoverageRect(rects.coverageRect);
+    if (needsToPaint)
         noteLayerPropertyChanged(WCLayerChange::Background, DontScheduleFlush);
 
     flushCompositingStateForThisLayerOnly();

Added: trunk/Source/WebKit/WebProcess/WebPage/wc/WCTileGrid.cpp (0 => 291048)


--- trunk/Source/WebKit/WebProcess/WebPage/wc/WCTileGrid.cpp	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/WebPage/wc/WCTileGrid.cpp	2022-03-09 14:30:14 UTC (rev 291048)
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2022 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WCTileGrid.h"
+
+namespace WebKit {
+
+WCTileGrid::Tile::Tile(WebCore::IntRect rect)
+    : m_tileRect(rect)
+    , m_dirtyRect(rect)
+{
+}
+
+void WCTileGrid::Tile::addDirtyRect(const WebCore::IntRect& dirtyRect)
+{
+    WebCore::IntRect rect { dirtyRect };
+    rect.intersect(m_tileRect);
+    m_dirtyRect.unite(rect);
+}
+
+void WCTileGrid::Tile::clearDirtyRect()
+{
+    m_dirtyRect = { };
+}
+
+bool WCTileGrid::Tile::hasDirtyRect() const
+{
+    return !m_dirtyRect.isEmpty();
+}
+
+void WCTileGrid::setSize(const WebCore::IntSize& size)
+{
+    m_size = size;
+    m_tiles.clear();
+}
+
+WebCore::IntRect WCTileGrid::tileRectFromPixelRect(const WebCore::IntRect& rect)
+{
+    int x = std::max(rect.x(), 0);
+    int y = std::max(rect.y(), 0);
+    int maxX = std::max(rect.maxX(), 0);
+    int maxY = std::max(rect.maxY(), 0);
+    x /= tilePixelSize().width();
+    y /= tilePixelSize().height();
+    maxX = (maxX + tilePixelSize().width() - 1) / tilePixelSize().width();
+    maxY = (maxY + tilePixelSize().height() - 1) / tilePixelSize().height();
+    return { x, y, maxX - x, maxY - y };
+}
+
+WebCore::IntSize WCTileGrid::tileSizeFromPixelSize(const WebCore::IntSize& size)
+{
+    int width = (size.width() + tilePixelSize().width() - 1) / tilePixelSize().width();
+    int height = (size.height() + tilePixelSize().height() - 1) / tilePixelSize().height();
+    return { width, height };
+}
+
+WebCore::IntSize WCTileGrid::tilePixelSize() const
+{
+    return { 512, 512 };
+}
+
+void WCTileGrid::addDirtyRect(const WebCore::IntRect& dirtyRect)
+{
+    for (auto& iterator : m_tiles)
+        iterator.value->addDirtyRect(dirtyRect);
+}
+
+void WCTileGrid::clearDirtyRects()
+{
+    m_tiles.removeIf([](auto& tile) {
+        return tile.value->willRemove();
+    });
+    for (auto& iterator : m_tiles)
+        iterator.value->clearDirtyRect();
+}
+
+bool WCTileGrid::ensureTile(TileIndex index)
+{
+    return m_tiles.ensure(index, [&]() {
+        int x1 = index.x() * tilePixelSize().width();
+        int y1 = index.y() * tilePixelSize().height();
+        int x2 = std::min(x1 + tilePixelSize().width(), m_size.width());
+        int y2 = std::min(y1 + tilePixelSize().height(), m_size.height());
+        WebCore::IntRect rect { x1, y1, x2 - x1, y2 - y1 };
+        ASSERT(WebCore::IntRect({ }, m_size).contains(rect));
+        return makeUnique<Tile>(rect);
+    }).isNewEntry;
+}
+
+bool WCTileGrid::setCoverageRect(const WebCore::IntRect& coverage)
+{
+    bool needsToPaint = false;
+    auto tileRect = tileRectFromPixelRect(coverage);
+
+    for (auto& iterator : m_tiles) {
+        if (!tileRect.contains(iterator.key))
+            iterator.value->setWillRemove(true);
+    }
+    for (int y = tileRect.y(); y < tileRect.maxY(); y++) {
+        for (int x = tileRect.x(); x < tileRect.maxX(); x++) {
+            if (ensureTile({ x, y }))
+                needsToPaint = true;
+        }
+    }
+    return needsToPaint;
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit/WebProcess/WebPage/wc/WCTileGrid.h (0 => 291048)


--- trunk/Source/WebKit/WebProcess/WebPage/wc/WCTileGrid.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/WebPage/wc/WCTileGrid.h	2022-03-09 14:30:14 UTC (rev 291048)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2022 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <WebCore/IntRect.h>
+#include <WebCore/TextureMapperSparseBackingStore.h>
+
+namespace WebKit {
+
+class WCTileGrid {
+public:
+    using TileIndex = WebCore::TextureMapperSparseBackingStore::TileIndex;
+
+    class Tile {
+        WTF_MAKE_FAST_ALLOCATED;
+        WTF_MAKE_NONCOPYABLE(Tile);
+    public:
+        Tile(WebCore::IntRect);
+        bool willRemove() const { return m_willRemove; }
+        void setWillRemove(bool v) { m_willRemove = v; }
+        void addDirtyRect(const WebCore::IntRect&);
+        void clearDirtyRect();
+        bool hasDirtyRect() const;
+        WebCore::IntRect& dirtyRect() { return m_dirtyRect; }
+
+    private:
+        bool m_willRemove { false };
+        WebCore::IntRect m_tileRect;
+        WebCore::IntRect m_dirtyRect;
+    };
+
+    void setSize(const WebCore::IntSize&);
+    void addDirtyRect(const WebCore::IntRect&);
+    void clearDirtyRects();
+    bool setCoverageRect(const WebCore::IntRect&);
+    auto& tiles() { return m_tiles; }
+    WebCore::IntSize tilePixelSize() const;
+
+private:
+    bool ensureTile(TileIndex);
+    WebCore::IntRect tileRectFromPixelRect(const WebCore::IntRect&);
+    WebCore::IntSize tileSizeFromPixelSize(const WebCore::IntSize&);
+    
+    WebCore::IntSize m_size;
+    HashMap<TileIndex, std::unique_ptr<Tile>> m_tiles;
+};
+
+} // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/WebPage/wc/WCUpateInfo.h (291047 => 291048)


--- trunk/Source/WebKit/WebProcess/WebPage/wc/WCUpateInfo.h	2022-03-09 13:44:20 UTC (rev 291047)
+++ trunk/Source/WebKit/WebProcess/WebPage/wc/WCUpateInfo.h	2022-03-09 14:30:14 UTC (rev 291048)
@@ -29,6 +29,7 @@
 #include "WCContentBufferIdentifier.h"
 #include "WebCoreArgumentCoders.h"
 #include <WebCore/GraphicsLayer.h>
+#include <WebCore/TextureMapperSparseBackingStore.h>
 #include <optional>
 #include <wtf/EnumTraits.h>
 #include <wtf/OptionSet.h>
@@ -35,6 +36,38 @@
 
 namespace WebKit {
 
+struct WCTileUpdate {
+    WebCore::TextureMapperSparseBackingStore::TileIndex index;
+    bool willRemove { false };
+    WCBackingStore backingStore;
+    WebCore::IntRect dirtyRect;
+
+    template<class Encoder>
+    void encode(Encoder& encoder) const
+    {
+        encoder << index << willRemove;
+        if (!willRemove)
+            encoder << backingStore << dirtyRect;
+    }
+
+    template <class Decoder>
+    static std::optional<WCTileUpdate> decode(Decoder& decoder)
+    {
+        WCTileUpdate result;
+        if (!decoder.decode(result.index))
+            return std::nullopt;
+        if (!decoder.decode(result.willRemove))
+            return std::nullopt;
+        if (!result.willRemove) {
+            if (!decoder.decode(result.backingStore))
+                return std::nullopt;
+            if (!decoder.decode(result.dirtyRect))
+                return std::nullopt;
+        }
+        return result;
+    }
+};
+
 enum class WCLayerChange : uint32_t {
     Children                = 1 <<  0,
     MaskLayer               = 1 <<  1,
@@ -83,9 +116,6 @@
     float debugBorderWidth;
     int repaintCount;
     WebCore::FloatRect contentsRect;
-    WCBackingStore backingStore;
-    WebCore::IntRect dirtyRect;
-    WebCore::IntRect coverageRect;
     WebCore::TransformationMatrix transform;
     WebCore::TransformationMatrix childrenTransform;
     WebCore::FilterOperations filters;
@@ -92,6 +122,7 @@
     WebCore::FilterOperations backdropFilters;
     WebCore::FloatRoundedRect backdropFiltersRect;
     WebCore::FloatRoundedRect contentsClippingRect;
+    Vector<WCTileUpdate> tileUpdate;
     Vector<WCContentBufferIdentifier> contentBufferIdentifiers;
 
     template<class Encoder>
@@ -128,7 +159,7 @@
         if (changes & WCLayerChange::Opacity)
             encoder << opacity;
         if (changes & WCLayerChange::Background)
-            encoder << backgroundColor << hasBackingStore << backingStore << dirtyRect << coverageRect;
+            encoder << backgroundColor << hasBackingStore << tileUpdate;
         if (changes & WCLayerChange::Transform)
             encoder << transform;
         if (changes & WCLayerChange::ChildrenTransform)
@@ -221,12 +252,8 @@
                 return false;
             if (!decoder.decode(result.hasBackingStore))
                 return false;
-            if (!decoder.decode(result.backingStore))
+            if (!decoder.decode(result.tileUpdate))
                 return false;
-            if (!decoder.decode(result.dirtyRect))
-                return false;
-            if (!decoder.decode(result.coverageRect))
-                return false;
         }
         if (result.changes & WCLayerChange::Transform) {
             if (!decoder.decode(result.transform))
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to