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

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: 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 | « no previous file | 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 static void determine_lcd_support(int) {
165 SkAutoMutexAcquire lock(gFTMutex);
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 }
173
163 // Lazy, once, wrapper to ask the FreeType Library if it can support LCD text 174 // Lazy, once, wrapper to ask the FreeType Library if it can support LCD text
164 static bool is_lcd_supported() { 175 static bool is_lcd_supported() {
165 if (!gLCDSupportValid) { 176 SK_DECLARE_STATIC_ONCE(once);
166 SkAutoMutexAcquire ac(gFTMutex); 177 SkOnce(&once, determine_lcd_support, 0);
167 178
168 if (!gLCDSupportValid) { 179 SkAutoMutexAcquire lock(gFTMutex);
bungeman-skia 2014/02/05 18:02:04 Why are we still taking this lock, just to return
mtklein 2014/02/05 18:10:26 You know, that's a thought provoking question. I
169 InitFreetype();
170 FT_Done_FreeType(gFTLibrary);
171 }
172 }
173 return gLCDSupport; 180 return gLCDSupport;
174 } 181 }
175 182
176 class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base { 183 class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base {
177 public: 184 public:
178 SkScalerContext_FreeType(SkTypeface*, const SkDescriptor* desc); 185 SkScalerContext_FreeType(SkTypeface*, const SkDescriptor* desc);
179 virtual ~SkScalerContext_FreeType(); 186 virtual ~SkScalerContext_FreeType();
180 187
181 bool success() const { 188 bool success() const {
182 return fFaceRec != NULL && 189 return fFaceRec != NULL &&
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 *style = (SkTypeface::Style) tempStyle; 1684 *style = (SkTypeface::Style) tempStyle;
1678 } 1685 }
1679 if (isFixedPitch) { 1686 if (isFixedPitch) {
1680 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1687 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1681 } 1688 }
1682 1689
1683 FT_Done_Face(face); 1690 FT_Done_Face(face);
1684 FT_Done_FreeType(library); 1691 FT_Done_FreeType(library);
1685 return true; 1692 return true;
1686 } 1693 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698