Font antialiasing (smoothing) changes when elements are rendered into compositing...
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Mar 2016 05:26:25 +0000 (05:26 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Mar 2016 05:26:25 +0000 (05:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=23364
rdar://problem/7288429

Reviewed by Tim Horton.
Source/WebCore:

Improve the appearance of subpixel-antialiased ("smoothed") text in non-opaque layers
by opting in to a new CALayer backing store format.

GraphicsLayer now has setSupportsSmoothedFonts(), which is called by RenderLayerBacking
when the platform has support for the new feature. Ideally this would only be set when
we know a layer has smoothed text drawn into it, but, for now, enable this for all
layers. The right thing happens with opaque layers under the hood.

setSupportsSmoothedFonts() is turned into a PlatformCALayer contentsFormat flag, which
is ultimately passed to setBackingStoreFormat().

We also need to propagate this flag to TileController tiles.

* platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::supportsSmoothedFontsInNonOpaqueLayers):
(WebCore::GraphicsLayer::GraphicsLayer):
* platform/graphics/GraphicsLayer.h:
(WebCore::GraphicsLayer::supportsSmoothedFonts):
(WebCore::GraphicsLayer::setSupportsSmoothedFonts):
* platform/graphics/TiledBacking.h:
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayer::supportsSmoothedFontsInNonOpaqueLayers):
(WebCore::GraphicsLayerCA::setSupportsSmoothedFonts):
(WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers):
(WebCore::GraphicsLayerCA::updateContentsFormat):
* platform/graphics/ca/GraphicsLayerCA.h:
* platform/graphics/ca/PlatformCALayer.cpp:
(WebCore::PlatformCALayer::drawRepaintIndicator): Give the number a "shadow" when
the contents format says we support smoothed fonts.
* platform/graphics/ca/PlatformCALayer.h:
* platform/graphics/ca/TileController.cpp:
(WebCore::TileController::setTileContentsFormatFlags):
(WebCore::TileController::createTileLayer):
* platform/graphics/ca/TileController.h:
* platform/graphics/ca/TileGrid.cpp:
(WebCore::TileGrid::updateTileLayerProperties):
* platform/graphics/ca/cocoa/PlatformCALayerCocoa.h:
* platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
(WebCore::setBackingStoreFormat):
(PlatformCALayerCocoa::commonInit):
(PlatformCALayerCocoa::setContentsFormat):
(PlatformCALayer::drawLayerContents): Previously, we turned off font smoothing in
non-opaque layers to improve text appearance. We no longer need to do that when
the contents format has "SmoothedFonts".
* platform/ios/LegacyTileGridTile.mm:
(WebCore::setBackingStoreFormat):
(WebCore::LegacyTileGridTile::LegacyTileGridTile):
* rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::createGraphicsLayer):

Source/WebKit2:

Send the ContentsFormat to the UI process (but nothing happens to it there yet).

* Shared/mac/RemoteLayerTreeTransaction.h:
* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::RemoteLayerTreeTransaction::LayerProperties::encode):
(WebKit::RemoteLayerTreeTransaction::LayerProperties::decode):
* WebProcess/WebPage/mac/PlatformCALayerRemote.cpp:
(WebKit::PlatformCALayerRemote::setContentsFormat):
(WebKit::PlatformCALayerRemote::contentsFormat):
* WebProcess/WebPage/mac/PlatformCALayerRemote.h:

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

22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GraphicsLayer.cpp
Source/WebCore/platform/graphics/GraphicsLayer.h
Source/WebCore/platform/graphics/TiledBacking.h
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h
Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp
Source/WebCore/platform/graphics/ca/PlatformCALayer.h
Source/WebCore/platform/graphics/ca/TileController.cpp
Source/WebCore/platform/graphics/ca/TileController.h
Source/WebCore/platform/graphics/ca/TileGrid.cpp
Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h
Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.cpp
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.h
Source/WebCore/platform/ios/LegacyTileGridTile.mm
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/RemoteLayerTreeTransaction.h
Source/WebKit2/Shared/mac/RemoteLayerTreeTransaction.mm
Source/WebKit2/WebProcess/WebPage/mac/PlatformCALayerRemote.cpp
Source/WebKit2/WebProcess/WebPage/mac/PlatformCALayerRemote.h

