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 "include/core/SkFontMgr.h" 9 #include "include/core/SkRefCnt.h" 10 #include "include/ports/SkFontConfigInterface.h" 11 #include "include/private/SkMutex.h" 12 font_config_interface_mutex()13static SkMutex& font_config_interface_mutex() { 14 static SkMutex& mutex = *(new SkMutex); 15 return mutex; 16 } 17 static SkFontConfigInterface* gFontConfigInterface; 18 RefGlobal()19sk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() { 20 SkAutoMutexExclusive ac(font_config_interface_mutex()); 21 22 if (gFontConfigInterface) { 23 return sk_ref_sp(gFontConfigInterface); 24 } 25 return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface()); 26 } 27 SetGlobal(sk_sp<SkFontConfigInterface> fc)28void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) { 29 SkAutoMutexExclusive ac(font_config_interface_mutex()); 30 31 SkSafeUnref(gFontConfigInterface); 32 gFontConfigInterface = fc.release(); 33 } 34