1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2016 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "include/core/SkFontMgr.h"
9cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h"
10cb93a386Sopenharmony_ci#include "include/ports/SkFontConfigInterface.h"
11cb93a386Sopenharmony_ci#include "include/private/SkMutex.h"
12cb93a386Sopenharmony_ci
13cb93a386Sopenharmony_cistatic SkMutex& font_config_interface_mutex() {
14cb93a386Sopenharmony_ci    static SkMutex& mutex = *(new SkMutex);
15cb93a386Sopenharmony_ci    return mutex;
16cb93a386Sopenharmony_ci}
17cb93a386Sopenharmony_cistatic SkFontConfigInterface* gFontConfigInterface;
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_cisk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() {
20cb93a386Sopenharmony_ci    SkAutoMutexExclusive ac(font_config_interface_mutex());
21cb93a386Sopenharmony_ci
22cb93a386Sopenharmony_ci    if (gFontConfigInterface) {
23cb93a386Sopenharmony_ci        return sk_ref_sp(gFontConfigInterface);
24cb93a386Sopenharmony_ci    }
25cb93a386Sopenharmony_ci    return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface());
26cb93a386Sopenharmony_ci}
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_civoid SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) {
29cb93a386Sopenharmony_ci    SkAutoMutexExclusive ac(font_config_interface_mutex());
30cb93a386Sopenharmony_ci
31cb93a386Sopenharmony_ci    SkSafeUnref(gFontConfigInterface);
32cb93a386Sopenharmony_ci    gFontConfigInterface = fc.release();
33cb93a386Sopenharmony_ci}
34