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" |
Ben Wagner | a588de1 | 2018-05-15 19:12:44 +0000 | [diff] [blame^] | 9 | #include "SkFontMgr.h" |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 10 | #include "SkMutex.h" |
| 11 | #include "SkRefCnt.h" |
| 12 | |
| 13 | SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex); |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 14 | static sk_sp<SkFontConfigInterface> gFontConfigInterface(nullptr); |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 15 | |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 16 | sk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() { |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 17 | SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); |
| 18 | |
| 19 | if (gFontConfigInterface) { |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 20 | return gFontConfigInterface; |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 21 | } |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 22 | return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface()); |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Ben Wagner | a588de1 | 2018-05-15 19:12:44 +0000 | [diff] [blame^] | 25 | SkFontConfigInterface* SkFontConfigInterface::SetGlobal(SkFontConfigInterface* fc) { |
| 26 | SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); |
| 27 | |
| 28 | gFontConfigInterface = sk_ref_sp(fc); |
| 29 | return fc; |
| 30 | } |
| 31 | |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 32 | void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) { |
| 33 | SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); |
| 34 | |
| 35 | gFontConfigInterface = std::move(fc); |
| 36 | } |