Split SkFontConfigInterface globals and factory.

Chromium needs to be able to set up their build such that the globals
continue existing but the SkFontMgr::Factory can be defined separately.

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2346333002
CQ_INCLUDE_TRYBOTS=master.client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac-Clang-x86_64-Release-CMake-Trybot

Review-Url: https://codereview.chromium.org/2346333002
This commit is contained in:
bungeman 2016-09-19 12:13:16 -07:00 committed by Commit bot
parent 0262b5c1a0
commit 1ae0e01acc
9 changed files with 79 additions and 48 deletions

View File

@ -263,6 +263,7 @@ optional("fontmgr_fontconfig") {
"//third_party/freetype2",
]
sources = [
"src/ports/SkFontConfigInterface.cpp",
"src/ports/SkFontConfigInterface_direct.cpp",
"src/ports/SkFontConfigInterface_direct_factory.cpp",
"src/ports/SkFontMgr_FontConfigInterface.cpp",

View File

@ -51,7 +51,8 @@ endfunction()
# This file is empty and is only used to trick GYP.
remove_srcs (../src/core/SkForceCPlusPlusLinking.cpp)
# Chrome only?
remove_srcs (../src/ports/SkFontConfigInterface_direct.cpp
remove_srcs (../src/ports/SkFontConfigInterface.cpp
../src/ports/SkFontConfigInterface_direct.cpp
../src/ports/SkFontConfigInterface_direct_factory.cpp
../src/ports/SkFontConfigInterface_direct_google3.cpp
../src/ports/SkFontConfigInterface_direct_google3_factory.cpp

View File

@ -70,6 +70,7 @@
'../include/ports/SkFontMgr_android.h',
'../include/ports/SkFontMgr_custom.h',
'../include/ports/SkFontMgr_fontconfig.h',
'../include/ports/SkFontMgr_FontConfigInterface.h',
'../include/ports/SkFontMgr_indirect.h',
'../include/ports/SkRemotableFontMgr.h',
],
@ -139,6 +140,7 @@
},
'sources': [
'../src/ports/SkFontMgr_fontconfig.cpp',
'../src/ports/SkFontConfigInterface.cpp',
'../src/ports/SkFontConfigInterface_direct.cpp',
'../src/ports/SkFontConfigInterface_direct_factory.cpp',
],

View File

@ -25,9 +25,10 @@ class SK_API SkFontConfigInterface : public SkRefCnt {
public:
/**
* Returns the global SkFontConfigInterface instance, and if it is not
* NULL, calls ref() on it. The caller must balance this with a call to
* unref().
* Returns the global SkFontConfigInterface instance. If it is not
* nullptr, calls ref() on it. The caller must balance this with a call to
* unref(). The default SkFontConfigInterface is the result of calling
* GetSingletonDirectInterface.
*/
static SkFontConfigInterface* RefGlobal();
@ -105,7 +106,6 @@ public:
/**
* Return a singleton instance of a direct subclass that calls into
* libfontconfig. This does not affect the refcnt of the returned instance.
* The mutex may be used to guarantee the singleton is only constructed once.
*/
static SkFontConfigInterface* GetSingletonDirectInterface();
@ -115,7 +115,4 @@ public:
typedef SkRefCnt INHERITED;
};
/** Creates a SkFontMgr which wraps a SkFontConfigInterface. */
SK_API SkFontMgr* SkFontMgr_New_FCI(SkFontConfigInterface* fci);
#endif

View File

@ -0,0 +1,20 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkFontMgr_FontConfigInterface_DEFINED
#define SkFontMgr_FontConfigInterface_DEFINED
#include "SkTypes.h"
#include "SkRefCnt.h"
class SkFontMgr;
class SkFontConfigInterface;
/** Creates a SkFontMgr which wraps a SkFontConfigInterface. */
SK_API SkFontMgr* SkFontMgr_New_FCI(sk_sp<SkFontConfigInterface> fci);
#endif // #ifndef SkFontMgr_FontConfigInterface_DEFINED

View File

@ -0,0 +1,30 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkFontConfigInterface.h"
#include "SkFontMgr.h"
#include "SkMutex.h"
#include "SkRefCnt.h"
SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex);
static SkFontConfigInterface* gFontConfigInterface;
SkFontConfigInterface* SkFontConfigInterface::RefGlobal() {
SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
if (gFontConfigInterface) {
return SkRef(gFontConfigInterface);
}
return SkSafeRef(SkFontConfigInterface::GetSingletonDirectInterface());
}
SkFontConfigInterface* SkFontConfigInterface::SetGlobal(SkFontConfigInterface* fc) {
SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
SkRefCnt_SafeAssign(gFontConfigInterface, fc);
return fc;
}

