Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Side by Side Diff: src/ports/SkFontConfigInterface_direct.cpp

Issue 304383005: Port most uses of SkOnce to SkLazyPtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add mutex Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/lazy/SkDiscardableMemoryPool.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 Google Inc. 2 * Copyright 2009 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ 8 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */
9 9
10 #include <string> 10 #include <string>
11 #include <unistd.h> 11 #include <unistd.h>
12 #include <fcntl.h> 12 #include <fcntl.h>
13 13
14 #include <fontconfig/fontconfig.h> 14 #include <fontconfig/fontconfig.h>
15 15
16 #include "SkBuffer.h" 16 #include "SkBuffer.h"
17 #include "SkFontConfigInterface.h" 17 #include "SkFontConfigInterface.h"
18 #include "SkOnce.h" 18 #include "SkLazyPtr.h"
19 #include "SkStream.h" 19 #include "SkStream.h"
20 20
21 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const { 21 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const {
22 size_t size = sizeof(fID) + sizeof(fTTCIndex); 22 size_t size = sizeof(fID) + sizeof(fTTCIndex);
23 size += sizeof(int32_t) + sizeof(int32_t) + sizeof(uint8_t); // weight, widt h, italic 23 size += sizeof(int32_t) + sizeof(int32_t) + sizeof(uint8_t); // weight, widt h, italic
24 size += sizeof(int32_t) + fString.size(); // store length+data 24 size += sizeof(int32_t) + fString.size(); // store length+data
25 if (addr) { 25 if (addr) {
26 SkWBuffer buffer(addr, size); 26 SkWBuffer buffer(addr, size);
27 27
28 buffer.write32(fID); 28 buffer.write32(fID);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // new APIs 117 // new APIs
118 virtual SkDataTable* getFamilyNames() SK_OVERRIDE; 118 virtual SkDataTable* getFamilyNames() SK_OVERRIDE;
119 virtual bool matchFamilySet(const char inFamilyName[], 119 virtual bool matchFamilySet(const char inFamilyName[],
120 SkString* outFamilyName, 120 SkString* outFamilyName,
121 SkTArray<FontIdentity>*) SK_OVERRIDE; 121 SkTArray<FontIdentity>*) SK_OVERRIDE;
122 122
123 private: 123 private:
124 SkMutex mutex_; 124 SkMutex mutex_;
125 }; 125 };
126 126
127 static void create_singleton_direct_interface(SkFontConfigInterface** singleton) { 127 namespace {
128 *singleton = new SkFontConfigInterfaceDirect; 128 SkFontConfigInterface* create_direct() { return SkNEW(SkFontConfigInterfaceDirec t); }
129 } 129 } // namespace
130
130 SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface() { 131 SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface() {
131 static SkFontConfigInterface* gDirect; 132 SK_DECLARE_STATIC_LAZY_PTR(SkFontConfigInterface, direct, create_direct);
132 SK_DECLARE_STATIC_ONCE(once); 133 return direct.get();
133 SkOnce(&once, create_singleton_direct_interface, &gDirect);
134 return gDirect;
135 } 134 }
136 135
137 /////////////////////////////////////////////////////////////////////////////// 136 ///////////////////////////////////////////////////////////////////////////////
138 137
139 // Returns the string from the pattern, or NULL 138 // Returns the string from the pattern, or NULL
140 static const char* get_name(FcPattern* pattern, const char field[], 139 static const char* get_name(FcPattern* pattern, const char field[],
141 int index = 0) { 140 int index = 0) {
142 const char* name; 141 const char* name;
143 if (FcPatternGetString(pattern, field, index, 142 if (FcPatternGetString(pattern, field, index,
144 (FcChar8**)&name) != FcResultMatch) { 143 (FcChar8**)&name) != FcResultMatch) {
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 *trimmedMatches.append() = match[i]; 724 *trimmedMatches.append() = match[i];
726 } 725 }
727 } 726 }
728 727
729 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC, 728 SkFontStyleSet_FC* sset = SkNEW_ARGS(SkFontStyleSet_FC,
730 (trimmedMatches.begin(), 729 (trimmedMatches.begin(),
731 trimmedMatches.count())); 730 trimmedMatches.count()));
732 #endif 731 #endif
733 return false; 732 return false;
734 } 733 }
OLDNEW
« no previous file with comments | « src/lazy/SkDiscardableMemoryPool.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698