Show repaint counters in individual tiles
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jan 2012 02:04:09 +0000 (02:04 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jan 2012 02:04:09 +0000 (02:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77390
<rdar://problem/10767967>

Reviewed by Darin Adler.

* platform/graphics/ca/mac/TileCache.h:
* platform/graphics/ca/mac/TileCache.mm:
(WebCore::TileCache::setNeedsDisplayInRect):
Make sure to invalidate the repaint counter rect if necessary.

(WebCore::TileCache::drawLayer):
Draw the repaint counter.

(WebCore::TileCache::showRepaintCounter):
New function that determines whether we should show repaint counters for the given tile cache.

* platform/graphics/ca/mac/WebTileLayer.h:
* platform/graphics/ca/mac/WebTileLayer.mm:
(-[WebTileLayer incrementRepaintCount]):
Add method for getting the repaint count.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@106311 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ca/mac/TileCache.h
Source/WebCore/platform/graphics/ca/mac/TileCache.mm
Source/WebCore/platform/graphics/ca/mac/WebTileLayer.h
Source/WebCore/platform/graphics/ca/mac/WebTileLayer.mm

index 6a9e4f582917bab91467784c6141661d2d094703..94752f9f85abecb08ac18c51b78241e3044acdf7 100644 (file)
@@ -1,3 +1,27 @@
+2012-01-30  Anders Carlsson  <andersca@apple.com>
+
+        Show repaint counters in individual tiles
+        https://bugs.webkit.org/show_bug.cgi?id=77390
+        <rdar://problem/10767967>
+
+        Reviewed by Darin Adler.
+
+        * platform/graphics/ca/mac/TileCache.h:
+        * platform/graphics/ca/mac/TileCache.mm:
+        (WebCore::TileCache::setNeedsDisplayInRect):
+        Make sure to invalidate the repaint counter rect if necessary.
+
+        (WebCore::TileCache::drawLayer):
+        Draw the repaint counter.
+
+        (WebCore::TileCache::showRepaintCounter):
+        New function that determines whether we should show repaint counters for the given tile cache.
+
+        * platform/graphics/ca/mac/WebTileLayer.h:
+        * platform/graphics/ca/mac/WebTileLayer.mm:
+        (-[WebTileLayer incrementRepaintCount]):
+        Add method for getting the repaint count.
+
 2012-01-30  Dan Bernstein  <mitz@apple.com>
 
         <rdar://problem/10778045> REGRESSION (r91935): text-combine fails
index 4003d7e89c92bb8eb6f9f44e3877e5520b0c285a..ef29c5efa923d228c172f104098db52da00eca77 100644 (file)
@@ -75,6 +75,8 @@ private:
     WebTileLayer* tileLayerAtPosition(const IntPoint&) const;
     RetainPtr<WebTileLayer> createTileLayer();
 
+    bool shouldShowRepaintCounters() const;
+
     WebTileCacheLayer* m_tileCacheLayer;
     const IntSize m_tileSize;
 
index 5e610dea3d9025fa2ec8cf33d9dbe47f4773f0e3..075211d9ca0a76488328ea831f1a5f9d245bdd15 100644 (file)
@@ -91,8 +91,15 @@ void TileCache::setNeedsDisplayInRect(const IntRect& rect)
 
             CGRect tileRect = [m_tileCacheLayer convertRect:rect toLayer:tileLayer];
 
-            if (!CGRectIsEmpty(tileRect))
+            if (!CGRectIsEmpty(tileRect)) {
                 [tileLayer setNeedsDisplayInRect:tileRect];
+
+                if (shouldShowRepaintCounters()) {
+                    CGRect bounds = [tileLayer bounds];
+                    CGRect indicatorRect = CGRectMake(bounds.origin.x, bounds.origin.y, 52, 27);
+                    [tileLayer setNeedsDisplayInRect:indicatorRect];
+                }
+            }
         }
     }
 }
@@ -110,6 +117,37 @@ void TileCache::drawLayer(WebTileLayer* layer, CGContextRef context)
     drawLayerContents(context, layer, platformLayer);
 
     CGContextRestoreGState(context);
+
+    unsigned repaintCount = [layer incrementRepaintCount];
+    if (!shouldShowRepaintCounters())
+        return;
+
+    // FIXME: Some of this code could be shared with WebLayer.
+    char text[16]; // that's a lot of repaints
+    snprintf(text, sizeof(text), "%d", repaintCount);
+
+    CGRect indicatorBox = [layer bounds];
+    indicatorBox.size.width = 12 + 10 * strlen(text);
+    indicatorBox.size.height = 27;
+    CGContextSaveGState(context);
+
+    CGContextSetAlpha(context, 0.5f);
+    CGContextBeginTransparencyLayerWithRect(context, indicatorBox, 0);
+
+    CGContextSetFillColorWithColor(context, m_tileDebugBorderColor.get());
+    CGContextFillRect(context, indicatorBox);
+
+    if (platformLayer->acceleratesDrawing())
+        CGContextSetRGBFillColor(context, 1, 0, 0, 1);
+    else
+        CGContextSetRGBFillColor(context, 1, 1, 1, 1);
+
+    CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1, -1));
+    CGContextSelectFont(context, "Helvetica", 22, kCGEncodingMacRoman);
+    CGContextShowTextAtPoint(context, indicatorBox.origin.x + 5, indicatorBox.origin.y + 22, text, strlen(text));
+
+    CGContextEndTransparencyLayer(context);
+    CGContextRestoreGState(context);
 }
 
 void TileCache::setAcceleratesDrawing(bool acceleratesDrawing)
@@ -224,4 +262,18 @@ RetainPtr<WebTileLayer> TileCache::createTileLayer()
     return layer;
 }
 
+bool TileCache::shouldShowRepaintCounters() const
+{
+    PlatformCALayer* platformLayer = PlatformCALayer::platformCALayer(m_tileCacheLayer);
+    if (!platformLayer)
+        return false;
+
+    WebCore::PlatformCALayerClient* layerContents = platformLayer->owner();
+    ASSERT(layerContents);
+    if (!layerContents)
+        return false;
+
+    return layerContents->platformCALayerShowRepaintCounter();
+}
+
 } // namespace WebCore
index cb52c1cbd0cea1c3c7fc5a38b9d9574a1b6862f1..577e34a39686c84cc8ec52a0cd9983547ba8e2fc 100644 (file)
@@ -32,8 +32,11 @@ namespace WebCore {
 
 @interface WebTileLayer : CALayer {
     WebCore::TileCache* _tileCache;
+    unsigned _repaintCount;
 }
+
 - (void)setTileCache:(WebCore::TileCache*)tileCache;
+- (unsigned)incrementRepaintCount;
 @end
 
 
index ef42d7c67cb672c39d08b739654e946994eddc31..6f7c85c084d97b7e3af036ff9e2e5a0624eac703 100644 (file)
@@ -52,5 +52,10 @@ using namespace WebCore;
     _tileCache = tileCache;
 }
 
+- (unsigned)incrementRepaintCount
+{
+    return ++_repaintCount;
+}
+
 @end