tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 32d5e28eaadb7959e00008ef31e35ba35330033f
parent d99f80eefef95212f825c381e13540754b97d860
Author: Lee Salzman <lsalzman@mozilla.com>
Date:   Thu,  2 Oct 2025 14:01:55 +0000

Bug 1991899 - Only use dash pattern storage when necessary. r=aosmond

Differential Revision: https://phabricator.services.mozilla.com/D267059

Diffstat:
Mgfx/2d/RecordedEvent.h | 18++++++++++++------
Mgfx/2d/RecordedEventImpl.h | 55+++++++++++++++++++++++++++++++++++--------------------
2 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/gfx/2d/RecordedEvent.h b/gfx/2d/RecordedEvent.h @@ -494,11 +494,6 @@ class RecordedEvent { template <class S> void ReadPatternData(S& aStream, PatternStorage& aPatternStorage) const; void StorePattern(PatternStorage& aDestination, const Pattern& aSource) const; - template <class S> - void RecordStrokeOptions(S& aStream, - const StrokeOptions& aStrokeOptions) const; - template <class S> - void ReadStrokeOptions(S& aStream, StrokeOptions& aStrokeOptions); virtual std::string GetName() const = 0; @@ -532,7 +527,18 @@ class RecordedEvent { MOZ_IMPLICIT RecordedEvent(EventType aType) : mType(aType) {} EventType mType; - std::vector<Float> mDashPatternStorage; +}; + +class RecordedStrokeOptionsMixin { + public: + template <class S> + void RecordStrokeOptions(S& aStream, + const StrokeOptions& aStrokeOptions) const; + template <class S> + void ReadStrokeOptions(S& aStream, StrokeOptions& aStrokeOptions); + + protected: + UniquePtr<Float[]> mDashPatternStorage; }; template <class Derived> diff --git a/gfx/2d/RecordedEventImpl.h b/gfx/2d/RecordedEventImpl.h @@ -248,7 +248,8 @@ class RecordedFillRect : public RecordedEventDerived<RecordedFillRect> { DrawOptions mOptions; }; -class RecordedStrokeRect : public RecordedEventDerived<RecordedStrokeRect> { +class RecordedStrokeRect : public RecordedEventDerived<RecordedStrokeRect>, + public RecordedStrokeOptionsMixin { public: RecordedStrokeRect(const Rect& aRect, const Pattern& aPattern, const StrokeOptions& aStrokeOptions, @@ -281,7 +282,8 @@ class RecordedStrokeRect : public RecordedEventDerived<RecordedStrokeRect> { DrawOptions mOptions; }; -class RecordedStrokeLine : public RecordedEventDerived<RecordedStrokeLine> { +class RecordedStrokeLine : public RecordedEventDerived<RecordedStrokeLine>, + public RecordedStrokeOptionsMixin { public: RecordedStrokeLine(const Point& aBegin, const Point& aEnd, const Pattern& aPattern, @@ -317,7 +319,8 @@ class RecordedStrokeLine : public RecordedEventDerived<RecordedStrokeLine> { DrawOptions mOptions; }; -class RecordedStrokeCircle : public RecordedEventDerived<RecordedStrokeCircle> { +class RecordedStrokeCircle : public RecordedEventDerived<RecordedStrokeCircle>, + public RecordedStrokeOptionsMixin { public: RecordedStrokeCircle(Circle aCircle, const Pattern& aPattern, const StrokeOptions& aStrokeOptions, @@ -474,7 +477,8 @@ class RecordedFillGlyphs : public RecordedDrawGlyphs<RecordedFillGlyphs> { } }; -class RecordedStrokeGlyphs : public RecordedDrawGlyphs<RecordedStrokeGlyphs> { +class RecordedStrokeGlyphs : public RecordedDrawGlyphs<RecordedStrokeGlyphs>, + public RecordedStrokeOptionsMixin { public: RecordedStrokeGlyphs(ReferencePtr aScaledFont, const Pattern& aPattern, const StrokeOptions& aStrokeOptions, @@ -538,7 +542,8 @@ class RecordedMask : public RecordedEventDerived<RecordedMask> { DrawOptions mOptions; }; -class RecordedStroke : public RecordedEventDerived<RecordedStroke> { +class RecordedStroke : public RecordedEventDerived<RecordedStroke>, + public RecordedStrokeOptionsMixin { public: RecordedStroke(ReferencePtr aPath, const Pattern& aPattern, const StrokeOptions& aStrokeOptions, @@ -969,7 +974,8 @@ class RecordedDrawSurfaceWithShadow CompositionOp mOp; }; -class RecordedDrawShadow : public RecordedEventDerived<RecordedDrawShadow> { +class RecordedDrawShadow : public RecordedEventDerived<RecordedDrawShadow>, + public RecordedStrokeOptionsMixin { public: RecordedDrawShadow(ReferencePtr aPath, const Pattern& aPattern, const ShadowOptions& aShadow, const DrawOptions& aOptions, @@ -1231,7 +1237,8 @@ class RecordedFilterNodeCreation }; class RecordedDeferFilterInput - : public RecordedEventDerived<RecordedDeferFilterInput> { + : public RecordedEventDerived<RecordedDeferFilterInput>, + public RecordedStrokeOptionsMixin { public: RecordedDeferFilterInput(ReferencePtr aRefPtr, ReferencePtr aPath, const Pattern& aPattern, const IntRect& aSourceRect, @@ -2043,7 +2050,7 @@ inline void RecordedEvent::StorePattern(PatternStorage& aDestination, } template <class S> -void RecordedEvent::RecordStrokeOptions( +void RecordedStrokeOptionsMixin::RecordStrokeOptions( S& aStream, const StrokeOptions& aStrokeOptions) const { JoinStyle joinStyle = aStrokeOptions.mLineJoin; CapStyle capStyle = aStrokeOptions.mLineCap; @@ -2064,34 +2071,42 @@ void RecordedEvent::RecordStrokeOptions( } template <class S> -void RecordedEvent::ReadStrokeOptions(S& aStream, - StrokeOptions& aStrokeOptions) { - uint64_t dashLength; +void RecordedStrokeOptionsMixin::ReadStrokeOptions( + S& aStream, StrokeOptions& aStrokeOptions) { + uint64_t dashLength64 = 0; JoinStyle joinStyle; CapStyle capStyle; - ReadElement(aStream, dashLength); + ReadElement(aStream, dashLength64); ReadElement(aStream, aStrokeOptions.mLineWidth); ReadElement(aStream, aStrokeOptions.mMiterLimit); ReadElementConstrained(aStream, joinStyle, JoinStyle::BEVEL, JoinStyle::MITER_OR_BEVEL); ReadElementConstrained(aStream, capStyle, CapStyle::BUTT, CapStyle::SQUARE); - // On 32 bit we truncate the value of dashLength. - // See also bug 811850 for history. - aStrokeOptions.mDashLength = size_t(dashLength); aStrokeOptions.mLineJoin = joinStyle; aStrokeOptions.mLineCap = capStyle; - if (!aStrokeOptions.mDashLength || !aStream.good()) { + // On 32 bit we truncate the value of dashLength. + // See also bug 811850 for history. + size_t dashLength = size_t(dashLength64); + if (!dashLength || !aStream.good()) { return; } ReadElement(aStream, aStrokeOptions.mDashOffset); - mDashPatternStorage.resize(aStrokeOptions.mDashLength); - aStrokeOptions.mDashPattern = &mDashPatternStorage.front(); - aStream.read((char*)aStrokeOptions.mDashPattern, - sizeof(Float) * aStrokeOptions.mDashLength); + mDashPatternStorage = MakeUniqueFallible<Float[]>(dashLength); + if (!mDashPatternStorage) { + aStream.SetIsBad(); + return; + } + aStream.read((char*)mDashPatternStorage.get(), sizeof(Float) * dashLength); + if (!aStream.good()) { + aStream.SetIsBad(); + return; + } + aStrokeOptions.mDashLength = dashLength; + aStrokeOptions.mDashPattern = mDashPatternStorage.get(); } template <class S>