Changeset 91205 in webkit


Ignore:
Timestamp:
Jul 18, 2011 1:36:31 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Patch by Yuzhu Shen <yzshen@chromium.com> on 2011-07-18
Reviewed by James Robinson.

[chromium] WebFontImpl::drawText needs to handle the canvasIsOpaque input.
https://bugs.webkit.org/show_bug.cgi?id=64555

This change handles canvasIsOpaque for the WEBKIT_USING_SKIA case.

  • src/WebFontImpl.cpp: handled canvasIsOpaque.
  • src/WebFontImpl.h: added method declaration.
Location:
trunk/Source/WebKit/chromium
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r91161 r91205  
     12011-07-18  Yuzhu Shen  <yzshen@chromium.com>
     2
     3        Reviewed by James Robinson.
     4
     5        [chromium] WebFontImpl::drawText needs to handle the canvasIsOpaque input.
     6        https://bugs.webkit.org/show_bug.cgi?id=64555
     7       
     8        This change handles canvasIsOpaque for the WEBKIT_USING_SKIA case.
     9 
     10        * src/WebFontImpl.cpp: handled canvasIsOpaque.
     11        * src/WebFontImpl.h: added method declaration.
     12
    1132011-07-16  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/Source/WebKit/chromium/src/WebFontImpl.cpp

    r77383 r91205  
    9292                           int from, int to) const
    9393{
    94     // FIXME hook canvasIsOpaque up to the platform-specific indicators for
    95     // whether subpixel AA can be used for this draw. On Windows, this is
    96     // PlatformContextSkia::setDrawingToImageBuffer.
    97 
    9894    GraphicsContextBuilder builder(canvas);
    9995    GraphicsContext& gc = builder.context();
     96
     97#if WEBKIT_USING_SKIA
     98    gc.platformContext()->setDrawingToImageBuffer(!canvasIsOpaque);
     99#elif WEBKIT_USING_CG
     100    // FIXME hook canvasIsOpaque up to the platform-specific indicators for
     101    // whether subpixel AA can be used for this draw.
     102#endif
    100103
    101104    gc.save();
     
    104107    m_font.drawText(&gc, run, leftBaseline, from, to);
    105108    gc.restore();
     109
     110#if defined(WIN32)
     111    if (canvasIsOpaque && SkColorGetA(color) == 0xFF) {
     112        SkCanvas::LayerIter iter(const_cast<SkCanvas*>(canvas), false);
     113        iter.next(); // There is always at least one layer.
     114        bool multipleLayers = !iter.done();
     115        if (!multipleLayers) {
     116            // The text drawing logic on Windows ignores the alpha component
     117            // intentionally, for performance reasons.
     118            // (Please see TransparencyAwareFontPainter::initializeForGDI in
     119            // FontChromiumWin.cpp.)
     120            const SkBitmap& bitmap = canvas->getTopDevice()->accessBitmap(true);
     121            IntRect textBounds = estimateTextBounds(run, leftBaseline);
     122            IntRect destRect = gc.getCTM().mapRect(textBounds);
     123            destRect.intersect(IntRect(0, 0, bitmap.width(), bitmap.height()));
     124            for (int y = destRect.y(), maxY = destRect.maxY(); y < maxY; y++) {
     125                uint32_t* row = bitmap.getAddr32(0, y);
     126                for (int x = destRect.x(), maxX = destRect.maxX(); x < maxX; x++)
     127                    row[x] |= (0xFF << SK_A32_SHIFT);
     128            }
     129        }
     130    }
     131#endif
    106132}
    107133
     
    121147}
    122148
     149WebRect WebFontImpl::estimateTextBounds(const WebTextRun& run, const WebFloatPoint& leftBaseline) const
     150{
     151    int totalWidth = m_font.width(run, 0);
     152    const FontMetrics& fontMetrics = m_font.fontMetrics();
     153    return WebRect(leftBaseline.x - (fontMetrics.ascent() + fontMetrics.descent()) / 2,
     154                   leftBaseline.y - fontMetrics.ascent() - fontMetrics.lineGap(),
     155                   totalWidth + fontMetrics.ascent() + fontMetrics.descent(),
     156                   fontMetrics.lineSpacing());
     157}
     158
    123159} // namespace WebKit
  • trunk/Source/WebKit/chromium/src/WebFontImpl.h

    r64160 r91205  
    5959
    6060private:
     61    // Estimates the bounding box of the given text.
     62    WebRect estimateTextBounds(const WebTextRun&, const WebFloatPoint& leftBaseline) const;
     63
    6164    WebCore::Font m_font;
    6265};
Note: See TracChangeset for help on using the changeset viewer.