From 7b3c03d35b77ff1e9de9c87b75c3c5c7396b06e9 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 19 Jan 2024 16:02:41 +0000 Subject: [PATCH] Bug 1875364 - Make recordings cache current filter rather than include for each event. r=gfx-reviewers,lsalzman This patch also makes it so that creating a new draw target or filter node will set the current, as well as making destruction of a draw target use the current pointer. Differential Revision: https://phabricator.services.mozilla.com/D199023 UltraBlame original commit: b6393478fdf670fcce10fd4334c2601561eaea5d --- gfx/2d/DrawEventRecorder.cpp | 30 +- gfx/2d/DrawEventRecorder.h | 168 ++++++++++- gfx/2d/DrawTargetRecording.cpp | 113 ++++++-- gfx/2d/InlineTranslator.h | 59 ++-- gfx/2d/RecordedEvent.cpp | 16 ++ gfx/2d/RecordedEvent.h | 34 ++- gfx/2d/RecordedEventImpl.h | 404 ++++++++++++++++----------- gfx/layers/RecordedCanvasEventImpl.h | 14 + layout/printing/PrintTranslator.h | 57 ++-- 9 files changed, 670 insertions(+), 225 deletions(-) diff --git a/gfx/2d/DrawEventRecorder.cpp b/gfx/2d/DrawEventRecorder.cpp index 3f7503593f0a6..db8d905ec00c8 100644 --- a/gfx/2d/DrawEventRecorder.cpp +++ b/gfx/2d/DrawEventRecorder.cpp @@ -72,7 +72,7 @@ void DrawEventRecorderPrivate : : -SetDrawTarget +RecordSetCurrentDrawTarget ( ReferencePtr aDT @@ -100,6 +100,34 @@ void DrawEventRecorderPrivate : : +RecordSetCurrentFilterNode +( +ReferencePtr +aFilter +) +{ +NS_ASSERT_OWNINGTHREAD +( +DrawEventRecorderPrivate +) +; +RecordEvent +( +RecordedSetCurrentFilterNode +( +aFilter +) +) +; +mCurrentFilter += +aFilter +; +} +void +DrawEventRecorderPrivate +: +: StoreExternalSurfaceRecording ( SourceSurface diff --git a/gfx/2d/DrawEventRecorder.h b/gfx/2d/DrawEventRecorder.h index e49b1d5ea1b52..51e4a35250b22 100644 --- a/gfx/2d/DrawEventRecorder.h +++ b/gfx/2d/DrawEventRecorder.h @@ -89,6 +89,9 @@ class DrawTargetRecording ; class +FilterNodeRecording +; +class PathRecording ; class @@ -377,7 +380,7 @@ mCurrentDT dt ) { -SetDrawTarget +RecordSetCurrentDrawTarget ( dt ) @@ -390,14 +393,27 @@ aEvent ; } void -SetDrawTarget +RecordSetCurrentDrawTarget ( ReferencePtr aDT ) ; void -ClearDrawTarget +SetCurrentDrawTarget +( +DrawTargetRecording +* +aDT +) +{ +mCurrentDT += +aDT +; +} +void +ClearCurrentDrawTarget ( DrawTargetRecording * @@ -424,6 +440,149 @@ 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 @@ -992,6 +1151,9 @@ mStoredSurfaces ReferencePtr mCurrentDT ; +ReferencePtr +mCurrentFilter +; ExternalSurfacesHolder mExternalSurfaces ; diff --git a/gfx/2d/DrawTargetRecording.cpp b/gfx/2d/DrawTargetRecording.cpp index 427d0e38c2d7a..67d14cdaf23fb 100644 --- a/gfx/2d/DrawTargetRecording.cpp +++ b/gfx/2d/DrawTargetRecording.cpp @@ -639,13 +639,18 @@ mRecorder > RecordEvent ( +this RecordedFilterNodeDestruction ( -ReferencePtr -( -this ) ) +; +mRecorder +- +> +ClearCurrentFilterNode +( +this ) ; } @@ -674,9 +679,9 @@ mRecorder > RecordEvent ( +this RecordedFilterNodeSetInput ( -this aIndex aSurface ) @@ -710,9 +715,9 @@ mRecorder > RecordEvent ( +this RecordedFilterNodeSetInput ( -this aIndex aFilter ) @@ -743,10 +748,11 @@ mRecorder > RecordEvent ( +\ +this RecordedFilterNodeSetAttribute ( \ -this aIndex aValue \ @@ -882,9 +888,9 @@ mRecorder > RecordEvent ( +this RecordedFilterNodeSetAttribute ( -this aIndex aFloat aSize @@ -993,6 +999,14 @@ GetFormat ) ) ; +mRecorder +- +> +SetCurrentDrawTarget +( +this +) +; mFormat = mFinalDT @@ -1110,6 +1124,14 @@ snapshot ) ) ; +mRecorder +- +> +SetCurrentDrawTarget +( +this +) +; mFormat = mFinalDT @@ -1194,19 +1216,16 @@ mRecorder > RecordEvent ( +this RecordedDrawTargetDestruction ( -ReferencePtr -( -this -) ) ) ; mRecorder - > -ClearDrawTarget +ClearCurrentDrawTarget ( this ) @@ -2728,6 +2747,17 @@ if ( ! aNode +| +| +aNode +- +> +GetBackendType +( +) +! += +FILTER_BACKEND_RECORDING ) { return @@ -2750,9 +2780,16 @@ mRecorder RecordEvent ( this -RecordedDrawFilter +static_cast +< +FilterNodeRecording +* +> ( aNode +) +RecordedDrawFilter +( aSourceRect aDestPoint aOptions @@ -2775,7 +2812,7 @@ aType { RefPtr < -FilterNode +FilterNodeRecording > retNode = @@ -2798,6 +2835,14 @@ aType ) ) ; +mRecorder +- +> +SetCurrentFilterNode +( +retNode +) +; return retNode . @@ -3700,7 +3745,7 @@ const { RefPtr < -DrawTarget +DrawTargetRecording > similarDT ; @@ -3759,6 +3804,14 @@ aFormat ) ) ; +mRecorder +- +> +SetCurrentDrawTarget +( +similarDT +) +; } else if @@ -3841,11 +3894,9 @@ aFormat { RefPtr < -DrawTarget +DrawTargetRecording > similarDT -; -similarDT = new DrawTargetRecording @@ -3873,6 +3924,14 @@ aFormat ) ) ; +mRecorder +- +> +SetCurrentDrawTarget +( +similarDT +) +; similarDT - > @@ -3918,7 +3977,7 @@ aDestPoint { RefPtr < -DrawTarget +DrawTargetRecording > similarDT ; @@ -3974,6 +4033,14 @@ aDestPoint ) ) ; +mRecorder +- +> +SetCurrentDrawTarget +( +similarDT +) +; } else if @@ -4441,6 +4508,14 @@ nullptr mRecorder - > +SetCurrentDrawTarget +( +this +) +; +mRecorder +- +> RecordEvent ( this diff --git a/gfx/2d/InlineTranslator.h b/gfx/2d/InlineTranslator.h index 74055055a5a29..54b47f532d776 100644 --- a/gfx/2d/InlineTranslator.h +++ b/gfx/2d/InlineTranslator.h @@ -588,36 +588,26 @@ aScaledFontResouce void RemoveDrawTarget ( -ReferencePtr -aRefPtr ) override { -ReferencePtr -currentDT -= -mCurrentDT -; if ( -currentDT -= -= -aRefPtr +mCurrentDT ) { -mCurrentDT -= -nullptr -; -} mDrawTargets . Remove ( -aRefPtr +mCurrentDT ) ; +mCurrentDT += +nullptr +; +} } bool SetCurrentDrawTarget @@ -677,17 +667,48 @@ aRefPtr void RemoveFilterNode ( -ReferencePtr -aRefPtr ) final { +if +( +mCurrentFilter +) +{ mFilterNodes . Remove ( +mCurrentFilter +) +; +mCurrentFilter += +nullptr +; +} +} +bool +SetCurrentFilterNode +( +ReferencePtr aRefPtr ) +override +{ +mCurrentFilter += +mFilterNodes +. +GetWeak +( +aRefPtr +) +; +return +! +! +mCurrentFilter ; } void diff --git a/gfx/2d/RecordedEvent.cpp b/gfx/2d/RecordedEvent.cpp index d3947cc404106..f031524949c88 100644 --- a/gfx/2d/RecordedEvent.cpp +++ b/gfx/2d/RecordedEvent.cpp @@ -176,6 +176,14 @@ Destruction " ; case +SETCURRENTDRAWTARGET +: +return +" +SetCurrentDrawTarget +" +; +case FILLRECT : return @@ -376,6 +384,14 @@ FilterNodeDestruction " ; case +SETCURRENTFILTERNODE +: +return +" +SetCurrentFilterNode +" +; +case GRADIENTSTOPSCREATION : return diff --git a/gfx/2d/RecordedEvent.h b/gfx/2d/RecordedEvent.h index 33f24dcbad20f..2fec3f24237c2 100644 --- a/gfx/2d/RecordedEvent.h +++ b/gfx/2d/RecordedEvent.h @@ -500,8 +500,6 @@ virtual void RemoveDrawTarget ( -ReferencePtr -aRefPtr ) = 0 @@ -585,12 +583,14 @@ virtual void RemoveFilterNode ( -mozilla -: -: -gfx -: -: +) += +0 +; +virtual +bool +SetCurrentFilterNode +( ReferencePtr aRefPtr ) @@ -787,6 +787,17 @@ return mCurrentDT ; } +FilterNode +* +GetCurrentFilterNode +( +) +const +{ +return +mCurrentFilter +; +} nsRefPtrHashtable < nsUint64HashKey @@ -803,6 +814,12 @@ mCurrentDT = nullptr ; +FilterNode +* +mCurrentFilter += +nullptr +; } ; struct @@ -1752,6 +1769,7 @@ SCALEDFONTDESTRUCTION MASKSURFACE FILTERNODECREATION FILTERNODEDESTRUCTION +SETCURRENTFILTERNODE DRAWFILTER FILTERNODESETATTRIBUTE FILTERNODESETINPUT diff --git a/gfx/2d/RecordedEventImpl.h b/gfx/2d/RecordedEventImpl.h index c567617e1a1be..75f316626d3b3 100644 --- a/gfx/2d/RecordedEventImpl.h +++ b/gfx/2d/RecordedEventImpl.h @@ -240,28 +240,15 @@ RecordedDrawTargetDestruction { public : -MOZ_IMPLICIT +explicit RecordedDrawTargetDestruction ( -ReferencePtr -aRefPtr ) : RecordedEventDerived ( DRAWTARGETDESTRUCTION ) -mRefPtr -( -aRefPtr -) -mBackendType -( -BackendType -: -: -NONE -) { } bool @@ -321,9 +308,6 @@ Destruction ReferencePtr mRefPtr ; -BackendType -mBackendType -; private : friend @@ -356,7 +340,7 @@ RecordedSetCurrentDrawTarget { public : -MOZ_IMPLICIT +explicit RecordedSetCurrentDrawTarget ( ReferencePtr @@ -4222,8 +4206,6 @@ public : RecordedDrawFilter ( -ReferencePtr -aNode const Rect & @@ -4242,10 +4224,6 @@ RecordedEventDerived ( DRAWFILTER ) -mNode -( -aNode -) mSourceRect ( aSourceRect @@ -4332,9 +4310,6 @@ S aStream ) ; -ReferencePtr -mNode -; Rect mSourceRect ; @@ -5199,16 +5174,113 @@ RecordedFilterNodeDestruction { public : +explicit +RecordedFilterNodeDestruction +( +) +: +RecordedEventDerived +( +FILTERNODEDESTRUCTION +) +{ +} +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 +" +FilterNode +Destruction +" +; +} +private +: +friend +class +RecordedEvent +; +template +< +class +S +> MOZ_IMPLICIT RecordedFilterNodeDestruction ( +S +& +aStream +) +; +} +; +class +RecordedSetCurrentFilterNode +: +public +RecordedEventDerived +< +RecordedSetCurrentFilterNode +> +{ +public +: +explicit +RecordedSetCurrentFilterNode +( ReferencePtr aRefPtr ) : RecordedEventDerived ( -FILTERNODEDESTRUCTION +SETCURRENTFILTERNODE ) mRefPtr ( @@ -5265,27 +5337,26 @@ override { return " -FilterNode -Destruction +SetCurrentFilterNode " ; } +ReferencePtr +mRefPtr +; private : friend class RecordedEvent ; -ReferencePtr -mRefPtr -; template < class S > MOZ_IMPLICIT -RecordedFilterNodeDestruction +RecordedSetCurrentFilterNode ( S & @@ -7210,9 +7281,6 @@ T > RecordedFilterNodeSetAttribute ( -FilterNode -* -aNode uint32_t aIndex T @@ -7225,10 +7293,6 @@ RecordedEventDerived ( FILTERNODESETATTRIBUTE ) -mNode -( -aNode -) mIndex ( aIndex @@ -7267,9 +7331,6 @@ T } RecordedFilterNodeSetAttribute ( -FilterNode -* -aNode uint32_t aIndex const @@ -7284,10 +7345,6 @@ RecordedEventDerived ( FILTERNODESETATTRIBUTE ) -mNode -( -aNode -) mIndex ( aIndex @@ -7386,9 +7443,6 @@ friend class RecordedEvent ; -ReferencePtr -mNode -; uint32_t mIndex ; @@ -7432,9 +7486,6 @@ public : RecordedFilterNodeSetInput ( -FilterNode -* -aNode uint32_t aIndex FilterNode @@ -7446,10 +7497,6 @@ RecordedEventDerived ( FILTERNODESETINPUT ) -mNode -( -aNode -) mIndex ( aIndex @@ -7466,9 +7513,6 @@ nullptr } RecordedFilterNodeSetInput ( -FilterNode -* -aNode uint32_t aIndex SourceSurface @@ -7480,10 +7524,6 @@ RecordedEventDerived ( FILTERNODESETINPUT ) -mNode -( -aNode -) mIndex ( aIndex @@ -7557,9 +7597,6 @@ friend class RecordedEvent ; -ReferencePtr -mNode -; uint32_t mIndex ; @@ -9724,6 +9761,14 @@ dataRect ) ; } +aTranslator +- +> +SetCurrentDrawTarget +( +mRefPtr +) +; return true ; @@ -10157,7 +10202,6 @@ aTranslator > RemoveDrawTarget ( -mRefPtr ) ; return @@ -10181,12 +10225,6 @@ aStream ) const { -WriteElement -( -aStream -mRefPtr -) -; } template < @@ -10208,12 +10246,6 @@ RecordedEventDerived DRAWTARGETDESTRUCTION ) { -ReadElement -( -aStream -mRefPtr -) -; } inline void @@ -10424,6 +10456,14 @@ mRefPtr newDT ) ; +aTranslator +- +> +SetCurrentDrawTarget +( +mRefPtr +) +; return true ; @@ -10862,6 +10902,14 @@ mRefPtr newDT ) ; +aTranslator +- +> +SetCurrentDrawTarget +( +mRefPtr +) +; return true ; @@ -10934,6 +10982,14 @@ mRefPtr newDT ) ; +aTranslator +- +> +SetCurrentDrawTarget +( +mRefPtr +) +; return true ; @@ -15824,9 +15880,8 @@ filter aTranslator - > -LookupFilterNode +GetCurrentFilterNode ( -mNode ) ; if @@ -15874,12 +15929,6 @@ const WriteElement ( aStream -mNode -) -; -WriteElement -( -aStream mSourceRect ) ; @@ -15919,12 +15968,6 @@ DRAWFILTER ReadElement ( aStream -mNode -) -; -ReadElement -( -aStream mSourceRect ) ; @@ -15962,15 +16005,6 @@ aStringStream < " DrawFilter -( -" -< -< -mNode -< -< -" -) " ; } @@ -17887,6 +17921,14 @@ mRefPtr node ) ; +aTranslator +- +> +SetCurrentFilterNode +( +mRefPtr +) +; return true ; @@ -18029,7 +18071,6 @@ aTranslator > RemoveFilterNode ( -mRefPtr ) ; return @@ -18053,6 +18094,93 @@ aStream ) const { +} +template +< +class +S +> +RecordedFilterNodeDestruction +: +: +RecordedFilterNodeDestruction +( +S +& +aStream +) +: +RecordedEventDerived +( +FILTERNODEDESTRUCTION +) +{ +} +inline +void +RecordedFilterNodeDestruction +: +: +OutputSimpleEventInfo +( +std +: +: +stringstream +& +aStringStream +) +const +{ +aStringStream +< +< +" +FilterNode +Destroyed +" +; +} +inline +bool +RecordedSetCurrentFilterNode +: +: +PlayEvent +( +Translator +* +aTranslator +) +const +{ +return +aTranslator +- +> +SetCurrentFilterNode +( +mRefPtr +) +; +} +template +< +class +S +> +void +RecordedSetCurrentFilterNode +: +: +Record +( +S +& +aStream +) +const +{ WriteElement ( aStream @@ -18065,10 +18193,10 @@ template class S > -RecordedFilterNodeDestruction +RecordedSetCurrentFilterNode : : -RecordedFilterNodeDestruction +RecordedSetCurrentFilterNode ( S & @@ -18077,7 +18205,7 @@ aStream : RecordedEventDerived ( -FILTERNODEDESTRUCTION +SETCURRENTFILTERNODE ) { ReadElement @@ -18089,7 +18217,7 @@ mRefPtr } inline void -RecordedFilterNodeDestruction +RecordedSetCurrentFilterNode : : OutputSimpleEventInfo @@ -18116,8 +18244,7 @@ mRefPtr < " ] -FilterNode -Destroyed +SetCurrentFilterNode " ; } @@ -21231,9 +21358,8 @@ node aTranslator - > -LookupFilterNode +GetCurrentFilterNode ( -mNode ) ; if @@ -21425,12 +21551,6 @@ const WriteElement ( aStream -mNode -) -; -WriteElement -( -aStream mIndex ) ; @@ -21499,12 +21619,6 @@ FILTERNODESETATTRIBUTE ReadElement ( aStream -mNode -) -; -ReadElement -( -aStream mIndex ) ; @@ -21592,15 +21706,6 @@ aStringStream < < " -[ -" -< -< -mNode -< -< -" -] SetAttribute ( " @@ -21634,9 +21739,8 @@ node aTranslator - > -LookupFilterNode +GetCurrentFilterNode ( -mNode ) ; if @@ -21712,12 +21816,6 @@ const WriteElement ( aStream -mNode -) -; -WriteElement -( -aStream mIndex ) ; @@ -21757,12 +21855,6 @@ FILTERNODESETINPUT ReadElement ( aStream -mNode -) -; -ReadElement -( -aStream mIndex ) ; @@ -21799,15 +21891,6 @@ aStringStream < < " -[ -" -< -< -mNode -< -< -" -] SetAttribute ( " @@ -22524,6 +22607,13 @@ RecordedFilterNodeDestruction \ f ( +SETCURRENTFILTERNODE +RecordedSetCurrentFilterNode +) +; +\ +f +( GRADIENTSTOPSCREATION RecordedGradientStopsCreation ) diff --git a/gfx/layers/RecordedCanvasEventImpl.h b/gfx/layers/RecordedCanvasEventImpl.h index 0be076c3e5d07..bc617f7fe9958 100644 --- a/gfx/layers/RecordedCanvasEventImpl.h +++ b/gfx/layers/RecordedCanvasEventImpl.h @@ -2587,6 +2587,20 @@ mSize mFormat ) ; +if +( +newDT +) +{ +aTranslator +- +> +SetCurrentDrawTarget +( +mRefPtr +) +; +} return ! ! diff --git a/layout/printing/PrintTranslator.h b/layout/printing/PrintTranslator.h index c008ab17b4841..487c801038783 100644 --- a/layout/printing/PrintTranslator.h +++ b/layout/printing/PrintTranslator.h @@ -559,36 +559,26 @@ aScaledFontResouce void RemoveDrawTarget ( -ReferencePtr -aRefPtr ) final { -ReferencePtr -currentDT -= -mCurrentDT -; if ( -currentDT -= -= -aRefPtr +mCurrentDT ) { -mCurrentDT -= -nullptr -; -} mDrawTargets . Remove ( -aRefPtr +mCurrentDT ) ; +mCurrentDT += +nullptr +; +} } bool SetCurrentDrawTarget @@ -648,18 +638,49 @@ aRefPtr void RemoveFilterNode ( +) +final +{ +if +( +mCurrentFilter +) +{ +mFilterNodes +. +Remove +( +mCurrentFilter +) +; +mCurrentFilter += +nullptr +; +} +} +bool +SetCurrentFilterNode +( ReferencePtr aRefPtr ) final { +mCurrentFilter += mFilterNodes . -Remove +GetWeak ( aRefPtr ) ; +return +! +! +mCurrentFilter +; } void RemoveGradientStops