зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1380014. Add the ability to record UnscaledFonts by index. r=lsalzman
This commit is contained in:
Родитель
2922532654
Коммит
f1e1608327
|
@ -12,7 +12,7 @@ namespace gfx {
|
|||
|
||||
using namespace std;
|
||||
|
||||
DrawEventRecorderPrivate::DrawEventRecorderPrivate()
|
||||
DrawEventRecorderPrivate::DrawEventRecorderPrivate() : mExternalFonts(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <fstream>
|
||||
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
@ -85,6 +86,22 @@ public:
|
|||
return mStoredFontData.find(aFontDataKey) != mStoredFontData.end();
|
||||
}
|
||||
|
||||
// Returns the index of the UnscaledFont
|
||||
size_t GetUnscaledFontIndex(UnscaledFont *aFont) {
|
||||
auto i = mUnscaledFontMap.find(aFont);
|
||||
size_t index;
|
||||
if (i == mUnscaledFontMap.end()) {
|
||||
mUnscaledFonts.push_back(aFont);
|
||||
index = mUnscaledFonts.size() - 1;
|
||||
mUnscaledFontMap.insert({{aFont, index}});
|
||||
} else {
|
||||
index = i->second;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
bool WantsExternalFonts() { return mExternalFonts; }
|
||||
|
||||
protected:
|
||||
virtual void Flush() = 0;
|
||||
|
||||
|
@ -92,6 +109,9 @@ protected:
|
|||
std::unordered_set<uint64_t> mStoredFontData;
|
||||
std::unordered_set<ScaledFont*> mStoredFonts;
|
||||
std::unordered_set<SourceSurface*> mStoredSurfaces;
|
||||
std::vector<RefPtr<UnscaledFont>> mUnscaledFonts;
|
||||
std::unordered_map<UnscaledFont*, size_t> mUnscaledFontMap;
|
||||
bool mExternalFonts;
|
||||
};
|
||||
|
||||
class DrawEventRecorderFile : public DrawEventRecorderPrivate
|
||||
|
|
|
@ -332,32 +332,34 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont,
|
|||
UserDataKey* userDataKey = reinterpret_cast<UserDataKey*>(mRecorder.get());
|
||||
if (!aFont->GetUserData(userDataKey)) {
|
||||
UnscaledFont* unscaledFont = aFont->GetUnscaledFont();
|
||||
if (!mRecorder->HasStoredObject(unscaledFont)) {
|
||||
RecordedFontData fontData(unscaledFont);
|
||||
RecordedFontDetails fontDetails;
|
||||
if (fontData.GetFontDetails(fontDetails)) {
|
||||
// Try to serialise the whole font, just in case this is a web font that
|
||||
// is not present on the system.
|
||||
if (!mRecorder->HasStoredFontData(fontDetails.fontDataKey)) {
|
||||
mRecorder->RecordEvent(fontData);
|
||||
mRecorder->AddStoredFontData(fontDetails.fontDataKey);
|
||||
}
|
||||
mRecorder->RecordEvent(RecordedUnscaledFontCreation(unscaledFont, fontDetails));
|
||||
} else {
|
||||
// If that fails, record just the font description and try to load it from
|
||||
// the system on the other side.
|
||||
RecordedFontDescriptor fontDesc(unscaledFont);
|
||||
if (fontDesc.IsValid()) {
|
||||
mRecorder->RecordEvent(fontDesc);
|
||||
} else {
|
||||
gfxWarning() << "DrawTargetRecording::FillGlyphs failed to serialise UnscaledFont";
|
||||
}
|
||||
if (mRecorder->WantsExternalFonts()) {
|
||||
size_t index = mRecorder->GetUnscaledFontIndex(unscaledFont);
|
||||
mRecorder->RecordEvent(RecordedScaledFontCreationByIndex(aFont, index));
|
||||
} else {
|
||||
if (!mRecorder->HasStoredObject(unscaledFont)) {
|
||||
RecordedFontData fontData(unscaledFont);
|
||||
RecordedFontDetails fontDetails;
|
||||
if (fontData.GetFontDetails(fontDetails)) {
|
||||
// Try to serialise the whole font, just in case this is a web font that
|
||||
// is not present on the system.
|
||||
if (!mRecorder->HasStoredFontData(fontDetails.fontDataKey)) {
|
||||
mRecorder->RecordEvent(fontData);
|
||||
mRecorder->AddStoredFontData(fontDetails.fontDataKey);
|
||||
}
|
||||
mRecorder->RecordEvent(RecordedUnscaledFontCreation(unscaledFont, fontDetails));
|
||||
} else {
|
||||
// If that fails, record just the font description and try to load it from
|
||||
// the system on the other side.
|
||||
RecordedFontDescriptor fontDesc(unscaledFont);
|
||||
if (fontDesc.IsValid()) {
|
||||
mRecorder->RecordEvent(fontDesc);
|
||||
} else {
|
||||
gfxWarning() << "DrawTargetRecording::FillGlyphs failed to serialise UnscaledFont";
|
||||
}
|
||||
}
|
||||
mRecorder->AddStoredObject(unscaledFont);
|
||||
}
|
||||
mRecorder->AddStoredObject(unscaledFont);
|
||||
}
|
||||
|
||||
mRecorder->RecordEvent(RecordedScaledFontCreation(aFont, unscaledFont));
|
||||
|
||||
RecordingFontUserData *userData = new RecordingFontUserData;
|
||||
userData->refPtr = aFont;
|
||||
userData->recorder = mRecorder;
|
||||
|
|
|
@ -76,13 +76,19 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) final
|
||||
UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) override final
|
||||
{
|
||||
UnscaledFont* result = mUnscaledFonts.GetWeak(aRefPtr);
|
||||
MOZ_ASSERT(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual UnscaledFont* LookupUnscaledFontByIndex(size_t index) override final
|
||||
{
|
||||
UnscaledFont* result = mUnscaledFontTable[index];
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeFontResource* LookupNativeFontResource(uint64_t aKey) final
|
||||
{
|
||||
NativeFontResource* result = mNativeFontResources.GetWeak(aKey);
|
||||
|
@ -179,6 +185,7 @@ private:
|
|||
RefPtr<DrawTarget> mBaseDT;
|
||||
void* mFontContext;
|
||||
|
||||
std::vector<RefPtr<UnscaledFont>> mUnscaledFontTable;
|
||||
nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets;
|
||||
nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths;
|
||||
nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces;
|
||||
|
|
|
@ -88,6 +88,8 @@ RecordedEvent::GetEventName(EventType aType)
|
|||
return "Snapshot";
|
||||
case SCALEDFONTCREATION:
|
||||
return "ScaledFontCreation";
|
||||
case SCALEDFONTCREATIONBYINDEX:
|
||||
return "ScaledFontCreationByIndex";
|
||||
case SCALEDFONTDESTRUCTION:
|
||||
return "ScaledFontDestruction";
|
||||
case MASKSURFACE:
|
||||
|
|
|
@ -89,6 +89,7 @@ public:
|
|||
virtual GradientStops *LookupGradientStops(ReferencePtr aRefPtr) = 0;
|
||||
virtual ScaledFont *LookupScaledFont(ReferencePtr aRefPtr) = 0;
|
||||
virtual UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) = 0;
|
||||
virtual UnscaledFont* LookupUnscaledFontByIndex(size_t aIndex) { return nullptr; }
|
||||
virtual NativeFontResource *LookupNativeFontResource(uint64_t aKey) = 0;
|
||||
virtual void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) = 0;
|
||||
virtual void RemoveDrawTarget(ReferencePtr aRefPtr) = 0;
|
||||
|
@ -241,6 +242,7 @@ public:
|
|||
GRADIENTSTOPSDESTRUCTION,
|
||||
SNAPSHOT,
|
||||
SCALEDFONTCREATION,
|
||||
SCALEDFONTCREATIONBYINDEX,
|
||||
SCALEDFONTDESTRUCTION,
|
||||
MASKSURFACE,
|
||||
FILTERNODECREATION,
|
||||
|
|
|
@ -1068,6 +1068,49 @@ private:
|
|||
MOZ_IMPLICIT RecordedScaledFontCreation(S &aStream);
|
||||
};
|
||||
|
||||
class RecordedScaledFontCreationByIndex : public RecordedEventDerived<RecordedScaledFontCreationByIndex> {
|
||||
public:
|
||||
|
||||
static void FontInstanceDataProc(const uint8_t* aData, uint32_t aSize,
|
||||
const FontVariation* aVariations, uint32_t aNumVariations,
|
||||
void* aBaton)
|
||||
{
|
||||
auto recordedScaledFontCreation = static_cast<RecordedScaledFontCreation*>(aBaton);
|
||||
recordedScaledFontCreation->SetFontInstanceData(aData, aSize, aVariations, aNumVariations);
|
||||
}
|
||||
|
||||
RecordedScaledFontCreationByIndex(ScaledFont* aScaledFont, size_t aUnscaledFontIndex)
|
||||
: RecordedEventDerived(SCALEDFONTCREATIONBYINDEX)
|
||||
, mRefPtr(aScaledFont)
|
||||
, mUnscaledFontIndex(aUnscaledFontIndex)
|
||||
, mGlyphSize(aScaledFont->GetSize())
|
||||
{
|
||||
aScaledFont->GetFontInstanceData(FontInstanceDataProc, this);
|
||||
}
|
||||
|
||||
virtual bool PlayEvent(Translator *aTranslator) const;
|
||||
|
||||
template<class S> void Record(S &aStream) const;
|
||||
virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
|
||||
|
||||
virtual std::string GetName() const { return "ScaledFont Creation"; }
|
||||
virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
|
||||
|
||||
void SetFontInstanceData(const uint8_t *aData, uint32_t aSize);
|
||||
|
||||
private:
|
||||
friend class RecordedEvent;
|
||||
|
||||
ReferencePtr mRefPtr;
|
||||
size_t mUnscaledFontIndex;
|
||||
Float mGlyphSize;
|
||||
std::vector<uint8_t> mInstanceData;
|
||||
std::vector<FontVariation> mVariations;
|
||||
|
||||
template<class S>
|
||||
MOZ_IMPLICIT RecordedScaledFontCreationByIndex(S &aStream);
|
||||
};
|
||||
|
||||
class RecordedScaledFontDestruction : public RecordedEventDerived<RecordedScaledFontDestruction> {
|
||||
public:
|
||||
MOZ_IMPLICIT RecordedScaledFontDestruction(ReferencePtr aRefPtr)
|
||||
|
@ -2954,6 +2997,68 @@ RecordedScaledFontCreation::RecordedScaledFontCreation(S &aStream)
|
|||
aStream.read((char*)mVariations.data(), sizeof(FontVariation) * numVariations);
|
||||
}
|
||||
|
||||
inline bool
|
||||
RecordedScaledFontCreationByIndex::PlayEvent(Translator *aTranslator) const
|
||||
{
|
||||
UnscaledFont* unscaledFont = aTranslator->LookupUnscaledFontByIndex(mUnscaledFontIndex);
|
||||
if (!unscaledFont) {
|
||||
gfxDevCrash(LogReason::UnscaledFontNotFound) <<
|
||||
"UnscaledFont lookup failed for key |" << hexa(mUnscaledFontIndex) << "|.";
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<ScaledFont> scaledFont =
|
||||
unscaledFont->CreateScaledFont(mGlyphSize,
|
||||
mInstanceData.data(), mInstanceData.size(),
|
||||
mVariations.data(), mVariations.size());
|
||||
|
||||
aTranslator->AddScaledFont(mRefPtr, scaledFont);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class S>
|
||||
void
|
||||
RecordedScaledFontCreationByIndex::Record(S &aStream) const
|
||||
{
|
||||
WriteElement(aStream, mRefPtr);
|
||||
WriteElement(aStream, mUnscaledFontIndex);
|
||||
WriteElement(aStream, mGlyphSize);
|
||||
WriteElement(aStream, (size_t)mInstanceData.size());
|
||||
aStream.write((char*)mInstanceData.data(), mInstanceData.size());
|
||||
WriteElement(aStream, (size_t)mVariations.size());
|
||||
aStream.write((char*)mVariations.data(), sizeof(FontVariation) * mVariations.size());
|
||||
}
|
||||
|
||||
inline void
|
||||
RecordedScaledFontCreationByIndex::OutputSimpleEventInfo(std::stringstream &aStringStream) const
|
||||
{
|
||||
aStringStream << "[" << mRefPtr << "] ScaledFont Created By Index";
|
||||
}
|
||||
|
||||
inline void
|
||||
RecordedScaledFontCreationByIndex::SetFontInstanceData(const uint8_t *aData, uint32_t aSize)
|
||||
{
|
||||
mInstanceData.assign(aData, aData + aSize);
|
||||
}
|
||||
|
||||
template<class S>
|
||||
RecordedScaledFontCreationByIndex::RecordedScaledFontCreationByIndex(S &aStream)
|
||||
: RecordedEventDerived(SCALEDFONTCREATIONBYINDEX)
|
||||
{
|
||||
ReadElement(aStream, mRefPtr);
|
||||
ReadElement(aStream, mUnscaledFontIndex);
|
||||
ReadElement(aStream, mGlyphSize);
|
||||
|
||||
size_t size;
|
||||
ReadElement(aStream, size);
|
||||
mInstanceData.resize(size);
|
||||
aStream.read((char*)mInstanceData.data(), size);
|
||||
size_t numVariations;
|
||||
ReadElement(aStream, numVariations);
|
||||
mVariations.resize(numVariations);
|
||||
aStream.read((char*)mVariations.data(), sizeof(FontVariation) * numVariations);
|
||||
}
|
||||
|
||||
inline bool
|
||||
RecordedScaledFontDestruction::PlayEvent(Translator *aTranslator) const
|
||||
{
|
||||
|
@ -3169,6 +3274,7 @@ RecordedFilterNodeSetInput::OutputSimpleEventInfo(std::stringstream &aStringStre
|
|||
f(GRADIENTSTOPSDESTRUCTION, RecordedGradientStopsDestruction); \
|
||||
f(SNAPSHOT, RecordedSnapshot); \
|
||||
f(SCALEDFONTCREATION, RecordedScaledFontCreation); \
|
||||
f(SCALEDFONTCREATIONBYINDEX, RecordedScaledFontCreationByIndex); \
|
||||
f(SCALEDFONTDESTRUCTION, RecordedScaledFontDestruction); \
|
||||
f(MASKSURFACE, RecordedMaskSurface); \
|
||||
f(FILTERNODESETATTRIBUTE, RecordedFilterNodeSetAttribute); \
|
||||
|
|
Загрузка…
Ссылка в новой задаче