Skip to content

Commit

Permalink
Bug 1876538 - Backout changes from bug 1875364 to cache current filte…
Browse files Browse the repository at this point in the history
…r for recordings. r=gfx-reviewers,jrmuizel

Differential Revision: https://phabricator.services.mozilla.com/D199723
  • Loading branch information
aosmond committed Jan 26, 2024
1 parent 81450a1 commit 0c5c013
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 190 deletions.
10 changes: 1 addition & 9 deletions gfx/2d/DrawEventRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,13 @@ DrawEventRecorderPrivate::~DrawEventRecorderPrivate() {
NS_ASSERT_OWNINGTHREAD(DrawEventRecorderPrivate);
}

void DrawEventRecorderPrivate::RecordSetCurrentDrawTarget(ReferencePtr aDT) {
void DrawEventRecorderPrivate::SetDrawTarget(ReferencePtr aDT) {
NS_ASSERT_OWNINGTHREAD(DrawEventRecorderPrivate);

RecordEvent(RecordedSetCurrentDrawTarget(aDT));
mCurrentDT = aDT;
}

void DrawEventRecorderPrivate::RecordSetCurrentFilterNode(
ReferencePtr aFilter) {
NS_ASSERT_OWNINGTHREAD(DrawEventRecorderPrivate);

RecordEvent(RecordedSetCurrentFilterNode(aFilter));
mCurrentFilter = aFilter;
}

void DrawEventRecorderPrivate::StoreExternalSurfaceRecording(
SourceSurface* aSurface, uint64_t aKey) {
NS_ASSERT_OWNINGTHREAD(DrawEventRecorderPrivate);
Expand Down
44 changes: 3 additions & 41 deletions gfx/2d/DrawEventRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace mozilla {
namespace gfx {

class DrawTargetRecording;
class FilterNodeRecording;
class PathRecording;

class DrawEventRecorderPrivate : public DrawEventRecorder {
Expand Down Expand Up @@ -87,56 +86,20 @@ class DrawEventRecorderPrivate : public DrawEventRecorder {
void RecordEvent(DrawTargetRecording* aDT, const RecordedEvent& aEvent) {
ReferencePtr dt = aDT;
if (mCurrentDT != dt) {
RecordSetCurrentDrawTarget(dt);
SetDrawTarget(dt);
}
RecordEvent(aEvent);
}

void RecordSetCurrentDrawTarget(ReferencePtr aDT);
void SetDrawTarget(ReferencePtr aDT);

void SetCurrentDrawTarget(DrawTargetRecording* aDT) { mCurrentDT = aDT; }

void ClearCurrentDrawTarget(DrawTargetRecording* aDT) {
void ClearDrawTarget(DrawTargetRecording* aDT) {
ReferencePtr dt = aDT;
if (mCurrentDT == dt) {
mCurrentDT = nullptr;
}
}

void RecordEvent(FilterNodeRecording* aFilter, const RecordedEvent& aEvent) {
ReferencePtr filter = aFilter;
if (mCurrentFilter != filter) {
RecordSetCurrentFilterNode(filter);
}
RecordEvent(aEvent);
}

void RecordSetCurrentFilterNode(ReferencePtr aFilter);

void SetCurrentFilterNode(FilterNodeRecording* aFilter) {
mCurrentFilter = aFilter;
}

void ClearCurrentFilterNode(FilterNodeRecording* aFilter) {
ReferencePtr filter = aFilter;
if (mCurrentFilter == filter) {
mCurrentFilter = nullptr;
}
}

void RecordEvent(DrawTargetRecording* aDT, FilterNodeRecording* aFilter,
const RecordedEvent& aEvent) {
ReferencePtr dt = aDT;
if (mCurrentDT != dt) {
RecordSetCurrentDrawTarget(dt);
}
ReferencePtr filter = aFilter;
if (mCurrentFilter != filter) {
RecordSetCurrentFilterNode(filter);
}
RecordEvent(aEvent);
}

void AddStoredObject(const ReferencePtr aObject) {
ProcessPendingDeletions();
mStoredObjects.Insert(aObject);
Expand Down Expand Up @@ -289,7 +252,6 @@ class DrawEventRecorderPrivate : public DrawEventRecorder {
nsTHashMap<void*, ThreadSafeWeakPtr<SourceSurface>> mStoredSurfaces;

ReferencePtr mCurrentDT;
ReferencePtr mCurrentFilter;
ExternalSurfacesHolder mExternalSurfaces;
bool mExternalFonts;
};
Expand Down
47 changes: 19 additions & 28 deletions gfx/2d/DrawTargetRecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,25 @@ class FilterNodeRecording : public FilterNode {

virtual ~FilterNodeRecording() {
mRecorder->RemoveStoredObject(this);
mRecorder->RecordEvent(this, RecordedFilterNodeDestruction());
mRecorder->ClearCurrentFilterNode(this);
mRecorder->RecordEvent(RecordedFilterNodeDestruction(ReferencePtr(this)));
}

void SetInput(uint32_t aIndex, SourceSurface* aSurface) override {
EnsureSurfaceStoredRecording(mRecorder, aSurface, "SetInput");

mRecorder->RecordEvent(this, RecordedFilterNodeSetInput(aIndex, aSurface));
mRecorder->RecordEvent(RecordedFilterNodeSetInput(this, aIndex, aSurface));
}
void SetInput(uint32_t aIndex, FilterNode* aFilter) override {
MOZ_ASSERT(mRecorder->HasStoredObject(aFilter));

mRecorder->RecordEvent(this, RecordedFilterNodeSetInput(aIndex, aFilter));
mRecorder->RecordEvent(RecordedFilterNodeSetInput(this, aIndex, aFilter));
}

#define FORWARD_SET_ATTRIBUTE(type, argtype) \
void SetAttribute(uint32_t aIndex, type aValue) override { \
mRecorder->RecordEvent( \
this, RecordedFilterNodeSetAttribute( \
aIndex, aValue, \
RecordedFilterNodeSetAttribute::ARGTYPE_##argtype)); \
#define FORWARD_SET_ATTRIBUTE(type, argtype) \
void SetAttribute(uint32_t aIndex, type aValue) override { \
mRecorder->RecordEvent(RecordedFilterNodeSetAttribute( \
this, aIndex, aValue, \
RecordedFilterNodeSetAttribute::ARGTYPE_##argtype)); \
}

FORWARD_SET_ATTRIBUTE(bool, BOOL);
Expand All @@ -184,7 +182,7 @@ class FilterNodeRecording : public FilterNode {
void SetAttribute(uint32_t aIndex, const Float* aFloat,
uint32_t aSize) override {
mRecorder->RecordEvent(
this, RecordedFilterNodeSetAttribute(aIndex, aFloat, aSize));
RecordedFilterNodeSetAttribute(this, aIndex, aFloat, aSize));
}

FilterBackend GetBackendType() override { return FILTER_BACKEND_RECORDING; }
Expand All @@ -202,7 +200,6 @@ DrawTargetRecording::DrawTargetRecording(
mRecorder->RecordEvent(layers::RecordedCanvasDrawTargetCreation(
this, aTextureId, aTextureOwnerId, mFinalDT->GetBackendType(), aSize,
mFinalDT->GetFormat()));
mRecorder->SetCurrentDrawTarget(this);
mFormat = mFinalDT->GetFormat();
DrawTarget::SetPermitSubpixelAA(IsOpaque(mFormat));
}
Expand All @@ -218,7 +215,6 @@ DrawTargetRecording::DrawTargetRecording(DrawEventRecorder* aRecorder,
mRecorder->RecordEvent(
RecordedDrawTargetCreation(this, mFinalDT->GetBackendType(), mRect,
mFinalDT->GetFormat(), aHasData, snapshot));
mRecorder->SetCurrentDrawTarget(this);
mFormat = mFinalDT->GetFormat();
DrawTarget::SetPermitSubpixelAA(IsOpaque(mFormat));
}
Expand All @@ -231,8 +227,8 @@ DrawTargetRecording::DrawTargetRecording(const DrawTargetRecording* aDT,
}

DrawTargetRecording::~DrawTargetRecording() {
mRecorder->RecordEvent(this, RecordedDrawTargetDestruction());
mRecorder->ClearCurrentDrawTarget(this);
mRecorder->RecordEvent(RecordedDrawTargetDestruction(ReferencePtr(this)));
mRecorder->ClearDrawTarget(this);
}

void DrawTargetRecording::Link(const char* aDestination, const Rect& aRect) {
Expand Down Expand Up @@ -518,22 +514,21 @@ void DrawTargetRecording::DrawSurfaceWithShadow(SourceSurface* aSurface,
void DrawTargetRecording::DrawFilter(FilterNode* aNode, const Rect& aSourceRect,
const Point& aDestPoint,
const DrawOptions& aOptions) {
if (!aNode || aNode->GetBackendType() != FILTER_BACKEND_RECORDING) {
if (!aNode) {
return;
}

MOZ_ASSERT(mRecorder->HasStoredObject(aNode));

mRecorder->RecordEvent(this, static_cast<FilterNodeRecording*>(aNode),
RecordedDrawFilter(aSourceRect, aDestPoint, aOptions));
mRecorder->RecordEvent(
this, RecordedDrawFilter(aNode, aSourceRect, aDestPoint, aOptions));
}

already_AddRefed<FilterNode> DrawTargetRecording::CreateFilter(
FilterType aType) {
RefPtr<FilterNodeRecording> retNode = new FilterNodeRecording(mRecorder);
RefPtr<FilterNode> retNode = new FilterNodeRecording(mRecorder);

mRecorder->RecordEvent(this, RecordedFilterNodeCreation(retNode, aType));
mRecorder->SetCurrentFilterNode(retNode);

return retNode.forget();
}
Expand Down Expand Up @@ -716,14 +711,13 @@ DrawTargetRecording::CreateSimilarDrawTargetWithBacking(

already_AddRefed<DrawTarget> DrawTargetRecording::CreateSimilarDrawTarget(
const IntSize& aSize, SurfaceFormat aFormat) const {
RefPtr<DrawTargetRecording> similarDT;
RefPtr<DrawTarget> similarDT;
if (mFinalDT->CanCreateSimilarDrawTarget(aSize, aFormat)) {
similarDT =
new DrawTargetRecording(this, IntRect(IntPoint(0, 0), aSize), aFormat);
mRecorder->RecordEvent(
const_cast<DrawTargetRecording*>(this),
RecordedCreateSimilarDrawTarget(similarDT.get(), aSize, aFormat));
mRecorder->SetCurrentDrawTarget(similarDT);
} else if (XRE_IsContentProcess()) {
// Crash any content process that calls this function with arguments that
// would fail to create a similar draw target. We do this to root out bad
Expand All @@ -743,11 +737,10 @@ bool DrawTargetRecording::CanCreateSimilarDrawTarget(

RefPtr<DrawTarget> DrawTargetRecording::CreateClippedDrawTarget(
const Rect& aBounds, SurfaceFormat aFormat) {
RefPtr<DrawTargetRecording> similarDT =
new DrawTargetRecording(this, mRect, aFormat);
RefPtr<DrawTarget> similarDT;
similarDT = new DrawTargetRecording(this, mRect, aFormat);
mRecorder->RecordEvent(
this, RecordedCreateClippedDrawTarget(similarDT.get(), aBounds, aFormat));
mRecorder->SetCurrentDrawTarget(similarDT);
similarDT->SetTransform(mTransform);
return similarDT;
}
Expand All @@ -756,15 +749,14 @@ already_AddRefed<DrawTarget>
DrawTargetRecording::CreateSimilarDrawTargetForFilter(
const IntSize& aMaxSize, SurfaceFormat aFormat, FilterNode* aFilter,
FilterNode* aSource, const Rect& aSourceRect, const Point& aDestPoint) {
RefPtr<DrawTargetRecording> similarDT;
RefPtr<DrawTarget> similarDT;
if (mFinalDT->CanCreateSimilarDrawTarget(aMaxSize, aFormat)) {
similarDT = new DrawTargetRecording(this, IntRect(IntPoint(0, 0), aMaxSize),
aFormat);
mRecorder->RecordEvent(
this, RecordedCreateDrawTargetForFilter(similarDT.get(), aMaxSize,
aFormat, aFilter, aSource,
aSourceRect, aDestPoint));
mRecorder->SetCurrentDrawTarget(similarDT);
} else if (XRE_IsContentProcess()) {
// See CreateSimilarDrawTarget
MOZ_CRASH(
Expand Down Expand Up @@ -847,7 +839,6 @@ void DrawTargetRecording::FlushItem(const IntRect& aBounds) {
mRecorder->RecordEvent(
RecordedDrawTargetCreation(this, mFinalDT->GetBackendType(), mRect,
mFinalDT->GetFormat(), false, nullptr));
mRecorder->SetCurrentDrawTarget(this);
// Add the current transform to the new recording
mRecorder->RecordEvent(this,
RecordedSetTransform(DrawTarget::GetTransform()));
Expand Down
19 changes: 6 additions & 13 deletions gfx/2d/InlineTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ class InlineTranslator : public Translator {
mNativeFontResources.InsertOrUpdate(aKey, RefPtr{aScaledFontResouce});
}

void RemoveDrawTarget() override {
if (mCurrentDT) {
mDrawTargets.Remove(mCurrentDT);
void RemoveDrawTarget(ReferencePtr aRefPtr) override {
ReferencePtr currentDT = mCurrentDT;
if (currentDT == aRefPtr) {
mCurrentDT = nullptr;
}
mDrawTargets.Remove(aRefPtr);
}

bool SetCurrentDrawTarget(ReferencePtr aRefPtr) override {
Expand All @@ -144,16 +145,8 @@ class InlineTranslator : public Translator {
mSourceSurfaces.Remove(aRefPtr);
}

void RemoveFilterNode() final {
if (mCurrentFilter) {
mFilterNodes.Remove(mCurrentFilter);
mCurrentFilter = nullptr;
}
}

bool SetCurrentFilterNode(ReferencePtr aRefPtr) override {
mCurrentFilter = mFilterNodes.GetWeak(aRefPtr);
return !!mCurrentFilter;
void RemoveFilterNode(ReferencePtr aRefPtr) final {
mFilterNodes.Remove(aRefPtr);
}

void RemoveGradientStops(ReferencePtr aRefPtr) final {
Expand Down
4 changes: 0 additions & 4 deletions gfx/2d/RecordedEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ std::string RecordedEvent::GetEventName(EventType aType) {
return "DrawTarget Creation";
case DRAWTARGETDESTRUCTION:
return "DrawTarget Destruction";
case SETCURRENTDRAWTARGET:
return "SetCurrentDrawTarget";
case FILLRECT:
return "FillRect";
case STROKERECT:
Expand Down Expand Up @@ -90,8 +88,6 @@ std::string RecordedEvent::GetEventName(EventType aType) {
return "FilterNodeCreation";
case FILTERNODEDESTRUCTION:
return "FilterNodeDestruction";
case SETCURRENTFILTERNODE:
return "SetCurrentFilterNode";
case GRADIENTSTOPSCREATION:
return "GradientStopsCreation";
case GRADIENTSTOPSDESTRUCTION:
Expand Down
9 changes: 2 additions & 7 deletions gfx/2d/RecordedEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,15 @@ class Translator {
}
void DrawDependentSurface(uint64_t aKey, const Rect& aRect);
virtual void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget* aDT) = 0;
virtual void RemoveDrawTarget() = 0;
virtual void RemoveDrawTarget(ReferencePtr aRefPtr) = 0;
virtual bool SetCurrentDrawTarget(ReferencePtr aRefPtr) = 0;
virtual void AddPath(ReferencePtr aRefPtr, Path* aPath) = 0;
virtual void RemovePath(ReferencePtr aRefPtr) = 0;
virtual void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface* aPath) = 0;
virtual void RemoveSourceSurface(ReferencePtr aRefPtr) = 0;
virtual void AddFilterNode(mozilla::gfx::ReferencePtr aRefPtr,
FilterNode* aSurface) = 0;
virtual void RemoveFilterNode() = 0;
virtual bool SetCurrentFilterNode(ReferencePtr aRefPtr) = 0;
virtual void RemoveFilterNode(mozilla::gfx::ReferencePtr aRefPtr) = 0;

/**
* Get GradientStops compatible with the translation DrawTarget type.
Expand Down Expand Up @@ -152,12 +151,9 @@ class Translator {

DrawTarget* GetCurrentDrawTarget() const { return mCurrentDT; }

FilterNode* GetCurrentFilterNode() const { return mCurrentFilter; }

nsRefPtrHashtable<nsUint64HashKey, RecordedDependentSurface>*
mDependentSurfaces = nullptr;
DrawTarget* mCurrentDT = nullptr;
FilterNode* mCurrentFilter = nullptr;
};

struct ColorPatternStorage {
Expand Down Expand Up @@ -408,7 +404,6 @@ class RecordedEvent {
MASKSURFACE,
FILTERNODECREATION,
FILTERNODEDESTRUCTION,
SETCURRENTFILTERNODE,
DRAWFILTER,
FILTERNODESETATTRIBUTE,
FILTERNODESETINPUT,
Expand Down
Loading

0 comments on commit 0c5c013

Please sign in to comment.