Title: [182549] tags/Safari-601.1.26/Source/WebCore

Diff

Modified: tags/Safari-601.1.26/Source/WebCore/ChangeLog (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/ChangeLog	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/ChangeLog	2015-04-08 17:49:56 UTC (rev 182549)
@@ -1,3 +1,52 @@
+2015-04-08  Babak Shafiei  <[email protected]>
+
+        Merge r182516.
+
+    2015-04-07  Simon Fraser  <[email protected]>
+
+            Add experimental code to use custom font dilation when rendering into non-opaque contexts
+            https://bugs.webkit.org/show_bug.cgi?id=143508
+
+            Reviewed by Sam Weinig.
+
+            Add GraphicsContext::setAntialiasedFontDilationEnabled(), and set it to true
+            when rendering into a compositing layer which is not opaque (at the same location
+            where we disable font smoothing).
+
+            If Settings::antialiasedFontDilationEnabled() is true, when rendering non-smoothed
+            text (and if CSS hasn't opted into antialiased mode), use custom font dilation
+            parameters, chosen using a light/medium/dark heuristic, to make this text
+            match more closely with LCD-smoothed text.
+
+            * page/Settings.cpp:
+            (WebCore::Settings::Settings):
+            (WebCore::Settings::setAntialiasedFontDilationEnabled): Set global state
+            in FontCascade (which can't easily get at Settings). This it not ideal,
+            but is temporary.
+            * page/Settings.h:
+            (WebCore::Settings::antialiasedFontDilationEnabled):
+            * page/Settings.in: Can't autogenerate this setting any more.
+            * platform/graphics/FontCascade.cpp:
+            (WebCore::FontCascade::setAntialiasedFontDilationEnabled): Set the global.
+            (WebCore::FontCascade::antialiasedFontDilationEnabled):
+            * platform/graphics/FontCascade.h:
+            * platform/graphics/GraphicsContext.cpp:
+            (WebCore::GraphicsContext::setAntialiasedFontDilationEnabled): Set graphics state
+            to say that we should do dilation of antialiased text.
+            * platform/graphics/GraphicsContext.h:
+            (WebCore::GraphicsContextState::GraphicsContextState):
+            (WebCore::GraphicsContext::antialiasedFontDilationEnabled):
+            * platform/graphics/ca/mac/PlatformCALayerMac.mm:
+            (PlatformCALayer::drawLayerContents): If the layer is not opaque, enable the
+            dilated text code path.
+            * platform/graphics/cocoa/FontCascadeCocoa.mm:
+            (WebCore::dilationSizeForTextColor): Heuristic (values chosen empirically) to
+            computed custom dilation based on foreground color.
+            (WebCore::FontCascade::drawGlyphs): Set the custom dilation parameters, and the
+            antialiasing state if we're not doing smoothing, and CSS hasn't opted into the
+            antialiased path.
+            * platform/spi/cg/CoreGraphicsSPI.h: New SPI.
+
 2015-04-07  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r182511.

Modified: tags/Safari-601.1.26/Source/WebCore/page/Settings.cpp (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/page/Settings.cpp	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/page/Settings.cpp	2015-04-08 17:49:56 UTC (rev 182549)
@@ -180,6 +180,7 @@
     , m_needsAdobeFrameReloadingQuirk(false)
     , m_usesPageCache(false)
     , m_fontRenderingMode(0)
+    , m_antialiasedFontDilationEnabled(true)
     , m_showTiledScrollingIndicator(false)
     , m_backgroundShouldExtendBeyondPage(false)
     , m_dnsPrefetchingEnabled(false)
@@ -341,6 +342,12 @@
 
 #endif
 
+void Settings::setAntialiasedFontDilationEnabled(bool enabled)
+{
+    // FIXME: It's wrong for a setting to toggle a global, but this code is temporary.
+    FontCascade::setAntialiasedFontDilationEnabled(enabled);
+}
+
 void Settings::setMediaTypeOverride(const String& mediaTypeOverride)
 {
     if (m_mediaTypeOverride == mediaTypeOverride)

Modified: tags/Safari-601.1.26/Source/WebCore/page/Settings.h (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/page/Settings.h	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/page/Settings.h	2015-04-08 17:49:56 UTC (rev 182549)
@@ -109,6 +109,9 @@
     const IntSize& textAutosizingWindowSizeOverride() const { return m_textAutosizingWindowSizeOverride; }
 #endif
 
+    WEBCORE_EXPORT void setAntialiasedFontDilationEnabled(bool);
+    bool antialiasedFontDilationEnabled() const { return m_antialiasedFontDilationEnabled; }
+
     // Only set by Layout Tests.
     WEBCORE_EXPORT void setMediaTypeOverride(const String&);
     const String& mediaTypeOverride() const { return m_mediaTypeOverride; }
@@ -295,6 +298,7 @@
     bool m_needsAdobeFrameReloadingQuirk : 1;
     bool m_usesPageCache : 1;
     unsigned m_fontRenderingMode : 1;
+    bool m_antialiasedFontDilationEnabled : 1;
     bool m_showTiledScrollingIndicator : 1;
     bool m_backgroundShouldExtendBeyondPage : 1;
     bool m_dnsPrefetchingEnabled : 1;

Modified: tags/Safari-601.1.26/Source/WebCore/page/Settings.in (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/page/Settings.in	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/page/Settings.in	2015-04-08 17:49:56 UTC (rev 182549)
@@ -36,7 +36,6 @@
 minimumLogicalFontSize type=int, initial=0, setNeedsStyleRecalcInAllFrames=1
 defaultFontSize type=int, initial=0, setNeedsStyleRecalcInAllFrames=1
 defaultFixedFontSize type=int, initial=0, setNeedsStyleRecalcInAllFrames=1
-antialiasedFontDilationEnabled type=bool, initial=true, setNeedsStyleRecalcInAllFrames=1
 
 editingBehaviorType type=EditingBehaviorType, initial=editingBehaviorTypeForPlatform()
 maximumHTMLParserDOMTreeDepth type=unsigned, initial=defaultMaximumHTMLParserDOMTreeDepth

Modified: tags/Safari-601.1.26/Source/WebCore/platform/graphics/FontCascade.cpp (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/platform/graphics/FontCascade.cpp	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/platform/graphics/FontCascade.cpp	2015-04-08 17:49:56 UTC (rev 182549)
@@ -592,6 +592,18 @@
     return shouldUseFontSmoothing;
 }
 
+static bool antialiasedFontDilationIsEnabled = true;
+
+void FontCascade::setAntialiasedFontDilationEnabled(bool enabled)
+{
+    antialiasedFontDilationIsEnabled = enabled;
+}
+
+bool FontCascade::antialiasedFontDilationEnabled()
+{
+    return antialiasedFontDilationIsEnabled;
+}
+
 void FontCascade::setCodePath(CodePath p)
 {
     s_codePath = p;

Modified: tags/Safari-601.1.26/Source/WebCore/platform/graphics/FontCascade.h (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/platform/graphics/FontCascade.h	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/platform/graphics/FontCascade.h	2015-04-08 17:49:56 UTC (rev 182549)
@@ -205,6 +205,9 @@
     static bool leadingExpansionOpportunity(const StringView&, TextDirection);
     static bool trailingExpansionOpportunity(const StringView&, TextDirection);
 
+    WEBCORE_EXPORT static void setAntialiasedFontDilationEnabled(bool);
+    WEBCORE_EXPORT static bool antialiasedFontDilationEnabled();
+
     WEBCORE_EXPORT static void setShouldUseSmoothing(bool);
     WEBCORE_EXPORT static bool shouldUseSmoothing();
 

Modified: tags/Safari-601.1.26/Source/WebCore/platform/graphics/GraphicsContext.cpp (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/platform/graphics/GraphicsContext.cpp	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/platform/graphics/GraphicsContext.cpp	2015-04-08 17:49:56 UTC (rev 182549)
@@ -257,6 +257,11 @@
     setPlatformShouldSmoothFonts(shouldSmoothFonts);
 }
 
+void GraphicsContext::setAntialiasedFontDilationEnabled(bool antialiasedFontDilationEnabled)
+{
+    m_state.antialiasedFontDilationEnabled = antialiasedFontDilationEnabled;
+}
+
 void GraphicsContext::setStrokePattern(Ref<Pattern>&& pattern)
 {
     m_state.strokeGradient.clear();

Modified: tags/Safari-601.1.26/Source/WebCore/platform/graphics/GraphicsContext.h (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/platform/graphics/GraphicsContext.h	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/platform/graphics/GraphicsContext.h	2015-04-08 17:49:56 UTC (rev 182549)
@@ -114,6 +114,7 @@
         GraphicsContextState()
             : shouldAntialias(true)
             , shouldSmoothFonts(true)
+            , antialiasedFontDilationEnabled(true)
             , shouldSubpixelQuantizeFonts(true)
             , paintingDisabled(false)
             , shadowsIgnoreTransforms(false)
@@ -156,6 +157,7 @@
 
         bool shouldAntialias : 1;
         bool shouldSmoothFonts : 1;
+        bool antialiasedFontDilationEnabled : 1;
         bool shouldSubpixelQuantizeFonts : 1;
         bool paintingDisabled : 1;
         bool shadowsIgnoreTransforms : 1;
@@ -239,6 +241,9 @@
         WEBCORE_EXPORT void setShouldAntialias(bool);
         bool shouldAntialias() const { return m_state.shouldAntialias; }
 
+        WEBCORE_EXPORT void setAntialiasedFontDilationEnabled(bool);
+        bool antialiasedFontDilationEnabled() const { return m_state.antialiasedFontDilationEnabled; }
+
         WEBCORE_EXPORT void setShouldSmoothFonts(bool);
         bool shouldSmoothFonts() const { return m_state.shouldSmoothFonts; }
 

Modified: tags/Safari-601.1.26/Source/WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm	2015-04-08 17:49:56 UTC (rev 182549)
@@ -1045,6 +1045,7 @@
     if (!layerContents->platformCALayerContentsOpaque()) {
         // Turn off font smoothing to improve the appearance of text rendered onto a transparent background.
         graphicsContext.setShouldSmoothFonts(false);
+        graphicsContext.setAntialiasedFontDilationEnabled(true);
     }
     
 #if PLATFORM(MAC)

Modified: tags/Safari-601.1.26/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2015-04-08 17:49:56 UTC (rev 182549)
@@ -203,6 +203,26 @@
 }
 #endif
 
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+static CGSize dilationSizeForTextColor(const Color& color)
+{
+    double hue;
+    double saturation;
+    double lightness;
+    color.getHSL(hue, saturation, lightness);
+    
+    // These values were derived empirically, and are only experimental.
+    if (lightness < 0.3333) // Dark
+        return CGSizeMake(0.007, 0.019);
+
+    if (lightness < 0.6667) // Medium
+        return CGSizeMake(0.032, 0.032);
+
+    // Light
+    return CGSizeMake(0.0475, 0.039);
+}
+#endif
+
 void FontCascade::drawGlyphs(GraphicsContext* context, const Font* font, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& anchorPoint) const
 {
     const FontPlatformData& platformData = font->platformData();
@@ -213,29 +233,34 @@
 
     bool shouldSmoothFonts;
     bool changeFontSmoothing;
+    bool matchAntialiasedAndSmoothedFonts = context->antialiasedFontDilationEnabled();
     
     switch (fontDescription().fontSmoothing()) {
     case Antialiased: {
         context->setShouldAntialias(true);
         shouldSmoothFonts = false;
         changeFontSmoothing = true;
+        matchAntialiasedAndSmoothedFonts = false; // CSS has opted into strictly antialiased fonts.
         break;
     }
     case SubpixelAntialiased: {
         context->setShouldAntialias(true);
         shouldSmoothFonts = true;
         changeFontSmoothing = true;
+        matchAntialiasedAndSmoothedFonts = true;
         break;
     }
     case NoSmoothing: {
         context->setShouldAntialias(false);
         shouldSmoothFonts = false;
         changeFontSmoothing = true;
+        matchAntialiasedAndSmoothedFonts = false;
         break;
     }
     case AutoSmoothing: {
         shouldSmoothFonts = true;
         changeFontSmoothing = false;
+        matchAntialiasedAndSmoothedFonts = true;
         break;
     }
     }
@@ -243,6 +268,7 @@
     if (!shouldUseSmoothing()) {
         shouldSmoothFonts = false;
         changeFontSmoothing = true;
+        matchAntialiasedAndSmoothedFonts = true;
     }
 
 #if !PLATFORM(IOS)
@@ -251,7 +277,18 @@
         originalShouldUseFontSmoothing = CGContextGetShouldSmoothFonts(cgContext);
         CGContextSetShouldSmoothFonts(cgContext, shouldSmoothFonts);
     }
+    
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    CGFontAntialiasingStyle oldAntialiasingStyle;
+    bool resetAntialiasingStyle = false;
+    if (antialiasedFontDilationEnabled() && !CGContextGetShouldSmoothFonts(cgContext) && matchAntialiasedAndSmoothedFonts) {
+        resetAntialiasingStyle = true;
+        oldAntialiasingStyle = CGContextGetFontAntialiasingStyle(cgContext);
+        CGContextSetFontAntialiasingStyle(cgContext, kCGFontAntialiasingStyleUnfilteredCustomDilation);
+        CGContextSetFontDilation(cgContext, dilationSizeForTextColor(context->fillColor()));
+    }
 #endif
+#endif
 
 #if !PLATFORM(IOS)
     NSFont* drawFont = [platformData.nsFont() printerFont];
@@ -368,6 +405,11 @@
         context->setShadow(shadowOffset, shadowBlur, shadowColor, shadowColorSpace);
 
 #if !PLATFORM(IOS)
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    if (resetAntialiasingStyle)
+        CGContextSetFontAntialiasingStyle(cgContext, oldAntialiasingStyle);
+#endif
+    
     if (changeFontSmoothing)
         CGContextSetShouldSmoothFonts(cgContext, originalShouldUseFontSmoothing);
 #endif

Modified: tags/Safari-601.1.26/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h (182548 => 182549)


--- tags/Safari-601.1.26/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h	2015-04-08 17:27:33 UTC (rev 182548)
+++ tags/Safari-601.1.26/Source/WebCore/platform/spi/cg/CoreGraphicsSPI.h	2015-04-08 17:49:56 UTC (rev 182549)
@@ -79,6 +79,9 @@
 enum {
     kCGFontAntialiasingStyleUnfiltered = 0 << 7,
     kCGFontAntialiasingStyleFilterLight = 1 << 7,
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+    kCGFontAntialiasingStyleUnfilteredCustomDilation = (8 << 7),
+#endif
 };
 typedef uint32_t CGFontAntialiasingStyle;
 
@@ -126,6 +129,9 @@
 void CGContextSetCTM(CGContextRef, CGAffineTransform);
 void CGContextSetCompositeOperation(CGContextRef, CGCompositeOperation);
 void CGContextSetShouldAntialiasFonts(CGContextRef, bool shouldAntialiasFonts);
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100
+void CGContextSetFontDilation(CGContextRef, CGSize);
+#endif
 
 CFStringRef CGFontCopyFamilyName(CGFontRef);
 bool CGFontGetDescriptor(CGFontRef, CGFontDescriptor*);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to