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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/SkLazyFnPtr.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkTypes.h" // Keep this before any #ifdef ... 9 #include "SkTypes.h" // Keep this before any #ifdef ...
10 10
(...skipping 10 matching lines...) Expand all
21 21
22 #include "SkAdvancedTypefaceMetrics.h" 22 #include "SkAdvancedTypefaceMetrics.h"
23 #include "SkCGUtils.h" 23 #include "SkCGUtils.h"
24 #include "SkColorPriv.h" 24 #include "SkColorPriv.h"
25 #include "SkDescriptor.h" 25 #include "SkDescriptor.h"
26 #include "SkEndian.h" 26 #include "SkEndian.h"
27 #include "SkFloatingPoint.h" 27 #include "SkFloatingPoint.h"
28 #include "SkFontDescriptor.h" 28 #include "SkFontDescriptor.h"
29 #include "SkFontMgr.h" 29 #include "SkFontMgr.h"
30 #include "SkGlyph.h" 30 #include "SkGlyph.h"
31 #include "SkLazyFnPtr.h"
32 #include "SkMaskGamma.h" 31 #include "SkMaskGamma.h"
33 #include "SkMutex.h" 32 #include "SkMutex.h"
34 #include "SkOTTable_glyf.h" 33 #include "SkOTTable_glyf.h"
35 #include "SkOTTable_head.h" 34 #include "SkOTTable_head.h"
36 #include "SkOTTable_hhea.h" 35 #include "SkOTTable_hhea.h"
37 #include "SkOTTable_loca.h" 36 #include "SkOTTable_loca.h"
38 #include "SkOTUtils.h" 37 #include "SkOTUtils.h"
38 #include "SkOncePtr.h"
39 #include "SkPaint.h" 39 #include "SkPaint.h"
40 #include "SkPath.h" 40 #include "SkPath.h"
41 #include "SkSFNTHeader.h" 41 #include "SkSFNTHeader.h"
42 #include "SkStream.h" 42 #include "SkStream.h"
43 #include "SkString.h" 43 #include "SkString.h"
44 #include "SkTypefaceCache.h" 44 #include "SkTypefaceCache.h"
45 #include "SkTypeface_mac.h" 45 #include "SkTypeface_mac.h"
46 #include "SkUtils.h" 46 #include "SkUtils.h"
47 #include "SkUtils.h" 47 #include "SkUtils.h"
48 48
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &fTransform, ctFontDesc)); 763 fCTFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, &fTransform, ctFontDesc));
764 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr)); 764 fCGFont.reset(CTFontCopyGraphicsFont(fCTFont, nullptr));
765 fCTUnrotatedFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize, 765 fCTUnrotatedFont.reset(CTFontCreateCopyWithAttributes(ctFont, textSize,
766 &CGAffineTransformIden tity, nullptr)); 766 &CGAffineTransformIden tity, nullptr));
767 767
768 // The fUnitMatrix includes the text size (and em) as it is used to scale th e raw font data. 768 // The fUnitMatrix includes the text size (and em) as it is used to scale th e raw font data.
769 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo nt))); 769 SkScalar emPerFUnit = SkScalarInvert(SkIntToScalar(CGFontGetUnitsPerEm(fCGFo nt)));
770 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit); 770 fFUnitMatrix.preScale(emPerFUnit, -emPerFUnit);
771 } 771 }
772 772
773 extern "C" { 773 /** This is an implementation of CTFontDrawGlyphs for 10.6; it was introduced in 10.7. */
774 774 static void legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGP oint points[],
775 /** CTFontDrawGlyphs was introduced in 10.7. */ 775 size_t count, CGContextRef cg) {
776 typedef void (*CTFontDrawGlyphsProc)(CTFontRef, const CGGlyph[], const CGPoint[] ,
777 size_t, CGContextRef);
778
779 /** This is an implementation of CTFontDrawGlyphs for 10.6. */
780 static void sk_legacy_CTFontDrawGlyphs(CTFontRef, const CGGlyph glyphs[], const CGPoint points[],
781 size_t count, CGContextRef cg)
782 {
783 CGContextShowGlyphsAtPositions(cg, glyphs, points, count); 776 CGContextShowGlyphsAtPositions(cg, glyphs, points, count);
784 } 777 }
785 778
779 typedef decltype(legacy_CTFontDrawGlyphs) CTFontDrawGlyphsProc;
780
781 static CTFontDrawGlyphsProc* choose_CTFontDrawGlyphs() {
782 if (void* real = dlsym(RTLD_DEFAULT, "CTFontDrawGlyphs")) {
783 return (CTFontDrawGlyphsProc*)real;
784 }
785 return &legacy_CTFontDrawGlyphs;
786 } 786 }
787 787
788 CTFontDrawGlyphsProc SkChooseCTFontDrawGlyphs() { 788 SK_DECLARE_STATIC_ONCE_PTR(CTFontDrawGlyphsProc, gCTFontDrawGlyphs);
789 CTFontDrawGlyphsProc realCTFontDrawGlyphs;
790 *reinterpret_cast<void**>(&realCTFontDrawGlyphs) = dlsym(RTLD_DEFAULT, "CTFo ntDrawGlyphs");
791 return realCTFontDrawGlyphs ? realCTFontDrawGlyphs : sk_legacy_CTFontDrawGly phs;
792 };
793
794 SK_DECLARE_STATIC_LAZY_FN_PTR(CTFontDrawGlyphsProc, gCTFontDrawGlyphs, SkChooseC TFontDrawGlyphs);
795 789
796 CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph& glyph, 790 CGRGBPixel* Offscreen::getCG(const SkScalerContext_Mac& context, const SkGlyph& glyph,
797 CGGlyph glyphID, size_t* rowBytesPtr, 791 CGGlyph glyphID, size_t* rowBytesPtr,
798 bool generateA8FromLCD) 792 bool generateA8FromLCD) {
799 { 793 auto ctFontDrawGlyphs = gCTFontDrawGlyphs.get(choose_CTFontDrawGlyphs);
800 CTFontDrawGlyphsProc ctFontDrawGlyphs = gCTFontDrawGlyphs.get();
801 794
802 if (!fRGBSpace) { 795 if (!fRGBSpace) {
803 //It doesn't appear to matter what color space is specified. 796 //It doesn't appear to matter what color space is specified.
804 //Regular blends and antialiased text are always (s*a + d*(1-a)) 797 //Regular blends and antialiased text are always (s*a + d*(1-a))
805 //and smoothed text is always g=2.0. 798 //and smoothed text is always g=2.0.
806 fRGBSpace.reset(CGColorSpaceCreateDeviceRGB()); 799 fRGBSpace.reset(CGColorSpaceCreateDeviceRGB());
807 } 800 }
808 801
809 // default to kBW_Format 802 // default to kBW_Format
810 bool doAA = false; 803 bool doAA = false;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 CGContextSetTextDrawingMode(fCG, kCGTextFill); 853 CGContextSetTextDrawingMode(fCG, kCGTextFill);
861 854
862 // Draw white on black to create mask. 855 // Draw white on black to create mask.
863 // TODO: Draw black on white and invert, CG has a special case codepath. 856 // TODO: Draw black on white and invert, CG has a special case codepath.
864 CGContextSetGrayFillColor(fCG, 1.0f, 1.0f); 857 CGContextSetGrayFillColor(fCG, 1.0f, 1.0f);
865 858
866 // force our checks below to happen 859 // force our checks below to happen
867 fDoAA = !doAA; 860 fDoAA = !doAA;
868 fDoLCD = !doLCD; 861 fDoLCD = !doLCD;
869 862
870 if (sk_legacy_CTFontDrawGlyphs == ctFontDrawGlyphs) { 863 if (legacy_CTFontDrawGlyphs == ctFontDrawGlyphs) {
871 // CTFontDrawGlyphs will apply the font, font size, and font matrix to the CGContext. 864 // CTFontDrawGlyphs will apply the font, font size, and font matrix to the CGContext.
872 // Our 'fake' one does not, so set up the CGContext here. 865 // Our 'fake' one does not, so set up the CGContext here.
873 CGContextSetFont(fCG, context.fCGFont); 866 CGContextSetFont(fCG, context.fCGFont);
874 CGContextSetFontSize(fCG, CTFontGetSize(context.fCTFont)); 867 CGContextSetFontSize(fCG, CTFontGetSize(context.fCTFont));
875 } 868 }
876 CGContextSetTextMatrix(fCG, context.fTransform); 869 CGContextSetTextMatrix(fCG, context.fTransform);
877 } 870 }
878 871
879 if (fDoAA != doAA) { 872 if (fDoAA != doAA) {
880 CGContextSetShouldAntialias(fCG, doAA); 873 CGContextSetShouldAntialias(fCG, doAA);
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 face->ref(); 2474 face->ref();
2482 } 2475 }
2483 } 2476 }
2484 return face; 2477 return face;
2485 } 2478 }
2486 }; 2479 };
2487 2480
2488 /////////////////////////////////////////////////////////////////////////////// 2481 ///////////////////////////////////////////////////////////////////////////////
2489 2482
2490 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; } 2483 SkFontMgr* SkFontMgr::Factory() { return new SkFontMgr_Mac; }
OLDNEW
« 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