index abce09c..2932856 100644 (file)
@@ -1,3 +1,61 @@
+2016-03-09  Simon Fraser  <simon.fraser@apple.com>
+
+        Font antialiasing (smoothing) changes when elements are rendered into compositing layers
+        https://bugs.webkit.org/show_bug.cgi?id=23364
+        rdar://problem/7288429
+
+        Reviewed by Tim Horton.
+
+        Improve the appearance of subpixel-antialiased ("smoothed") text in non-opaque layers
+        by opting in to a new CALayer backing store format.
+        
+        GraphicsLayer now has setSupportsSmoothedFonts(), which is called by RenderLayerBacking
+        when the platform has support for the new feature. Ideally this would only be set when
+        we know a layer has smoothed text drawn into it, but, for now, enable this for all
+        layers. The right thing happens with opaque layers under the hood.
+        
+        setSupportsSmoothedFonts() is turned into a PlatformCALayer contentsFormat flag, which
+        is ultimately passed to setBackingStoreFormat().
+        
+        We also need to propagate this flag to TileController tiles.
+
+        * platform/graphics/GraphicsLayer.cpp:
+        (WebCore::GraphicsLayer::supportsSmoothedFontsInNonOpaqueLayers):
+        (WebCore::GraphicsLayer::GraphicsLayer):
+        * platform/graphics/GraphicsLayer.h:
+        (WebCore::GraphicsLayer::supportsSmoothedFonts):
+        (WebCore::GraphicsLayer::setSupportsSmoothedFonts):
+        * platform/graphics/TiledBacking.h:
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayer::supportsSmoothedFontsInNonOpaqueLayers):
+        (WebCore::GraphicsLayerCA::setSupportsSmoothedFonts):
+        (WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers):
+        (WebCore::GraphicsLayerCA::updateContentsFormat):
+        * platform/graphics/ca/GraphicsLayerCA.h:
+        * platform/graphics/ca/PlatformCALayer.cpp:
+        (WebCore::PlatformCALayer::drawRepaintIndicator): Give the number a "shadow" when
+        the contents format says we support smoothed fonts.
+        * platform/graphics/ca/PlatformCALayer.h:
+        * platform/graphics/ca/TileController.cpp:
+        (WebCore::TileController::setTileContentsFormatFlags):
+        (WebCore::TileController::createTileLayer):
+        * platform/graphics/ca/TileController.h:
+        * platform/graphics/ca/TileGrid.cpp:
+        (WebCore::TileGrid::updateTileLayerProperties):
+        * platform/graphics/ca/cocoa/PlatformCALayerCocoa.h:
+        * platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
+        (WebCore::setBackingStoreFormat):
+        (PlatformCALayerCocoa::commonInit):
+        (PlatformCALayerCocoa::setContentsFormat):
+        (PlatformCALayer::drawLayerContents): Previously, we turned off font smoothing in
+        non-opaque layers to improve text appearance. We no longer need to do that when
+        the contents format has "SmoothedFonts".
+        * platform/ios/LegacyTileGridTile.mm:
+        (WebCore::setBackingStoreFormat):
+        (WebCore::LegacyTileGridTile::LegacyTileGridTile):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::createGraphicsLayer):
+
 2016-03-09  Gavin Barraclough  <barraclough@apple.com>
 
         WebKit should adopt journal_mode=wal for all SQLite databases.
index 3411fe0..8d81a9a 100644 (file)
@@ -105,6 +105,13 @@ bool GraphicsLayer::supportsContentsTiling()
 }
 #endif
 
+#if !USE(CA)
+bool GraphicsLayer::supportsSmoothedFontsInNonOpaqueLayers()
+{
+    return false;
+}
+#endif
+
 GraphicsLayer::GraphicsLayer(Type type, GraphicsLayerClient& client)
     : m_client(client)
     , m_anchorPoint(0.5f, 0.5f, 0)
@@ -115,6 +122,7 @@ GraphicsLayer::GraphicsLayer(Type type, GraphicsLayerClient& client)
 #endif
     , m_type(type)
     , m_contentsOpaque(false)
+    , m_supportsSmoothedFonts(false)
     , m_preserves3D(false)
     , m_backfaceVisibility(true)
     , m_usingTiledBacking(false)
index 835f96a..3875b50 100644 (file)
@@ -364,6 +364,9 @@ public:
     bool contentsOpaque() const { return m_contentsOpaque; }
     virtual void setContentsOpaque(bool b) { m_contentsOpaque = b; }
 
