From 1bbf59e57c817f2cb78fea588d7272545d34b6e1 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Fri, 6 Sep 2024 15:20:15 +0000 Subject: [PATCH] Bug 1917156 - Implement RemoveAllClips for DrawTargetRecording. r=aosmond CanvasRenderingContext2D depends on RemoveAllClips for efficient resetting, but DrawTargetRecording did not implement this, causing fast resets to fail. Differential Revision: https://phabricator.services.mozilla.com/D221285 --- gfx/2d/DrawTargetRecording.cpp | 5 ++++ gfx/2d/DrawTargetRecording.h | 3 +++ gfx/2d/RecordedEvent.cpp | 2 ++ gfx/2d/RecordedEvent.h | 1 + gfx/2d/RecordedEventImpl.h | 44 ++++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+) diff --git a/gfx/2d/DrawTargetRecording.cpp b/gfx/2d/DrawTargetRecording.cpp index 141c454b661d..094a724e02f6 100644 --- a/gfx/2d/DrawTargetRecording.cpp +++ b/gfx/2d/DrawTargetRecording.cpp @@ -640,6 +640,11 @@ void DrawTargetRecording::PopClip() { RecordEventSelfSkipFlushTransform(RecordedPopClip()); } +bool DrawTargetRecording::RemoveAllClips() { + RecordEventSelfSkipFlushTransform(RecordedRemoveAllClips()); + return true; +} + void DrawTargetRecording::PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask, const Matrix& aMaskTransform, diff --git a/gfx/2d/DrawTargetRecording.h b/gfx/2d/DrawTargetRecording.h index 88673e062a06..48291d2bf329 100644 --- a/gfx/2d/DrawTargetRecording.h +++ b/gfx/2d/DrawTargetRecording.h @@ -223,6 +223,9 @@ class DrawTargetRecording final : public DrawTarget { */ virtual void PopClip() override; + /* Remove all applied clips. */ + virtual bool RemoveAllClips() override; + /** * Push a 'layer' to the DrawTarget, a layer is a temporary surface that all * drawing will be redirected to, this is used for example to support group diff --git a/gfx/2d/RecordedEvent.cpp b/gfx/2d/RecordedEvent.cpp index c89bd99d4c2b..33fa355ce266 100644 --- a/gfx/2d/RecordedEvent.cpp +++ b/gfx/2d/RecordedEvent.cpp @@ -58,6 +58,8 @@ std::string RecordedEvent::GetEventName(EventType aType) { return "PushClipRect"; case POPCLIP: return "PopClip"; + case REMOVEALLCLIPS: + return "RemoveAllClips"; case FILL: return "Fill"; case FILLGLYPHS: diff --git a/gfx/2d/RecordedEvent.h b/gfx/2d/RecordedEvent.h index 835460ff2501..34d21a6a5787 100644 --- a/gfx/2d/RecordedEvent.h +++ b/gfx/2d/RecordedEvent.h @@ -388,6 +388,7 @@ class RecordedEvent { PUSHCLIP, PUSHCLIPRECT, POPCLIP, + REMOVEALLCLIPS, FILL, FILLCIRCLE, FILLGLYPHS, diff --git a/gfx/2d/RecordedEventImpl.h b/gfx/2d/RecordedEventImpl.h index 2fe5705e1381..731c0fbee251 100644 --- a/gfx/2d/RecordedEventImpl.h +++ b/gfx/2d/RecordedEventImpl.h @@ -681,6 +681,27 @@ class RecordedPopClip : public RecordedEventDerived { MOZ_IMPLICIT RecordedPopClip(S& aStream); }; +class RecordedRemoveAllClips + : public RecordedEventDerived { + public: + MOZ_IMPLICIT RecordedRemoveAllClips() + : RecordedEventDerived(REMOVEALLCLIPS) {} + + bool PlayEvent(Translator* aTranslator) const override; + + template + void Record(S& aStream) const; + void OutputSimpleEventInfo(std::stringstream& aStringStream) const override; + + std::string GetName() const override { return "RemoveAllClips"; } + + private: + friend class RecordedEvent; + + template + MOZ_IMPLICIT RecordedRemoveAllClips(S& aStream); +}; + class RecordedPushLayer : public RecordedEventDerived { public: RecordedPushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask, @@ -2973,6 +2994,28 @@ inline void RecordedPopClip::OutputSimpleEventInfo( aStringStream << "PopClip"; } +inline bool RecordedRemoveAllClips::PlayEvent(Translator* aTranslator) const { + DrawTarget* dt = aTranslator->GetCurrentDrawTarget(); + if (!dt) { + return false; + } + + dt->RemoveAllClips(); + return true; +} + +template +void RecordedRemoveAllClips::Record(S& aStream) const {} + +template +RecordedRemoveAllClips::RecordedRemoveAllClips(S& aStream) + : RecordedEventDerived(REMOVEALLCLIPS) {} + +inline void RecordedRemoveAllClips::OutputSimpleEventInfo( + std::stringstream& aStringStream) const { + aStringStream << "RemoveAllClips"; +} + inline bool RecordedPushLayer::PlayEvent(Translator* aTranslator) const { DrawTarget* dt = aTranslator->GetCurrentDrawTarget(); if (!dt) { @@ -4474,6 +4517,7 @@ inline void RecordedDestination::OutputSimpleEventInfo( f(PUSHCLIPRECT, RecordedPushClipRect); \ f(PUSHCLIP, RecordedPushClip); \ f(POPCLIP, RecordedPopClip); \ + f(REMOVEALLCLIPS, RecordedRemoveAllClips); \ f(FILL, RecordedFill); \ f(FILLCIRCLE, RecordedFillCircle); \ f(FILLGLYPHS, RecordedFillGlyphs); \