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

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

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, just in case. Created 5 years, 11 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/ports/SkFontHost_FreeType.cpp ('k') | src/ports/SkFontHost_linux.cpp » ('j') | 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 2008 Google Inc. 2 * Copyright 2008 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 #include "SkFontConfigInterface.h" 8 #include "SkFontConfigInterface.h"
9 #include "SkFontConfigTypeface.h" 9 #include "SkFontConfigTypeface.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 /////////////////////////////////////////////////////////////////////////////// 127 ///////////////////////////////////////////////////////////////////////////////
128 128
129 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { 129 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
130 SkStream* stream = this->getLocalStream(); 130 SkStream* stream = this->getLocalStream();
131 if (stream) { 131 if (stream) {
132 // should have been provided by CreateFromStream() 132 // should have been provided by CreateFromStream()
133 *ttcIndex = 0; 133 *ttcIndex = 0;
134 134
135 SkAutoTUnref<SkStream> dupStream(stream->duplicate()); 135 SkAutoTDelete<SkStream> dupStream(stream->duplicate());
136 if (dupStream) { 136 if (dupStream) {
137 return dupStream.detach(); 137 return dupStream.detach();
138 } 138 }
139 139
140 // TODO: update interface use, remove the following code in this block. 140 // TODO: update interface use, remove the following code in this block.
141 size_t length = stream->getLength(); 141 size_t length = stream->getLength();
142 142
143 const void* memory = stream->getMemoryBase(); 143 const void* memory = stream->getMemoryBase();
144 if (memory) { 144 if (memory) {
145 return new SkMemoryStream(memory, length, true); 145 return new SkMemoryStream(memory, length, true);
146 } 146 }
147 147
148 SkAutoTMalloc<uint8_t> allocMemory(length); 148 SkAutoTMalloc<uint8_t> allocMemory(length);
149 stream->rewind(); 149 stream->rewind();
150 if (length == stream->read(allocMemory.get(), length)) { 150 if (length == stream->read(allocMemory.get(), length)) {
151 SkAutoTUnref<SkMemoryStream> copyStream(new SkMemoryStream()); 151 SkAutoTDelete<SkMemoryStream> copyStream(new SkMemoryStream());
152 copyStream->setMemoryOwned(allocMemory.detach(), length); 152 copyStream->setMemoryOwned(allocMemory.detach(), length);
153 return copyStream.detach(); 153 return copyStream.detach();
154 } 154 }
155
156 stream->rewind();
157 stream->ref();
158 } else { 155 } else {
159 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); 156 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
160 if (NULL == fci.get()) { 157 if (NULL == fci.get()) {
161 return NULL; 158 return NULL;
162 } 159 }
163 stream = fci->openStream(this->getIdentity()); 160 stream = fci->openStream(this->getIdentity());
164 *ttcIndex = this->getIdentity().fTTCIndex; 161 *ttcIndex = this->getIdentity().fTTCIndex;
165 } 162 }
166 return stream; 163 return stream;
167 } 164 }
168 165
169 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const { 166 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const {
170 *familyName = this->getFamilyName(); 167 *familyName = this->getFamilyName();
171 } 168 }
172 169
173 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, 170 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
174 bool* isLocalStream) const { 171 bool* isLocalStream) const {
175 desc->setFamilyName(this->getFamilyName()); 172 desc->setFamilyName(this->getFamilyName());
176 desc->setFontIndex(this->getIdentity().fTTCIndex); 173 desc->setFontIndex(this->getIdentity().fTTCIndex);
177 *isLocalStream = SkToBool(this->getLocalStream()); 174 *isLocalStream = SkToBool(this->getLocalStream());
178 } 175 }
OLDNEW
« no previous file with comments | « src/ports/SkFontHost_FreeType.cpp ('k') | src/ports/SkFontHost_linux.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698