blob: 864d6159ef33ebcfea648ad5147a1db7df435969 [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"
bungeman1ae0e012016-09-19 12:13:16 -07009#include "SkMutex.h"
10#include "SkRefCnt.h"
11
12SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex);
Ben Wagnera20681c2018-05-14 13:51:10 -040013static sk_sp<SkFontConfigInterface> gFontConfigInterface(nullptr);
bungeman1ae0e012016-09-19 12:13:16 -070014
Ben Wagnera20681c2018-05-14 13:51:10 -040015sk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() {
bungeman1ae0e012016-09-19 12:13:16 -070016 SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
17
18 if (gFontConfigInterface) {
Ben Wagnera20681c2018-05-14 13:51:10 -040019 return gFontConfigInterface;
bungeman1ae0e012016-09-19 12:13:16 -070020 }
Ben Wagnera20681c2018-05-14 13:51:10 -040021 return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface());
bungeman1ae0e012016-09-19 12:13:16 -070022}
23
Ben Wagnera20681c2018-05-14 13:51:10 -040024void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) {
25 SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
26
27 gFontConfigInterface = std::move(fc);
28}