blob: f81c48744eaa23451f7a721b659a103059c85bbd [file] [log] [blame]
bungeman1ae0e012016-09-19 12:13:16 -07001/*
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 Wagnera588de12018-05-15 19:12:44 +00009#include "SkFontMgr.h"
bungeman1ae0e012016-09-19 12:13:16 -070010#include "SkMutex.h"
11#include "SkRefCnt.h"
12
13SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex);
Ben Wagnerd2152c42018-05-17 09:47:30 -040014static SkFontConfigInterface* gFontConfigInterface;
bungeman1ae0e012016-09-19 12:13:16 -070015
Ben Wagnera20681c2018-05-14 13:51:10 -040016sk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() {
bungeman1ae0e012016-09-19 12:13:16 -070017 SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
18
19 if (gFontConfigInterface) {
Ben Wagnerd2152c42018-05-17 09:47:30 -040020 return sk_ref_sp(gFontConfigInterface);
bungeman1ae0e012016-09-19 12:13:16 -070021 }
Ben Wagnera20681c2018-05-14 13:51:10 -040022 return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface());
bungeman1ae0e012016-09-19 12:13:16 -070023}
24
Ben Wagnera20681c2018-05-14 13:51:10 -040025void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) {
26 SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
27
Ben Wagnerd2152c42018-05-17 09:47:30 -040028 SkSafeUnref(gFontConfigInterface);
29 gFontConfigInterface = fc.release();
Ben Wagnera20681c2018-05-14 13:51:10 -040030}