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

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

Issue 447003002: Fix reference counting on SkStream in SkFontMgr_android. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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 | « no previous file | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkFontConfigParser_android.h" 8 #include "SkFontConfigParser_android.h"
9 #include "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontHost_FreeType_common.h" 10 #include "SkFontHost_FreeType_common.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 }; 88 };
89 89
90 class SkTypeface_AndroidStream : public SkTypeface_Android { 90 class SkTypeface_AndroidStream : public SkTypeface_Android {
91 public: 91 public:
92 SkTypeface_AndroidStream(SkStream* stream, 92 SkTypeface_AndroidStream(SkStream* stream,
93 int index, 93 int index,
94 Style style, 94 Style style,
95 bool isFixedPitch, 95 bool isFixedPitch,
96 const SkString familyName) 96 const SkString familyName)
97 : INHERITED(index, style, isFixedPitch, familyName) 97 : INHERITED(index, style, isFixedPitch, familyName)
98 , fStream(stream) { } 98 , fStream(SkRef(stream)) { }
99 99
100 virtual void onGetFontDescriptor(SkFontDescriptor* desc, 100 virtual void onGetFontDescriptor(SkFontDescriptor* desc,
101 bool* serialize) const SK_OVERRIDE { 101 bool* serialize) const SK_OVERRIDE {
102 SkASSERT(desc); 102 SkASSERT(desc);
103 SkASSERT(serialize); 103 SkASSERT(serialize);
104 desc->setFamilyName(fFamilyName.c_str()); 104 desc->setFamilyName(fFamilyName.c_str());
105 desc->setFontFileName(NULL); 105 desc->setFontFileName(NULL);
106 *serialize = true; 106 *serialize = true;
107 } 107 }
108 108
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE { 375 virtual SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OV ERRIDE {
376 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data)); 376 SkAutoTUnref<SkStream> stream(new SkMemoryStream(data));
377 return this->createFromStream(stream, ttcIndex); 377 return this->createFromStream(stream, ttcIndex);
378 } 378 }
379 379
380 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE { 380 virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE {
381 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 381 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
382 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL; 382 return stream.get() ? this->createFromStream(stream, ttcIndex) : NULL;
383 } 383 }
384 384
385 virtual SkTypeface* onCreateFromStream(SkStream* s, int ttcIndex) const SK_O VERRIDE { 385 virtual SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE {
386 SkAutoTUnref<SkStream> stream(s);
387
388 bool isFixedPitch; 386 bool isFixedPitch;
389 SkTypeface::Style style; 387 SkTypeface::Style style;
390 SkString name; 388 SkString name;
391 if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isF ixedPitch)) { 389 if (!SkTypeface_FreeType::ScanFont(stream, ttcIndex, &name, &style, &isF ixedPitch)) {
392 return NULL; 390 return NULL;
393 } 391 }
394 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream.detach(), ttcIndex, 392 return SkNEW_ARGS(SkTypeface_AndroidStream, (stream, ttcIndex,
395 style, isFixedPitch, name)) ; 393 style, isFixedPitch, name)) ;
396 } 394 }
397 395
398 396
399 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], 397 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
400 unsigned styleBits) const SK_OVER RIDE { 398 unsigned styleBits) const SK_OVER RIDE {
401 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits; 399 SkTypeface::Style oldStyle = (SkTypeface::Style)styleBits;
402 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold 400 SkFontStyle style = SkFontStyle(oldStyle & SkTypeface::kBold
403 ? SkFontStyle::kBold_Weight 401 ? SkFontStyle::kBold_Weight
404 : SkFontStyle::kNormal_Weight, 402 : SkFontStyle::kNormal_Weight,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 480 }
483 481
484 typedef SkFontMgr INHERITED; 482 typedef SkFontMgr INHERITED;
485 }; 483 };
486 484
487 /////////////////////////////////////////////////////////////////////////////// 485 ///////////////////////////////////////////////////////////////////////////////
488 486
489 SkFontMgr* SkFontMgr::Factory() { 487 SkFontMgr* SkFontMgr::Factory() {
490 return SkNEW(SkFontMgr_Android); 488 return SkNEW(SkFontMgr_Android);
491 } 489 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698