Changeset 91805 in webkit


Ignore:
Timestamp:
Jul 26, 2011 6:10:04 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

[skia] never draw with GDI, so that all text can be gpu-accelerated
https://bugs.webkit.org/show_bug.cgi?id=65203

Patch by Mike Reed <reed@google.com> on 2011-07-26
Reviewed by Kenneth Russell.

No new tests. existing tests apply to the new drawing path

  • platform/graphics/chromium/FontChromiumWin.cpp:

(WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs):

  • platform/graphics/skia/SkiaFontWin.cpp:

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

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r91796 r91805  
    18461846
    18471847BUGWK38705 : http/tests/security/sandbox-inherit-to-initial-document-2.html = TEXT
     1848
     1849// Switching windows over from GDI to Skia for all text rendering.
     1850// When that lands, we will rebaseline these images.
     1851BUGWK65203 WIN : editing/selection/vertical-lr-ltr-extend-line-backward-br.html = IMAGE
     1852BUGWK65203 WIN : editing/selection/vertical-lr-ltr-extend-line-forward-br.html = IMAGE
     1853BUGWK65203 WIN : editing/selection/vertical-rl-ltr-extend-line-backward-br.html = IMAGE
     1854BUGWK65203 WIN : editing/selection/vertical-rl-ltr-extend-line-backward-p.html = IMAGE
     1855BUGWK65203 WIN : editing/selection/vertical-rl-ltr-extend-line-backward-wrap.html = IMAGE
     1856BUGWK65203 WIN : editing/selection/vertical-rl-ltr-extend-line-forward-br.html = IMAGE
     1857BUGWK65203 WIN : editing/selection/vertical-rl-ltr-extend-line-forward-p.html = IMAGE
     1858BUGWK65203 WIN : editing/selection/vertical-rl-ltr-extend-line-forward-wrap.html = IMAGE
     1859BUGWK65203 WIN : fast/borders/border-antialiasing.html = IMAGE
     1860BUGWK65203 WIN : fast/reflections/reflection-overflow-hidden.html = IMAGE
     1861BUGWK65203 WIN : fast/repaint/reflection-redraw.html = IMAGE
     1862BUGWK65203 WIN : fast/repaint/shadow-multiple-horizontal.html = IMAGE
     1863BUGWK65203 WIN : fast/repaint/shadow-multiple-strict-horizontal.html = IMAGE
     1864BUGWK65203 WIN : fast/repaint/shadow-multiple-strict-vertical.html = IMAGE
     1865BUGWK65203 WIN : fast/repaint/shadow-multiple-vertical.html = IMAGE
     1866BUGWK65203 WIN : fast/text/atsui-spacing-features.html = IMAGE
     1867BUGWK65203 WIN : fast/text/cg-vs-atsui.html = IMAGE
     1868BUGWK65203 WIN : fast/text/complex-text-opacity.html = IMAGE
     1869BUGWK65203 WIN : fast/text/international/complex-character-based-fallback.html = IMAGE
     1870BUGWK65203 WIN : fast/text/international/danda-space.html = IMAGE
     1871BUGWK65203 WIN : fast/text/international/thai-baht-space.html = IMAGE
     1872BUGWK65203 WIN : fast/text/international/thai-line-breaks.html = IMAGE
     1873BUGWK65203 WIN : fast/transforms/shadows.html = IMAGE
     1874BUGWK65203 WIN : media/audio-repaint.html = IMAGE
     1875BUGWK65203 WIN : platform/win/fast/text/uniscribe-missing-glyph.html = IMAGE
     1876BUGWK65203 WIN : svg/W3C-SVG-1.1-SE/text-intro-05-t.svg = IMAGE
     1877BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-37-t.svg = IMAGE
     1878BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-39-t.svg = IMAGE
     1879BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-40-t.svg = IMAGE
     1880BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-41-t.svg = IMAGE
     1881BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-46-t.svg = IMAGE
     1882BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-60-t.svg = IMAGE
     1883BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-61-t.svg = IMAGE
     1884BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-62-t.svg = IMAGE
     1885BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-63-t.svg = IMAGE
     1886BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-64-t.svg = IMAGE
     1887BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-65-t.svg = IMAGE
     1888BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-66-t.svg = IMAGE
     1889BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-67-t.svg = IMAGE
     1890BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-68-t.svg = IMAGE
     1891BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-69-t.svg = IMAGE
     1892BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-70-t.svg = IMAGE
     1893BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-81-t.svg = IMAGE
     1894BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-82-t.svg = IMAGE
     1895BUGWK65203 WIN : svg/W3C-SVG-1.1/animate-elem-83-t.svg = IMAGE
     1896BUGWK65203 WIN : svg/W3C-SVG-1.1/pservers-grad-07-b.svg = IMAGE
     1897BUGWK65203 WIN : svg/W3C-SVG-1.1/struct-frag-02-t.svg = IMAGE
     1898BUGWK65203 WIN : svg/W3C-SVG-1.1/text-align-04-b.svg = IMAGE
     1899BUGWK65203 WIN : svg/W3C-SVG-1.1/text-align-05-b.svg = IMAGE
     1900BUGWK65203 WIN : svg/W3C-SVG-1.1/text-align-06-b.svg = IMAGE
     1901BUGWK65203 WIN : svg/W3C-SVG-1.1/text-path-01-b.svg = IMAGE
     1902BUGWK65203 WIN : svg/W3C-SVG-1.1/text-text-05-t.svg = IMAGE
     1903BUGWK65203 WIN : svg/as-background-image/animated-svg-as-background.html = IMAGE
     1904BUGWK65203 WIN : svg/as-image/animated-svg-as-image.html = IMAGE
     1905BUGWK65203 WIN : svg/batik/filters/feTile.svg = IMAGE
     1906BUGWK65203 WIN : svg/batik/filters/filterRegions.svg = IMAGE
     1907BUGWK65203 WIN : svg/batik/text/longTextOnPath.svg = IMAGE
     1908BUGWK65203 WIN : svg/batik/text/textAnchor.svg = IMAGE
     1909BUGWK65203 WIN : svg/batik/text/textFeatures.svg = IMAGE
     1910BUGWK65203 WIN : svg/batik/text/textLayout.svg = IMAGE
     1911BUGWK65203 WIN : svg/batik/text/textPCDATA.svg = IMAGE
     1912BUGWK65203 WIN : svg/batik/text/textProperties.svg = IMAGE
     1913BUGWK65203 WIN : svg/batik/text/textProperties2.svg = IMAGE
     1914BUGWK65203 WIN : svg/batik/text/textStyles.svg = IMAGE
     1915BUGWK65203 WIN : svg/carto.net/textbox.svg = IMAGE
     1916BUGWK65203 WIN : svg/carto.net/window.svg = IMAGE
     1917BUGWK65203 WIN : svg/css/group-with-shadow.svg = IMAGE
     1918BUGWK65203 WIN : svg/css/text-gradient-shadow.svg = IMAGE
     1919BUGWK65203 WIN : svg/css/text-shadow-multiple.xhtml = IMAGE
     1920BUGWK65203 WIN : svg/custom/js-late-clipPath-and-object-creation.svg = IMAGE
     1921BUGWK65203 WIN : svg/custom/js-late-clipPath-creation.svg = IMAGE
     1922BUGWK65203 WIN : svg/custom/linking-a-03-b-viewBox.svg = IMAGE
     1923BUGWK65203 WIN : svg/custom/linking-uri-01-b.svg = IMAGE
     1924BUGWK65203 WIN : svg/custom/svg-fonts-fallback.xhtml = IMAGE
     1925BUGWK65203 WIN : svg/dynamic-updates/SVGTextElement-dom-lengthAdjust-attr.html = IMAGE
     1926BUGWK65203 WIN : svg/dynamic-updates/SVGTextElement-svgdom-lengthAdjust-prop.html = IMAGE
     1927BUGWK65203 WIN : svg/hixie/mixed/009.xml = IMAGE
     1928BUGWK65203 WIN : svg/text/foreignObject-text-clipping-bug.xml = IMAGE
     1929BUGWK65203 WIN : svg/text/scaling-font-with-geometric-precision.html = IMAGE
     1930BUGWK65203 WIN : svg/text/text-align-01-b.svg = IMAGE
     1931BUGWK65203 WIN : svg/text/text-align-05-b.svg = IMAGE
     1932BUGWK65203 WIN : svg/text/text-align-06-b.svg = IMAGE
     1933BUGWK65203 WIN : svg/text/text-intro-05-t.svg = IMAGE
     1934BUGWK65203 WIN : svg/text/text-path-01-b.svg = IMAGE
     1935BUGWK65203 WIN : svg/text/textPathBoundsBug.svg = IMAGE
     1936BUGWK65203 WIN : svg/zoom/page/zoom-coords-viewattr-01-b.svg = IMAGE
     1937BUGWK65203 WIN : svg/zoom/page/zoom-hixie-mixed-008.xml = IMAGE
     1938BUGWK65203 WIN : svg/zoom/page/zoom-hixie-mixed-009.xml = IMAGE
     1939BUGWK65203 WIN : svg/zoom/text/zoom-coords-viewattr-01-b.svg = IMAGE
     1940BUGWK65203 WIN : svg/zoom/text/zoom-hixie-mixed-009.xml = IMAGE
    18481941
    18491942// WebKit roll 58791:58807
  • trunk/Source/WebCore/ChangeLog

    r91803 r91805  
     12011-07-26  Mike Reed  <reed@google.com>
     2
     3        [skia] never draw with GDI, so that all text can be gpu-accelerated
     4        https://bugs.webkit.org/show_bug.cgi?id=65203
     5
     6        Reviewed by Kenneth Russell.
     7
     8        No new tests. existing tests apply to the new drawing path
     9
     10        * platform/graphics/chromium/FontChromiumWin.cpp:
     11        (WebCore::TransparencyAwareFontPainter::TransparencyAwareGlyphPainter::drawGlyphs):
     12        * platform/graphics/skia/SkiaFontWin.cpp:
     13        (WebCore::windowsCanHandleDrawTextShadow):
     14        (WebCore::windowsCanHandleTextDrawing):
     15        (WebCore::windowsCanHandleTextDrawingWithoutShadow):
     16
    1172011-07-26  Kenneth Russell  <kbr@google.com>
    218
  • trunk/Source/WebCore/platform/graphics/chromium/FontChromiumWin.cpp

    r91069 r91805  
    6363public:
    6464    TransparencyAwareFontPainter(GraphicsContext*, const FloatPoint&);
    65     ~TransparencyAwareFontPainter();
    6665
    6766protected:
    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 
    7367    virtual IntRect estimateTextBounds() = 0;
    7468
     
    7973
    8074    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 
    89 private:
    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.
    9575};
    9676
     
    10080    , m_platformContext(context->platformContext())
    10181    , m_point(point)
    102     , m_useGDI(windowsCanHandleTextDrawing(context))
    103     , m_hdc(0)
    104     , m_createdTransparencyLayer(false)
    105 {
    106 }
    107 
    108 void TransparencyAwareFontPainter::init()
    109 {
    110     if (m_useGDI)
    111         initializeForGDI();
    112 }
    113 
    114 void 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 
    174 TransparencyAwareFontPainter::~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());
     82{
    18483}
    18584
     
    19291                                  int from, int numGlyphs,
    19392                                  const FloatPoint&);
    194     ~TransparencyAwareGlyphPainter();
    19593
    19694    // Draws the partial string of glyphs, starting at |startAdvance| to the
    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;
     95    // left of m_point.
     96    void drawGlyphs(int numGlyphs, const WORD* glyphs, const int* advances, float startAdvance) const;
    20197
    20298 private:
     
    207103    int m_from;
    208104    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.
    213105};
    214106
     
    224116    , m_from(from)
    225117    , m_numGlyphs(numGlyphs)
    226     , m_oldFont(0)
    227 {
    228     init();
    229 
    230     if (m_hdc)
    231         m_oldFont = ::SelectObject(m_hdc, m_font->platformData().hfont());
    232 }
    233 
    234 TransparencyAwareGlyphPainter::~TransparencyAwareGlyphPainter()
    235 {
    236     if (m_useGDI && m_hdc)
    237         ::SelectObject(m_hdc, m_oldFont);
    238 }
    239 
     118{
     119}
    240120
    241121// Estimates the bounding box of the given text. This is copied from
     
    255135}
    256136
    257 bool TransparencyAwareGlyphPainter::drawGlyphs(int numGlyphs,
     137void TransparencyAwareGlyphPainter::drawGlyphs(int numGlyphs,
    258138                                               const WORD* glyphs,
    259139                                               const int* advances,
    260140                                               float startAdvance) const
    261141{
    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]);
     142    SkPoint origin = m_point;
     143    origin.fX += SkFloatToScalar(startAdvance);
     144    paintSkiaText(m_graphicsContext, m_font->platformData().hfont(),
     145                  numGlyphs, glyphs, advances, 0, &origin);
    298146}
    299147
     
    305153                                      int from, int to,
    306154                                      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; }
    311155
    312156 private:
     
    330174    , m_from(from)
    331175    , m_to(to)
    332 {
    333     init();
    334 }
    335 
    336 TransparencyAwareUniscribePainter::~TransparencyAwareUniscribePainter()
    337176{
    338177}
     
    426265        }
    427266
    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");
     267        painter.drawGlyphs(curLen, &glyphs[0], &advances[0], horizontalOffset - point.x() - currentWidth);
    442268    }
    443269}
     
    493319        return;
    494320
    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 
    524321    // Uniscribe counts the coordinates from the upper left, while WebKit uses
    525322    // the baseline, so we have to subtract off the ascent.
     323    HDC hdc = 0;
    526324    state.draw(graphicsContext, hdc, lroundf(point.x()), lroundf(point.y() - fontMetrics().ascent()), from, to);
    527325}
  • trunk/Source/WebCore/platform/graphics/chromium/UniscribeHelper.cpp

    r91069 r91805  
    270270    int curX = x;
    271271    bool firstRun = true;
    272     bool useWindowsDrawing = windowsCanHandleTextDrawing(graphicsContext);
    273272
    274273    for (size_t screenIndex = 0; screenIndex < m_runs.size(); screenIndex++) {
     
    349348            const int* justify = shaping.m_justify.size() == 0 ? 0 : &shaping.m_justify[fromGlyph];
    350349
    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 
    359350            // Fonts with different ascents can be used to render different
    360351            // runs.  'Across-runs' y-coordinate correction needs to be
     
    362353            bool textOutOk = false;
    363354            for (int executions = 0; executions < 2; ++executions) {
    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                 }
     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;
    388366
    389367                if (!textOutOk && 0 == executions) {
  • trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp

    r90872 r91805  
    570570}
    571571
    572 bool 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 
    583572void PlatformContextSkia::getImageResamplingHint(IntSize* srcSize, FloatSize* dstSize) const
    584573{
  • trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h

    r90872 r91805  
    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 
    175170    void getImageResamplingHint(IntSize* srcSize, FloatSize* dstSize) const;
    176171    void setImageResamplingHint(const IntSize& srcSize, const FloatSize& dstSize);
  • trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.cpp

    r91768 r91805  
    4343
    4444namespace WebCore {
    45 
    46 bool 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 
    57 bool 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 
    69 bool 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 }
    9745
    9846static void skiaDrawText(SkCanvas* canvas,
  • trunk/Source/WebCore/platform/graphics/skia/SkiaFontWin.h

    r91069 r91805  
    4040
    4141class GraphicsContext;
    42 class 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.
    61 bool windowsCanHandleDrawTextShadow(GraphicsContext*);
    62 
    63 // Returns true if advanced font rendering is recommended.
    64 bool windowsCanHandleTextDrawing(GraphicsContext*);
    65 
    66 // Returns true if advanced font rendering is recommended if shadows are
    67 // disregarded.
    68 bool windowsCanHandleTextDrawingWithoutShadow(GraphicsContext*);
    6942
    7043// Note that the offsets parameter is optional.  If not NULL it represents a
Note: See TracChangeset for help on using the changeset viewer.