Title: [103114] trunk/Source
Revision
103114
Author
ander...@apple.com
Date
2011-12-16 15:05:23 -0800 (Fri, 16 Dec 2011)

Log Message

Add a pretty dumb tile cache to WebTileCacheLayer
https://bugs.webkit.org/show_bug.cgi?id=74753

Reviewed by Simon Fraser.

Source/WebCore:

* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::requiresTiledLayer):
If a layer is a tile cache layer, we never want to swap it out for a tiled layer.

(WebCore::GraphicsLayerCA::swapFromOrToTiledLayer):
Assert that we don't have a tile cache layer.

* platform/graphics/ca/mac/PlatformCALayerMac.mm:
(PlatformCALayer::PlatformCALayer):
If we have a tile cache layer, add its tile container to the list of custom sublayers.

* platform/graphics/ca/mac/TileCache.h: Added.
(WebCore::TileCache::tileContainerLayer):
Return the tile container layer.

* platform/graphics/ca/mac/TileCache.mm: Added.
(WebCore::TileCache::tileCacheLayerBoundsChanged):
Resize the tile grid if necessary.

(WebCore::TileCache::setNeedsDisplayInRect):
Invalidate the necessary tiles.

(WebCore::TileCache::drawLayer):
Set up the transform and draw the layer.

(WebCore::TileCache::getTileRangeForRect):
Given a rect, return the range of tiles that it covers.

(WebCore::TileCache::numTilesForGridSize):
Given a size, return how many tiles are needed to completely cover it.

(WebCore::TileCache::resizeTileGrid):
Create new tile layers if needed, or reuse already existing ones.

(WebCore::TileCache::tileLayerAtPosition):
Given a position in the grid, return the tile layer.

(WebCore::TileCache::createTileLayer):
Create a WebTileLayer and set it up.

* platform/graphics/ca/mac/WebTileCacheLayer.h:
* platform/graphics/ca/mac/WebTileCacheLayer.mm:
(-[WebTileCacheLayer setBounds:]):
(-[WebTileCacheLayer setNeedsDisplayInRect:]):
(-[WebTileCacheLayer tileContainerLayer]):
Call down to the tile cache object.

* platform/graphics/ca/mac/WebTileLayer.h: Added.
* platform/graphics/ca/mac/WebTileLayer.mm: Added.

(-[WebTileLayer drawInContext:]):
Ask the tile cache to draw the given layer.

(-[WebTileLayer setTileCache:WebCore::]):

Source/WebKit2:

* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::flushLayers):
Always do a layout here, to prevent an ASSERT(!needsLayout()) when painting.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (103113 => 103114)


--- trunk/Source/WebCore/ChangeLog	2011-12-16 22:54:29 UTC (rev 103113)
+++ trunk/Source/WebCore/ChangeLog	2011-12-16 23:05:23 UTC (rev 103114)
@@ -1,3 +1,66 @@
+2011-12-16  Anders Carlsson  <ander...@apple.com>
+
+        Add a pretty dumb tile cache to WebTileCacheLayer
+        https://bugs.webkit.org/show_bug.cgi?id=74753
+
+        Reviewed by Simon Fraser.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::requiresTiledLayer):
+        If a layer is a tile cache layer, we never want to swap it out for a tiled layer.
+
+        (WebCore::GraphicsLayerCA::swapFromOrToTiledLayer):
+        Assert that we don't have a tile cache layer.
+
+        * platform/graphics/ca/mac/PlatformCALayerMac.mm:
+        (PlatformCALayer::PlatformCALayer):
+        If we have a tile cache layer, add its tile container to the list of custom sublayers.
+
+        * platform/graphics/ca/mac/TileCache.h: Added.
+        (WebCore::TileCache::tileContainerLayer):
+        Return the tile container layer.
+
+        * platform/graphics/ca/mac/TileCache.mm: Added.
+        (WebCore::TileCache::tileCacheLayerBoundsChanged):
+        Resize the tile grid if necessary.
+
+        (WebCore::TileCache::setNeedsDisplayInRect):
+        Invalidate the necessary tiles.
+
+        (WebCore::TileCache::drawLayer):
+        Set up the transform and draw the layer.
+
+        (WebCore::TileCache::getTileRangeForRect):
+        Given a rect, return the range of tiles that it covers.
+
+        (WebCore::TileCache::numTilesForGridSize):
+        Given a size, return how many tiles are needed to completely cover it.
+
+        (WebCore::TileCache::resizeTileGrid):
+        Create new tile layers if needed, or reuse already existing ones.
+
+        (WebCore::TileCache::tileLayerAtPosition):
+        Given a position in the grid, return the tile layer.
+
+        (WebCore::TileCache::createTileLayer):
+        Create a WebTileLayer and set it up.
+
+        * platform/graphics/ca/mac/WebTileCacheLayer.h:
+        * platform/graphics/ca/mac/WebTileCacheLayer.mm:
+        (-[WebTileCacheLayer setBounds:]):
+        (-[WebTileCacheLayer setNeedsDisplayInRect:]):
+        (-[WebTileCacheLayer tileContainerLayer]):
+        Call down to the tile cache object.
+
+        * platform/graphics/ca/mac/WebTileLayer.h: Added.
+        * platform/graphics/ca/mac/WebTileLayer.mm: Added.
+
+        (-[WebTileLayer drawInContext:]):
+        Ask the tile cache to draw the given layer.
+
+        (-[WebTileLayer setTileCache:WebCore::]):
+
 2011-12-16  Sam Weinig  <s...@webkit.org>
 
         Give PlatformEvents a base class

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (103113 => 103114)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-12-16 22:54:29 UTC (rev 103113)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-12-16 23:05:23 UTC (rev 103114)
@@ -477,6 +477,9 @@
 		1A927FD31416A15B003A83C8 /* npruntime.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A927FD01416A15B003A83C8 /* npruntime.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1A927FD41416A15B003A83C8 /* nptypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A927FD11416A15B003A83C8 /* nptypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1A98956B0AA78F80005EF5EF /* KURLCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */; };
