From 88d1a64077752b4bc6dab4ab13822ffe33210848 Mon Sep 17 00:00:00 2001 From: Daniel Holbert Date: Wed, 15 May 2024 07:29:20 +0000 Subject: [PATCH] Bug 1896711 part 2: Use MakeRefPtr to reduce boilerplate, in layout/svg. r=TYLin Also remove one unnecessary null-check for an object that we're allocating infallibly. Differential Revision: https://phabricator.services.mozilla.com/D210388 --- layout/svg/SVGMarkerFrame.cpp | 2 +- layout/svg/SVGObserverUtils.cpp | 3 +-- layout/svg/SVGPatternFrame.cpp | 8 ++------ layout/svg/SVGTextFrame.cpp | 2 +- layout/svg/SVGUtils.cpp | 2 +- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/layout/svg/SVGMarkerFrame.cpp b/layout/svg/SVGMarkerFrame.cpp index 4a8733369b34..a133a452063d 100644 --- a/layout/svg/SVGMarkerFrame.cpp +++ b/layout/svg/SVGMarkerFrame.cpp @@ -134,7 +134,7 @@ void SVGMarkerFrame::PaintMark(gfxContext& aContext, ISVGDisplayableFrame* SVGFrame = do_QueryFrame(kid); // The CTM of each frame referencing us may be different. SVGFrame->NotifySVGChanged(ISVGDisplayableFrame::TRANSFORM_CHANGED); - RefPtr contextPaint = new SVGContextPaintImpl(); + auto contextPaint = MakeRefPtr(); contextPaint->Init(aContext.GetDrawTarget(), aContext.CurrentMatrixDouble(), aMarkedFrame, SVGContextPaint::GetContextPaint(marker), aImgParams); diff --git a/layout/svg/SVGObserverUtils.cpp b/layout/svg/SVGObserverUtils.cpp index 9d35849f4d07..16191463c8d1 100644 --- a/layout/svg/SVGObserverUtils.cpp +++ b/layout/svg/SVGObserverUtils.cpp @@ -1676,8 +1676,7 @@ Element* SVGObserverUtils::GetAndObserveBackgroundImage(nsIFrame* aFrame, aFrame->GetContent() ->OwnerDoc() ->ReferrerInfoForInternalCSSAndSVGResources(); - RefPtr url = - new URLAndReferrerInfo(targetURI, referrerInfo); + auto url = MakeRefPtr(targetURI, referrerInfo); return static_cast( hashtable diff --git a/layout/svg/SVGPatternFrame.cpp b/layout/svg/SVGPatternFrame.cpp index 7d1e99cedc75..da7d0ce592fd 100644 --- a/layout/svg/SVGPatternFrame.cpp +++ b/layout/svg/SVGPatternFrame.cpp @@ -688,13 +688,9 @@ already_AddRefed SVGPatternFrame::GetPaintServerPattern( return nullptr; } - RefPtr pattern = new gfxPattern(surface, pMatrix); - - if (!pattern) { - return nullptr; - } - + auto pattern = MakeRefPtr(surface, pMatrix); pattern->SetExtend(ExtendMode::REPEAT); + return pattern.forget(); } diff --git a/layout/svg/SVGTextFrame.cpp b/layout/svg/SVGTextFrame.cpp index d53637af0ab9..3690b80b4424 100644 --- a/layout/svg/SVGTextFrame.cpp +++ b/layout/svg/SVGTextFrame.cpp @@ -3142,7 +3142,7 @@ void SVGTextFrame::PaintSVG(gfxContext& aContext, const gfxMatrix& aTransform, while (run.mFrame) { nsTextFrame* frame = run.mFrame; - RefPtr contextPaint = new SVGContextPaintImpl(); + auto contextPaint = MakeRefPtr(); DrawMode drawMode = contextPaint->Init(&aDrawTarget, initialMatrix, frame, outerContextPaint, aImgParams); if (drawMode & DrawMode::GLYPH_STROKE) { diff --git a/layout/svg/SVGUtils.cpp b/layout/svg/SVGUtils.cpp index 2967bac78010..fef0a0c9b729 100644 --- a/layout/svg/SVGUtils.cpp +++ b/layout/svg/SVGUtils.cpp @@ -513,7 +513,7 @@ class MixModeBlender { gfxContextAutoSaveRestore save(mSourceCtx); mSourceCtx->SetMatrix(Matrix()); // This will be restored right after. - RefPtr pattern = new gfxPattern( + auto pattern = MakeRefPtr( targetSurf, Matrix::Translation(mTargetOffset.x, mTargetOffset.y)); mSourceCtx->SetPattern(pattern); mSourceCtx->Paint();