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 | d2152c4 | 2018-05-17 09:47:30 -0400 | [diff] [blame^] | 14 | static SkFontConfigInterface* gFontConfigInterface; |
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 | d2152c4 | 2018-05-17 09:47:30 -0400 | [diff] [blame^] | 20 | return sk_ref_sp(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 | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 25 | void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) { |
| 26 | SkAutoMutexAcquire ac(gFontConfigInterfaceMutex); |
| 27 | |
Ben Wagner | d2152c4 | 2018-05-17 09:47:30 -0400 | [diff] [blame^] | 28 | SkSafeUnref(gFontConfigInterface); |
| 29 | gFontConfigInterface = fc.release(); |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 30 | } |