+		1AA7160A149BC4DB0016EC19 /* TileCache.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AA71608149BC4DA0016EC19 /* TileCache.mm */; };
+		1AA7160B149BC4DB0016EC19 /* TileCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA71609149BC4DB0016EC19 /* TileCache.h */; };
+		1AA7161E149BF2FA0016EC19 /* WebTileLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AA7161C149BF2FA0016EC19 /* WebTileLayer.mm */; };
 		1AA84F04143BA7BD0051D153 /* ScrollElasticityController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AA84F02143BA7BD0051D153 /* ScrollElasticityController.mm */; };
 		1AA84F05143BA7BD0051D153 /* ScrollElasticityController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA84F03143BA7BD0051D153 /* ScrollElasticityController.h */; };
 		1AA8799011CBE846003C664F /* PluginStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AA8798F11CBE846003C664F /* PluginStrategy.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -7610,6 +7613,10 @@
 		1A927FD01416A15B003A83C8 /* npruntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = npruntime.h; sourceTree = "<group>"; };
 		1A927FD11416A15B003A83C8 /* nptypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nptypes.h; sourceTree = "<group>"; };
 		1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = KURLCFNet.cpp; sourceTree = "<group>"; };
+		1AA71608149BC4DA0016EC19 /* TileCache.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TileCache.mm; path = ca/mac/TileCache.mm; sourceTree = "<group>"; };
+		1AA71609149BC4DB0016EC19 /* TileCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TileCache.h; path = ca/mac/TileCache.h; sourceTree = "<group>"; };
+		1AA7161C149BF2FA0016EC19 /* WebTileLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebTileLayer.mm; path = ca/mac/WebTileLayer.mm; sourceTree = "<group>"; };
+		1AA71625149BFFB20016EC19 /* WebTileLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebTileLayer.h; path = ca/mac/WebTileLayer.h; sourceTree = "<group>"; };
 		1AA84F02143BA7BD0051D153 /* ScrollElasticityController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollElasticityController.mm; sourceTree = "<group>"; };
 		1AA84F03143BA7BD0051D153 /* ScrollElasticityController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollElasticityController.h; sourceTree = "<group>"; };
 		1AA8798F11CBE846003C664F /* PluginStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginStrategy.h; sourceTree = "<group>"; };
@@ -15078,8 +15085,12 @@
 				2917B565147349950052C9D0 /* LayerFlushSchedulerMac.cpp */,
 				4958781F12A57DDF007238AC /* PlatformCAAnimationMac.mm */,
 				4958782012A57DDF007238AC /* PlatformCALayerMac.mm */,
+				1AA71609149BC4DB0016EC19 /* TileCache.h */,
+				1AA71608149BC4DA0016EC19 /* TileCache.mm */,
 				0F580FA11496939100FB5BD8 /* WebTileCacheLayer.h */,
 				0F580FA21496939100FB5BD8 /* WebTileCacheLayer.mm */,
