Title: [91205] trunk/Source/WebKit/chromium
Revision
91205
Author
[email protected]
Date
2011-07-18 13:36:31 -0700 (Mon, 18 Jul 2011)

Log Message

Patch by Yuzhu Shen <[email protected]> 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.

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (91204 => 91205)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-07-18 20:20:25 UTC (rev 91204)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-07-18 20:36:31 UTC (rev 91205)
@@ -1,3 +1,15 @@
+2011-07-18  Yuzhu Shen  <[email protected]>
+
+        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.
+
 2011-07-16  Simon Fraser  <[email protected]>
 
         Add code to attempt to align compositing layers to pixel boundaries when page scale changes

Modified: trunk/Source/WebKit/chromium/src/WebFontImpl.cpp (91204 => 91205)


--- trunk/Source/WebKit/chromium/src/WebFontImpl.cpp	2011-07-18 20:20:25 UTC (rev 91204)
+++ trunk/Source/WebKit/chromium/src/WebFontImpl.cpp	2011-07-18 20:36:31 UTC (rev 91205)
@@ -91,18 +91,44 @@
                            WebColor color, const WebRect& clip, bool canvasIsOpaque,
                            int from, int to) const
 {
-    // FIXME hook canvasIsOpaque up to the platform-specific indicators for
-    // whether subpixel AA can be used for this draw. On Windows, this is
-    // PlatformContextSkia::setDrawingToImageBuffer.
-
     GraphicsContextBuilder builder(canvas);
     GraphicsContext& gc = builder.context();
 
+#if WEBKIT_USING_SKIA
+    gc.platformContext()->setDrawingToImageBuffer(!canvasIsOpaque);
+#elif WEBKIT_USING_CG
+    // FIXME hook canvasIsOpaque up to the platform-specific indicators for
+    // whether subpixel AA can be used for this draw.
+#endif
+
     gc.save();
     gc.setFillColor(color, ColorSpaceDeviceRGB);
     gc.clip(WebCore::FloatRect(clip));
     m_font.drawText(&gc, run, leftBaseline, from, to);
     gc.restore();
+
+#if defined(WIN32)
+    if (canvasIsOpaque && SkColorGetA(color) == 0xFF) {
+        SkCanvas::LayerIter iter(const_cast<SkCanvas*>(canvas), false);
+        iter.next(); // There is always at least one layer.
+        bool multipleLayers = !iter.done();
+        if (!multipleLayers) {
+            // The text drawing logic on Windows ignores the alpha component
+            // intentionally, for performance reasons.
+            // (Please see TransparencyAwareFontPainter::initializeForGDI in
+            // FontChromiumWin.cpp.)
+            const SkBitmap& bitmap = canvas->getTopDevice()->accessBitmap(true);
+            IntRect textBounds = estimateTextBounds(run, leftBaseline);
+            IntRect destRect = gc.getCTM().mapRect(textBounds);
+            destRect.intersect(IntRect(0, 0, bitmap.width(), bitmap.height()));
+            for (int y = destRect.y(), maxY = destRect.maxY(); y < maxY; y++) {
+                uint32_t* row = bitmap.getAddr32(0, y);
+                for (int x = destRect.x(), maxX = destRect.maxX(); x < maxX; x++)
+                    row[x] |= (0xFF << SK_A32_SHIFT);
+            }
+        }
+    }
+#endif
 }
 
 int WebFontImpl::calculateWidth(const WebTextRun& run) const
@@ -120,4 +146,14 @@
     return m_font.selectionRectForText(run, leftBaseline, height, from, to);
 }
 
+WebRect WebFontImpl::estimateTextBounds(const WebTextRun& run, const WebFloatPoint& leftBaseline) const
+{
+    int totalWidth = m_font.width(run, 0);
+    const FontMetrics& fontMetrics = m_font.fontMetrics();
+    return WebRect(leftBaseline.x - (fontMetrics.ascent() + fontMetrics.descent()) / 2,
+                   leftBaseline.y - fontMetrics.ascent() - fontMetrics.lineGap(),
+                   totalWidth + fontMetrics.ascent() + fontMetrics.descent(),
+                   fontMetrics.lineSpacing()); 
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/chromium/src/WebFontImpl.h (91204 => 91205)


--- trunk/Source/WebKit/chromium/src/WebFontImpl.h	2011-07-18 20:20:25 UTC (rev 91204)
+++ trunk/Source/WebKit/chromium/src/WebFontImpl.h	2011-07-18 20:36:31 UTC (rev 91205)
@@ -58,6 +58,9 @@
                                               int height, int from = 0, int to = -1) const;
 
 private:
+    // Estimates the bounding box of the given text.
+    WebRect estimateTextBounds(const WebTextRun&, const WebFloatPoint& leftBaseline) const;
+
     WebCore::Font m_font;
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to