diff options
author | Mike Klein <mtklein@chromium.org> | 2017-09-19 13:07:27 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-19 17:27:09 +0000 |
commit | 7028443d1d70a2497f315443dfd45a157f300854 (patch) | |
tree | 2e2724f0e9f2e740930aa997fad187ff3845d0f9 | |
parent | b858da928b5ba20adff914637526b847aea9035f (diff) |
fix race in SkFontHost_mac.cpp
We've not got any sort of synchronization guarding gSupportsLCD.
If we simply move the work into its initializer, it will happen
once in a thread safe way.
Change-Id: I86d87bea2850d0ce4d3886069f6f1f968d323343
Reviewed-on: https://skia-review.googlesource.com/48582
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
-rw-r--r-- | src/ports/SkFontHost_mac.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 2564ab5b04..d8bac13cdd 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -206,30 +206,28 @@ static CGAffineTransform MatrixToCGAffineTransform(const SkMatrix& matrix) { * smoothing is applied a gamma of 2.0 will be used, if not a gamma of 1.0. */ static bool supports_LCD() { - static int gSupportsLCD = -1; - if (gSupportsLCD >= 0) { - return (bool) gSupportsLCD; - } - uint32_t rgb = 0; - UniqueCFRef<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB()); - UniqueCFRef<CGContextRef> cgContext( - CGBitmapContextCreate(&rgb, 1, 1, 8, 4, colorspace.get(), BITMAP_INFO_RGB)); - UniqueCFRef<CTFontRef> ctFont(CTFontCreateWithName(CFSTR("Helvetica"), 16, nullptr)); - CGContextSetShouldSmoothFonts(cgContext.get(), true); - CGContextSetShouldAntialias(cgContext.get(), true); - CGContextSetTextDrawingMode(cgContext.get(), kCGTextFill); - CGContextSetGrayFillColor(cgContext.get(), 1, 1); - CGPoint point = CGPointMake(-1, 0); - static const UniChar pipeChar = '|'; - CGGlyph pipeGlyph; - CTFontGetGlyphsForCharacters(ctFont.get(), &pipeChar, &pipeGlyph, 1); - CTFontDrawGlyphs(ctFont.get(), &pipeGlyph, &point, 1, cgContext.get()); - - uint32_t r = (rgb >> 16) & 0xFF; - uint32_t g = (rgb >> 8) & 0xFF; - uint32_t b = (rgb >> 0) & 0xFF; - gSupportsLCD = (r != g || r != b); - return (bool) gSupportsLCD; + static bool gSupportsLCD = []{ + uint32_t rgb = 0; + UniqueCFRef<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB()); + UniqueCFRef<CGContextRef> cgContext( + CGBitmapContextCreate(&rgb, 1, 1, 8, 4, colorspace.get(), BITMAP_INFO_RGB)); + UniqueCFRef<CTFontRef> ctFont(CTFontCreateWithName(CFSTR("Helvetica"), 16, nullptr)); + CGContextSetShouldSmoothFonts(cgContext.get(), true); + CGContextSetShouldAntialias(cgContext.get(), true); + CGContextSetTextDrawingMode(cgContext.get(), kCGTextFill); + CGContextSetGrayFillColor(cgContext.get(), 1, 1); + CGPoint point = CGPointMake(-1, 0); + static const UniChar pipeChar = '|'; + CGGlyph pipeGlyph; + CTFontGetGlyphsForCharacters(ctFont.get(), &pipeChar, &pipeGlyph, 1); + CTFontDrawGlyphs(ctFont.get(), &pipeGlyph, &point, 1, cgContext.get()); + + uint32_t r = (rgb >> 16) & 0xFF; + uint32_t g = (rgb >> 8) & 0xFF; + uint32_t b = (rgb >> 0) & 0xFF; + return (r != g || r != b); + }(); + return gSupportsLCD; } class Offscreen { |