+				1AA71625149BFFB20016EC19 /* WebTileLayer.h */,
+				1AA7161C149BF2FA0016EC19 /* WebTileLayer.mm */,
 			);
 			name = mac;
 			sourceTree = "<group>";
@@ -24893,6 +24904,7 @@
 				49ECEB6A1499790D00CDD3A4 /* FEGaussianBlurNEON.h in Headers */,
 				49ECEB6C1499790D00CDD3A4 /* FELightingNEON.h in Headers */,
 				1A2F9D7A14968C740065AC63 /* ScrollingCoordinator.h in Headers */,
+				1AA7160B149BC4DB0016EC19 /* TileCache.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -27788,6 +27800,8 @@
 				49ECEB6D1499790D00CDD3A4 /* FilterOperation.cpp in Sources */,
 				49ECEB6F1499790D00CDD3A4 /* FilterOperations.cpp in Sources */,
 				1A2F9D7914968C740065AC63 /* ScrollingCoordinator.cpp in Sources */,
+				1AA7160A149BC4DB0016EC19 /* TileCache.mm in Sources */,
+				1AA7161E149BF2FA0016EC19 /* WebTileLayer.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp (103113 => 103114)


--- trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp	2011-12-16 22:54:29 UTC (rev 103113)
+++ trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp	2011-12-16 23:05:23 UTC (rev 103114)
@@ -2138,7 +2138,7 @@
 
 bool GraphicsLayerCA::requiresTiledLayer(float pageScaleFactor) const
 {
-    if (!m_drawsContent || !m_allowTiledLayer)
+    if (!m_drawsContent || !m_allowTiledLayer || m_layer->layerType() == PlatformCALayer::LayerTypeTileCacheLayer)
         return false;
 
     float contentsScale = pageScaleFactor * deviceScaleFactor();
@@ -2149,6 +2149,7 @@
 
 void GraphicsLayerCA::swapFromOrToTiledLayer(bool useTiledLayer, float pageScaleFactor, const FloatPoint& positionRelativeToBase)
 {
+    ASSERT(m_layer->layerType() != PlatformCALayer::LayerTypeTileCacheLayer);
     ASSERT(useTiledLayer != m_usingTiledLayer);
     RefPtr<PlatformCALayer> oldLayer = m_layer;
     

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm (103113 => 103114)


--- trunk/Source/WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm	2011-12-16 22:54:29 UTC (rev 103113)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm	2011-12-16 23:05:23 UTC (rev 103114)
@@ -217,10 +217,9 @@
     }
     
     if (m_layerType == LayerTypeTileCacheLayer) {
-        // FIXME: hook this up to the tile cache.
-//        m_customSublayers = adoptPtr(new PlatformCALayerList(1));
-//        CALayer* tileCacheTileContainerLayer = [static_cast<WebTileCacheLayer *>(m_layer.get()) tileContainerLayer];
-//        m_customSublayers->append(PlatformCALayer::create(tileCacheTileContainerLayer, 0));
+        m_customSublayers = adoptPtr(new PlatformCALayerList(1));
+        CALayer* tileCacheTileContainerLayer = [static_cast<WebTileCacheLayer *>(m_layer.get()) tileContainerLayer];
+        (*m_customSublayers)[0] = PlatformCALayer::create(tileCacheTileContainerLayer, 0);
     }
     
     END_BLOCK_OBJC_EXCEPTIONS

Added: trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.h (0 => 103114)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.h	2011-12-16 23:05:23 UTC (rev 103114)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#ifndef TileCache_h
+#define TileCache_h
+
+#include "IntSize.h"
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/RetainPtr.h>
+
+#ifdef __OBJC__
+@class CALayer;
+@class WebTileCacheLayer;
+@class WebTileLayer;
+#else
+class CALayer;
+class WebTileCacheLayer;
+class WebTileLayer;
+#endif
+
+namespace WebCore {
+
+class IntPoint;
+class IntRect;
+
+class TileCache {
+    WTF_MAKE_NONCOPYABLE(TileCache);
+
+public:
+    static PassOwnPtr<TileCache> create(WebTileCacheLayer*, const IntSize& tileSize);
+
+    void tileCacheLayerBoundsChanged();
+    void setNeedsDisplayInRect(const IntRect&);
+    void drawLayer(WebTileLayer*, CGContextRef);
+
+    CALayer *tileContainerLayer() const { return m_tileContainerLayer.get(); }
+
+private:
+    TileCache(WebTileCacheLayer*, const IntSize& tileSize);
+
+    IntRect bounds() const;
+    void getTileRangeForRect(const IntRect&, IntPoint& topLeft, IntPoint& bottomRight);
+
+    IntSize numTilesForGridSize(const IntSize&) const;
+    void resizeTileGrid(const IntSize& numTiles);
+
+    WebTileLayer* tileLayerAtPosition(const IntPoint&) const;
+    RetainPtr<WebTileLayer> createTileLayer();
+
+    WebTileCacheLayer* m_tileCacheLayer;
+    const IntSize m_tileSize;
+
+    RetainPtr<CALayer> m_tileContainerLayer;
+
+    // Number of tiles in each dimension.
+    IntSize m_numTilesInGrid;
+};
+
+} // namespace WebCore
+
+#endif // TileCache_h

Added: trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.mm (0 => 103114)


--- trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/TileCache.mm	2011-12-16 23:05:23 UTC (rev 103114)
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#import "config.h"
+#import "TileCache.h"
+
+#import "IntRect.h"
+#import "PlatformCALayer.h"
+#import "WebLayer.h"
+#import "WebTileCacheLayer.h"
+#import "WebTileLayer.h"
+#import <utility>
+
+using namespace std;
+
+namespace WebCore {
+
+PassOwnPtr<TileCache> TileCache::create(WebTileCacheLayer* tileCacheLayer, const IntSize& tileSize)
+{
+    return adoptPtr(new TileCache(tileCacheLayer, tileSize));
+}
+
+TileCache::TileCache(WebTileCacheLayer* tileCacheLayer, const IntSize& tileSize)
+    : m_tileCacheLayer(tileCacheLayer)
+    , m_tileSize(tileSize)
+    , m_tileContainerLayer(adoptCF([[CALayer alloc] init]))
+{
+    [CATransaction begin];
+    [CATransaction setDisableActions:YES];
+    [m_tileCacheLayer addSublayer:m_tileContainerLayer.get()];
+    [CATransaction commit];
+}
+
+void TileCache::tileCacheLayerBoundsChanged()
+{
+    IntSize numTilesInGrid = numTilesForGridSize(bounds().size());
+    if (numTilesInGrid == m_numTilesInGrid)
+        return;
+
+    resizeTileGrid(numTilesInGrid);
+}
+
+void TileCache::setNeedsDisplayInRect(const IntRect& rect)
+{
+    if (m_numTilesInGrid.isZero())
+        return;
+
+    // Find the tiles that need to be invalidated.
+    IntPoint topLeft;
+    IntPoint bottomRight;
+    getTileRangeForRect(rect, topLeft, bottomRight);
+
+    for (int y = topLeft.y(); y <= bottomRight.y(); ++y) {
+        for (int x = topLeft.x(); x <= bottomRight.x(); ++x) {
+            WebTileLayer* tileLayer = tileLayerAtPosition(IntPoint(x, y));
+
+            CGRect tileRect = [m_tileCacheLayer convertRect:rect toLayer:tileLayer];
+
+            if (!CGRectIsEmpty(tileRect))
+                [tileLayer setNeedsDisplayInRect:tileRect];
+        }
+    }
+}
+
+void TileCache::drawLayer(WebTileLayer* layer, CGContextRef context)
+{
+    PlatformCALayer* platformLayer = PlatformCALayer::platformCALayer(m_tileCacheLayer);
+    if (!platformLayer)
+        return;
+
+    CGContextSaveGState(context);
+
+    CGPoint layerOrigin = [layer frame].origin;
+    CGContextTranslateCTM(context, -layerOrigin.x, -layerOrigin.y);
+    drawLayerContents(context, layer, platformLayer);
+
+    CGContextRestoreGState(context);
+}
+
+IntRect TileCache::bounds() const
+{
+    return IntRect(IntPoint(), IntSize([m_tileCacheLayer bounds].size));
+}
+
+void TileCache::getTileRangeForRect(const IntRect& rect, IntPoint& topLeft, IntPoint& bottomRight)
+{
+    topLeft.setX(max(rect.x() / m_tileSize.width(), 0));
+    topLeft.setY(max(rect.y() / m_tileSize.height(), 0));
+    bottomRight.setX(min(rect.maxX() / m_tileSize.width(), m_numTilesInGrid.width() - 1));
+    bottomRight.setY(min(rect.maxY() / m_tileSize.height(), m_numTilesInGrid.height() - 1));
+}
+
+IntSize TileCache::numTilesForGridSize(const IntSize& gridSize) const
+{
+    int numXTiles = ceil(static_cast<double>(gridSize.width()) / m_tileSize.width());
+    int numYTiles = ceil(static_cast<double>(gridSize.height()) / m_tileSize.height());
+
+    return IntSize(numXTiles, numYTiles);
+}
+
+void TileCache::resizeTileGrid(const IntSize& numTilesInGrid)
+{
+    [CATransaction begin];
+    [CATransaction setDisableActions:YES];
+
+    RetainPtr<NSMutableArray> newSublayers = adoptNS([[NSMutableArray alloc] initWithCapacity:numTilesInGrid.width() * numTilesInGrid.height()]);
+
+    for (int y = 0; y < numTilesInGrid.height(); ++y) {
+        for (int x = 0; x < numTilesInGrid.width(); ++x) {
+            RetainPtr<WebTileLayer> tileLayer;
+
+            if (x < m_numTilesInGrid.width() && y < m_numTilesInGrid.height()) {
+                // We can reuse the tile layer at this position.
+                tileLayer = tileLayerAtPosition(IntPoint(x, y));
+            } else {
+                tileLayer = createTileLayer();
+            }
+
+            [tileLayer.get() setPosition:CGPointMake(x * m_tileSize.width(), y * m_tileSize.height())];
+            [newSublayers.get() addObject:tileLayer.get()];
+        }
+    }
+
+    // FIXME: Make sure to call setTileCache:0 on the layers that get thrown away here.
+    [m_tileContainerLayer.get() setSublayers:newSublayers.get()];
+    m_numTilesInGrid = numTilesInGrid;
+
+    [CATransaction commit];
+}
+
+WebTileLayer* TileCache::tileLayerAtPosition(const IntPoint& point) const
+{
+    ASSERT(point.x() >= 0);
+    ASSERT(point.x() <= m_numTilesInGrid.width());
+    ASSERT(point.y() >= 0);
+    ASSERT(point.y() <= m_numTilesInGrid.height());
+
+    return [[m_tileContainerLayer.get() sublayers] objectAtIndex:point.y() * m_numTilesInGrid.width() + point.x()];
+}
+
+RetainPtr<WebTileLayer> TileCache::createTileLayer()
+{
+    RetainPtr<WebTileLayer> layer = adoptNS([[WebTileLayer alloc] init]);
+    [layer.get() setBounds:CGRectMake(0, 0, m_tileSize.width(), m_tileSize.height())];
+    [layer.get() setAnchorPoint:CGPointZero];
+    [layer.get() setTileCache:this];
+
+    return layer;
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/WebTileCacheLayer.h (103113 => 103114)


--- trunk/Source/WebCore/platform/graphics/ca/mac/WebTileCacheLayer.h	2011-12-16 22:54:29 UTC (rev 103113)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/WebTileCacheLayer.h	2011-12-16 23:05:23 UTC (rev 103114)
@@ -23,8 +23,16 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#import "WebTiledLayer.h"
+#import <QuartzCore/QuartzCore.h>
+#import <wtf/OwnPtr.h>
 
-@interface WebTileCacheLayer : WebTiledLayer
+namespace WebCore {
+    class TileCache;
+}
 
+@interface WebTileCacheLayer : CALayer {
+    OwnPtr<WebCore::TileCache> _tileCache;
+}
+
+- (CALayer *)tileContainerLayer;
 @end

Modified: trunk/Source/WebCore/platform/graphics/ca/mac/WebTileCacheLayer.mm (103113 => 103114)


--- trunk/Source/WebCore/platform/graphics/ca/mac/WebTileCacheLayer.mm	2011-12-16 22:54:29 UTC (rev 103113)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/WebTileCacheLayer.mm	2011-12-16 23:05:23 UTC (rev 103114)
@@ -24,10 +24,42 @@
  */
 
 #import "config.h"
