blob: 0d52c0efc2664205192146a724ebfd4ebeabb1d4 [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 Wagnera20681c2018-05-14 13:51:10 -040014static sk_sp<SkFontConfigInterface> gFontConfigInterface(nullptr);
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 Wagnera20681c2018-05-14 13:51:10 -040020 return 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
28 gFontConfigInterface = std::move(fc);
29}