blob: 5569c6917576605422cf985493d6a43235218d13 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkFontMgr.h"
9#include "include/core/SkRefCnt.h"
10#include "include/ports/SkFontConfigInterface.h"
11#include "include/private/SkMutex.h"
bungeman1ae0e012016-09-19 12:13:16 -070012
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}