-
 #import "WebTileCacheLayer.h"
 
+#import "IntRect.h"
+#import "TileCache.h"
+
+using namespace WebCore;
+
 @implementation WebTileCacheLayer
 
+- (id)init
+{
+    self = [super init];
+    if (!self)
+        return nil;
 
+    // FIXME: The tile size should be configurable.
+    _tileCache = TileCache::create(self, IntSize(512, 512));
+
+    return self;
+}
+
+- (void)setBounds:(CGRect)bounds
+{
+    [super setBounds:bounds];
+
+    _tileCache->tileCacheLayerBoundsChanged();
+}
+
+- (void)setNeedsDisplayInRect:(CGRect)rect
+{
+    _tileCache->setNeedsDisplayInRect(enclosingIntRect(rect));
+}
+
+- (CALayer *)tileContainerLayer
+{
+    return _tileCache->tileContainerLayer();
+}
+
 @end

Added: trunk/Source/WebCore/platform/graphics/ca/mac/WebTileLayer.h (0 => 103114)


--- trunk/Source/WebCore/platform/graphics/ca/mac/WebTileLayer.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/WebTileLayer.h	2011-12-16 23:05:23 UTC (rev 103114)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#ifndef WebTileLayer_h
+#define WebTileLayer_h
+
+namespace WebCore {
+    class TileCache;
+}
+
+@interface WebTileLayer : CALayer {
+    WebCore::TileCache* _tileCache;
+}
+- (void)setTileCache:(WebCore::TileCache*)tileCache;
+@end
+
+
+#endif // WebTileLayer_h

