bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkFontConfigInterface.h" |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 9 | #include "SkMutex.h" |
| 10 | #include "SkRefCnt.h" |
| 11 | |
| 12 | SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex); |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 13 | static sk_sp<SkFontConfigInterface> gFontConfigInterface(nullptr); |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 14 | |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 15 | sk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() { |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 16 | SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); |
| 17 | |
| 18 | if (gFontConfigInterface) { |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 19 | return gFontConfigInterface; |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 20 | } |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 21 | return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface()); |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 24 | void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) { |
| 25 | SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); |
| 26 | |
| 27 | gFontConfigInterface = std::move(fc); |
| 28 | } |