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

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: Treat SkFontMgr::createFromStream as taking ownership of the stream (is this correct?) 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
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 155
156 stream->rewind(); 156 stream->rewind();
157 stream->ref(); 157 stream->ref();
bungeman-skia 2015/01/15 22:56:04 At this point I think these two lines can be remov
scroggo 2015/01/16 19:13:37 Definitely need to delete ref(); just hadn't teste
158 } else { 158 } else {
159 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); 159 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
160 if (NULL == fci.get()) { 160 if (NULL == fci.get()) {
161 return NULL; 161 return NULL;
162 } 162 }
163 stream = fci->openStream(this->getIdentity()); 163 stream = fci->openStream(this->getIdentity());
164 *ttcIndex = this->getIdentity().fTTCIndex; 164 *ttcIndex = this->getIdentity().fTTCIndex;
165 } 165 }
166 return stream; 166 return stream;
167 } 167 }
168 168
169 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const { 169 void FontConfigTypeface::onGetFamilyName(SkString* familyName) const {
170 *familyName = this->getFamilyName(); 170 *familyName = this->getFamilyName();
171 } 171 }
172 172
173 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, 173 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
174 bool* isLocalStream) const { 174 bool* isLocalStream) const {
175 desc->setFamilyName(this->getFamilyName()); 175 desc->setFamilyName(this->getFamilyName());
176 desc->setFontIndex(this->getIdentity().fTTCIndex); 176 desc->setFontIndex(this->getIdentity().fTTCIndex);
177 *isLocalStream = SkToBool(this->getLocalStream()); 177 *isLocalStream = SkToBool(this->getLocalStream());
178 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698