Bug 1829026 - Implement DrawShadow in DrawTargetRecording. r=aosmond

DrawTargetWebgl relies upon DrawShadow for shadow performance. This was never
implemented in DrawTargetRecording, which this patch rectifies.

Differential Revision: https://phabricator.services.mozilla.com/D194354
This commit is contained in:
Lee Salzman 2023-12-18 18:10:47 +00:00
parent 3a265d3692
commit 30d651cabd
4 changed files with 105 additions and 0 deletions

View File

@ -393,6 +393,17 @@ void DrawTargetRecording::Stroke(const Path* aPath, const Pattern& aPattern,
RecordedStroke(this, pathRecording, aPattern, aStrokeOptions, aOptions));
}
void DrawTargetRecording::DrawShadow(const Path* aPath, const Pattern& aPattern,
const ShadowOptions& aShadow,
const DrawOptions& aOptions,
const StrokeOptions* aStrokeOptions) {
RefPtr<PathRecording> pathRecording = EnsurePathStored(aPath);
EnsurePatternDependenciesStored(aPattern);
mRecorder->RecordEvent(RecordedDrawShadow(this, pathRecording, aPattern,
aShadow, aOptions, aStrokeOptions));
}
already_AddRefed<SourceSurface> DrawTargetRecording::Snapshot() {
RefPtr<SourceSurface> retSurf =
new SourceSurfaceRecording(mRect.Size(), mFormat, mRecorder);

View File

@ -73,6 +73,11 @@ class DrawTargetRecording : public DrawTarget {
const ShadowOptions& aShadow,
CompositionOp aOperator) override;
virtual void DrawShadow(const Path* aPath, const Pattern& aPattern,
const ShadowOptions& aShadow,
const DrawOptions& aOptions,
const StrokeOptions* aStrokeOptions) override;
/*
* Clear a rectangle on the draw target to transparent black. This will
* respect the clipping region and transform.

View File

@ -384,6 +384,7 @@ class RecordedEvent {
DRAWSURFACE,
DRAWDEPENDENTSURFACE,
DRAWSURFACEWITHSHADOW,
DRAWSHADOW,
PATHCREATION,
PATHDESTRUCTION,
SOURCESURFACECREATION,

View File

@ -824,6 +824,44 @@ class RecordedDrawSurfaceWithShadow
CompositionOp mOp;
};
class RecordedDrawShadow : public RecordedDrawingEvent<RecordedDrawShadow> {
public:
RecordedDrawShadow(DrawTarget* aDT, ReferencePtr aPath,
const Pattern& aPattern, const ShadowOptions& aShadow,
const DrawOptions& aOptions,
const StrokeOptions* aStrokeOptions)
: RecordedDrawingEvent(DRAWSHADOW, aDT),
mPath(aPath),
mPattern(),
mShadow(aShadow),
mOptions(aOptions),
mHasStrokeOptions(!!aStrokeOptions),
mStrokeOptions(aStrokeOptions ? *aStrokeOptions : StrokeOptions()) {
StorePattern(mPattern, aPattern);
}
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 "DrawShadow"; }
private:
friend class RecordedEvent;
template <class S>
MOZ_IMPLICIT RecordedDrawShadow(S& aStream);
ReferencePtr mPath;
PatternStorage mPattern;
ShadowOptions mShadow;
DrawOptions mOptions;
bool mHasStrokeOptions;
StrokeOptions mStrokeOptions;
};
class RecordedDrawFilter : public RecordedDrawingEvent<RecordedDrawFilter> {
public:
RecordedDrawFilter(DrawTarget* aDT, ReferencePtr aNode,
@ -3098,6 +3136,55 @@ inline void RecordedDrawSurfaceWithShadow::OutputSimpleEventInfo(
<< mShadow.mColor.a << ")";
}
inline bool RecordedDrawShadow::PlayEvent(Translator* aTranslator) const {
DrawTarget* dt = aTranslator->LookupDrawTarget(mDT);
if (!dt) {
return false;
}
Path* path = aTranslator->LookupPath(mPath);
if (!path) {
return false;
}
dt->DrawShadow(path, *GenericPattern(mPattern, aTranslator), mShadow,
mOptions, mHasStrokeOptions ? &mStrokeOptions : nullptr);
return true;
}
template <class S>
void RecordedDrawShadow::Record(S& aStream) const {
RecordedDrawingEvent::Record(aStream);
WriteElement(aStream, mPath);
RecordPatternData(aStream, mPattern);
WriteElement(aStream, mShadow);
WriteElement(aStream, mOptions);
WriteElement(aStream, mHasStrokeOptions);
if (mHasStrokeOptions) {
RecordStrokeOptions(aStream, mStrokeOptions);
}
}
template <class S>
RecordedDrawShadow::RecordedDrawShadow(S& aStream)
: RecordedDrawingEvent(DRAWSHADOW, aStream) {
ReadElement(aStream, mPath);
ReadPatternData(aStream, mPattern);
ReadElement(aStream, mShadow);
ReadDrawOptions(aStream, mOptions);
ReadElement(aStream, mHasStrokeOptions);
if (mHasStrokeOptions) {
ReadStrokeOptions(aStream, mStrokeOptions);
}
}
inline void RecordedDrawShadow::OutputSimpleEventInfo(
std::stringstream& aStringStream) const {
aStringStream << "[" << mDT << "] DrawShadow (" << mPath << ") DeviceColor: ("
<< mShadow.mColor.r << ", " << mShadow.mColor.g << ", "
<< mShadow.mColor.b << ", " << mShadow.mColor.a << ")";
}
inline RecordedPathCreation::RecordedPathCreation(PathRecording* aPath)
: RecordedEventDerived(PATHCREATION),
mRefPtr(aPath),
@ -4154,6 +4241,7 @@ inline void RecordedDestination::OutputSimpleEventInfo(
f(DRAWSURFACE, RecordedDrawSurface); \
f(DRAWDEPENDENTSURFACE, RecordedDrawDependentSurface); \
f(DRAWSURFACEWITHSHADOW, RecordedDrawSurfaceWithShadow); \
f(DRAWSHADOW, RecordedDrawShadow); \
f(DRAWFILTER, RecordedDrawFilter); \
f(PATHCREATION, RecordedPathCreation); \
f(PATHDESTRUCTION, RecordedPathDestruction); \