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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkThread.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_FreeType.cpp
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index fe32ebb42a7fe33c7e7758738cc40f26f7afaa8d..cb7ce8028dccd4e92d81b1e8ce63fc3b08c4b438 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -6,6 +6,7 @@
* found in the LICENSE file.
*/
+#include "SkAdvancedTypefaceMetrics.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColorPriv.h"
@@ -18,7 +19,7 @@
#include "SkMask.h"
#include "SkMaskGamma.h"
#include "SkOTUtils.h"
-#include "SkAdvancedTypefaceMetrics.h"
+#include "SkOnce.h"
#include "SkScalerContext.h"
#include "SkStream.h"
#include "SkString.h"
@@ -160,17 +161,22 @@ static bool InitFreetype() {
return true;
}
-// Lazy, once, wrapper to ask the FreeType Library if it can support LCD text
-static bool is_lcd_supported() {
+// Called while holding gFTMutex.
+static void determine_lcd_support(bool* lcdSupported) {
if (!gLCDSupportValid) {
- SkAutoMutexAcquire ac(gFTMutex);
-
- if (!gLCDSupportValid) {
- InitFreetype();
- FT_Done_FreeType(gFTLibrary);
- }
+ // This will determine LCD support as a side effect.
+ InitFreetype();
+ FT_Done_FreeType(gFTLibrary);
}
- return gLCDSupport;
+ SkASSERT(gLCDSupportValid);
+ *lcdSupported = gLCDSupport;
+}
+
+// Lazy, once, wrapper to ask the FreeType Library if it can support LCD text
+static bool is_lcd_supported() {
+ static bool lcdSupported = false;
+ SkOnce(&gLCDSupportValid, &gFTMutex, determine_lcd_support, &lcdSupported);
+ return lcdSupported;
}
class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base {
« 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