aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkFontHost_win.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-10-18 09:58:54 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-10-19 12:53:46 +0000
commit0341f160befa4450f645d5d0814bc1f9b527332a (patch)
treed2ed9df64762cfc84a644a9574d70c4cd2c1c8d1 /src/ports/SkFontHost_win.cpp
parent6fb802e2b2e34d6eabb7bd73e30deac68d21d70f (diff)
replace gInited with SkOnce
The bug was originally about TSAN failures on Mac, but we might as well also fix _win. Bug: skia:7187 Change-Id: I086060c9f6719afbb6b0a067a9601b6abcc29d78 Reviewed-on: https://skia-review.googlesource.com/61300 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Diffstat (limited to 'src/ports/SkFontHost_win.cpp')
-rw-r--r--src/ports/SkFontHost_win.cpp39
1 files changed, 7 insertions, 32 deletions
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 5cd02a4f73..231841423a 100644
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -19,6 +19,7 @@
#include "SkMakeUnique.h"
#include "SkMaskGamma.h"
#include "SkMatrix22.h"
+#include "SkOnce.h"
#include "SkOTTable_maxp.h"
#include "SkOTTable_name.h"
#include "SkOTUtils.h"
@@ -1045,24 +1046,11 @@ static void build_power_table(uint8_t table[], float ee) {
* that shifting into other color spaces is imprecise.
*/
static const uint8_t* getInverseGammaTableGDI() {
- // Since build_power_table is idempotent, many threads can build gTableGdi
- // simultaneously.
-
- // Microsoft Specific:
- // Making gInited volatile provides read-aquire and write-release in vc++.
- // In VS2012, see compiler option /volatile:(ms|iso).
- // Replace with C++11 atomics when possible.
- static volatile bool gInited;
+ static SkOnce once;
static uint8_t gTableGdi[256];
- if (gInited) {
- // Need a L/L (read) barrier (full acquire not needed). If gInited is observed
- // true then gTableGdi is observable, but it must be requested.
- } else {
+ once([]{
build_power_table(gTableGdi, 2.3f);
- // Need a S/S (write) barrier (full release not needed) here so that this
- // write to gInited becomes observable after gTableGdi.
- gInited = true;
- }
+ });
return gTableGdi;
}
@@ -1074,29 +1062,16 @@ static const uint8_t* getInverseGammaTableGDI() {
* If this value is not specified, the default is a gamma of 1.4.
*/
static const uint8_t* getInverseGammaTableClearType() {
- // We don't expect SPI_GETFONTSMOOTHINGCONTRAST to ever change, so building
- // gTableClearType with build_power_table is effectively idempotent.
-
- // Microsoft Specific:
- // Making gInited volatile provides read-aquire and write-release in vc++.
- // In VS2012, see compiler option /volatile:(ms|iso).
- // Replace with C++11 atomics when possible.
- static volatile bool gInited;
+ static SkOnce once;
static uint8_t gTableClearType[256];
- if (gInited) {
- // Need a L/L (read) barrier (acquire not needed). If gInited is observed
- // true then gTableClearType is observable, but it must be requested.
- } else {
+ once([]{
UINT level = 0;
if (!SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &level, 0) || !level) {
// can't get the data, so use a default
level = 1400;
}
build_power_table(gTableClearType, level / 1000.0f);
- // Need a S/S (write) barrier (release not needed) here so that this
- // write to gInited becomes observable after gTableClearType.
- gInited = true;
- }
+ });
return gTableClearType;
}