+    bool supportsSmoothedFonts() const { return m_supportsSmoothedFonts; }
+    virtual void setSupportsSmoothedFonts(bool b) { m_supportsSmoothedFonts = b; }
+
     bool backfaceVisibility() const { return m_backfaceVisibility; }
     virtual void setBackfaceVisibility(bool b) { m_backfaceVisibility = b; }
 
@@ -540,6 +543,7 @@ public:
     static bool supportsBackgroundColorContent();
     static bool supportsLayerType(Type);
     static bool supportsContentsTiling();
+    static bool supportsSmoothedFontsInNonOpaqueLayers();
 
     void updateDebugIndicators();
 
@@ -613,6 +617,7 @@ protected:
     const Type m_type;
 
     bool m_contentsOpaque : 1;
+    bool m_supportsSmoothedFonts : 1;
     bool m_preserves3D: 1;
     bool m_backfaceVisibility : 1;
     bool m_usingTiledBacking : 1;
index d6456a5..0c8ac06 100644 (file)
@@ -79,6 +79,8 @@ public:
     virtual void setTiledScrollingIndicatorPosition(const FloatPoint&) = 0;
     virtual void setTopContentInset(float) = 0;
 
+    virtual void setTileContentsFormatFlags(unsigned) = 0;
+
     virtual void setVelocity(const VelocityData&) = 0;
     
     enum {
index 230a8f6..5f8b7ea 100644 (file)
@@ -309,6 +309,14 @@ bool GraphicsLayer::supportsBackgroundColorContent()
     return true;
 }
 
+bool GraphicsLayer::supportsSmoothedFontsInNonOpaqueLayers()
+{
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
+    return true;
+#endif
+    return false;
+}
+
 std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType)
 {
     std::unique_ptr<GraphicsLayer> graphicsLayer;
@@ -709,6 +717,15 @@ void GraphicsLayerCA::setContentsOpaque(bool opaque)
     noteLayerPropertyChanged(ContentsOpaqueChanged);
 }
 
+void GraphicsLayerCA::setSupportsSmoothedFonts(bool supportsSmoothedFonts)
+{
+    if (m_supportsSmoothedFonts == supportsSmoothedFonts)
+        return;
+
+    GraphicsLayer::setSupportsSmoothedFonts(supportsSmoothedFonts);
+    noteLayerPropertyChanged(ContentsFormatChanged);
+}
+
 void GraphicsLayerCA::setBackfaceVisibility(bool visible)
 {
     if (m_backfaceVisibility == visible)
@@ -1580,6 +1597,9 @@ void GraphicsLayerCA::commitLayerChangesBeforeSublayers(CommitState& commitState
     if (m_uncommittedChanges & ContentsOpaqueChanged)
         updateContentsOpaque(pageScaleFactor);
 
+    if (m_uncommittedChanges & ContentsFormatChanged)
+        updateContentsFormat();
+
     if (m_uncommittedChanges & BackfaceVisibilityChanged)
         updateBackfaceVisibility();
 
@@ -1890,6 +1910,20 @@ void GraphicsLayerCA::updateContentsOpaque(float pageScaleFactor)
     }
 }
 
