зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1256678 - Fall back to loading GDI fonts from system in DrawTargetRecording - r=bas
This commit is contained in:
Родитель
4a167320a0
Коммит
cdd3b63026
|
@ -645,6 +645,7 @@ public:
|
|||
virtual ~ScaledFont() {}
|
||||
|
||||
typedef void (*FontFileDataOutput)(const uint8_t *aData, uint32_t aLength, uint32_t aIndex, Float aGlyphSize, void *aBaton);
|
||||
typedef void (*FontDescriptorOutput)(const uint8_t *aData, uint32_t aLength, Float aFontSize, void *aBaton);
|
||||
|
||||
virtual FontType GetType() const = 0;
|
||||
|
||||
|
@ -664,6 +665,8 @@ public:
|
|||
|
||||
virtual bool GetFontFileData(FontFileDataOutput, void *) { return false; }
|
||||
|
||||
virtual bool GetFontDescriptor(FontDescriptorOutput, void *) { return false; }
|
||||
|
||||
void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) {
|
||||
mUserData.Add(key, userData, destroy);
|
||||
}
|
||||
|
|
|
@ -395,11 +395,22 @@ DrawTargetRecording::FillGlyphs(ScaledFont *aFont,
|
|||
RecordedFontData fontData(aFont);
|
||||
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(RecordedScaledFontCreation(aFont, fontDetails));
|
||||
} else {
|
||||
// If that fails, record just the font description and try to load it from
|
||||
// the system on the other side.
|
||||
RecordedFontDescriptor fontDesc(aFont);
|
||||
if (fontDesc.IsValid()) {
|
||||
mRecorder->RecordEvent(fontDesc);
|
||||
} else {
|
||||
gfxWarning() << "DrawTargetRecording::FillGlyphs failed to serialise ScaledFont";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
RecordingFontUserData *userData = new RecordingFontUserData;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "Tools.h"
|
||||
#include "Filters.h"
|
||||
#include "Logging.h"
|
||||
#include "ScaledFontBase.h"
|
||||
#include "SFNTData.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -80,6 +81,7 @@ RecordedEvent::LoadEventFromStream(std::istream &aStream, EventType aType)
|
|||
LOAD_EVENT_TYPE(FILTERNODESETINPUT, RecordedFilterNodeSetInput);
|
||||
LOAD_EVENT_TYPE(CREATESIMILARDRAWTARGET, RecordedCreateSimilarDrawTarget);
|
||||
LOAD_EVENT_TYPE(FONTDATA, RecordedFontData);
|
||||
LOAD_EVENT_TYPE(FONTDESC, RecordedFontDescriptor);
|
||||
LOAD_EVENT_TYPE(PUSHLAYER, RecordedPushLayer);
|
||||
LOAD_EVENT_TYPE(POPLAYER, RecordedPopLayer);
|
||||
default:
|
||||
|
@ -159,6 +161,8 @@ RecordedEvent::GetEventName(EventType aType)
|
|||
return "CreateSimilarDrawTarget";
|
||||
case FONTDATA:
|
||||
return "FontData";
|
||||
case FONTDESC:
|
||||
return "FontDescriptor";
|
||||
case PUSHLAYER:
|
||||
return "PushLayer";
|
||||
case POPLAYER:
|
||||
|
@ -1523,6 +1527,66 @@ RecordedFontData::RecordedFontData(istream &aStream)
|
|||
aStream.read((char*)mData, mFontDetails.size);
|
||||
}
|
||||
|
||||
RecordedFontDescriptor::~RecordedFontDescriptor()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RecordedFontDescriptor::PlayEvent(Translator *aTranslator) const
|
||||
{
|
||||
MOZ_ASSERT(mType == FontType::GDI);
|
||||
|
||||
NativeFont nativeFont;
|
||||
nativeFont.mType = (NativeFontType)mType;
|
||||
nativeFont.mFont = (void*)&mData[0];
|
||||
|
||||
RefPtr<ScaledFont> font =
|
||||
Factory::CreateScaledFontForNativeFont(nativeFont, mFontSize);
|
||||
|
||||
#ifdef USE_CAIRO_SCALED_FONT
|
||||
static_cast<ScaledFontBase*>(font.get())->PopulateCairoScaledFont();
|
||||
#endif
|
||||
|
||||
aTranslator->AddScaledFont(mRefPtr, font);
|
||||
}
|
||||
|
||||
void
|
||||
RecordedFontDescriptor::RecordToStream(std::ostream &aStream) const
|
||||
{
|
||||
MOZ_ASSERT(mHasDesc);
|
||||
WriteElement(aStream, mType);
|
||||
WriteElement(aStream, mFontSize);
|
||||
WriteElement(aStream, mRefPtr);
|
||||
WriteElement(aStream, (size_t)mData.size());
|
||||
aStream.write((char*)&mData[0], mData.size());
|
||||
}
|
||||
|
||||
void
|
||||
RecordedFontDescriptor::OutputSimpleEventInfo(stringstream &aStringStream) const
|
||||
{
|
||||
aStringStream << "[" << mRefPtr << "] Font Descriptor";
|
||||
}
|
||||
|
||||
void
|
||||
RecordedFontDescriptor::SetFontDescriptor(const uint8_t* aData, uint32_t aSize, Float aFontSize)
|
||||
{
|
||||
mData.assign(aData, aData + aSize);
|
||||
mFontSize = aFontSize;
|
||||
}
|
||||
|
||||
RecordedFontDescriptor::RecordedFontDescriptor(istream &aStream)
|
||||
: RecordedEvent(FONTDATA)
|
||||
{
|
||||
ReadElement(aStream, mType);
|
||||
ReadElement(aStream, mFontSize);
|
||||
ReadElement(aStream, mRefPtr);
|
||||
|
||||
size_t size;
|
||||
ReadElement(aStream, size);
|
||||
mData.resize(size);
|
||||
aStream.read((char*)&mData[0], size);
|
||||
}
|
||||
|
||||
void
|
||||
RecordedScaledFontCreation::PlayEvent(Translator *aTranslator) const
|
||||
{
|
||||
|
|
|
@ -192,6 +192,7 @@ public:
|
|||
FILTERNODESETINPUT,
|
||||
CREATESIMILARDRAWTARGET,
|
||||
FONTDATA,
|
||||
FONTDESC,
|
||||
PUSHLAYER,
|
||||
POPLAYER,
|
||||
};
|
||||
|
@ -1042,6 +1043,51 @@ private:
|
|||
MOZ_IMPLICIT RecordedFontData(std::istream &aStream);
|
||||
};
|
||||
|
||||
class RecordedFontDescriptor : public RecordedEvent {
|
||||
public:
|
||||
|
||||
static void FontDescCb(const uint8_t *aData, uint32_t aSize,
|
||||
Float aFontSize, void* aBaton)
|
||||
{
|
||||
auto recordedFontDesc = static_cast<RecordedFontDescriptor*>(aBaton);
|
||||
recordedFontDesc->SetFontDescriptor(aData, aSize, aFontSize);
|
||||
}
|
||||
|
||||
explicit RecordedFontDescriptor(ScaledFont* aScaledFont)
|
||||
: RecordedEvent(FONTDESC)
|
||||
, mType(aScaledFont->GetType())
|
||||
, mRefPtr(aScaledFont)
|
||||
{
|
||||
mHasDesc = aScaledFont->GetFontDescriptor(FontDescCb, this);
|
||||
}
|
||||
|
||||
~RecordedFontDescriptor();
|
||||
|
||||
bool IsValid() const { return mHasDesc; }
|
||||
|
||||
virtual void PlayEvent(Translator *aTranslator) const;
|
||||
|
||||
virtual void RecordToStream(std::ostream &aStream) const;
|
||||
virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
|
||||
|
||||
virtual std::string GetName() const { return "Font Desc"; }
|
||||
virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
|
||||
|
||||
private:
|
||||
friend class RecordedEvent;
|
||||
|
||||
void SetFontDescriptor(const uint8_t* aData, uint32_t aSize, Float aFontSize);
|
||||
|
||||
bool mHasDesc;
|
||||
|
||||
FontType mType;
|
||||
Float mFontSize;
|
||||
std::vector<uint8_t> mData;
|
||||
ReferencePtr mRefPtr;
|
||||
|
||||
MOZ_IMPLICIT RecordedFontDescriptor(std::istream &aStream);
|
||||
};
|
||||
|
||||
class RecordedScaledFontCreation : public RecordedEvent {
|
||||
public:
|
||||
|
||||
|
|
|
@ -75,6 +75,13 @@ ScaledFontWin::GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ScaledFontWin::GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton)
|
||||
{
|
||||
aCb(reinterpret_cast<uint8_t*>(&mLogFont), sizeof(mLogFont), mSize, aBaton);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef USE_SKIA
|
||||
SkTypeface* ScaledFontWin::GetSkTypeface()
|
||||
{
|
||||
|
|
|
@ -21,6 +21,8 @@ public:
|
|||
|
||||
bool GetFontFileData(FontFileDataOutput aDataCallback, void *aBaton) override;
|
||||
|
||||
virtual bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override;
|
||||
|
||||
#ifdef USE_SKIA
|
||||
virtual SkTypeface* GetSkTypeface();
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче