Changeset 92150 in webkit


Ignore:
Timestamp:
Aug 1, 2011 4:12:49 PM (13 years ago)
Author:
zmo@google.com
Message:

Unreviewed, rolling out r92022.
http://trac.webkit.org/changeset/92022
https://bugs.webkit.org/show_bug.cgi?id=65203

try to see if this is causing a bunch of browser tests failues
on win bots - will recommit if not

Source/WebCore:

  • platform/graphics/chromium/FontChromiumWin.cpp:

(WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::TransparencyAwareFontPainter):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::init):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::initializeForGDI):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::~TransparencyAwareFontPainter):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::TransparencyAwareGlyphPainter):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::~TransparencyAwareGlyphPainter):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareUniscribePainter::hdc):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareUniscribePainter::TransparencyAwareUniscribePainter):
(WebCore::TransparencyAwareFontPainter::TransparencyAwareUniscribePainter::~TransparencyAwareUniscribePainter):
(WebCore::drawGlyphsWin):
(WebCore::Font::drawComplexText):

  • platform/graphics/chromium/UniscribeHelper.cpp:

(WebCore::UniscribeHelper::draw):

  • platform/graphics/skia/PlatformContextSkia.cpp:

(WebCore::PlatformContextSkia::isNativeFontRenderingAllowed):

  • platform/graphics/skia/PlatformContextSkia.h:
  • platform/graphics/skia/SkiaFontWin.cpp:

(WebCore::windowsCanHandleDrawTextShadow):
(WebCore::windowsCanHandleTextDrawing):
(WebCore::windowsCanHandleTextDrawingWithoutShadow):

  • platform/graphics/skia/SkiaFontWin.h:

LayoutTests:

  • platform/chromium/test_expectations.txt:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r92149 r92150  
     12011-08-01  Zhenyao Mo  <zmo@google.com>
     2
     3        Unreviewed, rolling out r92022.
     4        http://trac.webkit.org/changeset/92022
     5        https://bugs.webkit.org/show_bug.cgi?id=65203
     6
     7        try to see if this is causing a bunch of browser tests failues
     8        on win bots - will recommit if not
     9
     10        * platform/chromium/test_expectations.txt:
     11
    1122011-08-01  Ryosuke Niwa  <rniwa@webkit.org>
    213
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r92126 r92150  
    18341834
    18351835BUGWK38705 : http/tests/security/sandbox-inherit-to-initial-document-2.html = TEXT
    1836 
    1837 // Switching windows over from GDI to Skia for all text rendering.
    1838 // When that lands, we will rebaseline these images.
    1839 BUGWK65203 WIN : fast/borders/border-antialiasing.html = IMAGE
    1840 BUGWK65203 WIN : fast/reflections/reflection-overflow-hidden.html = IMAGE
    1841 BUGWK65203 WIN : fast/repaint/reflection-redraw.html = IMAGE
    1842 BUGWK65203 WIN : fast/text/atsui-spacing-features.html = IMAGE
    1843 BUGWK65203 WIN : fast/text/cg-vs-atsui.html = IMAGE
    1844 BUGWK65203 WIN : fast/text/complex-text-opacity.html = IMAGE
    1845 BUGWK65203 WIN : fast/text/international/complex-character-based-fallback.html = IMAGE
    1846 BUGWK65203 WIN : fast/text/international/danda-space.html = IMAGE
    1847 BUGWK65203 WIN : fast/text/international/thai-baht-space.html = IMAGE
    1848 BUGWK65203 WIN : fast/text/international/thai-line-breaks.html = IMAGE
    1849 BUGWK65203 WIN : media/audio-repaint.html = IMAGE
    1850 BUGWK65203 WIN : platform/win/fast/text/uniscribe-missing-glyph.html = IMAGE
    1851 BUGWK65203 WIN : svg/W3C-SVG-1.1-SE/text-intro-05-t.svg = IMAGE
    1852 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-37-t.svg = IMAGE
    1853 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-39-t.svg = IMAGE
    1854 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-40-t.svg = IMAGE
    1855 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-41-t.svg = IMAGE
    1856 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-46-t.svg = IMAGE
    1857 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-60-t.svg = IMAGE
    1858 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-61-t.svg = IMAGE
    1859 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-62-t.svg = IMAGE
    1860 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-63-t.svg = IMAGE
    1861 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-64-t.svg = IMAGE
    1862 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-65-t.svg = IMAGE
    1863 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-66-t.svg = IMAGE
    1864 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-67-t.svg = IMAGE
    1865 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-68-t.svg = IMAGE
    1866 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-69-t.svg = IMAGE
    1867 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-70-t.svg = IMAGE
    1868 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-81-t.svg = IMAGE
    1869 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-82-t.svg = IMAGE
    1870 BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-83-t.svg = IMAGE
    1871 BUGWK65203 WIN : svg/W3C-SVG-1.1/pservers-grad-07-b.svg = IMAGE
    1872 BUGWK65203 WIN : svg/W3C-SVG-1.1/struct-frag-02-t.svg = IMAGE
    1873 BUGWK65203 WIN : svg/W3C-SVG-1.1/text-align-04-b.svg = IMAGE
    1874 BUGWK65203 WIN : svg/W3C-SVG-1.1/text-align-05-b.svg = IMAGE
    1875 BUGWK65203 WIN : svg/W3C-SVG-1.1/text-align-06-b.svg = IMAGE
    1876 BUGWK65203 WIN : svg/W3C-SVG-1.1/text-path-01-b.svg = IMAGE
    1877 BUGWK65203 WIN : svg/W3C-SVG-1.1/text-text-05-t.svg = IMAGE
    1878 BUGWK65203 WIN : svg/as-background-image/animated-svg-as-background.html = IMAGE
    1879 BUGWK65203 WIN : svg/as-image/animated-svg-as-image.html = IMAGE
    1880 BUGWK65203 WIN : svg/batik/filters/feTile.svg = IMAGE
    1881 BUGWK65203 WIN : svg/batik/filters/filterRegions.svg = IMAGE
    1882 BUGWK65203 WIN : svg/batik/text/longTextOnPath.svg = IMAGE
    1883 BUGWK65203 WIN : svg/batik/text/textAnchor.svg = IMAGE
    1884 BUGWK65203 WIN : svg/batik/text/textFeatures.svg = IMAGE
    1885 BUGWK65203 WIN : svg/batik/text/textLayout.svg = IMAGE
    1886 BUGWK65203 WIN : svg/batik/text/textPCDATA.svg = IMAGE
    1887 BUGWK65203 WIN : svg/batik/text/textProperties.svg = IMAGE
    1888 BUGWK65203 WIN : svg/batik/text/textProperties2.svg = IMAGE
    1889 BUGWK65203 WIN : svg/batik/text/textStyles.svg = IMAGE
    1890 BUGWK65203 WIN : svg/carto.net/textbox.svg = IMAGE
    1891 BUGWK65203 WIN : svg/carto.net/window.svg = IMAGE
    1892 BUGWK65203 WIN : svg/custom/js-late-clipPath-and-object-creation.svg = IMAGE
    1893 BUGWK65203 WIN : svg/custom/js-late-clipPath-creation.svg = IMAGE
    1894 BUGWK65203 WIN : svg/custom/linking-a-03-b-viewBox.svg = IMAGE
    1895 BUGWK65203 WIN : svg/custom/linking-uri-01-b.svg = IMAGE
    1896 BUGWK65203 WIN : svg/custom/svg-fonts-fallback.xhtml = IMAGE
    1897 BUGWK65203 WIN : svg/dynamic-updates/SVGTextElement-dom-lengthAdjust-attr.html = IMAGE
    1898 BUGWK65203 WIN : svg/dynamic-updates/SVGTextElement-svgdom-lengthAdjust-prop.html = IMAGE
    1899 BUGWK65203 WIN : svg/hixie/mixed/009.xml = IMAGE
    1900 BUGWK65203 WIN : svg/text/foreignObject-text-clipping-bug.xml = IMAGE
    1901 BUGWK65203 WIN : svg/text/scaling-font-with-geometric-precision.html = IMAGE
    1902 BUGWK65203 WIN : svg/text/text-align-01-b.svg = IMAGE
    1903 BUGWK65203 WIN : svg/text/text-align-05-b.svg = IMAGE
    1904 BUGWK65203 WIN : svg/text/text-align-06-b.svg = IMAGE
    1905 BUGWK65203 WIN : svg/text/text-intro-05-t.svg = IMAGE
    1906 BUGWK65203 WIN : svg/text/text-path-01-b.svg = IMAGE
    1907 BUGWK65203 WIN : svg/text/textPathBoundsBug.svg = IMAGE
    1908 BUGWK65203 WIN : svg/zoom/page/zoom-coords-viewattr-01-b.svg = IMAGE
    1909 BUGWK65203 WIN : svg/zoom/page/zoom-hixie-mixed-008.xml = IMAGE
    1910 BUGWK65203 WIN : svg/zoom/page/zoom-hixie-mixed-009.xml = IMAGE
    1911 BUGWK65203 WIN : svg/zoom/text/zoom-coords-viewattr-01-b.svg = IMAGE
    1912 BUGWK65203 WIN : svg/zoom/text/zoom-hixie-mixed-009.xml = IMAGE
    19131836
    19141837// WebKit roll 58791:58807
  • trunk/Source/WebCore/ChangeLog

    r92143 r92150  
     12011-08-01  Zhenyao Mo  <zmo@google.com>
     2
     3        Unreviewed, rolling out r92022.
     4        http://trac.webkit.org/changeset/92022
     5        https://bugs.webkit.org/show_bug.cgi?id=65203
     6
     7        try to see if this is causing a bunch of browser tests failues
     8        on win bots - will recommit if not
     9
     10        * platform/graphics/chromium/FontChromiumWin.cpp:
     11        (WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::TransparencyAwareFontPainter):
     12        (WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::init):
     13        (WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::initializeForGDI):
     14        (WebCore::TransparencyAwareFontPainter::TransparencyAwareFontPainter::~TransparencyAwareFontPainter):
     15        (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::TransparencyAwareGlyphPainter):
     16        (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::~TransparencyAwareGlyphPainter):
     17        (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs):
     18        (WebCore::TransparencyAwareFontPainter::TransparencyAwareUniscribePainter::hdc):
     19        (WebCore::TransparencyAwareFontPainter::TransparencyAwareUniscribePainter::TransparencyAwareUniscribePainter):
     20        (WebCore::TransparencyAwareFontPainter::TransparencyAwareUniscribePainter::~TransparencyAwareUniscribePainter):
     21        (WebCore::drawGlyphsWin):
     22        (WebCore::Font::drawComplexText):
     23        * platform/graphics/chromium/UniscribeHelper.cpp:
     24        (WebCore::UniscribeHelper::draw):
     25        * platform/graphics/skia/PlatformContextSkia.cpp:
     26        (WebCore::PlatformContextSkia::isNativeFontRenderingAllowed):
     27        * platform/graphics/skia/PlatformContextSkia.h:
     28        * platform/graphics/skia/SkiaFontWin.cpp:
     29        (WebCore::windowsCanHandleDrawTextShadow):
     30        (WebCore::windowsCanHandleTextDrawing):
     31        (WebCore::windowsCanHandleTextDrawingWithoutShadow):
     32        * platform/graphics/skia/SkiaFontWin.h:
     33
    1342011-08-01  Scott Graham  <scottmg@chromium.org>
    235
  • trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp

    r92022 r92150  
    6363public:
    6464    TransparencyAwareFontPainter(GraphicsContext*, const FloatPoint&);
     65    ~TransparencyAwareFontPainter();
    6566
    6667protected:
     68    // Called by our subclass' constructor to initialize GDI if necessary. This
     69    // is a separate function so it can be called after the subclass finishes
     70    // construction (it calls virtual functions).
     71    void init();
     72
    6773    virtual IntRect estimateTextBounds() = 0;
    6874
     
    7379
    7480    FloatPoint m_point;
     81
     82    // Set when Windows can handle the type of drawing we're doing.
     83    bool m_useGDI;
     84
     85    // These members are valid only when m_useGDI is set.
     86    HDC m_hdc;
     87    TransparencyWin m_transparency;
     88
     89private:
     90    // Call when we're using GDI mode to initialize the TransparencyWin to help
     91    // us draw GDI text.
     92    void initializeForGDI();
     93
     94    bool m_createdTransparencyLayer;  // We created a layer to give the font some alpha.
    7595};
    7696
     
    80100    , m_platformContext(context->platformContext())
    81101    , m_point(point)
    82 {
     102    , m_useGDI(windowsCanHandleTextDrawing(context))
     103    , m_hdc(0)
     104    , m_createdTransparencyLayer(false)
     105{
     106}
     107
     108void TransparencyAwareFontPainter::init()
     109{
     110    if (m_useGDI)
     111        initializeForGDI();
     112}
     113
     114void TransparencyAwareFontPainter::initializeForGDI()
     115{
     116    m_graphicsContext->save();
     117    SkColor color = m_platformContext->effectiveFillColor();
     118    // Used only when m_createdTransparencyLayer is true.
     119    float layerAlpha = 0.0f;
     120    if (SkColorGetA(color) != 0xFF) {
     121        // When the font has some transparency, apply it by creating a new
     122        // transparency layer with that opacity applied. We'll actually create
     123        // a new transparency layer after we calculate the bounding box.
     124        m_createdTransparencyLayer = true;
     125        layerAlpha = SkColorGetA(color) / 255.0f;
     126        // The color should be opaque now.
     127        color = SkColorSetRGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color));
     128    }
     129
     130    TransparencyWin::LayerMode layerMode;
     131    IntRect layerRect;
     132    if (m_platformContext->isDrawingToImageBuffer()) {
     133        // Assume if we're drawing to an image buffer that the background
     134        // is not opaque and we have to undo ClearType. We may want to
     135        // enhance this to actually check, since it will often be opaque
     136        // and we could do ClearType in that case.
     137        layerMode = TransparencyWin::TextComposite;
     138        layerRect = estimateTextBounds();
     139        m_graphicsContext->clip(layerRect);
     140        if (m_createdTransparencyLayer)
     141            m_graphicsContext->beginTransparencyLayer(layerAlpha);
     142
     143        // The transparency helper requires that we draw text in black in
     144        // this mode and it will apply the color.
     145        m_transparency.setTextCompositeColor(color);
     146        color = SkColorSetRGB(0, 0, 0);
     147    } else if (m_createdTransparencyLayer || canvasHasMultipleLayers(m_platformContext->canvas())) {
     148        // When we're drawing a web page, we know the background is opaque,
     149        // but if we're drawing to a layer, we still need extra work.
     150        layerMode = TransparencyWin::OpaqueCompositeLayer;
     151        layerRect = estimateTextBounds();
     152        m_graphicsContext->clip(layerRect);
     153        if (m_createdTransparencyLayer)
     154            m_graphicsContext->beginTransparencyLayer(layerAlpha);
     155    } else {
     156        // Common case of drawing onto the bottom layer of a web page: we
     157        // know everything is opaque so don't need to do anything special.
     158        layerMode = TransparencyWin::NoLayer;
     159    }
     160
     161    // Bug 26088 - init() might fail if layerRect is invalid. Given this, we
     162    // need to be careful to check for null pointers everywhere after this call
     163    m_transparency.init(m_graphicsContext, layerMode,
     164                        TransparencyWin::KeepTransform, layerRect);
     165
     166    // Set up the DC, using the one from the transparency helper.
     167    if (m_transparency.platformContext()) {
     168        m_hdc = skia::BeginPlatformPaint(m_transparency.platformContext()->canvas());
     169        SetTextColor(m_hdc, skia::SkColorToCOLORREF(color));
     170        SetBkMode(m_hdc, TRANSPARENT);
     171    }
     172}
     173
     174TransparencyAwareFontPainter::~TransparencyAwareFontPainter()
     175{
     176    if (!m_useGDI || !m_graphicsContext || !m_platformContext)
     177        return;  // Nothing to do.
     178    m_transparency.composite();
     179    if (m_createdTransparencyLayer)
     180        m_graphicsContext->endTransparencyLayer();
     181    m_graphicsContext->restore();
     182    if (m_transparency.platformContext())
     183        skia::EndPlatformPaint(m_transparency.platformContext()->canvas());
    83184}
    84185
     
    91192                                  int from, int numGlyphs,
    92193                                  const FloatPoint&);
     194    ~TransparencyAwareGlyphPainter();
    93195
    94196    // Draws the partial string of glyphs, starting at |startAdvance| to the
    95     // left of m_point.
    96     void drawGlyphs(int numGlyphs, const WORD* glyphs, const int* advances, float startAdvance) const;
     197    // left of m_point. We express it this way so that if we're using the Skia
     198    // drawing path we can use floating-point positioning, even though we have
     199    // to use integer positioning in the GDI path.
     200    bool drawGlyphs(int numGlyphs, const WORD* glyphs, const int* advances, float startAdvance) const;
    97201
    98202 private:
     
    103207    int m_from;
    104208    int m_numGlyphs;
     209
     210    // When m_useGdi is set, this stores the previous HFONT selected into the
     211    // m_hdc so we can restore it.
     212    HGDIOBJ m_oldFont;  // For restoring the DC to its original state.
    105213};
    106214
     
    116224    , m_from(from)
    117225    , m_numGlyphs(numGlyphs)
    118 {
    119 }
     226    , m_oldFont(0)
     227{
     228    init();
     229
     230    if (m_hdc)
     231        m_oldFont = ::SelectObject(m_hdc, m_font->platformData().hfont());
     232}
     233
     234TransparencyAwareGlyphPainter::~TransparencyAwareGlyphPainter()
     235{
     236    if (m_useGDI && m_hdc)
     237        ::SelectObject(m_hdc, m_oldFont);
     238}
     239
    120240
    121241// Estimates the bounding box of the given text. This is copied from
     
    135255}
    136256
    137 void TransparencyAwareGlyphPainter::drawGlyphs(int numGlyphs,
     257bool TransparencyAwareGlyphPainter::drawGlyphs(int numGlyphs,
    138258                                               const WORD* glyphs,
    139259                                               const int* advances,
    140260                                               float startAdvance) const
    141261{
    142     SkPoint origin = m_point;
    143     origin.fX += SkFloatToScalar(startAdvance);
    144     paintSkiaText(m_graphicsContext, m_font->platformData().hfont(),
    145                   numGlyphs, glyphs, advances, 0, &origin);
     262    if (!m_useGDI) {
     263        SkPoint origin = m_point;
     264        origin.fX += SkFloatToScalar(startAdvance);
     265        paintSkiaText(m_graphicsContext, m_font->platformData().hfont(),
     266                      numGlyphs, glyphs, advances, 0, &origin);
     267        return true;
     268    }
     269
     270    if (!m_graphicsContext || !m_hdc)
     271        return true;
     272
     273    // Windows' origin is the top-left of the bounding box, so we have
     274    // to subtract off the font ascent to get it.
     275    int x = lroundf(m_point.x() + startAdvance);
     276    int y = lroundf(m_point.y() - m_font->fontMetrics().ascent());
     277
     278    // If there is a non-blur shadow and both the fill color and shadow color
     279    // are opaque, handle without skia.
     280    FloatSize shadowOffset;
     281    float shadowBlur;
     282    Color shadowColor;
     283    ColorSpace shadowColorSpace;
     284    if (m_graphicsContext->getShadow(shadowOffset, shadowBlur, shadowColor, shadowColorSpace)) {
     285        // If there is a shadow and this code is reached, windowsCanHandleDrawTextShadow()
     286        // will have already returned true during the ctor initiatization of m_useGDI
     287        ASSERT(shadowColor.alpha() == 255);
     288        ASSERT(m_graphicsContext->fillColor().alpha() == 255);
     289        ASSERT(shadowBlur == 0);
     290        COLORREF textColor = skia::SkColorToCOLORREF(SkColorSetARGB(255, shadowColor.red(), shadowColor.green(), shadowColor.blue()));
     291        COLORREF savedTextColor = GetTextColor(m_hdc);
     292        SetTextColor(m_hdc, textColor);
     293        ExtTextOut(m_hdc, x + shadowOffset.width(), y + shadowOffset.height(), ETO_GLYPH_INDEX, 0, reinterpret_cast<const wchar_t*>(&glyphs[0]), numGlyphs, &advances[0]);
     294        SetTextColor(m_hdc, savedTextColor);
     295    }
     296   
     297    return !!ExtTextOut(m_hdc, x, y, ETO_GLYPH_INDEX, 0, reinterpret_cast<const wchar_t*>(&glyphs[0]), numGlyphs, &advances[0]);
    146298}
    147299
     
    153305                                      int from, int to,
    154306                                      const FloatPoint&);
     307    ~TransparencyAwareUniscribePainter();
     308
     309    // Uniscibe will draw directly into our buffer, so we need to expose our DC.
     310    HDC hdc() const { return m_hdc; }
    155311
    156312 private:
     
    174330    , m_from(from)
    175331    , m_to(to)
     332{
     333    init();
     334}
     335
     336TransparencyAwareUniscribePainter::~TransparencyAwareUniscribePainter()
    176337{
    177338}
     
    265426        }
    266427
    267         painter.drawGlyphs(curLen, &glyphs[0], &advances[0], horizontalOffset - point.x() - currentWidth);
     428        // Actually draw the glyphs (with retry on failure).
     429        bool success = false;
     430        for (int executions = 0; executions < 2; ++executions) {
     431            success = painter.drawGlyphs(curLen, &glyphs[0], &advances[0], horizontalOffset - point.x() - currentWidth);
     432            if (!success && executions == 0) {
     433                // Ask the browser to load the font for us and retry.
     434                PlatformBridge::ensureFontLoaded(font->platformData().hfont());
     435                continue;
     436            }
     437            break;
     438        }
     439
     440        if (!success)
     441            LOG_ERROR("Unable to draw the glyphs after second attempt");
    268442    }
    269443}
     
    319493        return;
    320494
     495    TransparencyAwareUniscribePainter painter(graphicsContext, this, run, from, to, point);
     496
     497    HDC hdc = painter.hdc();
     498    if (windowsCanHandleTextDrawing(graphicsContext) && !hdc)
     499        return;
     500
     501    // TODO(maruel): http://b/700464 SetTextColor doesn't support transparency.
     502    // Enforce non-transparent color.
     503    color = SkColorSetRGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color));
     504    if (hdc) {
     505        SetTextColor(hdc, skia::SkColorToCOLORREF(color));
     506        SetBkMode(hdc, TRANSPARENT);
     507    }
     508
     509    // If there is a non-blur shadow and both the fill color and shadow color
     510    // are opaque, handle without skia.
     511    FloatSize shadowOffset;
     512    float shadowBlur;
     513    Color shadowColor;
     514    ColorSpace shadowColorSpace;
     515    if (graphicsContext->getShadow(shadowOffset, shadowBlur, shadowColor, shadowColorSpace) && windowsCanHandleDrawTextShadow(graphicsContext)) {
     516        COLORREF textColor = skia::SkColorToCOLORREF(SkColorSetARGB(255, shadowColor.red(), shadowColor.green(), shadowColor.blue()));
     517        COLORREF savedTextColor = GetTextColor(hdc);
     518        SetTextColor(hdc, textColor);
     519        state.draw(graphicsContext, hdc, static_cast<int>(point.x()) + shadowOffset.width(),
     520                   static_cast<int>(point.y() - fontMetrics().ascent()) + shadowOffset.height(), from, to);
     521        SetTextColor(hdc, savedTextColor);
     522    }
     523
    321524    // Uniscribe counts the coordinates from the upper left, while WebKit uses
    322525    // the baseline, so we have to subtract off the ascent.
    323     HDC hdc = 0;
    324526    state.draw(graphicsContext, hdc, lroundf(point.x()), lroundf(point.y() - fontMetrics().ascent()), from, to);
    325527}
  • trunk/Source/WebCore/platform/graphics/chromium/UniscribeHelper.cpp

    r92022 r92150  
    270270    int curX = x;
    271271    bool firstRun = true;
     272    bool useWindowsDrawing = windowsCanHandleTextDrawing(graphicsContext);
    272273
    273274    for (size_t screenIndex = 0; screenIndex < m_runs.size(); screenIndex++) {
     
    348349            const int* justify = shaping.m_justify.size() == 0 ? 0 : &shaping.m_justify[fromGlyph];
    349350
     351            if (useWindowsDrawing) {
     352                if (firstRun) {
     353                    oldFont = SelectObject(dc, shaping.m_hfont);
     354                    firstRun = false;
     355                } else
     356                    SelectObject(dc, shaping.m_hfont);
     357            }
     358
    350359            // Fonts with different ascents can be used to render different
    351360            // runs.  'Across-runs' y-coordinate correction needs to be
     
    353362            bool textOutOk = false;
    354363            for (int executions = 0; executions < 2; ++executions) {
    355                 SkPoint origin;
    356                 origin.fX = curX + + innerOffset;
    357                 origin.fY = y + m_ascent;
    358                 paintSkiaText(graphicsContext,
    359                               shaping.m_hfont,
    360                               glyphCount,
    361                               &shaping.m_glyphs[fromGlyph],
    362                               &shaping.m_advance[fromGlyph],
    363                               &shaping.m_offsets[fromGlyph],
    364                               &origin);
    365                 textOutOk = true;
     364                if (useWindowsDrawing) {
     365                    HRESULT hr = ScriptTextOut(dc, shaping.m_scriptCache,
     366                                               curX + innerOffset,
     367                                               y - shaping.m_ascentOffset,
     368                                               0, 0, &item.a, 0, 0,
     369                                               &shaping.m_glyphs[fromGlyph],
     370                                               glyphCount,
     371                                               &shaping.m_advance[fromGlyph],
     372                                               justify,
     373                                               &shaping.m_offsets[fromGlyph]);
     374                    textOutOk = (hr == S_OK);
     375                } else {
     376                    SkPoint origin;
     377                    origin.fX = curX + + innerOffset;
     378                    origin.fY = y + m_ascent;
     379                    paintSkiaText(graphicsContext,
     380                                  shaping.m_hfont,
     381                                  glyphCount,
     382                                  &shaping.m_glyphs[fromGlyph],
     383                                  &shaping.m_advance[fromGlyph],
     384                                  &shaping.m_offsets[fromGlyph],
     385                                  &origin);
     386                    textOutOk = true;
     387                }
    366388
    367389                if (!textOutOk && 0 == executions) {
  • trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp

    r92022 r92150  
    570570}
    571571
     572bool PlatformContextSkia::isNativeFontRenderingAllowed()
     573{
     574#if ENABLE(SKIA_TEXT)
     575    return false;
     576#else
     577    if (useSkiaGPU())
     578        return false;
     579    return skia::SupportsPlatformPaint(m_canvas);
     580#endif
     581}
     582
    572583void PlatformContextSkia::getImageResamplingHint(IntSize* srcSize, FloatSize* dstSize) const
    573584{
  • trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h

    r92022 r92150  
    168168    void setPrinting(bool p) { m_printing = p; }
    169169
     170    // Returns if the context allows rendering of fonts using native platform
     171    // APIs. If false is returned font rendering is performed using the skia
     172    // text drawing APIs.
     173    bool isNativeFontRenderingAllowed();
     174
    170175    void getImageResamplingHint(IntSize* srcSize, FloatSize* dstSize) const;
    171176    void setImageResamplingHint(const IntSize& srcSize, const FloatSize& dstSize);
  • trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp

    r92022 r92150  
    4444namespace WebCore {
    4545
     46bool windowsCanHandleDrawTextShadow(GraphicsContext *context)
     47{
     48    FloatSize shadowOffset;
     49    float shadowBlur;
     50    Color shadowColor;
     51    ColorSpace shadowColorSpace;
     52
     53    bool hasShadow = context->getShadow(shadowOffset, shadowBlur, shadowColor, shadowColorSpace);
     54    return !hasShadow || (!shadowBlur && (shadowColor.alpha() == 255) && (context->fillColor().alpha() == 255));
     55}
     56
     57bool windowsCanHandleTextDrawing(GraphicsContext* context)
     58{
     59    if (!windowsCanHandleTextDrawingWithoutShadow(context))
     60        return false;
     61
     62    // Check for shadow effects.
     63    if (!windowsCanHandleDrawTextShadow(context))
     64        return false;
     65
     66    return true;
     67}
     68
     69bool windowsCanHandleTextDrawingWithoutShadow(GraphicsContext* context)
     70{
     71    // Check for non-translation transforms. Sometimes zooms will look better in
     72    // Skia, and sometimes better in Windows. The main problem is that zooming
     73    // in using Skia will show you the hinted outlines for the smaller size,
     74    // which look weird. All else being equal, it's better to use Windows' text
     75    // drawing, so we don't check for zooms.
     76    const AffineTransform& matrix = context->getCTM();
     77    if (matrix.b() != 0 || matrix.c() != 0)  // Check for skew.
     78        return false;
     79
     80    // Check for stroke effects.
     81    if (context->platformContext()->getTextDrawingMode() != TextModeFill)
     82        return false;
     83
     84    // Check for gradients.
     85    if (context->fillGradient() || context->strokeGradient())
     86        return false;
     87
     88    // Check for patterns.
     89    if (context->fillPattern() || context->strokePattern())
     90        return false;
     91
     92    if (!context->platformContext()->isNativeFontRenderingAllowed())
     93        return false;
     94
     95    return true;
     96}
     97
    4698static void skiaDrawText(SkCanvas* canvas,
    4799                         const SkPoint& point,
  • trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h

    r92022 r92150  
    4040
    4141class GraphicsContext;
     42class PlatformContextSkia;
     43
     44// The functions below are used for more complex font drawing (effects such as
     45// stroking and more complex transforms) than Windows supports directly.  Since
     46// Windows drawing is faster you should use windowsCanHandleTextDrawing first to
     47// check if using Skia is required at all.
     48// Note that the text will look different (no ClearType) so this should only be
     49// used when necessary.
     50//
     51// When you call a Skia* text drawing function, various glyph outlines will be
     52// cached. As a result, you should call SkiaWinOutlineCache::removePathsForFont
     53// when the font is destroyed so that the cache does not outlive the font (since
     54// the HFONTs are recycled).
     55//
     56// Remember that Skia's text drawing origin is the baseline, like WebKit, not
     57// the top, like Windows.
     58
     59// Returns true if the fillColor and shadowColor are opaque and the text-shadow
     60// is not blurred.
     61bool windowsCanHandleDrawTextShadow(GraphicsContext*);
     62
     63// Returns true if advanced font rendering is recommended.
     64bool windowsCanHandleTextDrawing(GraphicsContext*);
     65
     66// Returns true if advanced font rendering is recommended if shadows are
     67// disregarded.
     68bool windowsCanHandleTextDrawingWithoutShadow(GraphicsContext*);
    4269
    4370// Note that the offsets parameter is optional.  If not NULL it represents a
Note: See TracChangeset for help on using the changeset viewer.