+void GraphicsLayerCA::updateContentsFormat()
+{
+    PlatformCALayer::ContentsFormatFlags formatFlags = 0;
+    if (supportsSmoothedFonts())
+        formatFlags |= PlatformCALayer::SmoothedFonts;
+
+    m_layer->setContentsFormat(formatFlags);
+
+    if (LayerMap* layerCloneMap = m_layerClones.get()) {
+        for (auto& layer : layerCloneMap->values())
+            layer->setContentsFormat(formatFlags);
+    }
+}
+
 void GraphicsLayerCA::updateBackfaceVisibility()
 {
     if (m_structuralLayer && structuralLayerPurpose() == StructuralLayerForReplicaFlattening) {
index a46ba31..2ad43bc 100644 (file)
@@ -95,6 +95,8 @@ public:
     WEBCORE_EXPORT void setBackgroundColor(const Color&) override;
 
     WEBCORE_EXPORT void setContentsOpaque(bool) override;
+    WEBCORE_EXPORT void setSupportsSmoothedFonts(bool) override;
+
     WEBCORE_EXPORT void setBackfaceVisibility(bool) override;
 
     // return true if we started an animation
@@ -391,6 +393,7 @@ private:
     void updateMasksToBounds();
     void updateContentsVisibility();
     void updateContentsOpaque(float pageScaleFactor);
+    void updateContentsFormat();
     void updateBackfaceVisibility();
     void updateStructuralLayer();
     void updateDrawsContent();
@@ -455,43 +458,44 @@ private:
     bool appendToUncommittedAnimations(const KeyframeValueList&, const FilterOperation*, const Animation*, const String& animationName, int animationIndex, double timeOffset);
 
     enum LayerChange : uint64_t {
-        NoChange =                      0,
-        NameChanged =                   1LLU << 1,
-        ChildrenChanged =               1LLU << 2, // also used for content layer, and preserves-3d, and size if tiling changes?
-        GeometryChanged =               1LLU << 3,
-        TransformChanged =              1LLU << 4,
-        ChildrenTransformChanged =      1LLU << 5,
-        Preserves3DChanged =            1LLU << 6,
-        MasksToBoundsChanged =          1LLU << 7,
-        DrawsContentChanged =           1LLU << 8,
-        BackgroundColorChanged =        1LLU << 9,
-        ContentsOpaqueChanged =         1LLU << 10,
-        BackfaceVisibilityChanged =     1LLU << 11,
-        OpacityChanged =                1LLU << 12,
-        AnimationChanged =              1LLU << 13,
-        DirtyRectsChanged =             1LLU << 14,
-        ContentsImageChanged =          1LLU << 15,
-        ContentsPlatformLayerChanged =  1LLU << 16,
-        ContentsColorLayerChanged =     1LLU << 17,
-        ContentsRectsChanged =          1LLU << 18,
-        MasksToBoundsRectChanged =      1LLU << 19,
-        MaskLayerChanged =              1LLU << 20,
-        ReplicatedLayerChanged =        1LLU << 21,
-        ContentsNeedsDisplay =          1LLU << 22,
-        AcceleratesDrawingChanged =     1LLU << 23,
-        ContentsScaleChanged =          1LLU << 24,
-        ContentsVisibilityChanged =     1LLU << 25,
-        CoverageRectChanged =           1LLU << 26,
-        FiltersChanged =                1LLU << 27,
-        BackdropFiltersChanged =        1LLU << 28,
-        BackdropFiltersRectChanged =    1LLU << 29,
-        TilingAreaChanged =             1LLU << 30,
-        TilesAdded =                    1LLU << 31,
-        DebugIndicatorsChanged =        1LLU << 32,
-        CustomAppearanceChanged =       1LLU << 33,
-        BlendModeChanged =              1LLU << 34,
-        ShapeChanged =                  1LLU << 35,
-        WindRuleChanged =               1LLU << 36,
+        NoChange                        = 0,
+        NameChanged                     = 1LLU << 1,
+        ChildrenChanged                 = 1LLU << 2, // also used for content layer, and preserves-3d, and size if tiling changes?
+        GeometryChanged                 = 1LLU << 3,
+        TransformChanged                = 1LLU << 4,
+        ChildrenTransformChanged        = 1LLU << 5,
+        Preserves3DChanged              = 1LLU << 6,
+        MasksToBoundsChanged            = 1LLU << 7,
+        DrawsContentChanged             = 1LLU << 8,
+        BackgroundColorChanged          = 1LLU << 9,
+        ContentsOpaqueChanged           = 1LLU << 10,
+        ContentsFormatChanged           = 1LLU << 11,
+        BackfaceVisibilityChanged       = 1LLU << 12,
+        OpacityChanged                  = 1LLU << 13,
+        AnimationChanged                = 1LLU << 14,
+        DirtyRectsChanged               = 1LLU << 15,
+        ContentsImageChanged            = 1LLU << 16,
+        ContentsPlatformLayerChanged    = 1LLU << 17,
+        ContentsColorLayerChanged       = 1LLU << 18,
+        ContentsRectsChanged            = 1LLU << 19,
+        MasksToBoundsRectChanged        = 1LLU << 20,
+        MaskLayerChanged                = 1LLU << 21,
+        ReplicatedLayerChanged          = 1LLU << 22,
+        ContentsNeedsDisplay            = 1LLU << 23,
+        AcceleratesDrawingChanged       = 1LLU << 24,
+        ContentsScaleChanged            = 1LLU << 25,
+        ContentsVisibilityChanged       = 1LLU << 26,
+        CoverageRectChanged             = 1LLU << 27,
+        FiltersChanged                  = 1LLU << 28,
+        BackdropFiltersChanged          = 1LLU << 29,
+        BackdropFiltersRectChanged      = 1LLU << 30,
+        TilingAreaChanged               = 1LLU << 31,
+        TilesAdded                      = 1LLU << 32,
+        DebugIndicatorsChanged          = 1LLU << 33,
+        CustomAppearanceChanged         = 1LLU << 34,
+        BlendModeChanged                = 1LLU << 35,
+        ShapeChanged                    = 1LLU << 36,
+        WindRuleChanged                 = 1LLU << 37,
     };
     typedef uint64_t LayerChangeFlags;
     enum ScheduleFlushOrNot { ScheduleFlush, DontScheduleFlush };
index 817cc20..bb53794 100644 (file)
@@ -80,11 +80,6 @@ void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer
         CGContextSetRGBFillColor(context, 0, 0.5f, 0.25f, 1);
     
     CGContextFillRect(context, indicatorBox);
-    
-    if (platformCALayer->acceleratesDrawing())
-        CGContextSetRGBFillColor(context, 1, 0, 0, 1);
-    else
-        CGContextSetRGBFillColor(context, 1, 1, 1, 1);
 
     if (platformCALayer->owner()->isUsingDisplayListDrawing(platformCALayer)) {
         CGContextSetRGBStrokeColor(context, 0, 0, 0, 0.65);
@@ -92,6 +87,16 @@ void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer
         CGContextStrokeRect(context, indicatorBox);
     }
     
+    if (!platformCALayer->isOpaque() && (platformCALayer->contentsFormat() & SmoothedFonts)) {
+        CGContextSetRGBFillColor(context, 1, 1, 1, 0.4);
+        platformCALayer->drawTextAtPoint(context, indicatorBox.origin.x + 7, indicatorBox.origin.y + 24, CGSizeMake(1, -1), 22, text, strlen(text));
+    }
+
+    if (platformCALayer->acceleratesDrawing())
+        CGContextSetRGBFillColor(context, 1, 0, 0, 1);
+    else
+        CGContextSetRGBFillColor(context, 1, 1, 1, 1);
+    
     platformCALayer->drawTextAtPoint(context, indicatorBox.origin.x + 5, indicatorBox.origin.y + 22, CGSizeMake(1, -1), 22, text, strlen(text));
     
     CGContextEndTransparencyLayer(context);
index 3de642d..a151eb2 100644 (file)
@@ -139,6 +139,14 @@ public:
     virtual bool isOpaque() const = 0;
     virtual void setOpaque(bool) = 0;
 
+    enum ContentsFormatFlag {
+        DeepColor       = 1 << 0,
+        SmoothedFonts   = 1 << 1,
+    };
+    typedef unsigned ContentsFormatFlags;
+    virtual void setContentsFormat(ContentsFormatFlags) = 0;
+    virtual ContentsFormatFlags contentsFormat() const = 0;
+
     virtual FloatRect bounds() const = 0;
     virtual void setBounds(const FloatRect&) = 0;
 
index f5bc18d..2144e53 100644 (file)
@@ -175,6 +175,15 @@ void TileController::setTilesOpaque(bool opaque)
     tileGrid().updateTileLayerProperties();
 }
 
+void TileController::setTileContentsFormatFlags(PlatformCALayer::ContentsFormatFlags flags)
+{
+    if (flags == m_contentsFormatFlags)
+        return;
+
+    m_contentsFormatFlags = flags;
+    tileGrid().updateTileLayerProperties();
+}
+
 void TileController::setVisibleRect(const FloatRect& rect)
 {
     if (rect == m_visibleRect)
@@ -675,6 +684,7 @@ RefPtr<PlatformCALayer> TileController::createTileLayer(const IntRect& tileRect,
     layer->setBorderWidth(m_tileDebugBorderWidth);
     layer->setEdgeAntialiasingMask(0);
     layer->setOpaque(m_tilesAreOpaque);
+    layer->setContentsFormat(m_contentsFormatFlags);
 #ifndef NDEBUG
     layer->setName("Tile");
 #endif
index a21a0bb..4fc5c4d 100644 (file)
@@ -78,6 +78,9 @@ public:
     WEBCORE_EXPORT void setTilesOpaque(bool);
     bool tilesAreOpaque() const { return m_tilesAreOpaque; }
 
+    void setTileContentsFormatFlags(PlatformCALayer::ContentsFormatFlags) override;
+    PlatformCALayer::ContentsFormatFlags tileContentsFormatFlags() const { return m_contentsFormatFlags; }
+
     PlatformCALayer& rootLayer() { return *m_tileCacheLayer; }
     const PlatformCALayer& rootLayer() const { return *m_tileCacheLayer; }
 
@@ -206,6 +209,8 @@ private:
 
     int m_marginSize { kDefaultTileSize };
 
+    PlatformCALayer::ContentsFormatFlags m_contentsFormatFlags { 0 };
+
     // m_marginTop and m_marginBottom are the height in pixels of the top and bottom margin tiles. The width
     // of those tiles will be equivalent to the width of the other tiles in the grid. m_marginRight and
     // m_marginLeft are the width in pixels of the right and left margin tiles, respectively. The height of
index ebb8178..48cfbd9 100644 (file)
@@ -175,6 +175,7 @@ void TileGrid::updateTileLayerProperties()
 {
     bool acceleratesDrawing = m_controller.acceleratesDrawing();
     bool opaque = m_controller.tilesAreOpaque();
+    PlatformCALayer::ContentsFormatFlags formatFlags = m_controller.tileContentsFormatFlags();
     Color tileDebugBorderColor = m_controller.tileDebugBorderColor();
     float tileDebugBorderWidth = m_controller.tileDebugBorderWidth();
 
@@ -182,6 +183,7 @@ void TileGrid::updateTileLayerProperties()
         const TileInfo& tileInfo = it->value;
         tileInfo.layer->setAcceleratesDrawing(acceleratesDrawing);
         tileInfo.layer->setOpaque(opaque);
+        tileInfo.layer->setContentsFormat(formatFlags);
         tileInfo.layer->setBorderColor(tileDebugBorderColor);
         tileInfo.layer->setBorderWidth(tileDebugBorderWidth);
     }
index 73a2818..c7d6a1b 100644 (file)
@@ -72,6 +72,9 @@ public:
     bool isOpaque() const override;
     void setOpaque(bool) override;
 
+    void setContentsFormat(ContentsFormatFlags) override;
+    ContentsFormatFlags contentsFormat() const override { return m_contentsFormatFlags; }
+
     FloatRect bounds() const override;
     void setBounds(const FloatRect&) override;
 
@@ -179,6 +182,7 @@ private:
     std::unique_ptr<PlatformCALayerList> m_customSublayers;
     GraphicsLayer::CustomAppearance m_customAppearance;
     std::unique_ptr<FloatRoundedRect> m_shapeRoundedRect;
+    ContentsFormatFlags m_contentsFormatFlags { 0 };
 };
 
 } // namespace WebCore
index 35f5554..8f65fce 100644 (file)
@@ -69,7 +69,7 @@
 #import <WebKitAdditions/LayerBackingStoreAdditions.mm>
 #else
 namespace WebCore {
-static void setBackingStoreFormat(CALayer *)
+static void setBackingStoreFormat(CALayer *, PlatformCALayer::ContentsFormatFlags)
 {
 }
 } // namespace WebCore
@@ -308,7 +308,7 @@ void PlatformCALayerCocoa::commonInit()
         [m_layer setDelegate:[WebActionDisablingCALayerDelegate shared]];
 
     if (m_layerType == LayerTypeWebLayer || m_layerType == LayerTypeTiledBackingTileLayer)
-        setBackingStoreFormat(m_layer.get());
+        setBackingStoreFormat(m_layer.get(), 0);
 
     // So that the scrolling thread's performance logging code can find all the tiles, mark this as being a tile.
     if (m_layerType == LayerTypeTiledBackingTileLayer)
@@ -545,6 +545,22 @@ void PlatformCALayerCocoa::setOpaque(bool value)
     END_BLOCK_OBJC_EXCEPTIONS
 }
 
