diff options
author | 2016-09-19 12:13:16 -0700 | |
---|---|---|
committer | 2016-09-19 12:13:16 -0700 | |
commit | 1ae0e01accbca4b96a10b8a8c21917dd7bf27dc3 (patch) | |
tree | 61601c7afe04b356d2117fd2b00fd25faa01917b | |
parent | 0262b5c1a0ab704e42d367b070a09bb83188d983 (diff) |
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
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | cmake/CMakeLists.txt | 3 | ||||
-rw-r--r-- | gyp/ports.gyp | 2 | ||||
-rw-r--r-- | include/ports/SkFontConfigInterface.h | 11 | ||||
-rw-r--r-- | include/ports/SkFontMgr_FontConfigInterface.h | 20 | ||||
-rw-r--r-- | src/ports/SkFontConfigInterface.cpp | 30 | ||||
-rw-r--r-- | src/ports/SkFontConfigTypeface.h | 8 | ||||
-rw-r--r-- | src/ports/SkFontMgr_FontConfigInterface.cpp | 11 | ||||
-rw-r--r-- | src/ports/SkFontMgr_FontConfigInterface_factory.cpp | 41 |
9 files changed, 79 insertions, 48 deletions
@@ -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", diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index c54d430bee..0ed0957f79 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -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 diff --git a/gyp/ports.gyp b/gyp/ports.gyp index c0318fc106..3f537f7884 100644 --- a/gyp/ports.gyp +++ b/gyp/ports.gyp @@ -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', ], diff --git a/include/ports/SkFontConfigInterface.h b/include/ports/SkFontConfigInterface.h index 30fc8a35fb..74f766f52e 100644 --- a/include/ports/SkFontConfigInterface.h +++ b/include/ports/SkFontConfigInterface.h @@ -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 diff --git a/include/ports/SkFontMgr_FontConfigInterface.h b/include/ports/SkFontMgr_FontConfigInterface.h new file mode 100644 index 0000000000..356e54c87d --- /dev/null +++ b/include/ports/SkFontMgr_FontConfigInterface.h @@ -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 diff --git a/src/ports/SkFontConfigInterface.cpp b/src/ports/SkFontConfigInterface.cpp new file mode 100644 index 0000000000..5b8731c3d0 --- /dev/null +++ b/src/ports/SkFontConfigInterface.cpp @@ -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; +} diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h index 1a59d7c1ed..0da78aed87 100644 --- a/src/ports/SkFontConfigTypeface.h +++ b/src/ports/SkFontConfigTypeface.h @@ -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) {} diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp index a6a055a9d2..d4c7569009 100644 --- a/src/ports/SkFontMgr_FontConfigInterface.cpp +++ b/src/ports/SkFontMgr_FontConfigInterface.cpp @@ -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)); } diff --git a/src/ports/SkFontMgr_FontConfigInterface_factory.cpp b/src/ports/SkFontMgr_FontConfigInterface_factory.cpp index 0ffc26116f..92ed3b4e51 100644 --- a/src/ports/SkFontMgr_FontConfigInterface_factory.cpp +++ b/src/ports/SkFontMgr_FontConfigInterface_factory.cpp @@ -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)); } |