summaryrefslogtreecommitdiffstats
path: root/skia
diff options
context:
space:
mode:
authorpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-13 13:10:16 +0000
committerpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-13 13:10:16 +0000
commit0ba77c2638060f7ab6474a6bb8fec6cbb189b6a6 (patch)
treecd60245cc3921db225fda3438d4def0dc7918e35 /skia
parente54ba9b5af160a32f8ae8f0bbcd4c786b1b6bcc7 (diff)
downloadchromium_src-0ba77c2638060f7ab6474a6bb8fec6cbb189b6a6.zip
chromium_src-0ba77c2638060f7ab6474a6bb8fec6cbb189b6a6.tar.gz
chromium_src-0ba77c2638060f7ab6474a6bb8fec6cbb189b6a6.tar.bz2
Remove static initializers in Skia.
This patch does the following things: - Add missing SK_USE_POSIX_THREADS in skia.gyp. This enables the patch sent by David Turner making SkMutex POD in order to remove static initializers (on Android, Linux and Mac). - Remove static initializers in SkFontHost_fontconfig.cpp and SkMemory_new_handler.cpp. Note that the global_fc_typefaces map was populated but never read therefore I removed it. Let me know if I'm wrong. BUG=94925 Review URL: http://codereview.chromium.org/9668002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126385 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia')
-rw-r--r--skia/ext/SkFontHost_fontconfig.cpp42
-rw-r--r--skia/ext/SkMemory_new_handler.cpp4
-rw-r--r--skia/skia.gyp15
3 files changed, 37 insertions, 24 deletions
diff --git a/skia/ext/SkFontHost_fontconfig.cpp b/skia/ext/SkFontHost_fontconfig.cpp
index ef73553..076cb02 100644
--- a/skia/ext/SkFontHost_fontconfig.cpp
+++ b/skia/ext/SkFontHost_fontconfig.cpp
@@ -41,27 +41,34 @@ static FontConfigInterface* global_fc_impl = NULL;
void SkiaFontConfigUseDirectImplementation() {
if (global_fc_impl)
- delete global_fc_impl;
+ delete global_fc_impl;
global_fc_impl = new FontConfigDirect;
}
void SkiaFontConfigSetImplementation(FontConfigInterface* font_config) {
if (global_fc_impl)
- delete global_fc_impl;
+ delete global_fc_impl;
global_fc_impl = font_config;
}
static FontConfigInterface* GetFcImpl() {
if (!global_fc_impl)
- global_fc_impl = new FontConfigDirect;
+ global_fc_impl = new FontConfigDirect;
return global_fc_impl;
}
-static SkMutex global_fc_map_lock;
-static std::map<uint32_t, SkTypeface *> global_fc_typefaces;
+SK_DECLARE_STATIC_MUTEX(global_remote_font_map_lock);
+static std::map<uint32_t, std::pair<uint8_t*, size_t> >* global_remote_fonts;
+
+// Initialize the map declared above. Note that its corresponding mutex must be
+// locked before calling this function.
+static void AllocateGlobalRemoteFontsMapOnce() {
+ if (!global_remote_fonts) {
+ global_remote_fonts =
+ new std::map<uint32_t, std::pair<uint8_t*, size_t> >();
+ }
+}
-static SkMutex global_remote_font_map_lock;
-static std::map<uint32_t, std::pair<uint8_t*, size_t> > global_remote_fonts;
static unsigned global_next_remote_font_id;
// This is the maximum size of the font cache.
@@ -106,11 +113,12 @@ public:
const uint32_t id = uniqueID();
if (IsRemoteFont(UniqueIdToFileFaceId(id))) {
SkAutoMutexAcquire ac(global_remote_font_map_lock);
+ AllocateGlobalRemoteFontsMapOnce();
std::map<uint32_t, std::pair<uint8_t*, size_t> >::iterator iter
- = global_remote_fonts.find(id);
- if (iter != global_remote_fonts.end()) {
+ = global_remote_fonts->find(id);
+ if (iter != global_remote_fonts->end()) {
sk_free(iter->second.first); // remove the font on memory.
- global_remote_fonts.erase(iter);
+ global_remote_fonts->erase(iter);
}
}
}
@@ -153,12 +161,6 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
const unsigned id = FileFaceIdAndStyleToUniqueId(filefaceid,
resulting_style);
SkTypeface* typeface = SkNEW_ARGS(FontConfigTypeface, (resulting_style, id));
-
- {
- SkAutoMutexAcquire ac(global_fc_map_lock);
- global_fc_typefaces[id] = typeface;
- }
-
return typeface;
}
@@ -184,13 +186,14 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream)
unsigned id = 0;
{
SkAutoMutexAcquire ac(global_remote_font_map_lock);
+ AllocateGlobalRemoteFontsMapOnce();
id = FileFaceIdAndStyleToUniqueId(
global_next_remote_font_id | kRemoteFontMask, style);
if (++global_next_remote_font_id >= kRemoteFontMask)
global_next_remote_font_id = 0;
- if (!global_remote_fonts.insert(
+ if (!global_remote_fonts->insert(
std::make_pair(id, std::make_pair(font, length))).second) {
sk_free(font);
return NULL;
@@ -294,9 +297,10 @@ SkStream* SkFontHost::OpenStream(uint32_t id)
if (IsRemoteFont(filefaceid)) {
// remote font
SkAutoMutexAcquire ac(global_remote_font_map_lock);
+ AllocateGlobalRemoteFontsMapOnce();
std::map<uint32_t, std::pair<uint8_t*, size_t> >::const_iterator iter
- = global_remote_fonts.find(id);
- if (iter == global_remote_fonts.end())
+ = global_remote_fonts->find(id);
+ if (iter == global_remote_fonts->end())
return NULL;
return SkNEW_ARGS(
SkMemoryStream, (iter->second.first, iter->second.second));
diff --git a/skia/ext/SkMemory_new_handler.cpp b/skia/ext/SkMemory_new_handler.cpp
index b839d04..5f958c6 100644
--- a/skia/ext/SkMemory_new_handler.cpp
+++ b/skia/ext/SkMemory_new_handler.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -14,7 +14,7 @@
// during malloc(), when SK_MALLOC_THROW is not set (ie., when
// sk_malloc_flags() would not abort on NULL).
-static SkMutex gSkNewHandlerMutex;
+SK_DECLARE_STATIC_MUTEX(gSkNewHandlerMutex);
void sk_throw() {
SkASSERT(!"sk_throw");
diff --git a/skia/skia.gyp b/skia/skia.gyp
index 6780b20..b74f95f1 100644
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -771,6 +771,16 @@
'../third_party/skia/include/core/SkTypes.h',
],
'conditions': [
+ # For POSIX platforms, prefer the Mutex implementation provided by Skia
+ # since it does not generate static initializers.
+ [ 'OS == "android" or OS == "linux" or OS == "mac"', {
+ 'defines+': [
+ 'SK_USE_POSIX_THREADS',
+ ],
+ 'sources!': [
+ 'ext/SkThread_chrome.cc',
+ ],
+ }],
[ 'OS != "android"', {
'sources/': [
['exclude', '_android\\.(cc|cpp)$'],
@@ -778,7 +788,6 @@
'sources!': [
# Below files are only used by Android
'../third_party/skia/src/ports/SkFontHost_gamma.cpp',
- '../third_party/skia/src/ports/SkThread_pthread.cpp',
],
}],
[ 'OS != "mac"', {
@@ -875,7 +884,6 @@
'../third_party/expat/files/lib',
],
'sources!': [
- 'ext/SkThread_chrome.cc',
'ext/vector_platform_device_skia.cc',
'../third_party/skia/src/core/SkTypefaceCache.cpp',
'../third_party/skia/src/ports/SkFontHost_gamma_none.cpp',
@@ -925,8 +933,9 @@
[ 'OS == "win"', {
'sources!': [
'../third_party/skia/src/core/SkMMapStream.cpp',
- '../third_party/skia/src/ports/SkTime_Unix.cpp',
'../third_party/skia/src/ports/SkFontHost_sandbox_none.cpp',
+ '../third_party/skia/src/ports/SkThread_pthread.cpp',
+ '../third_party/skia/src/ports/SkTime_Unix.cpp',
'ext/SkThread_chrome.cc',
],
'include_dirs': [