+void PlatformCALayerCocoa::setContentsFormat(ContentsFormatFlags flags)
+{
+    if (flags == m_contentsFormatFlags)
+        return;
+
+    m_contentsFormatFlags = flags;
+
+    if (usesTiledBackingLayer()) {
+        WebTiledBackingLayer* tiledBackingLayer = static_cast<WebTiledBackingLayer*>(m_layer.get());
+        tiledBackingLayer.tiledBacking->setTileContentsFormatFlags(flags);
+        return;
+    }
+
+    setBackingStoreFormat(m_layer.get(), flags);
+}
+
 FloatRect PlatformCALayerCocoa::bounds() const
 {
     return [m_layer bounds];
@@ -1056,7 +1072,7 @@ void PlatformCALayer::drawLayerContents(CGContextRef context, WebCore::PlatformC
     graphicsContext.setIsCALayerContext(true);
     graphicsContext.setIsAcceleratedContext(platformCALayer->acceleratesDrawing());
     
-    if (!layerContents->platformCALayerContentsOpaque()) {
+    if (!layerContents->platformCALayerContentsOpaque() && !(platformCALayer->contentsFormat() & SmoothedFonts)) {
         // Turn off font smoothing to improve the appearance of text rendered onto a transparent background.
         graphicsContext.setShouldSmoothFonts(false);
     }
index ba8f28e..3049b40 100644 (file)
@@ -377,6 +377,16 @@ void PlatformCALayerWin::setOpaque(bool value)
     setNeedsCommit();
 }
 
+void PlatformCALayerWin::setContentsFormat(ContentsFormatFlags formatFlags)
+{
+    m_contentsFormat = formatFlags;
+}
+
+PlatformCALayer::ContentsFormatFlags PlatformCALayerWin::contentsFormat() const
+{
+    return m_contentsFormat;
+}
+
 FloatRect PlatformCALayerWin::bounds() const
 {
     return CACFLayerGetBounds(m_layer.get());
index db19e56..5535c83 100644 (file)
@@ -64,6 +64,9 @@ public:
     bool isOpaque() const override;
     void setOpaque(bool) override;
 
+    void setContentsFormat(ContentsFormatFlags) override;
+    ContentsFormatFlags contentsFormat() const override;
+
     FloatRect bounds() const override;
     void setBounds(const FloatRect&) override;
 
@@ -163,6 +166,7 @@ private:
     HashMap<String, RefPtr<PlatformCAAnimation>> m_animations;
     std::unique_ptr<PlatformCALayerList> m_customSublayers;
     GraphicsLayer::CustomAppearance m_customAppearance;
+    ContentsFormatFlags m_contentsFormat { 0 };
 };
 
 }
index 247124b..b807ff0 100644 (file)
 
 #if PLATFORM(IOS)
 
+#include "BlockExceptions.h"
 #include "Color.h"
 #include "LegacyTileCache.h"
 #include "LegacyTileGrid.h"
 #include "LegacyTileLayer.h"
 #include "LegacyTileLayerPool.h"
+#include "PlatformCALayer.h"
 #include "QuartzCoreSPI.h"
 #include "WAKWindow.h"
 #include <algorithm>
@@ -43,7 +45,7 @@
 #import <WebKitAdditions/LayerBackingStoreAdditions.mm>
 #else
 namespace WebCore {
-static void setBackingStoreFormat(CALayer *)
+static void setBackingStoreFormat(CALayer *, PlatformCALayer::ContentsFormatFlags)
 {
 }
 } // namespace WebCore
@@ -71,7 +73,7 @@ LegacyTileGridTile::LegacyTileGridTile(LegacyTileGrid* tileGrid, const IntRect&
         m_tileLayer = adoptNS([[LegacyTileLayer alloc] init]);
     }
     LegacyTileLayer* layer = m_tileLayer.get();
-    setBackingStoreFormat(layer);
+    setBackingStoreFormat(layer, 0);
     [layer setTileGrid:tileGrid];
     [layer setOpaque:m_tileGrid->tileCache().tilesOpaque()];
     [layer setEdgeAntialiasingMask:0];
index 20d3847..221e314 100644 (file)
@@ -178,6 +178,10 @@ std::unique_ptr<GraphicsLayer> RenderLayerBacking::createGraphicsLayer(const Str
     graphicsLayer->setAcceleratesDrawing(compositor().acceleratedDrawingEnabled());
     graphicsLayer->setUsesDisplayListDrawing(compositor().displayListDrawingEnabled());
 #endif
+
+    // FIXME: ideally we'd only do this if the layer contains smoothed text.
+    if (GraphicsLayer::supportsSmoothedFontsInNonOpaqueLayers())
+        graphicsLayer->setSupportsSmoothedFonts(true);
     
     return graphicsLayer;
 }
index d536438..32b1303 100644 (file)
@@ -1,3 +1,22 @@
+2016-03-09  Simon Fraser  <simon.fraser@apple.com>
+
+        Font antialiasing (smoothing) changes when elements are rendered into compositing layers
+        https://bugs.webkit.org/show_bug.cgi?id=23364
+        rdar://problem/7288429
+
+        Reviewed by Tim Horton.
+        
+        Send the ContentsFormat to the UI process (but nothing happens to it there yet).
+
+        * Shared/mac/RemoteLayerTreeTransaction.h:
+        * Shared/mac/RemoteLayerTreeTransaction.mm:
+        (WebKit::RemoteLayerTreeTransaction::LayerProperties::encode):
+        (WebKit::RemoteLayerTreeTransaction::LayerProperties::decode):
+        * WebProcess/WebPage/mac/PlatformCALayerRemote.cpp:
+        (WebKit::PlatformCALayerRemote::setContentsFormat):
+        (WebKit::PlatformCALayerRemote::contentsFormat):
+        * WebProcess/WebPage/mac/PlatformCALayerRemote.h:
+
 2016-03-09  Ryosuke Niwa  <rniwa@webkit.org>
 
         Add runtime flags for shadow DOM and custom elements
index 4e99acd..142e029 100644 (file)
@@ -87,7 +87,8 @@ public:
         FiltersChanged                  = 1LLU << 32,
         AnimationsChanged               = 1LLU << 33,
         EdgeAntialiasingMaskChanged     = 1LLU << 34,
-        CustomAppearanceChanged         = 1LLU << 35,
+        ContentsFormatFlagsChanged      = 1LLU << 35,
+        CustomAppearanceChanged         = 1LLU << 36,
     };
     typedef uint64_t LayerChange;
 
