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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkFontMgr.h" |
| 9 | #include "include/core/SkRefCnt.h" |
| 10 | #include "include/ports/SkFontConfigInterface.h" |
| 11 | #include "include/private/SkMutex.h" |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 12 | |
Herb Derby | 9c71e7b | 2019-06-17 14:40:42 -0400 | [diff] [blame] | 13 | static SkMutex& font_config_interface_mutex() { |
| 14 | static SkMutex& mutex = *(new SkMutex); |
| 15 | return mutex; |
| 16 | } |
Ben Wagner | d2152c4 | 2018-05-17 09:47:30 -0400 | [diff] [blame] | 17 | static SkFontConfigInterface* gFontConfigInterface; |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 18 | |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 19 | sk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() { |
Herb Derby | 9c71e7b | 2019-06-17 14:40:42 -0400 | [diff] [blame] | 20 | SkAutoMutexExclusive ac(font_config_interface_mutex()); |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 21 | |
| 22 | if (gFontConfigInterface) { |
Ben Wagner | d2152c4 | 2018-05-17 09:47:30 -0400 | [diff] [blame] | 23 | return sk_ref_sp(gFontConfigInterface); |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 24 | } |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 25 | return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface()); |
bungeman | 1ae0e01 | 2016-09-19 12:13:16 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 28 | void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) { |
Herb Derby | 9c71e7b | 2019-06-17 14:40:42 -0400 | [diff] [blame] | 29 | SkAutoMutexExclusive ac(font_config_interface_mutex()); |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 30 | |
Ben Wagner | d2152c4 | 2018-05-17 09:47:30 -0400 | [diff] [blame] | 31 | SkSafeUnref(gFontConfigInterface); |
| 32 | gFontConfigInterface = fc.release(); |
Ben Wagner | a20681c | 2018-05-14 13:51:10 -0400 | [diff] [blame] | 33 | } |