Added: trunk/Source/WebCore/platform/graphics/ca/mac/WebTileLayer.mm (0 => 103114)


--- trunk/Source/WebCore/platform/graphics/ca/mac/WebTileLayer.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ca/mac/WebTileLayer.mm	2011-12-16 23:05:23 UTC (rev 103114)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#import "config.h"
+#import "WebTileLayer.h"
+
+#import "TileCache.h"
+#import <wtf/UnusedParam.h>
+
+using namespace WebCore;
+
+@implementation WebTileLayer
+
+- (id<CAAction>)actionForKey:(NSString *)key
+{
+    UNUSED_PARAM(key);
+    
+    // Disable all animations.
+    return nil;
+}
+
+- (void)drawInContext:(CGContextRef)context
+{
+    if (_tileCache)
+        _tileCache->drawLayer(self, context);
+}
+
+- (void)setTileCache:(WebCore::TileCache*)tileCache
+{
+    _tileCache = tileCache;
+}
+
+@end
+

Modified: trunk/Source/WebKit2/ChangeLog (103113 => 103114)


--- trunk/Source/WebKit2/ChangeLog	2011-12-16 22:54:29 UTC (rev 103113)
+++ trunk/Source/WebKit2/ChangeLog	2011-12-16 23:05:23 UTC (rev 103114)
@@ -1,3 +1,24 @@
+2011-12-16  Anders Carlsson  <ander...@apple.com>
+
+        Add a pretty dumb tile cache to WebTileCacheLayer
+        https://bugs.webkit.org/show_bug.cgi?id=74753
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+        (WebKit::TiledCoreAnimationDrawingArea::flushLayers):
+        Always do a layout here, to prevent an ASSERT(!needsLayout()) when painting.
+
+2011-12-16  Anders Carlsson  <ander...@apple.com>
+
+        TiledCoreAnimationDrawingArea should enable the scrolling coordinator
+        https://bugs.webkit.org/show_bug.cgi?id=74724
+
+        Reviewed by Adam Roben.
+
+        * WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
+        (WebKit::TiledCoreAnimationDrawingArea::TiledCoreAnimationDrawingArea):
+
 2011-12-16  Sam Weinig  <s...@webkit.org>
 
         Give PlatformEvents a base class

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm (103113 => 103114)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm	2011-12-16 22:54:29 UTC (rev 103113)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm	2011-12-16 23:05:23 UTC (rev 103114)
@@ -56,9 +56,15 @@
     : DrawingArea(DrawingAreaTypeTiledCoreAnimation, webPage)
     , m_layerFlushScheduler(this)
 {
+    Page* page = webPage->corePage();
+
     // FIXME: It's weird that we're mucking around with the settings here.
-    webPage->corePage()->settings()->setForceCompositingMode(true);
+    page->settings()->setForceCompositingMode(true);
 
+#if ENABLE(THREADED_SCROLLING)
+    page->settings()->setScrollingCoordinatorEnabled(true);
+#endif
+
     m_rootLayer = [CALayer layer];
 
     CGRect rootLayerFrame = m_webPage->bounds();
@@ -112,6 +118,8 @@
     // This gets called outside of the normal event loop so wrap in an autorelease pool
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
+    m_webPage->layoutIfNeeded();
+
     bool returnValue = m_webPage->corePage()->mainFrame()->view()->syncCompositingStateIncludingSubframes();
 
     [pool drain];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to