| 1 |
/* |
| 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 |
#include "include/ports/SkFontConfigInterface.h" |
| 8 |
|
| 9 |
#include "include/core/SkFontMgr.h" |
| 10 |
#include "include/core/SkRefCnt.h" |
| 11 |
#include "include/private/base/SkMutex.h" |
| 12 |
|
| 13 |
static SkMutex& font_config_interface_mutex() { |
| 14 |
static SkMutex& mutex = *(new SkMutex); |
| 15 |
return mutex; |
| 16 |
} |
| 17 |
static SkFontConfigInterface* gFontConfigInterface; |
| 18 |
|
| 19 |
sk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() { |
| 20 |
SkAutoMutexExclusive ac(font_config_interface_mutex()); |
| 21 |
|
| 22 |
if (gFontConfigInterface) { |
| 23 |
return sk_ref_sp(gFontConfigInterface); |
| 24 |
} |
| 25 |
return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface()); |
| 26 |
} |
| 27 |
|
| 28 |
void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) { |
| 29 |
SkAutoMutexExclusive ac(font_config_interface_mutex()); |
| 30 |
|
| 31 |
SkSafeUnref(gFontConfigInterface); |
| 32 |
gFontConfigInterface = fc.release(); |
| 33 |
} |
| 34 |
|
| 35 |
sk_sp<SkTypeface> SkFontConfigInterface::makeTypeface(const FontIdentity& identity, |
| 36 |
sk_sp<SkFontMgr> mgr) { |
| 37 |
return mgr->makeFromStream(std::unique_ptr<SkStreamAsset>(this->openStream(identity)), |
| 38 |
identity.fTTCIndex); |
| 39 |
} |