@@ -153,6 +154,7 @@ public:
         WebCore::Color backgroundColor;
         WebCore::Color borderColor;
         unsigned edgeAntialiasingMask;
+        WebCore::PlatformCALayer::ContentsFormatFlags contentsFormatFlags;
         WebCore::GraphicsLayer::CustomAppearance customAppearance;
         WebCore::PlatformCALayer::FilterType minificationFilter;
         WebCore::PlatformCALayer::FilterType magnificationFilter;
index 73d734b..4b0e34c 100644 (file)
@@ -211,6 +211,9 @@ void RemoteLayerTreeTransaction::LayerProperties::encode(IPC::ArgumentEncoder& e
     if (changedProperties & OpaqueChanged)
         encoder << opaque;
 
+    if (changedProperties & ContentsFormatFlagsChanged)
+        encoder << contentsFormatFlags;
+
     if (changedProperties & MaskLayerChanged)
         encoder << maskLayerID;
 
@@ -374,6 +377,11 @@ bool RemoteLayerTreeTransaction::LayerProperties::decode(IPC::ArgumentDecoder& d
             return false;
     }
 
+    if (result.changedProperties & ContentsFormatFlagsChanged) {
+        if (!decoder.decode(result.contentsFormatFlags))
+            return false;
+    }
+
     if (result.changedProperties & MaskLayerChanged) {
         if (!decoder.decode(result.maskLayerID))
             return false;
index 7821667..792be52 100644 (file)
@@ -401,6 +401,20 @@ void PlatformCALayerRemote::setMask(PlatformCALayer* layer)
     m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::MaskLayerChanged);
 }
 
+void PlatformCALayerRemote::setContentsFormat(ContentsFormatFlags formatFlags)
+{
+    if (formatFlags == m_properties.contentsFormatFlags)
+        return;
+
+    m_properties.contentsFormatFlags = formatFlags;
+    m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::ContentsFormatFlagsChanged);
+}
+
+PlatformCALayer::ContentsFormatFlags PlatformCALayerRemote::contentsFormat() const
+{
+    return m_properties.contentsFormatFlags;
+}
+
 void PlatformCALayerRemote::setClonedLayer(const PlatformCALayer* layer)
 {
     if (isEquivalentLayer(layer, m_properties.clonedLayerID))
index f165206..6af7c2a 100644 (file)
@@ -76,6 +76,9 @@ public:
     bool isOpaque() const override;
     void setOpaque(bool) override;
 
+    void setContentsFormat(ContentsFormatFlags) override;
+    ContentsFormatFlags contentsFormat() const override;
+
     WebCore::FloatRect bounds() const override;
     void setBounds(const WebCore::FloatRect&) override;