skia2/include/ports/SkFontMgr_indirect.h
mtklein 72c9faab45 Fix up all the easy virtual ... SK_OVERRIDE cases.
This fixes every case where virtual and SK_OVERRIDE were on the same line,
which should be the bulk of cases.  We'll have to manually clean up the rest
over time unless I level up in regexes.

for f in (find . -type f); perl -p -i -e 's/virtual (.*)SK_OVERRIDE/\1SK_OVERRIDE/g' $f; end

BUG=skia:

Review URL: https://codereview.chromium.org/806653007
2015-01-09 10:06:40 -08:00

106 lines
3.6 KiB
C++

/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkFontMgr_indirect_DEFINED
#define SkFontMgr_indirect_DEFINED
#include "SkDataTable.h"
#include "SkFontMgr.h"
#include "SkFontStyle.h"
#include "SkRemotableFontMgr.h"
#include "SkTArray.h"
#include "SkTypeface.h"
class SkData;
class SkStream;
class SkString;
class SkTypeface;
class SK_API SkFontMgr_Indirect : public SkFontMgr {
public:
// TODO: The SkFontMgr is only used for createFromStream/File/Data.
// In the future these calls should be broken out into their own interface
// with a name like SkFontRenderer.
SkFontMgr_Indirect(SkFontMgr* impl, SkRemotableFontMgr* proxy)
: fImpl(SkRef(impl)), fProxy(SkRef(proxy)), fFamilyNamesInited(false)
{ }
protected:
int onCountFamilies() const SK_OVERRIDE;
void onGetFamilyName(int index, SkString* familyName) const SK_OVERRIDE;
SkFontStyleSet* onCreateStyleSet(int index) const SK_OVERRIDE;
SkFontStyleSet* onMatchFamily(const char familyName[]) const SK_OVERRIDE;
virtual SkTypeface* onMatchFamilyStyle(const char familyName[],
const SkFontStyle& fontStyle) const SK_OVERRIDE;
virtual SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
const SkFontStyle&,
const char* bcp47[],
int bcp47Count,
SkUnichar character) const SK_OVERRIDE;
virtual SkTypeface* onMatchFaceStyle(const SkTypeface* familyMember,
const SkFontStyle& fontStyle) const SK_OVERRIDE;
SkTypeface* onCreateFromStream(SkStream* stream, int ttcIndex) const SK_OVERRIDE;
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const SK_OVERRIDE;
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const SK_OVERRIDE;
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[],
unsigned styleBits) const SK_OVERRIDE;
private:
SkTypeface* createTypefaceFromFontId(const SkFontIdentity& fontId) const;
SkAutoTUnref<SkFontMgr> fImpl;
SkAutoTUnref<SkRemotableFontMgr> fProxy;
struct DataEntry {
uint32_t fDataId; // key1
uint32_t fTtcIndex; // key2
SkTypeface* fTypeface; // value: weak ref to typeface
DataEntry() { }
// This is a move!!!
DataEntry(DataEntry& that)
: fDataId(that.fDataId)
, fTtcIndex(that.fTtcIndex)
, fTypeface(that.fTypeface)
{
SkDEBUGCODE(that.fDataId = SkFontIdentity::kInvalidDataId;)
SkDEBUGCODE(that.fTtcIndex = 0xbbadbeef;)
that.fTypeface = NULL;
}
~DataEntry() {
if (fTypeface) {
fTypeface->weak_unref();
}
}
};
/**
* This cache is essentially { dataId: { ttcIndex: typeface } }
* For data caching we want a mapping from data id to weak references to
* typefaces with that data id. By storing the index next to the typeface,
* this data cache also acts as a typeface cache.
*/
mutable SkTArray<DataEntry> fDataCache;
mutable SkMutex fDataCacheMutex;
mutable SkAutoTUnref<SkDataTable> fFamilyNames;
mutable bool fFamilyNamesInited;
mutable SkMutex fFamilyNamesMutex;
static void set_up_family_names(const SkFontMgr_Indirect* self);
friend class SkStyleSet_Indirect;
};
#endif