Skip to content

Commit

Permalink
Bug 1874810 - Implement RecordedStrokeGlyphs. r=aosmond
Browse files Browse the repository at this point in the history
  • Loading branch information
lsalzman committed Jan 17, 2024
1 parent 1c02a6a commit 6f8d3af
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 38 deletions.
2 changes: 1 addition & 1 deletion dom/media/test/reftest/color_quads/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defaults pref(media.av1.enabled,true)
fuzzy(16-51,5234-5622) fuzzy-if(swgl,32-38,1600-91746) fuzzy-if(useDrawSnapshot,16-16,11600-11600) fuzzy-if(OSX,16-73,5212-5622) == ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.av1.webm ../reftest_img.html?src=color_quads/720p.png
fuzzy-if(winWidget&&swgl,0-20,0-5620) fuzzy-if(winWidget&&!swgl,0-1,0-78) fuzzy-if(Android,254-255,273680-273807) fuzzy-if(OSX,0-35,0-1947) fuzzy-if(OSX&&swgl,0-67,0-5451) fuzzy-if(appleSilicon,30-48,1760-187409) == ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.vp9.webm ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.av1.webm
fuzzy-if(winWidget,0-1,0-78) == ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.av1.mp4 ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.av1.webm
skip-if(winWidget&&isCoverageBuild) fuzzy(0-16,75-1941) fuzzy-if(Android,254-255,273680-273807) fuzzy-if(OSX,30-32,187326-187407) fuzzy-if(appleSilicon,30-48,1835-187409) == ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.h264.mp4 ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.av1.webm
skip-if(winWidget&&isCoverageBuild) fuzzy(0-16,75-1941) fuzzy-if(Android,28-255,273680-359920) fuzzy-if(OSX,30-32,187326-187407) fuzzy-if(appleSilicon,30-48,1835-187409) == ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.h264.mp4 ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.av1.webm
fuzzy-if(winWidget&&swgl,0-20,0-5620) fuzzy-if(winWidget&&!swgl,0-1,0-78) fuzzy-if(Android,254-255,273680-273807) fuzzy-if(OSX,0-35,0-1947) fuzzy-if(OSX&&swgl,0-67,0-5451) fuzzy-if(appleSilicon,30-48,1760-187409) == ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.vp9.mp4 ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.tv.yuv420p.av1.webm

skip-if(Android) fuzzy(16-48,8107-8818) fuzzy-if(winWidget&&swgl,31-38,8240-184080) fuzzy-if(appleSilicon,33-38,8819-11705) fuzzy-if(useDrawSnapshot,20-20,187200-187200) == ../reftest_video.html?src=color_quads/720p.png.bt709.bt709.pc.yuv420p.av1.webm ../reftest_img.html?src=color_quads/720p.png
Expand Down
31 changes: 26 additions & 5 deletions gfx/2d/DrawTargetRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,11 @@ static void RecordingFontUserDataDestroyFunc(void* aUserData) {
delete userData;
}

