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

Side by Side Diff: src/ports/SkFontHost_FreeType.cpp

Issue 155963003: SkOnce in is_lcd_supported instead of hand rolled double-checked locking. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SK -> Sk Created 6 years, 10 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 | « include/core/SkThread.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 "SkAdvancedTypefaceMetrics.h"
9 #include "SkBitmap.h" 10 #include "SkBitmap.h"
10 #include "SkCanvas.h" 11 #include "SkCanvas.h"
11 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
12 #include "SkDescriptor.h" 13 #include "SkDescriptor.h"
13 #include "SkFDot6.h" 14 #include "SkFDot6.h"
14 #include "SkFloatingPoint.h" 15 #include "SkFloatingPoint.h"
15 #include "SkFontHost.h" 16 #include "SkFontHost.h"
16 #include "SkFontHost_FreeType_common.h" 17 #include "SkFontHost_FreeType_common.h"
17 #include "SkGlyph.h" 18 #include "SkGlyph.h"
18 #include "SkMask.h" 19 #include "SkMask.h"
19 #include "SkMaskGamma.h" 20 #include "SkMaskGamma.h"
20 #include "SkOTUtils.h" 21 #include "SkOTUtils.h"
21 #include "SkAdvancedTypefaceMetrics.h" 22 #include "SkOnce.h"
22 #include "SkScalerContext.h" 23 #include "SkScalerContext.h"
23 #include "SkStream.h" 24 #include "SkStream.h"
24 #include "SkString.h" 25 #include "SkString.h"
25 #include "SkTemplates.h" 26 #include "SkTemplates.h"
26 #include "SkThread.h" 27 #include "SkThread.h"
27 28
28 #if defined(SK_CAN_USE_DLOPEN) 29 #if defined(SK_CAN_USE_DLOPEN)
29 #include <dlfcn.h> 30 #include <dlfcn.h>
30 #endif 31 #endif
31 #include <ft2build.h> 32 #include <ft2build.h>
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 #endif 154 #endif
154 } 155 }
155 #else 156 #else
156 gLCDSupport = false; 157 gLCDSupport = false;
157 #endif 158 #endif
158 gLCDSupportValid = true; 159 gLCDSupportValid = true;
159 160
160 return true; 161 return true;
161 } 162 }
162 163
164 // Called while holding gFTMutex.
165 static void determine_lcd_support(bool* lcdSupported) {
166 if (!gLCDSupportValid) {
167 // This will determine LCD support as a side effect.
168 InitFreetype();
169 FT_Done_FreeType(gFTLibrary);
170 }
171 SkASSERT(gLCDSupportValid);
172 *lcdSupported = gLCDSupport;
173 }
174
163 // Lazy, once, wrapper to ask the FreeType Library if it can support LCD text 175 // Lazy, once, wrapper to ask the FreeType Library if it can support LCD text
164 static bool is_lcd_supported() { 176 static bool is_lcd_supported() {
165 if (!gLCDSupportValid) { 177 static bool lcdSupported = false;
166 SkAutoMutexAcquire ac(gFTMutex); 178 SkOnce(&gLCDSupportValid, &gFTMutex, determine_lcd_support, &lcdSupported);
167 179 return lcdSupported;
168 if (!gLCDSupportValid) {
169 InitFreetype();
170 FT_Done_FreeType(gFTLibrary);
171 }
172 }
173 return gLCDSupport;
174 } 180 }
175 181
176 class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base { 182 class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base {
177 public: 183 public:
178 SkScalerContext_FreeType(SkTypeface*, const SkDescriptor* desc); 184 SkScalerContext_FreeType(SkTypeface*, const SkDescriptor* desc);
179 virtual ~SkScalerContext_FreeType(); 185 virtual ~SkScalerContext_FreeType();
180 186
181 bool success() const { 187 bool success() const {
182 return fFaceRec != NULL && 188 return fFaceRec != NULL &&
183 fFTSize != NULL && 189 fFTSize != NULL &&
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 *style = (SkTypeface::Style) tempStyle; 1683 *style = (SkTypeface::Style) tempStyle;
1678 } 1684 }
1679 if (isFixedPitch) { 1685 if (isFixedPitch) {
1680 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1686 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1681 } 1687 }
1682 1688
1683 FT_Done_Face(face); 1689 FT_Done_Face(face);
1684 FT_Done_FreeType(library); 1690 FT_Done_FreeType(library);
1685 return true; 1691 return true;
1686 } 1692 }
OLDNEW
« no previous file with comments | « include/core/SkThread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698