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

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

Issue 2339273002: SkFontData to use smart pointers. (Closed)
Patch Set: Add trivial bodies to the trivial implementations. Created 4 years, 3 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/SkFontConfigTypeface.h ('k') | src/ports/SkFontHost_FreeType_common.h » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkAdvancedTypefaceMetrics.h" 8 #include "SkAdvancedTypefaceMetrics.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 bool shouldSubpixelBitmap(const SkGlyph&, const SkMatrix&); 227 bool shouldSubpixelBitmap(const SkGlyph&, const SkMatrix&);
228 }; 228 };
229 229
230 /////////////////////////////////////////////////////////////////////////// 230 ///////////////////////////////////////////////////////////////////////////
231 /////////////////////////////////////////////////////////////////////////// 231 ///////////////////////////////////////////////////////////////////////////
232 232
233 struct SkFaceRec { 233 struct SkFaceRec {
234 SkFaceRec* fNext; 234 SkFaceRec* fNext;
235 FT_Face fFace; 235 FT_Face fFace;
236 FT_StreamRec fFTStream; 236 FT_StreamRec fFTStream;
237 SkAutoTDelete<SkStreamAsset> fSkStream; 237 std::unique_ptr<SkStreamAsset> fSkStream;
238 uint32_t fRefCnt; 238 uint32_t fRefCnt;
239 uint32_t fFontID; 239 uint32_t fFontID;
240 240
241 // assumes ownership of the stream, will delete when its done 241 SkFaceRec(std::unique_ptr<SkStreamAsset> stream, uint32_t fontID);
242 SkFaceRec(SkStreamAsset* strm, uint32_t fontID);
243 }; 242 };
244 243
245 extern "C" { 244 extern "C" {
246 static unsigned long sk_ft_stream_io(FT_Stream ftStream, 245 static unsigned long sk_ft_stream_io(FT_Stream ftStream,
247 unsigned long offset, 246 unsigned long offset,
248 unsigned char* buffer, 247 unsigned char* buffer,
249 unsigned long count) 248 unsigned long count)
250 { 249 {
251 SkStreamAsset* stream = static_cast<SkStreamAsset*>(ftStream->descriptor .pointer); 250 SkStreamAsset* stream = static_cast<SkStreamAsset*>(ftStream->descriptor .pointer);
252 251
253 if (count) { 252 if (count) {
254 if (!stream->seek(offset)) { 253 if (!stream->seek(offset)) {
255 return 0; 254 return 0;
256 } 255 }
257 count = stream->read(buffer, count); 256 count = stream->read(buffer, count);
258 } 257 }
259 return count; 258 return count;
260 } 259 }
261 260
262 static void sk_ft_stream_close(FT_Stream) {} 261 static void sk_ft_stream_close(FT_Stream) {}
263 } 262 }
264 263
265 SkFaceRec::SkFaceRec(SkStreamAsset* stream, uint32_t fontID) 264 SkFaceRec::SkFaceRec(std::unique_ptr<SkStreamAsset> stream, uint32_t fontID)
266 : fNext(nullptr), fSkStream(stream), fRefCnt(1), fFontID(fontID) 265 : fNext(nullptr), fSkStream(std::move(stream)), fRefCnt(1), fFontID(font ID)
267 { 266 {
268 sk_bzero(&fFTStream, sizeof(fFTStream)); 267 sk_bzero(&fFTStream, sizeof(fFTStream));
269 fFTStream.size = fSkStream->getLength(); 268 fFTStream.size = fSkStream->getLength();
270 fFTStream.descriptor.pointer = fSkStream; 269 fFTStream.descriptor.pointer = fSkStream.get();
271 fFTStream.read = sk_ft_stream_io; 270 fFTStream.read = sk_ft_stream_io;
272 fFTStream.close = sk_ft_stream_close; 271 fFTStream.close = sk_ft_stream_close;
273 } 272 }
274 273
275 static void ft_face_setup_axes(FT_Face face, const SkFontData& data) { 274 static void ft_face_setup_axes(FT_Face face, const SkFontData& data) {
276 if (!(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)) { 275 if (!(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)) {
277 return; 276 return;
278 } 277 }
279 278
280 SkDEBUGCODE( 279 SkDEBUGCODE(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 SkFaceRec* rec = gFaceRecHead; 311 SkFaceRec* rec = gFaceRecHead;
313 while (rec) { 312 while (rec) {
314 if (rec->fFontID == fontID) { 313 if (rec->fFontID == fontID) {
315 SkASSERT(rec->fFace); 314 SkASSERT(rec->fFace);
316 rec->fRefCnt += 1; 315 rec->fRefCnt += 1;
317 return rec->fFace; 316 return rec->fFace;
318 } 317 }
319 rec = rec->fNext; 318 rec = rec->fNext;
320 } 319 }
321 320
322 SkAutoTDelete<SkFontData> data(typeface->createFontData()); 321 std::unique_ptr<SkFontData> data = typeface->makeFontData();
323 if (nullptr == data || !data->hasStream()) { 322 if (nullptr == data || !data->hasStream()) {
324 return nullptr; 323 return nullptr;
325 } 324 }
326 325
327 // this passes ownership of stream to the rec
328 rec = new SkFaceRec(data->detachStream(), fontID); 326 rec = new SkFaceRec(data->detachStream(), fontID);
329 327
330 FT_Open_Args args; 328 FT_Open_Args args;
331 memset(&args, 0, sizeof(args)); 329 memset(&args, 0, sizeof(args));
332 const void* memoryBase = rec->fSkStream->getMemoryBase(); 330 const void* memoryBase = rec->fSkStream->getMemoryBase();
333 if (memoryBase) { 331 if (memoryBase) {
334 args.flags = FT_OPEN_MEMORY; 332 args.flags = FT_OPEN_MEMORY;
335 args.memory_base = (const FT_Byte*)memoryBase; 333 args.memory_base = (const FT_Byte*)memoryBase;
336 args.memory_size = rec->fSkStream->getLength(); 334 args.memory_size = rec->fSkStream->getLength();
337 } else { 335 } else {
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 return; 1555 return;
1558 } 1556 }
1559 FT_Add_Default_Modules(fLibrary); 1557 FT_Add_Default_Modules(fLibrary);
1560 } 1558 }
1561 SkTypeface_FreeType::Scanner::~Scanner() { 1559 SkTypeface_FreeType::Scanner::~Scanner() {
1562 if (fLibrary) { 1560 if (fLibrary) {
1563 FT_Done_Library(fLibrary); 1561 FT_Done_Library(fLibrary);
1564 } 1562 }
1565 } 1563 }
1566 1564
1567 FT_Face SkTypeface_FreeType::Scanner::openFace(SkStream* stream, int ttcIndex, 1565 FT_Face SkTypeface_FreeType::Scanner::openFace(SkStreamAsset* stream, int ttcInd ex,
1568 FT_Stream ftStream) const 1566 FT_Stream ftStream) const
1569 { 1567 {
1570 if (fLibrary == nullptr) { 1568 if (fLibrary == nullptr) {
1571 return nullptr; 1569 return nullptr;
1572 } 1570 }
1573 1571
1574 FT_Open_Args args; 1572 FT_Open_Args args;
1575 memset(&args, 0, sizeof(args)); 1573 memset(&args, 0, sizeof(args));
1576 1574
1577 const void* memoryBase = stream->getMemoryBase(); 1575 const void* memoryBase = stream->getMemoryBase();
(...skipping 13 matching lines...) Expand all
1591 args.stream = ftStream; 1589 args.stream = ftStream;
1592 } 1590 }
1593 1591
1594 FT_Face face; 1592 FT_Face face;
1595 if (FT_Open_Face(fLibrary, &args, ttcIndex, &face)) { 1593 if (FT_Open_Face(fLibrary, &args, ttcIndex, &face)) {
1596 return nullptr; 1594 return nullptr;
1597 } 1595 }
1598 return face; 1596 return face;
1599 } 1597 }
1600 1598
1601 bool SkTypeface_FreeType::Scanner::recognizedFont(SkStream* stream, int* numFace s) const { 1599 bool SkTypeface_FreeType::Scanner::recognizedFont(SkStreamAsset* stream, int* nu mFaces) const {
1602 SkAutoMutexAcquire libraryLock(fLibraryMutex); 1600 SkAutoMutexAcquire libraryLock(fLibraryMutex);
1603 1601
1604 FT_StreamRec streamRec; 1602 FT_StreamRec streamRec;
1605 FT_Face face = this->openFace(stream, -1, &streamRec); 1603 FT_Face face = this->openFace(stream, -1, &streamRec);
1606 if (nullptr == face) { 1604 if (nullptr == face) {
1607 return false; 1605 return false;
1608 } 1606 }
1609 1607
1610 *numFaces = face->num_faces; 1608 *numFaces = face->num_faces;
1611 1609
1612 FT_Done_Face(face); 1610 FT_Done_Face(face);
1613 return true; 1611 return true;
1614 } 1612 }
1615 1613
1616 #include "SkTSearch.h" 1614 #include "SkTSearch.h"
1617 bool SkTypeface_FreeType::Scanner::scanFont( 1615 bool SkTypeface_FreeType::Scanner::scanFont(
1618 SkStream* stream, int ttcIndex, 1616 SkStreamAsset* stream, int ttcIndex,
1619 SkString* name, SkFontStyle* style, bool* isFixedPitch, AxisDefinitions* axe s) const 1617 SkString* name, SkFontStyle* style, bool* isFixedPitch, AxisDefinitions* axe s) const
1620 { 1618 {
1621 SkAutoMutexAcquire libraryLock(fLibraryMutex); 1619 SkAutoMutexAcquire libraryLock(fLibraryMutex);
1622 1620
1623 FT_StreamRec streamRec; 1621 FT_StreamRec streamRec;
1624 FT_Face face = this->openFace(stream, ttcIndex, &streamRec); 1622 FT_Face face = this->openFace(stream, ttcIndex, &streamRec);
1625 if (nullptr == face) { 1623 if (nullptr == face) {
1626 return false; 1624 return false;
1627 } 1625 }
1628 1626
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", 1767 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n",
1770 name.c_str(), 1768 name.c_str(),
1771 (skTag >> 24) & 0xFF, 1769 (skTag >> 24) & 0xFF,
1772 (skTag >> 16) & 0xFF, 1770 (skTag >> 16) & 0xFF,
1773 (skTag >> 8) & 0xFF, 1771 (skTag >> 8) & 0xFF,
1774 (skTag) & 0xFF)); 1772 (skTag) & 0xFF));
1775 } 1773 }
1776 } 1774 }
1777 ) 1775 )
1778 } 1776 }
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigTypeface.h ('k') | src/ports/SkFontHost_FreeType_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698