void DrawTargetRecording::FillGlyphs(ScaledFont* aFont,
void DrawTargetRecording::DrawGlyphs(ScaledFont* aFont,
const GlyphBuffer& aBuffer,
const Pattern& aPattern,
const DrawOptions& aOptions) {
const DrawOptions& aOptions,
const StrokeOptions* aStrokeOptions) {
if (!aFont) {
return;
}
Expand Down Expand Up @@ -354,9 +355,29 @@ void DrawTargetRecording::FillGlyphs(ScaledFont* aFont,
userData->recorder->AddScaledFont(aFont);
}

mRecorder->RecordEvent(
this, RecordedFillGlyphs(aFont, aPattern, aOptions, aBuffer.mGlyphs,
aBuffer.mNumGlyphs));
if (aStrokeOptions) {
mRecorder->RecordEvent(
this, RecordedStrokeGlyphs(aFont, aPattern, *aStrokeOptions, aOptions,
aBuffer.mGlyphs, aBuffer.mNumGlyphs));
} else {
mRecorder->RecordEvent(RecordedFillGlyphs(
aFont, aPattern, aOptions, aBuffer.mGlyphs, aBuffer.mNumGlyphs));
}
}

void DrawTargetRecording::FillGlyphs(ScaledFont* aFont,
const GlyphBuffer& aBuffer,
const Pattern& aPattern,
const DrawOptions& aOptions) {
DrawGlyphs(aFont, aBuffer, aPattern, aOptions);
}

void DrawTargetRecording::StrokeGlyphs(ScaledFont* aFont,
const GlyphBuffer& aBuffer,
const Pattern& aPattern,
const StrokeOptions& aStrokeOptions,
const DrawOptions& aOptions) {
DrawGlyphs(aFont, aBuffer, aPattern, aOptions, &aStrokeOptions);
}

void DrawTargetRecording::Mask(const Pattern& aSource, const Pattern& aMask,
Expand Down
13 changes: 13 additions & 0 deletions gfx/2d/DrawTargetRecording.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ class DrawTargetRecording : public DrawTarget {
const Pattern& aPattern,
const DrawOptions& aOptions = DrawOptions()) override;

/**
* Stroke a series of glyphs on the draw target with a certain source pattern.
*/
virtual void StrokeGlyphs(
ScaledFont* aFont, const GlyphBuffer& aBuffer, const Pattern& aPattern,
const StrokeOptions& aStrokeOptions = StrokeOptions(),
const DrawOptions& aOptions = DrawOptions()) override;

/*
* This takes a source pattern and a mask, and composites the source pattern
* onto the destination surface using the alpha channel of the mask pattern
Expand Down Expand Up @@ -370,6 +378,11 @@ class DrawTargetRecording : public DrawTarget {
already_AddRefed<PathRecording> EnsurePathStored(const Path* aPath);
void EnsurePatternDependenciesStored(const Pattern& aPattern);

void DrawGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
const Pattern& aPattern,
const DrawOptions& aOptions = DrawOptions(),
const StrokeOptions* aStrokeOptions = nullptr);

RefPtr<DrawEventRecorderPrivate> mRecorder;
RefPtr<DrawTarget> mFinalDT;
IntRect mRect;
Expand Down
2 changes: 2 additions & 0 deletions gfx/2d/RecordedEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ std::string RecordedEvent::GetEventName(EventType aType) {
return "Fill";
case FILLGLYPHS:
return "FillGlyphs";
case STROKEGLYPHS:
return "StrokeGlyphs";
case MASK:
return "Mask";
case STROKE:
Expand Down
1 change: 1 addition & 0 deletions gfx/2d/RecordedEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class RecordedEvent {
FILL,
FILLCIRCLE,
FILLGLYPHS,
STROKEGLYPHS,
MASK,
STROKE,
DRAWSURFACE,
Expand Down
121 changes: 96 additions & 25 deletions gfx/2d/RecordedEventImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,35 +404,38 @@ class RecordedFillCircle : public RecordedEventDerived<RecordedFillCircle> {
DrawOptions mOptions;
};

class RecordedFillGlyphs : public RecordedEventDerived<RecordedFillGlyphs> {
template <class Derived>
class RecordedDrawGlyphs : public RecordedEventDerived<Derived> {
public:
RecordedFillGlyphs(ReferencePtr aScaledFont, const Pattern& aPattern,
const DrawOptions& aOptions, const Glyph* aGlyphs,
uint32_t aNumGlyphs)
: RecordedEventDerived(FILLGLYPHS),
RecordedDrawGlyphs(RecordedEvent::EventType aType, ReferencePtr aScaledFont,
const Pattern& aPattern, const DrawOptions& aOptions,
const Glyph* aGlyphs, uint32_t aNumGlyphs)
: RecordedEventDerived<Derived>(aType),
mScaledFont(aScaledFont),
mPattern(),
mOptions(aOptions) {
StorePattern(mPattern, aPattern);
RecordedEventDerived<Derived>::StorePattern(mPattern, aPattern);
mNumGlyphs = aNumGlyphs;
mGlyphs = new Glyph[aNumGlyphs];
memcpy(mGlyphs, aGlyphs, sizeof(Glyph) * aNumGlyphs);
}
virtual ~RecordedFillGlyphs();
virtual ~RecordedDrawGlyphs();

bool PlayEvent(Translator* aTranslator) const override;

template <class S>
void Record(S& aStream) const;
void OutputSimpleEventInfo(std::stringstream& aStringStream) const override;

std::string GetName() const override { return "FillGlyphs"; }

private:
protected:
friend class RecordedEvent;

template <class S>
MOZ_IMPLICIT RecordedFillGlyphs(S& aStream);
RecordedDrawGlyphs(RecordedEvent::EventType aType, S& aStream);

virtual void DrawGlyphs(DrawTarget* aDT, ScaledFont* aScaledFont,
const GlyphBuffer& aBuffer,
const Pattern& aPattern) const = 0;

ReferencePtr mScaledFont;
PatternStorage mPattern;
Expand All @@ -441,6 +444,66 @@ class RecordedFillGlyphs : public RecordedEventDerived<RecordedFillGlyphs> {
uint32_t mNumGlyphs = 0;
};

class RecordedFillGlyphs : public RecordedDrawGlyphs<RecordedFillGlyphs> {
public:
RecordedFillGlyphs(ReferencePtr aScaledFont, const Pattern& aPattern,
const DrawOptions& aOptions, const Glyph* aGlyphs,
uint32_t aNumGlyphs)
: RecordedDrawGlyphs(FILLGLYPHS, aScaledFont, aPattern, aOptions, aGlyphs,
aNumGlyphs) {}

std::string GetName() const override { return "FillGlyphs"; }

private:
friend class RecordedEvent;

template <class S>
MOZ_IMPLICIT RecordedFillGlyphs(S& aStream)
: RecordedDrawGlyphs(FILLGLYPHS, aStream) {}

void DrawGlyphs(DrawTarget* aDT, ScaledFont* aScaledFont,
const GlyphBuffer& aBuffer,
const Pattern& aPattern) const override {
aDT->FillGlyphs(aScaledFont, aBuffer, aPattern, mOptions);
}
};

class RecordedStrokeGlyphs : public RecordedDrawGlyphs<RecordedStrokeGlyphs> {
public:
RecordedStrokeGlyphs(ReferencePtr aScaledFont, const Pattern& aPattern,
const StrokeOptions& aStrokeOptions,
const DrawOptions& aOptions, const Glyph* aGlyphs,
uint32_t aNumGlyphs)
: RecordedDrawGlyphs(STROKEGLYPHS, aScaledFont, aPattern, aOptions,
aGlyphs, aNumGlyphs),
mStrokeOptions(aStrokeOptions) {}

std::string GetName() const override { return "StrokeGlyphs"; }

template <class S>
void Record(S& aStream) const {
RecordedDrawGlyphs::Record(aStream);
RecordStrokeOptions(aStream, mStrokeOptions);
}

private:
friend class RecordedEvent;

template <class S>
MOZ_IMPLICIT RecordedStrokeGlyphs(S& aStream)
: RecordedDrawGlyphs(STROKEGLYPHS, aStream) {
ReadStrokeOptions(aStream, mStrokeOptions);
}

void DrawGlyphs(DrawTarget* aDT, ScaledFont* aScaledFont,
const GlyphBuffer& aBuffer,
const Pattern& aPattern) const override {
aDT->StrokeGlyphs(aScaledFont, aBuffer, aPattern, mStrokeOptions, mOptions);
}

StrokeOptions mStrokeOptions;
};

class RecordedMask : public RecordedEventDerived<RecordedMask> {
public:
RecordedMask(const Pattern& aSource, const Pattern& aMask,
Expand Down Expand Up @@ -2529,14 +2592,18 @@ RecordedFillCircle::RecordedFillCircle(S& aStream)

inline void RecordedFillCircle::OutputSimpleEventInfo(
std::stringstream& aStringStream) const {
aStringStream << "StrokeCircle (" << mCircle.origin.x << ", "
aStringStream << "FillCircle (" << mCircle.origin.x << ", "
<< mCircle.origin.y << " - " << mCircle.radius << ")";
OutputSimplePatternInfo(mPattern, aStringStream);
}

inline RecordedFillGlyphs::~RecordedFillGlyphs() { delete[] mGlyphs; }
template <class T>
inline RecordedDrawGlyphs<T>::~RecordedDrawGlyphs() {
delete[] mGlyphs;
}

inline bool RecordedFillGlyphs::PlayEvent(Translator* aTranslator) const {
template <class T>
inline bool RecordedDrawGlyphs<T>::PlayEvent(Translator* aTranslator) const {
if (mNumGlyphs > 0 && !mGlyphs) {
// Glyph allocation failed
return false;
Expand All @@ -2555,45 +2622,48 @@ inline bool RecordedFillGlyphs::PlayEvent(Translator* aTranslator) const {
GlyphBuffer buffer;
buffer.mGlyphs = mGlyphs;
buffer.mNumGlyphs = mNumGlyphs;
dt->FillGlyphs(scaledFont, buffer, *GenericPattern(mPattern, aTranslator),
mOptions);
DrawGlyphs(dt, scaledFont, buffer, *GenericPattern(mPattern, aTranslator));
return true;
}

template <class T>
template <class S>
RecordedFillGlyphs::RecordedFillGlyphs(S& aStream)
: RecordedEventDerived(FILLGLYPHS) {
RecordedDrawGlyphs<T>::RecordedDrawGlyphs(RecordedEvent::EventType aType,
S& aStream)
: RecordedEventDerived<T>(aType) {
ReadElement(aStream, mScaledFont);
ReadDrawOptions(aStream, mOptions);
ReadPatternData(aStream, mPattern);
this->ReadPatternData(aStream, mPattern);
ReadElement(aStream, mNumGlyphs);
if (!aStream.good() || mNumGlyphs <= 0) {
return;
}

mGlyphs = new (fallible) Glyph[mNumGlyphs];
if (!mGlyphs) {
gfxCriticalNote << "RecordedFillGlyphs failed to allocate glyphs of size "
gfxCriticalNote << "RecordedDrawGlyphs failed to allocate glyphs of size "
<< mNumGlyphs;
aStream.SetIsBad();
} else {
aStream.read((char*)mGlyphs, sizeof(Glyph) * mNumGlyphs);
}
}

template <class T>
template <class S>
void RecordedFillGlyphs::Record(S& aStream) const {
void RecordedDrawGlyphs<T>::Record(S& aStream) const {
WriteElement(aStream, mScaledFont);
WriteElement(aStream, mOptions);
RecordPatternData(aStream, mPattern);
this->RecordPatternData(aStream, mPattern);
WriteElement(aStream, mNumGlyphs);
aStream.write((char*)mGlyphs, sizeof(Glyph) * mNumGlyphs);
}

inline void RecordedFillGlyphs::OutputSimpleEventInfo(
template <class T>
inline void RecordedDrawGlyphs<T>::OutputSimpleEventInfo(
std::stringstream& aStringStream) const {
aStringStream << "FillGlyphs (" << mScaledFont << ") ";
OutputSimplePatternInfo(mPattern, aStringStream);
aStringStream << this->GetName() << " (" << mScaledFont << ") ";
this->OutputSimplePatternInfo(mPattern, aStringStream);
}

inline bool RecordedMask::PlayEvent(Translator* aTranslator) const {
Expand Down Expand Up @@ -4180,6 +4250,7 @@ inline void RecordedDestination::OutputSimpleEventInfo(
f(FILL, RecordedFill); \
f(FILLCIRCLE, RecordedFillCircle); \
f(FILLGLYPHS, RecordedFillGlyphs); \
f(STROKEGLYPHS, RecordedStrokeGlyphs); \
f(MASK, RecordedMask); \
f(STROKE, RecordedStroke); \
f(DRAWSURFACE, RecordedDrawSurface); \
Expand Down
2 changes: 1 addition & 1 deletion layout/reftests/bugs/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ skip-if(Android) == 1727172-1.xhtml 1727172-1-ref.html
== 1726663-1.html 1726663-1-ref.html
== 1727016-1.html 1727016-1-ref.html
!= 1730314-1.html 1730314-1-ref.html
fuzzy(0-3,0-3) fuzzy-if(Android,0-3,0-1901) fuzzy-if(winWidget,0-154,0-118) == 1738700-1.html 1738700-1-ref.html
fuzzy(0-3,0-19) fuzzy-if(Android,0-3,0-1901) fuzzy-if(winWidget,0-154,0-118) == 1738700-1.html 1738700-1-ref.html

# Have to skip android because it doesn't set up example.org as a local host,
# so the test crashes there.
Expand Down
12 changes: 6 additions & 6 deletions layout/reftests/text-stroke/reftest.list
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# basic tests for webkit-text-stroke
# fuzzy is needed here for platform dependent backends
# These fail on Linux without webrender due to lack of antialiasing of the HTML text stroke
fuzzy(0-64,0-776) fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)&&(/^aarch64-msvc/.test(xulRuntime.XPCOMABI)||(winWidget&&!layersGPUAccelerated)),0-80,0-2822) == webkit-text-stroke-property-001.html webkit-text-stroke-property-001-ref.html
fuzzy(0-4,0-27) fuzzy-if(geckoview,0-4,0-1476) fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)&&(/^aarch64-msvc/.test(xulRuntime.XPCOMABI)||(winWidget&&!layersGPUAccelerated)),0-125,0-3725) == webkit-text-stroke-property-002.html webkit-text-stroke-property-002-ref.html
fuzzy(0-64,0-528) fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)&&(/^aarch64-msvc/.test(xulRuntime.XPCOMABI)||(winWidget&&!layersGPUAccelerated)),0-74,0-2596) == webkit-text-stroke-property-003.html webkit-text-stroke-property-003-ref.html
fuzzy(0-64,0-575) fuzzy-if(geckoview&&device,0-64,0-599) fuzzy-if(geckoview&&emulator,96-96,58-58) fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)&&(/^aarch64-msvc/.test(xulRuntime.XPCOMABI)||(winWidget&&!layersGPUAccelerated)),0-85,0-2147) == webkit-text-stroke-property-004.html webkit-text-stroke-property-004-ref.html
fuzzy(0-64,0-860) fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)&&(/^aarch64-msvc/.test(xulRuntime.XPCOMABI)||(winWidget&&!layersGPUAccelerated)),0-80,0-2822) == webkit-text-stroke-property-005.html webkit-text-stroke-property-005-ref.html
fuzzy(0-71,0-10) fuzzy-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)&&(/^aarch64-msvc/.test(xulRuntime.XPCOMABI)||(winWidget&&!layersGPUAccelerated)),0-48,0-351) == webkit-text-stroke-property-006.html webkit-text-stroke-property-006-ref.html
fuzzy(0-255,0-4100) == webkit-text-stroke-property-001.html webkit-text-stroke-property-001-ref.html
fuzzy(0-255,0-4400) == webkit-text-stroke-property-002.html webkit-text-stroke-property-002-ref.html
fuzzy(0-255,0-4100) == webkit-text-stroke-property-003.html webkit-text-stroke-property-003-ref.html
fuzzy(0-255,0-3000) == webkit-text-stroke-property-004.html webkit-text-stroke-property-004-ref.html
fuzzy(0-255,0-4100) == webkit-text-stroke-property-005.html webkit-text-stroke-property-005-ref.html
fuzzy(0-255,0-400) == webkit-text-stroke-property-006.html webkit-text-stroke-property-006-ref.html

0 comments on commit 6f8d3af

Please sign in to comment.