Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 1317263007: Port SkLazyFnPtr users to SkOncePtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkLazyFnPtr.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_mac.cpp
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 343936c6733081f1493ab9ebebbfeda2ddfb69dd..7d90d84695f386c6ad40d55f33317e9c5bacf09f 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -28,7 +28,6 @@
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
#include "SkGlyph.h"
-#include "SkLazyFnPtr.h"
#include "SkMaskGamma.h"
#include "SkMutex.h"
#include "SkOTTable_glyf.h"
@@ -36,6 +35,7 @@
#include "SkOTTable_hhea.h"
#include "SkOTTable_loca.h"
#include "SkOTUtils.h"
+#include "SkOncePtr.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkSFNTHeader.h"
@@ -770,34 +770,27 @@ SkScalerContext_Mac::SkScalerContext_Mac(SkTypeface_Mac* typeface,
fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit);
}
-extern "C" {
-
-/** CTFontDrawGlyphs was introduced in 10.7. */
-typedef void (*CTFontDrawGlyphsProc)(CTFontRef, const CGGlyph[], const CGPoint[],
- size_t, CGContextRef);
-
-/** This is an implementation of CTFontDrawGlyphs for 10.6. */
-static void sk_legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGPoint points[],
- size_t count, CGContextRef cg)
-{
+/** This is an implementation of CTFontDrawGlyphs for 10.6; it was introduced in 10.7. */
+static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGPoint points[],
+ size_t count, CGContextRef cg) {
CGContextShowGlyphsAtPositions(cg, glyphs, points, count);
}
-}
+typedef decltype(legacy_CTFontDrawGlyphs) CTFontDrawGlyphsProc;
-CTFontDrawGlyphsProc SkChooseCTFontDrawGlyphs() {
- CTFontDrawGlyphsProc realCTFontDrawGlyphs;
- *reinterpret_cast<void**>(&realCTFontDrawGlyphs) = dlsym(RTLD_DEFAULT, "CTFontDrawGlyphs");
- return realCTFontDrawGlyphs ? realCTFontDrawGlyphs : sk_legacy_CTFontDrawGlyphs;
-};
+static CTFontDrawGlyphsProc* choose_CTFontDrawGlyphs() {
+ if (void* real = dlsym(RTLD_DEFAULT, "CTFontDrawGlyphs")) {
+ return (CTFontDrawGlyphsProc*)real;
+ }
+ return &legacy_CTFontDrawGlyphs;
+}
-SK_DECLARE_STATIC_LAZY_FN_PTR(CTFontDrawGlyphsProc, gCTFontDrawGlyphs, SkChooseCTFontDrawGlyphs);
+SK_DECLARE_STATIC_ONCE_PTR(CTFontDrawGlyphsProc, gCTFontDrawGlyphs);
CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph& glyph,
CGGlyph glyphID, size_t* rowBytesPtr,
- bool generateA8FromLCD)
-{
- CTFontDrawGlyphsProc ctFontDrawGlyphs = gCTFontDrawGlyphs.get();
+ bool generateA8FromLCD) {
+ auto ctFontDrawGlyphs = gCTFontDrawGlyphs.get(choose_CTFontDrawGlyphs);
if (!fRGBSpace) {
//It doesn't appear to matter what color space is specified.
@@ -867,7 +860,7 @@ CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph&
fDoAA = !doAA;
fDoLCD = !doLCD;
- if (sk_legacy_CTFontDrawGlyphs == ctFontDrawGlyphs) {
+ if (legacy_CTFontDrawGlyphs == ctFontDrawGlyphs) {
// CTFontDrawGlyphs will apply the font, font size, and font matrix to the CGContext.
// Our 'fake' one does not, so set up the CGContext here.
CGContextSetFont(fCG, context.fCGFont);
« no previous file with comments | « src/core/SkLazyFnPtr.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698