aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-25 19:10:45 +0000
committerGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-25 19:10:45 +0000
commit0dbb31168dc7890c16baf939e45ca9d099c67b78 (patch)
tree3b5df624537c4aea031e2861595fee1e8d8b3d7e
parentc909a1ecadd422d91ff97d10ce08865290223b14 (diff)
Don't use LCD on grayscale devices.
http://codereview.appspot.com/5281041 M src/ports/SkFontHost_mac_coretext.cpp git-svn-id: http://skia.googlecode.com/svn/trunk@2528 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--src/ports/SkFontHost_mac_coretext.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/ports/SkFontHost_mac_coretext.cpp b/src/ports/SkFontHost_mac_coretext.cpp
index 195722807c..f786908a51 100644
--- a/src/ports/SkFontHost_mac_coretext.cpp
+++ b/src/ports/SkFontHost_mac_coretext.cpp
@@ -1220,6 +1220,30 @@ SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) {
return nextFontID;
}
+static bool supports_LCD() {
+ static int gSupportsLCD = -1;
+ if (gSupportsLCD >= 0) {
+ return (bool) gSupportsLCD;
+ }
+ int rgb = 0;
+ CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
+ CGContextRef cgContext = CGBitmapContextCreate(&rgb, 1, 1, 8, 4, colorspace,
+ BITMAP_INFO_RGB);
+ CGContextSelectFont(cgContext, "Helvetica", 16, kCGEncodingMacRoman);
+ CGContextSetShouldSmoothFonts(cgContext, true);
+ CGContextSetShouldAntialias(cgContext, true);
+ CGContextSetTextDrawingMode(cgContext, kCGTextFill);
+ CGContextSetGrayFillColor( cgContext, 1, 1.0);
+ CGContextShowTextAtPoint(cgContext, -1, 0, "|", 1);
+ CFSafeRelease(colorspace);
+ CFSafeRelease(cgContext);
+ int r = (rgb >> 16) & 0xFF;
+ int g = (rgb >> 8) & 0xFF;
+ int b = (rgb >> 0) & 0xFF;
+ gSupportsLCD = r != g || r != b;
+ return (bool) gSupportsLCD;
+}
+
void SkFontHost::FilterRec(SkScalerContext::Rec* rec) {
unsigned flagsWeDontSupport = SkScalerContext::kDevKernText_Flag |
SkScalerContext::kAutohinting_Flag;
@@ -1235,8 +1259,13 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) {
}
rec->setHinting(h);
- if (SkMask::kLCD16_Format == rec->fMaskFormat) {
- rec->fMaskFormat = SkMask::kLCD32_Format;
+ if (SkMask::kLCD16_Format == rec->fMaskFormat
+ || SkMask::kLCD32_Format == rec->fMaskFormat) {
+ if (supports_LCD()) {
+ rec->fMaskFormat = SkMask::kLCD32_Format;
+ } else {
+ rec->fMaskFormat = SkMask::kA8_Format;
+ }
}
}