View File

@ -20,12 +20,12 @@ class SkTypeface_FCI : public SkTypeface_FreeType {
std::unique_ptr<SkFontData> fFontData;
public:
static SkTypeface_FCI* Create(SkFontConfigInterface* fci,
static SkTypeface_FCI* Create(sk_sp<SkFontConfigInterface> fci,
const SkFontConfigInterface::FontIdentity& fi,
const SkString& familyName,
const SkFontStyle& style)
{
return new SkTypeface_FCI(fci, fi, familyName, style);
return new SkTypeface_FCI(std::move(fci), fi, familyName, style);
}
static SkTypeface_FCI* Create(std::unique_ptr<SkFontData> data,
@ -39,12 +39,12 @@ public:
}
protected:
SkTypeface_FCI(SkFontConfigInterface* fci,
SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,
const SkFontConfigInterface::FontIdentity& fi,
const SkString& familyName,
const SkFontStyle& style)
: INHERITED(style, false)
, fFCI(SkRef(fci))
, fFCI(std::move(fci))
, fIdentity(fi)
, fFamilyName(familyName)
, fFontData(nullptr) {}

View File

@ -9,6 +9,7 @@
#include "SkFontConfigTypeface.h"
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
#include "SkFontMgr_FontConfigInterface.h"
#include "SkFontStyle.h"
#include "SkMakeUnique.h"
#include "SkMutex.h"
@ -152,7 +153,7 @@ static bool find_by_FontIdentity(SkTypeface* cachedTypeface, void* ctx) {
///////////////////////////////////////////////////////////////////////////////
class SkFontMgr_FCI : public SkFontMgr {
SkAutoTUnref<SkFontConfigInterface> fFCI;
sk_sp<SkFontConfigInterface> fFCI;
sk_sp<SkDataTable> fFamilyNames;
SkTypeface_FreeType::Scanner fScanner;
@ -165,8 +166,8 @@ class SkFontMgr_FCI : public SkFontMgr {
mutable SkFontRequestCache fCache;
public:
SkFontMgr_FCI(SkFontConfigInterface* fci)
: fFCI(fci)
SkFontMgr_FCI(sk_sp<SkFontConfigInterface> fci)
: fFCI(std::move(fci))
, fFamilyNames(fFCI->getFamilyNames())
, fCache(kMaxSize)
{}
@ -295,7 +296,7 @@ protected:
}
};
SK_API SkFontMgr* SkFontMgr_New_FCI(SkFontConfigInterface* fci) {
SK_API SkFontMgr* SkFontMgr_New_FCI(sk_sp<SkFontConfigInterface> fci) {
SkASSERT(fci);
return new SkFontMgr_FCI(fci);
return new SkFontMgr_FCI(std::move(fci));
}

View File

@ -7,38 +7,17 @@
#include "SkFontConfigInterface.h"
#include "SkFontMgr.h"
#include "SkMutex.h"
#include "SkRefCnt.h"
#include "SkFontMgr_FontConfigInterface.h"
SK_DECLARE_STATIC_MUTEX(gFontConfigInterfaceMutex);
static SkFontConfigInterface* gFontConfigInterface;
SkFontConfigInterface* SkFontConfigInterface::RefGlobal() {
SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
return SkSafeRef(gFontConfigInterface);
}
SkFontConfigInterface* SkFontConfigInterface::SetGlobal(SkFontConfigInterface* fc) {
SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
SkRefCnt_SafeAssign(gFontConfigInterface, fc);
return fc;
}
///////////////////////////////////////////////////////////////////////////////
static SkFontConfigInterface* init_FCI() {
SkAutoMutexAcquire ac(gFontConfigInterfaceMutex);
if (gFontConfigInterface) {
return SkRef(gFontConfigInterface);
}
gFontConfigInterface = SkRef(SkFontConfigInterface::GetSingletonDirectInterface());
return gFontConfigInterface;
}
#ifdef SK_ADDING_src_ports_SkFontConfigInterface_cpp
// The code previously here is moving to SkFontConfigInterface.cpp
#include "SkFontConfigInterface.cpp"
#endif
SkFontMgr* SkFontMgr::Factory() {
SkFontConfigInterface* fci = init_FCI();
return fci ? SkFontMgr_New_FCI(fci) : nullptr;
sk_sp<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal());
if (!fci) {
return nullptr;
}
return SkFontMgr_New_FCI(std::move(fci));
}