summaryrefslogtreecommitdiff
path: root/chromium/skia/ext/fontmgr_default.cc
blob: d4b6201b06a7b159a2cee73ef5545ccfe08218ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "skia/ext/fontmgr_default.h"

#include "third_party/skia/include/core/SkFontMgr.h"

namespace {

SkDEBUGCODE(bool g_factory_called;)

    // This is a purposefully leaky pointer that has ownership of the FontMgr.
    SkFontMgr* g_fontmgr_override = nullptr;

}  // namespace

namespace skia {

void OverrideDefaultSkFontMgr(sk_sp<SkFontMgr> fontmgr) {
  SkASSERT(!g_factory_called);

  SkSafeUnref(g_fontmgr_override);
  g_fontmgr_override = fontmgr.release();
}

}  // namespace skia

SK_API sk_sp<SkFontMgr> SkFontMgr::Factory() {
  SkDEBUGCODE(g_factory_called = true;);

  return g_fontmgr_override ? sk_ref_sp(g_fontmgr_override)
                            : skia::CreateDefaultSkFontMgr();
}