Make the TileCache work with HiDPI again
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Mar 2012 23:11:15 +0000 (23:11 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Mar 2012 23:11:15 +0000 (23:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81569
<rdar://problem/11031542>

Reviewed by Sam Weinig.

Set the contentsScale of the individual tile layers to be the same as the device scale factor.
Also, take into account the fact that the value passed to TileCache::setScale is the product of the
page scale factor and the device scale factor, so divide it by the device scale factor before storing
it in m_scale.

* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::platformCALayerDeviceScaleFactor):
(WebCore):
* platform/graphics/ca/GraphicsLayerCA.h:
(GraphicsLayerCA):
* platform/graphics/ca/PlatformCALayerClient.h:
(PlatformCALayerClient):
* platform/graphics/ca/mac/TileCache.h:
(TileCache):
* platform/graphics/ca/mac/TileCache.mm:
(WebCore::TileCache::TileCache):
(WebCore::TileCache::setScale):
(WebCore::TileCache::createTileLayer):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h
Source/WebCore/platform/graphics/ca/PlatformCALayerClient.h
Source/WebCore/platform/graphics/ca/mac/TileCache.h
Source/WebCore/platform/graphics/ca/mac/TileCache.mm

index b85aec8..ce0ca9d 100644 (file)
@@ -1,3 +1,30 @@
+2012-03-19  Anders Carlsson  <andersca@apple.com>
+
+        Make the TileCache work with HiDPI again
+        https://bugs.webkit.org/show_bug.cgi?id=81569
+        <rdar://problem/11031542>
+
+        Reviewed by Sam Weinig.
+
+        Set the contentsScale of the individual tile layers to be the same as the device scale factor.
+        Also, take into account the fact that the value passed to TileCache::setScale is the product of the
+        page scale factor and the device scale factor, so divide it by the device scale factor before storing
+        it in m_scale.
+
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::platformCALayerDeviceScaleFactor):
+        (WebCore):
+        * platform/graphics/ca/GraphicsLayerCA.h:
+        (GraphicsLayerCA):
+        * platform/graphics/ca/PlatformCALayerClient.h:
+        (PlatformCALayerClient):
+        * platform/graphics/ca/mac/TileCache.h:
+        (TileCache):
+        * platform/graphics/ca/mac/TileCache.mm:
+        (WebCore::TileCache::TileCache):
+        (WebCore::TileCache::setScale):
+        (WebCore::TileCache::createTileLayer):
+
 2012-03-19  Abhishek Arya  <inferno@chromium.org>
 
         Crash due to layer tree information not updated when moving run-in children.
index 4723536..7041e10 100644 (file)
@@ -972,6 +972,11 @@ void GraphicsLayerCA::platformCALayerDidCreateTiles()
     client()->notifySyncRequired(this);
 }
 
+float GraphicsLayerCA::platformCALayerDeviceScaleFactor()
+{
+    return deviceScaleFactor();
+}
+
 void GraphicsLayerCA::commitLayerChangesBeforeSublayers(float pageScaleFactor, const FloatPoint& positionRelativeToBase)
 {
     if (!m_uncommittedChanges)
index 4337bf7..fef079f 100644 (file)
@@ -158,6 +158,7 @@ private:
     virtual bool platformCALayerDrawsContent() const { return drawsContent(); }
     virtual void platformCALayerLayerDidDisplay(PlatformLayer* layer) { return layerDidDisplay(layer); }
     virtual void platformCALayerDidCreateTiles() OVERRIDE;
+    virtual float platformCALayerDeviceScaleFactor() OVERRIDE;
 
     void updateOpacityOnLayer();
     
index be8e459..05d35eb 100644 (file)
@@ -60,6 +60,7 @@ public:
     virtual void platformCALayerLayerDidDisplay(PlatformLayer*) = 0;
 
     virtual void platformCALayerDidCreateTiles() = 0;
+    virtual float platformCALayerDeviceScaleFactor() = 0;
 
 protected:
     virtual ~PlatformCALayerClient() {}
index aea8113..36658fe 100644 (file)
@@ -98,6 +98,7 @@ private:
     IntRect m_tileCoverageRect;
 
     CGFloat m_scale;
+    CGFloat m_deviceScaleFactor;
 
     bool m_acceleratesDrawing;
 
index 8c88068..20042cc 100644 (file)
@@ -55,6 +55,7 @@ TileCache::TileCache(WebTileCacheLayer* tileCacheLayer, const IntSize& tileSize)
     , m_tileSize(tileSize)
     , m_tileRevalidationTimer(this, &TileCache::tileRevalidationTimerFired)
     , m_scale(1)
+    , m_deviceScaleFactor(1)
     , m_acceleratesDrawing(false)
     , m_tileDebugBorderWidth(0)
 {
@@ -169,19 +170,28 @@ void TileCache::drawLayer(WebTileLayer* layer, CGContextRef context)
 
 void TileCache::setScale(CGFloat scale)
 {
-    if (m_scale == scale)
+    PlatformCALayer* platformLayer = PlatformCALayer::platformCALayer(m_tileCacheLayer);
+    float deviceScaleFactor = platformLayer->owner()->platformCALayerDeviceScaleFactor();
+
+    // The scale we get is the produce of the page scale factor and device scale factor.
+    // Divide by the device scale factor so we'll get the page scale factor.
+    scale /= deviceScaleFactor;
+
+    if (m_scale == scale && m_deviceScaleFactor == deviceScaleFactor)
         return;
 
 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
+    m_deviceScaleFactor = deviceScaleFactor;
     m_scale = scale;
     [m_tileContainerLayer.get() setTransform:CATransform3DMakeScale(1 / m_scale, 1 / m_scale, 1)];
 
     revalidateTiles();
 
-    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it)
+    for (TileMap::const_iterator it = m_tiles.begin(), end = m_tiles.end(); it != end; ++it) {
+        [it->second.get() setContentsScale:deviceScaleFactor];
         [it->second.get() setNeedsDisplay];
+    }
 
-    PlatformCALayer* platformLayer = PlatformCALayer::platformCALayer(m_tileCacheLayer);
     platformLayer->owner()->platformCALayerDidCreateTiles();
 #endif
 }
@@ -365,6 +375,7 @@ RetainPtr<WebTileLayer> TileCache::createTileLayer(const IntRect& tileRect)
 {
     RetainPtr<WebTileLayer> layer = adoptNS([[WebTileLayer alloc] init]);
     [layer.get() setAnchorPoint:CGPointZero];
+    [layer.get() setContentsScale:m_deviceScaleFactor];
     [layer.get() setFrame:tileRect];
     [layer.get() setTileCache:this];
     [layer.get() setBorderColor:m_tileDebugBorderColor.get()];