diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 627094d0a830..1794875c7786 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -3857,14 +3857,14 @@ struct MOZ_STACK_CLASS CanvasBidiProcessor final return; } - RefPtr thebes = + UniquePtr thebes = gfxContext::CreatePreservingTransformOrNull(target); if (!thebes) { // If CreatePreservingTransformOrNull returns null, it will also have // issued a gfxCriticalNote already, so here we'll just bail out. return; } - gfxTextRun::DrawParams params(thebes); + gfxTextRun::DrawParams params(thebes.get()); params.allowGDI = false; @@ -5027,7 +5027,7 @@ void CanvasRenderingContext2D::DrawDirectlyToCanvas( // the matrix even though this is a temp gfxContext. AutoRestoreTransform autoRestoreTransform(mTarget); - RefPtr context = gfxContext::CreateOrNull(tempTarget); + UniquePtr context = gfxContext::CreateOrNull(tempTarget); if (!context) { gfxDevCrash(LogReason::InvalidContext) << "Canvas context problem"; return; @@ -5047,7 +5047,7 @@ void CanvasRenderingContext2D::DrawDirectlyToCanvas( SVGImageContext svgContext(Some(sz)); auto result = aImage.mImgContainer->Draw( - context, scaledImageSize, + context.get(), scaledImageSize, ImageRegion::Create(gfxRect(aSrc.x, aSrc.y, aSrc.width, aSrc.height)), aImage.mWhichFrame, SamplingFilter::GOOD, svgContext, modifiedFlags, CurrentState().globalAlpha); @@ -5225,7 +5225,7 @@ void CanvasRenderingContext2D::DrawWindow(nsGlobalWindowInner& aWindow, return; } - RefPtr thebes; + UniquePtr thebes; RefPtr drawDT; // Rendering directly is faster and can be done if mTarget supports Azure // and does not need alpha blending. @@ -5275,7 +5275,7 @@ void CanvasRenderingContext2D::DrawWindow(nsGlobalWindowInner& aWindow, RefPtr presShell = presContext->PresShell(); Unused << presShell->RenderDocument(r, renderDocFlags, backgroundColor, - thebes); + thebes.get()); // If this canvas was contained in the drawn window, the pre-transaction // callback may have returned its DT. If so, we must reacquire it here. EnsureTarget(discardContent ? &drawRect : nullptr); diff --git a/gfx/ipc/CrossProcessPaint.cpp b/gfx/ipc/CrossProcessPaint.cpp index 3c4e0967de65..5b05ce2065ce 100644 --- a/gfx/ipc/CrossProcessPaint.cpp +++ b/gfx/ipc/CrossProcessPaint.cpp @@ -140,12 +140,12 @@ PaintFragment PaintFragment::Record(dom::BrowsingContext* aBc, dt->AddUserData(&sDisablePixelSnapping, (void*)0x1, nullptr); } - RefPtr thebes = gfxContext::CreateOrNull(dt); + UniquePtr thebes = gfxContext::CreateOrNull(dt); thebes->SetMatrix(Matrix::Scaling(aScale, aScale)); thebes->SetCrossProcessPaintScale(aScale); RefPtr presShell = presContext->PresShell(); Unused << presShell->RenderDocument(r, renderDocFlags, aBackgroundColor, - thebes); + thebes.get()); } if (!recorder->mOutputStream.mValid) { diff --git a/gfx/layers/wr/WebRenderCommandBuilder.cpp b/gfx/layers/wr/WebRenderCommandBuilder.cpp index 1035858e3c12..74ecceefc755 100644 --- a/gfx/layers/wr/WebRenderCommandBuilder.cpp +++ b/gfx/layers/wr/WebRenderCommandBuilder.cpp @@ -657,7 +657,7 @@ struct DIGroup { RefPtr dt = gfx::Factory::CreateRecordingDrawTarget( recorder, dummyDt, mLayerBounds.ToUnknownRect()); // Setup the gfxContext - RefPtr context = gfxContext::CreateOrNull(dt); + UniquePtr context = gfxContext::CreateOrNull(dt); context->SetMatrix(Matrix::Scaling(mScale).PostTranslate( mResidualOffset.x, mResidualOffset.y)); @@ -673,7 +673,7 @@ struct DIGroup { return; } - PaintItemRange(aGrouper, aStartItem, aEndItem, context, recorder, + PaintItemRange(aGrouper, aStartItem, aEndItem, context.get(), recorder, rootManager, aResources); // XXX: set this correctly perhaps using @@ -2295,7 +2295,7 @@ static void PaintItemByDrawTarget(nsDisplayItem* aItem, gfx::DrawTarget* aDT, // XXX Why is this ClearRect() needed? aDT->ClearRect(Rect(visibleRect)); - RefPtr context = gfxContext::CreateOrNull(aDT); + UniquePtr context = gfxContext::CreateOrNull(aDT); MOZ_ASSERT(context); switch (aItem->GetType()) { @@ -2315,7 +2315,7 @@ static void PaintItemByDrawTarget(nsDisplayItem* aItem, gfx::DrawTarget* aDT, if (aDisplayListBuilder->IsPaintingToWindow()) { aItem->Frame()->AddStateBits(NS_FRAME_PAINTED_THEBES); } - aItem->AsPaintedDisplayItem()->Paint(aDisplayListBuilder, context); + aItem->AsPaintedDisplayItem()->Paint(aDisplayListBuilder, context.get()); break; } @@ -2782,7 +2782,7 @@ Maybe WebRenderCommandBuilder::BuildWrMaskImage( RefPtr dt = Factory::CreateRecordingDrawTarget( recorder, dummyDt, IntRect(IntPoint(0, 0), size)); - RefPtr context = gfxContext::CreateOrNull(dt); + UniquePtr context = gfxContext::CreateOrNull(dt); MOZ_ASSERT(context); context->SetMatrix(context->CurrentMatrix() @@ -2791,7 +2791,7 @@ Maybe WebRenderCommandBuilder::BuildWrMaskImage( bool maskPainted = false; bool maskIsComplete = aMaskItem->PaintMask( - aDisplayListBuilder, context, shouldHandleOpacity, &maskPainted); + aDisplayListBuilder, context.get(), shouldHandleOpacity, &maskPainted); if (!maskPainted) { return Nothing(); } diff --git a/gfx/layers/wr/WebRenderLayerManager.h b/gfx/layers/wr/WebRenderLayerManager.h index ec3bd3e869ab..a002224d43b4 100644 --- a/gfx/layers/wr/WebRenderLayerManager.h +++ b/gfx/layers/wr/WebRenderLayerManager.h @@ -254,7 +254,7 @@ class WebRenderLayerManager final : public WindowRenderer { // we send a message to our remote side to capture the actual pixels // being drawn to the default target, and then copy those pixels // back to mTarget. - RefPtr mTarget; + gfxContext* mTarget; // See equivalent field in ClientLayerManager uint32_t mPaintSequenceNumber; diff --git a/gfx/src/nsDeviceContext.cpp b/gfx/src/nsDeviceContext.cpp index b7490cbaf9aa..e7f970dca6b4 100644 --- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -116,16 +116,15 @@ void nsDeviceContext::Init(nsIWidget* aWidget) { } // XXX This is only for printing. We should make that obvious in the name. -already_AddRefed nsDeviceContext::CreateRenderingContext() { +UniquePtr nsDeviceContext::CreateRenderingContext() { return CreateRenderingContextCommon(/* not a reference context */ false); } -already_AddRefed -nsDeviceContext::CreateReferenceRenderingContext() { +UniquePtr nsDeviceContext::CreateReferenceRenderingContext() { return CreateRenderingContextCommon(/* a reference context */ true); } -already_AddRefed nsDeviceContext::CreateRenderingContextCommon( +UniquePtr nsDeviceContext::CreateRenderingContextCommon( bool aWantReferenceContext) { MOZ_ASSERT(IsPrinterContext()); MOZ_ASSERT(mWidth > 0 && mHeight > 0); @@ -154,14 +153,14 @@ already_AddRefed nsDeviceContext::CreateRenderingContextCommon( dt->AddUserData(&sDisablePixelSnapping, (void*)0x1, nullptr); - RefPtr pContext = gfxContext::CreateOrNull(dt); + UniquePtr pContext = gfxContext::CreateOrNull(dt); MOZ_ASSERT(pContext); // already checked draw target above gfxMatrix transform; transform.PreTranslate(mPrintingTranslate); transform.PreScale(mPrintingScale, mPrintingScale); pContext->SetMatrixDouble(transform); - return pContext.forget(); + return pContext; } uint32_t nsDeviceContext::GetDepth() { diff --git a/gfx/src/nsDeviceContext.h b/gfx/src/nsDeviceContext.h index d20005f99f6b..8ebb240650b7 100644 --- a/gfx/src/nsDeviceContext.h +++ b/gfx/src/nsDeviceContext.h @@ -73,7 +73,7 @@ class nsDeviceContext final { * * @return the new rendering context (guaranteed to be non-null) */ - already_AddRefed CreateRenderingContext(); + mozilla::UniquePtr CreateRenderingContext(); /** * Create a reference rendering context and initialize it. Only call this @@ -81,7 +81,7 @@ class nsDeviceContext final { * * @return the new rendering context. */ - already_AddRefed CreateReferenceRenderingContext(); + mozilla::UniquePtr CreateReferenceRenderingContext(); /** * Gets the number of app units in one device pixel; this number @@ -270,7 +270,7 @@ class nsDeviceContext final { * Implementation shared by CreateRenderingContext and * CreateReferenceRenderingContext. */ - already_AddRefed CreateRenderingContextCommon( + mozilla::UniquePtr CreateRenderingContextCommon( bool aWantReferenceContext); void SetDPI(); diff --git a/gfx/thebes/gfxBlur.cpp b/gfx/thebes/gfxBlur.cpp index c0e3dab079ed..4068e9f63509 100644 --- a/gfx/thebes/gfxBlur.cpp +++ b/gfx/thebes/gfxBlur.cpp @@ -23,13 +23,13 @@ using namespace mozilla::gfx; gfxAlphaBoxBlur::~gfxAlphaBoxBlur() = default; -already_AddRefed gfxAlphaBoxBlur::Init(gfxContext* aDestinationCtx, - const gfxRect& aRect, - const IntSize& aSpreadRadius, - const IntSize& aBlurRadius, - const gfxRect* aDirtyRect, - const gfxRect* aSkipRect, - bool aUseHardwareAccel) { +UniquePtr gfxAlphaBoxBlur::Init(gfxContext* aDestinationCtx, + const gfxRect& aRect, + const IntSize& aSpreadRadius, + const IntSize& aBlurRadius, + const gfxRect* aDirtyRect, + const gfxRect* aSkipRect, + bool aUseHardwareAccel) { DrawTarget* refDT = aDestinationCtx->GetDrawTarget(); Maybe dirtyRect = aDirtyRect ? Some(ToRect(*aDirtyRect)) : Nothing(); Maybe skipRect = aSkipRect ? Some(ToRect(*aSkipRect)) : Nothing(); @@ -40,10 +40,10 @@ already_AddRefed gfxAlphaBoxBlur::Init(gfxContext* aDestinationCtx, return nullptr; } - RefPtr context = gfxContext::CreateOrNull(dt); + UniquePtr context = gfxContext::CreateOrNull(dt); MOZ_ASSERT(context); // already checked for target above context->SetMatrix(Matrix::Translation(-mBlur.GetRect().TopLeft())); - return context.forget(); + return context; } already_AddRefed gfxAlphaBoxBlur::InitDrawTarget( diff --git a/gfx/thebes/gfxBlur.h b/gfx/thebes/gfxBlur.h index bd89883f1820..da6ccae9a701 100644 --- a/gfx/thebes/gfxBlur.h +++ b/gfx/thebes/gfxBlur.h @@ -77,13 +77,11 @@ class gfxAlphaBoxBlur final { * @param aUseHardwareAccel Flag to state whether or not we can use hardware * acceleration to speed up this blur. */ - already_AddRefed Init(gfxContext* aDestinationCtx, - const gfxRect& aRect, - const mozilla::gfx::IntSize& aSpreadRadius, - const mozilla::gfx::IntSize& aBlurRadius, - const gfxRect* aDirtyRect, - const gfxRect* aSkipRect, - bool aUseHardwareAccel = true); + mozilla::UniquePtr Init( + gfxContext* aDestinationCtx, const gfxRect& aRect, + const mozilla::gfx::IntSize& aSpreadRadius, + const mozilla::gfx::IntSize& aBlurRadius, const gfxRect* aDirtyRect, + const gfxRect* aSkipRect, bool aUseHardwareAccel = true); already_AddRefed InitDrawTarget( const mozilla::gfx::DrawTarget* aReferenceDT, diff --git a/gfx/thebes/gfxContext.cpp b/gfx/thebes/gfxContext.cpp index f9f8a6dee108..5b678954f870 100644 --- a/gfx/thebes/gfxContext.cpp +++ b/gfx/thebes/gfxContext.cpp @@ -62,7 +62,7 @@ gfxContext::gfxContext(DrawTarget* aTarget, const Point& aDeviceOffset) } /* static */ -already_AddRefed gfxContext::CreateOrNull( +UniquePtr gfxContext::CreateOrNull( DrawTarget* aTarget, const mozilla::gfx::Point& aDeviceOffset) { if (!aTarget || !aTarget->IsValid()) { gfxCriticalNote << "Invalid target in gfxContext::CreateOrNull " @@ -70,12 +70,11 @@ already_AddRefed gfxContext::CreateOrNull( return nullptr; } - RefPtr result = new gfxContext(aTarget, aDeviceOffset); - return result.forget(); + return MakeUnique(aTarget, aDeviceOffset); } /* static */ -already_AddRefed gfxContext::CreatePreservingTransformOrNull( +UniquePtr gfxContext::CreatePreservingTransformOrNull( DrawTarget* aTarget) { if (!aTarget || !aTarget->IsValid()) { gfxCriticalNote @@ -84,10 +83,11 @@ already_AddRefed gfxContext::CreatePreservingTransformOrNull( return nullptr; } - Matrix transform = aTarget->GetTransform(); - RefPtr result = new gfxContext(aTarget); + auto transform = aTarget->GetTransform(); + auto result = MakeUnique(aTarget); result->SetMatrix(transform); - return result.forget(); + + return result; } gfxContext::~gfxContext() { diff --git a/gfx/thebes/gfxContext.h b/gfx/thebes/gfxContext.h index 8cc2fa5fdd4a..16999372f28c 100644 --- a/gfx/thebes/gfxContext.h +++ b/gfx/thebes/gfxContext.h @@ -57,9 +57,20 @@ class gfxContext final { typedef mozilla::gfx::RectCornerRadii RectCornerRadii; typedef mozilla::gfx::Size Size; - NS_INLINE_DECL_REFCOUNTING(gfxContext) - public: + /** + * Initialize this context from a DrawTarget. + * Strips any transform from aTarget. + * aTarget will be flushed in the gfxContext's destructor. Use the static + * ContextForDrawTargetNoTransform() when you want this behavior, as that + * version deals with null DrawTarget better. + */ + explicit gfxContext( + mozilla::gfx::DrawTarget* aTarget, + const mozilla::gfx::Point& aDeviceOffset = mozilla::gfx::Point()); + + ~gfxContext(); + /** * Initialize this context from a DrawTarget. * Strips any transform from aTarget. @@ -67,7 +78,7 @@ class gfxContext final { * If aTarget is null or invalid, nullptr is returned. The caller * is responsible for handling this scenario as appropriate. */ - static already_AddRefed CreateOrNull( + static mozilla::UniquePtr CreateOrNull( mozilla::gfx::DrawTarget* aTarget, const mozilla::gfx::Point& aDeviceOffset = mozilla::gfx::Point()); @@ -78,7 +89,7 @@ class gfxContext final { * If aTarget is null or invalid, nullptr is returned. The caller * is responsible for handling this scenario as appropriate. */ - static already_AddRefed CreatePreservingTransformOrNull( + static mozilla::UniquePtr CreatePreservingTransformOrNull( mozilla::gfx::DrawTarget* aTarget); mozilla::gfx::DrawTarget* GetDrawTarget() { return mDT; } @@ -438,18 +449,6 @@ class gfxContext final { #endif private: - /** - * Initialize this context from a DrawTarget. - * Strips any transform from aTarget. - * aTarget will be flushed in the gfxContext's destructor. Use the static - * ContextForDrawTargetNoTransform() when you want this behavior, as that - * version deals with null DrawTarget better. - */ - explicit gfxContext( - mozilla::gfx::DrawTarget* aTarget, - const mozilla::gfx::Point& aDeviceOffset = mozilla::gfx::Point()); - ~gfxContext(); - friend class PatternFromState; friend class GlyphBufferAzure; @@ -543,7 +542,7 @@ class gfxContextAutoSaveRestore { ~gfxContextAutoSaveRestore() { Restore(); } void SetContext(gfxContext* aContext) { - NS_ASSERTION(!mContext, "Not going to call Restore() on some context!!!"); + MOZ_ASSERT(!mContext, "no context?"); mContext = aContext; mContext->Save(); } diff --git a/gfx/thebes/gfxDrawable.cpp b/gfx/thebes/gfxDrawable.cpp index 7b26f2de9c7f..7f5fa1ad2c7f 100644 --- a/gfx/thebes/gfxDrawable.cpp +++ b/gfx/thebes/gfxDrawable.cpp @@ -105,9 +105,9 @@ already_AddRefed gfxCallbackDrawable::MakeSurfaceDrawable( if (!dt || !dt->IsValid()) return nullptr; - RefPtr ctx = gfxContext::CreateOrNull(dt); + UniquePtr ctx = gfxContext::CreateOrNull(dt); MOZ_ASSERT(ctx); // already checked for target above - Draw(ctx, gfxRect(0, 0, mSize.width, mSize.height), ExtendMode::CLAMP, + Draw(ctx.get(), gfxRect(0, 0, mSize.width, mSize.height), ExtendMode::CLAMP, aSamplingFilter); RefPtr surface = dt->Snapshot(); diff --git a/gfx/thebes/gfxUtils.cpp b/gfx/thebes/gfxUtils.cpp index 921bb0407eb6..dc8884f94afd 100644 --- a/gfx/thebes/gfxUtils.cpp +++ b/gfx/thebes/gfxUtils.cpp @@ -321,13 +321,13 @@ static already_AddRefed CreateSamplingRestrictedDrawable( return nullptr; } - RefPtr tmpCtx = gfxContext::CreateOrNull(target); + UniquePtr tmpCtx = gfxContext::CreateOrNull(target); MOZ_ASSERT(tmpCtx); // already checked the target above if (aUseOptimalFillOp) { tmpCtx->SetOp(OptimalFillOp()); } - aDrawable->Draw(tmpCtx, needed - needed.TopLeft(), ExtendMode::REPEAT, + aDrawable->Draw(tmpCtx.get(), needed - needed.TopLeft(), ExtendMode::REPEAT, SamplingFilter::LINEAR, 1.0, gfxMatrix::Translation(needed.TopLeft())); RefPtr surface = target->Snapshot(); @@ -474,7 +474,7 @@ static bool PrescaleAndTileDrawable(gfxDrawable* aDrawable, return false; } - RefPtr tmpCtx = gfxContext::CreateOrNull(scaledDT); + UniquePtr tmpCtx = gfxContext::CreateOrNull(scaledDT); MOZ_ASSERT(tmpCtx); // already checked the target above scaledDT->SetTransform(scaleMatrix); @@ -482,8 +482,8 @@ static bool PrescaleAndTileDrawable(gfxDrawable* aDrawable, aImageRect.height); // Since this is just the scaled image, we don't want to repeat anything yet. - aDrawable->Draw(tmpCtx, gfxImageRect, ExtendMode::CLAMP, aSamplingFilter, 1.0, - gfxMatrix()); + aDrawable->Draw(tmpCtx.get(), gfxImageRect, ExtendMode::CLAMP, + aSamplingFilter, 1.0, gfxMatrix()); RefPtr scaledImage = scaledDT->Snapshot(); diff --git a/gfx/thebes/gfxWindowsNativeDrawing.h b/gfx/thebes/gfxWindowsNativeDrawing.h index bbb2af66a9af..87323966d91b 100644 --- a/gfx/thebes/gfxWindowsNativeDrawing.h +++ b/gfx/thebes/gfxWindowsNativeDrawing.h @@ -11,7 +11,7 @@ #include "gfxContext.h" #include "gfxWindowsSurface.h" -class gfxWindowsNativeDrawing { +class MOZ_STACK_CLASS gfxWindowsNativeDrawing { public: /* Flags for notifying this class what kind of operations the native * drawing supports @@ -79,7 +79,7 @@ class gfxWindowsNativeDrawing { void PaintToContext(); private: - RefPtr mContext; + gfxContext* mContext; gfxRect mNativeRect; uint32_t mNativeDrawFlags; diff --git a/gfx/webrender_bindings/WebRenderAPI.cpp b/gfx/webrender_bindings/WebRenderAPI.cpp index 4486c8a66c7d..f12cf89af895 100644 --- a/gfx/webrender_bindings/WebRenderAPI.cpp +++ b/gfx/webrender_bindings/WebRenderAPI.cpp @@ -1643,7 +1643,7 @@ DisplayListBuilder::FixedPosScrollTargetTracker::GetSideBitsForASR( return aAsr == mAsr ? Some(mSideBits) : Nothing(); } -already_AddRefed DisplayListBuilder::GetTextContext( +gfxContext* DisplayListBuilder::GetTextContext( wr::IpcResourceUpdateQueue& aResources, const layers::StackingContextHelper& aSc, layers::RenderRootStateManager* aManager, nsDisplayItem* aItem, @@ -1658,8 +1658,7 @@ already_AddRefed DisplayListBuilder::GetTextContext( mCachedContext->SetMatrix(gfx::Matrix()); } - RefPtr tmp = mCachedContext; - return tmp.forget(); + return mCachedContext.get(); } void DisplayListBuilder::PushInheritedClipChain( diff --git a/gfx/webrender_bindings/WebRenderAPI.h b/gfx/webrender_bindings/WebRenderAPI.h index 9d4d9c731a0c..cac01c59cbd7 100644 --- a/gfx/webrender_bindings/WebRenderAPI.h +++ b/gfx/webrender_bindings/WebRenderAPI.h @@ -684,11 +684,11 @@ class DisplayListBuilder final { Maybe GetContainingFixedPosSideBits(const ActiveScrolledRoot* aAsr); - already_AddRefed GetTextContext( - wr::IpcResourceUpdateQueue& aResources, - const layers::StackingContextHelper& aSc, - layers::RenderRootStateManager* aManager, nsDisplayItem* aItem, - nsRect& aBounds, const gfx::Point& aDeviceOffset); + gfxContext* GetTextContext(wr::IpcResourceUpdateQueue& aResources, + const layers::StackingContextHelper& aSc, + layers::RenderRootStateManager* aManager, + nsDisplayItem* aItem, nsRect& aBounds, + const gfx::Point& aDeviceOffset); // Try to avoid using this when possible. wr::WrState* Raw() { return mWrState; } @@ -771,7 +771,7 @@ class DisplayListBuilder final { Maybe mSuspendedClipChainLeaf; RefPtr mCachedTextDT; - RefPtr mCachedContext; + mozilla::UniquePtr mCachedContext; FixedPosScrollTargetTracker* mActiveFixedPosTracker; diff --git a/image/BlobSurfaceProvider.cpp b/image/BlobSurfaceProvider.cpp index 9a1fd68f3b45..6f756716c2d8 100644 --- a/image/BlobSurfaceProvider.cpp +++ b/image/BlobSurfaceProvider.cpp @@ -226,7 +226,7 @@ Maybe BlobSurfaceProvider::RecordDrawing( mSVGDocumentWrapper->UpdateViewportBounds(viewportSize); mSVGDocumentWrapper->FlushImageTransformInvalidation(); - RefPtr ctx = gfxContext::CreateOrNull(dt); + UniquePtr ctx = gfxContext::CreateOrNull(dt); MOZ_ASSERT(ctx); // Already checked the draw target above. nsRect svgRect; @@ -261,7 +261,7 @@ Maybe BlobSurfaceProvider::RecordDrawing( presShell->RenderDocument(svgRect, renderDocFlags, NS_RGBA(0, 0, 0, 0), // transparent - ctx); + ctx.get()); } recorder->FlushItem(imageRectOrigin); diff --git a/image/ClippedImage.cpp b/image/ClippedImage.cpp index 12e38bdde848..89e480acaf44 100644 --- a/image/ClippedImage.cpp +++ b/image/ClippedImage.cpp @@ -255,7 +255,7 @@ std::pair> ClippedImage::GetFrameInternal( RefPtr()); } - RefPtr ctx = gfxContext::CreateOrNull(target); + UniquePtr ctx = gfxContext::CreateOrNull(target); MOZ_ASSERT(ctx); // already checked the draw target above // Create our callback. @@ -266,7 +266,7 @@ std::pair> ClippedImage::GetFrameInternal( new gfxCallbackDrawable(drawTileCallback, aSize); // Actually draw. The callback will end up invoking DrawSingleTile. - gfxUtils::DrawPixelSnapped(ctx, drawable, SizeDouble(aSize), + gfxUtils::DrawPixelSnapped(ctx.get(), drawable, SizeDouble(aSize), ImageRegion::Create(aSize), SurfaceFormat::OS_RGBA, SamplingFilter::LINEAR, imgIContainer::FLAG_CLAMP); diff --git a/image/DynamicImage.cpp b/image/DynamicImage.cpp index 0a8774632bc9..efc325fa1efc 100644 --- a/image/DynamicImage.cpp +++ b/image/DynamicImage.cpp @@ -150,11 +150,12 @@ DynamicImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame, << "DynamicImage::GetFrame failed in CreateOffscreenContentDrawTarget"; return nullptr; } - RefPtr context = gfxContext::CreateOrNull(dt); + UniquePtr context = gfxContext::CreateOrNull(dt); MOZ_ASSERT(context); // already checked the draw target above - auto result = Draw(context, aSize, ImageRegion::Create(aSize), aWhichFrame, - SamplingFilter::POINT, SVGImageContext(), aFlags, 1.0); + auto result = + Draw(context.get(), aSize, ImageRegion::Create(aSize), aWhichFrame, + SamplingFilter::POINT, SVGImageContext(), aFlags, 1.0); return result == ImgDrawResult::SUCCESS ? dt->Snapshot() : nullptr; } diff --git a/image/OrientedImage.cpp b/image/OrientedImage.cpp index 1e6157facf05..a17b700edbba 100644 --- a/image/OrientedImage.cpp +++ b/image/OrientedImage.cpp @@ -108,10 +108,10 @@ already_AddRefed OrientedImage::OrientSurface( } // Draw. - RefPtr ctx = gfxContext::CreateOrNull(target); + UniquePtr ctx = gfxContext::CreateOrNull(target); MOZ_ASSERT(ctx); // already checked the draw target above ctx->Multiply(OrientationMatrix(aOrientation, originalSize)); - gfxUtils::DrawPixelSnapped(ctx, drawable, SizeDouble(originalSize), + gfxUtils::DrawPixelSnapped(ctx.get(), drawable, SizeDouble(originalSize), ImageRegion::Create(originalSize), surfaceFormat, SamplingFilter::LINEAR); diff --git a/image/imgFrame.cpp b/image/imgFrame.cpp index 4ff6dcec1977..00f6d0727504 100644 --- a/image/imgFrame.cpp +++ b/image/imgFrame.cpp @@ -359,9 +359,9 @@ nsresult imgFrame::InitWithDrawable(gfxDrawable* aDrawable, } // Draw using the drawable the caller provided. - RefPtr ctx = gfxContext::CreateOrNull(target); + UniquePtr ctx = gfxContext::CreateOrNull(target); MOZ_ASSERT(ctx); // Already checked the draw target above. - gfxUtils::DrawPixelSnapped(ctx, aDrawable, SizeDouble(mImageSize), + gfxUtils::DrawPixelSnapped(ctx.get(), aDrawable, SizeDouble(mImageSize), ImageRegion::Create(ThebesRect(GetRect())), mFormat, aSamplingFilter, aImageFlags); diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 44ae8a8e801a..ed4497daf27e 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -3080,9 +3080,9 @@ void PresShell::ClearFrameRefs(nsIFrame* aFrame) { } } -already_AddRefed PresShell::CreateReferenceRenderingContext() { +UniquePtr PresShell::CreateReferenceRenderingContext() { nsDeviceContext* devCtx = mPresContext->DeviceContext(); - RefPtr rc; + UniquePtr rc; if (mPresContext->IsScreen()) { rc = gfxContext::CreateOrNull( gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget().get()); @@ -3093,7 +3093,7 @@ already_AddRefed PresShell::CreateReferenceRenderingContext() { rc = devCtx->CreateReferenceRenderingContext(); } - return rc ? rc.forget() : nullptr; + return rc; } // https://html.spec.whatwg.org/#scroll-to-the-fragment-identifier @@ -5121,7 +5121,7 @@ already_AddRefed PresShell::PaintRangePaintInfo( return nullptr; } - RefPtr ctx = gfxContext::CreateOrNull(dt); + UniquePtr ctx = gfxContext::CreateOrNull(dt); MOZ_ASSERT(ctx); // already checked the draw target above if (aRegion) { @@ -5176,7 +5176,7 @@ already_AddRefed PresShell::PaintRangePaintInfo( ctx->SetMatrixDouble(initialTM.PreTranslate(rootOffset)); aArea.MoveBy(-rangeInfo->mRootOffset.x, -rangeInfo->mRootOffset.y); nsRegion visible(aArea); - rangeInfo->mList.PaintRoot(&rangeInfo->mBuilder, ctx, + rangeInfo->mList.PaintRoot(&rangeInfo->mBuilder, ctx.get(), nsDisplayList::PAINT_DEFAULT, Nothing()); aArea.MoveBy(rangeInfo->mRootOffset.x, rangeInfo->mRootOffset.y); } @@ -9536,7 +9536,7 @@ bool PresShell::DoReflow(nsIFrame* target, bool aInterruptible, "non-root frames"); // CreateReferenceRenderingContext can return nullptr - RefPtr rcx(CreateReferenceRenderingContext()); + UniquePtr rcx(CreateReferenceRenderingContext()); #ifdef DEBUG mCurrentReflowRoot = target; @@ -9564,7 +9564,7 @@ bool PresShell::DoReflow(nsIFrame* target, bool aInterruptible, // Don't pass size directly to the reflow input, since a // constrained height implies page/column breaking. LogicalSize reflowSize(wm, size.ISize(wm), NS_UNCONSTRAINEDSIZE); - ReflowInput reflowInput(mPresContext, target, rcx, reflowSize, + ReflowInput reflowInput(mPresContext, target, rcx.get(), reflowSize, ReflowInput::InitFlag::CallerWillInit); reflowInput.mOrthogonalLimit = size.BSize(wm); @@ -11507,11 +11507,11 @@ PresShell::WindowSizeConstraints PresShell::GetWindowSizeConstraints() { return {minSize, maxSize}; } if (rootFrame->IsXULBoxFrame()) { - RefPtr rcx(CreateReferenceRenderingContext()); + UniquePtr rcx(CreateReferenceRenderingContext()); if (!rcx) { return {minSize, maxSize}; } - nsBoxLayoutState state(mPresContext, rcx); + nsBoxLayoutState state(mPresContext, rcx.get()); minSize = rootFrame->GetXULMinSize(state); maxSize = rootFrame->GetXULMaxSize(state); } else { diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h index 9187c1f26ad5..3365209ced88 100644 --- a/layout/base/PresShell.h +++ b/layout/base/PresShell.h @@ -590,7 +590,7 @@ class PresShell final : public nsStubDocumentObserver, * be rendered to, but is suitable for measuring text and performing * other non-rendering operations. Guaranteed to return non-null. */ - already_AddRefed CreateReferenceRenderingContext(); + mozilla::UniquePtr CreateReferenceRenderingContext(); /** * Scrolls the view of the document so that the given area of a frame diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 2ae4deded4f7..2925c9b03ad6 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -823,7 +823,7 @@ static bool RecomputePosition(nsIFrame* aFrame) { // the frame, and then get the offsets and size from it. If the frame's size // doesn't need to change, we can simply update the frame position. Otherwise // we fall back to a reflow. - RefPtr rc = + UniquePtr rc = aFrame->PresShell()->CreateReferenceRenderingContext(); // Construct a bogus parent reflow input so that there's a usable reflow input @@ -834,7 +834,7 @@ static bool RecomputePosition(nsIFrame* aFrame) { LogicalSize parentSize = parentFrame->GetLogicalSize(); nsFrameState savedState = parentFrame->GetStateBits(); - ReflowInput parentReflowInput(aFrame->PresContext(), parentFrame, rc, + ReflowInput parentReflowInput(aFrame->PresContext(), parentFrame, rc.get(), parentSize); parentFrame->RemoveStateBits(~nsFrameState(0)); parentFrame->AddStateBits(savedState); @@ -849,7 +849,7 @@ static bool RecomputePosition(nsIFrame* aFrame) { parentFrame->IsTableFrame())) { const auto cbWM = cbFrame->GetWritingMode(); LogicalSize cbSize = cbFrame->GetLogicalSize(); - cbReflowInput.emplace(cbFrame->PresContext(), cbFrame, rc, cbSize); + cbReflowInput.emplace(cbFrame->PresContext(), cbFrame, rc.get(), cbSize); cbReflowInput->SetComputedLogicalMargin( cbWM, cbFrame->GetLogicalUsedMargin(cbWM)); cbReflowInput->SetComputedLogicalPadding( diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index d1018ac3b00e..479e020ae08c 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -2645,14 +2645,14 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsDocumentViewer::GetContentSize( aMaxHeight = std::min(aMaxHeight, constraints.mMaxSize.height); aMaxWidth = std::min(aMaxWidth, constraints.mMaxSize.width); - RefPtr rcx(presShell->CreateReferenceRenderingContext()); + UniquePtr rcx(presShell->CreateReferenceRenderingContext()); const nscoord minISize = wm.IsVertical() ? constraints.mMinSize.height : constraints.mMinSize.width; const nscoord maxISize = wm.IsVertical() ? aMaxHeight : aMaxWidth; if (aPrefWidth) { - prefISize = std::max(root->GetMinISize(rcx), aPrefWidth); + prefISize = std::max(root->GetMinISize(rcx.get()), aPrefWidth); } else { - prefISize = root->GetPrefISize(rcx); + prefISize = root->GetPrefISize(rcx.get()); } prefISize = std::max(minISize, std::min(prefISize, maxISize)); } diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index da72a66133e8..32428085c9e7 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -7156,7 +7156,7 @@ static RefPtr ScaleSourceSurface(SourceSurface& aSurface, return nullptr; } - RefPtr context = gfxContext::CreateOrNull(dt); + UniquePtr context = gfxContext::CreateOrNull(dt); MOZ_ASSERT(context); dt->DrawSurface(&aSurface, Rect(Point(), Size(aTargetSize)), diff --git a/layout/generic/TextOverflow.cpp b/layout/generic/TextOverflow.cpp index 6ef0396c7d5a..148511ed2788 100644 --- a/layout/generic/TextOverflow.cpp +++ b/layout/generic/TextOverflow.cpp @@ -40,7 +40,7 @@ class LazyReferenceRenderingDrawTargetGetterFromFrame final explicit LazyReferenceRenderingDrawTargetGetterFromFrame(nsIFrame* aFrame) : mFrame(aFrame) {} virtual already_AddRefed GetRefDrawTarget() override { - RefPtr ctx = + UniquePtr ctx = mFrame->PresShell()->CreateReferenceRenderingContext(); RefPtr dt = ctx->GetDrawTarget(); return dt.forget(); @@ -270,8 +270,8 @@ bool nsDisplayTextOverflowMarker::CreateWebRenderCommands( // Run the rendering algorithm to capture the glyphs and shadows RefPtr textDrawer = new TextDrawTarget(aBuilder, aResources, aSc, aManager, this, bounds); - RefPtr captureCtx = gfxContext::CreateOrNull(textDrawer); - Paint(aDisplayListBuilder, captureCtx); + UniquePtr captureCtx = gfxContext::CreateOrNull(textDrawer); + Paint(aDisplayListBuilder, captureCtx.get()); textDrawer->TerminateShadows(); return textDrawer->Finish(); @@ -916,7 +916,7 @@ void TextOverflow::Marker::SetupString(nsIFrame* aFrame) { mISize = 0; } } else { - RefPtr rc = + UniquePtr rc = aFrame->PresShell()->CreateReferenceRenderingContext(); RefPtr fm = nsLayoutUtils::GetInflatedFontMetricsForFrame(aFrame); diff --git a/layout/generic/nsColumnSetFrame.cpp b/layout/generic/nsColumnSetFrame.cpp index 8883de283e6b..b906f7e825b6 100644 --- a/layout/generic/nsColumnSetFrame.cpp +++ b/layout/generic/nsColumnSetFrame.cpp @@ -73,13 +73,13 @@ bool nsDisplayColumnRule::CreateWebRenderCommands( const StackingContextHelper& aSc, mozilla::layers::RenderRootStateManager* aManager, nsDisplayListBuilder* aDisplayListBuilder) { - RefPtr screenRefCtx = gfxContext::CreateOrNull( + UniquePtr screenRefCtx = gfxContext::CreateOrNull( gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget().get()); bool dummy; static_cast(mFrame)->CreateBorderRenderers( - mBorderRenderers, screenRefCtx, GetBounds(aDisplayListBuilder, &dummy), - ToReferenceFrame()); + mBorderRenderers, screenRefCtx.get(), + GetBounds(aDisplayListBuilder, &dummy), ToReferenceFrame()); if (mBorderRenderers.IsEmpty()) { return true; diff --git a/layout/generic/nsFloatManager.cpp b/layout/generic/nsFloatManager.cpp index 4a252ffe3b45..5d2d2895c18e 100644 --- a/layout/generic/nsFloatManager.cpp +++ b/layout/generic/nsFloatManager.cpp @@ -2703,7 +2703,7 @@ nsFloatManager::ShapeInfo::CreateImageShape(const StyleImage& aShapeImage, return nullptr; } - RefPtr context = gfxContext::CreateOrNull(drawTarget); + UniquePtr context = gfxContext::CreateOrNull(drawTarget); MOZ_ASSERT(context); // already checked the target above ImgDrawResult result = diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 116370ef327c..b20e51cbe32e 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -2048,7 +2048,7 @@ ImgDrawResult nsImageFrame::DisplayAltFeedbackWithoutLayer( RefPtr textDrawer = new TextDrawTarget(aBuilder, aResources, aSc, aManager, aItem, inner, /* aCallerDoesSaveRestore = */ true); - RefPtr captureCtx = gfxContext::CreateOrNull(textDrawer); + UniquePtr captureCtx = gfxContext::CreateOrNull(textDrawer); nsAutoString altText; nsCSSFrameConstructor::GetAlternateTextFor(*mContent->AsElement(), altText); diff --git a/layout/generic/nsPageSequenceFrame.cpp b/layout/generic/nsPageSequenceFrame.cpp index 4a4d2d30ac8b..07ef9635c1e2 100644 --- a/layout/generic/nsPageSequenceFrame.cpp +++ b/layout/generic/nsPageSequenceFrame.cpp @@ -589,7 +589,7 @@ nsresult nsPageSequenceFrame::PrePrintNextSheet(nsITimerCallback* aCallback, mCalledBeginPage = true; - RefPtr renderingContext = dc->CreateRenderingContext(); + UniquePtr renderingContext = dc->CreateRenderingContext(); NS_ENSURE_TRUE(renderingContext, NS_ERROR_OUT_OF_MEMORY); DrawTarget* drawTarget = renderingContext->GetDrawTarget(); @@ -684,12 +684,12 @@ nsresult nsPageSequenceFrame::PrintNextSheet() { mCurrentSheetIdx)); // CreateRenderingContext can fail - RefPtr gCtx = dc->CreateRenderingContext(); + UniquePtr gCtx = dc->CreateRenderingContext(); NS_ENSURE_TRUE(gCtx, NS_ERROR_OUT_OF_MEMORY); nsRect drawingRect(nsPoint(0, 0), currentSheetFrame->GetSize()); nsRegion drawingRegion(drawingRect); - nsLayoutUtils::PaintFrame(gCtx, currentSheetFrame, drawingRegion, + nsLayoutUtils::PaintFrame(gCtx.get(), currentSheetFrame, drawingRegion, NS_RGBA(0, 0, 0, 0), nsDisplayListBuilderMode::PaintForPrinting, nsLayoutUtils::PaintFrameFlags::SyncDecodeImages); diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index e543cb8e8f74..12ddb1162127 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -2258,7 +2258,7 @@ static gfxFontGroup* GetInflatedFontGroupForFrame(nsTextFrame* aFrame) { static already_AddRefed CreateReferenceDrawTarget( const nsTextFrame* aTextFrame) { - RefPtr ctx = + UniquePtr ctx = aTextFrame->PresShell()->CreateReferenceRenderingContext(); RefPtr dt = ctx->GetDrawTarget(); return dt.forget(); diff --git a/layout/painting/WindowRenderer.cpp b/layout/painting/WindowRenderer.cpp index d4f61e206794..fba75fe2c4da 100644 --- a/layout/painting/WindowRenderer.cpp +++ b/layout/painting/WindowRenderer.cpp @@ -208,14 +208,14 @@ void FallbackRenderer::EndTransactionWithList(nsDisplayListBuilder* aBuilder, RefPtr dest = gfxPlatform::GetPlatform()->CreateDrawTargetForBackend( backend, dt->GetSize(), dt->GetFormat()); - RefPtr ctx = gfxContext::CreatePreservingTransformOrNull(dest); + UniquePtr ctx = gfxContext::CreatePreservingTransformOrNull(dest); nsRegion opaque = aList->GetOpaqueRegion(aBuilder); if (opaque.Contains(aList->GetComponentAlphaBounds(aBuilder))) { dest->SetPermitSubpixelAA(true); } - aList->Paint(aBuilder, ctx, aAppUnitsPerDevPixel); + aList->Paint(aBuilder, ctx.get(), aAppUnitsPerDevPixel); RefPtr snapshot = dest->Snapshot(); dt->DrawSurface(snapshot, Rect(dest->GetRect()), Rect(dest->GetRect()), diff --git a/layout/painting/WindowRenderer.h b/layout/painting/WindowRenderer.h index b58ffd307a2a..e018a4cf563c 100644 --- a/layout/painting/WindowRenderer.h +++ b/layout/painting/WindowRenderer.h @@ -275,7 +275,7 @@ class FallbackRenderer : public WindowRenderer { int32_t aAppUnitsPerDevPixel, EndTransactionFlags aFlags); - RefPtr mTarget; + gfxContext* mTarget; layers::BufferMode mBufferMode; }; diff --git a/layout/painting/nsCSSRendering.cpp b/layout/painting/nsCSSRendering.cpp index eacb7e75db8e..12d192332c0b 100644 --- a/layout/painting/nsCSSRendering.cpp +++ b/layout/painting/nsCSSRendering.cpp @@ -4687,14 +4687,15 @@ gfxContext* nsContextBoxBlur::Init(const nsRect& aRect, nscoord aSpreadRadius, bool useHardwareAccel = !(aFlags & DISABLE_HARDWARE_ACCELERATION_BLUR); if (aSkipRect) { gfxRect skipRect = transform.TransformBounds(*aSkipRect); - mContext = + mOwnedContext = mAlphaBoxBlur.Init(aDestinationCtx, rect, spreadRadius, blurRadius, &dirtyRect, &skipRect, useHardwareAccel); } else { - mContext = + mOwnedContext = mAlphaBoxBlur.Init(aDestinationCtx, rect, spreadRadius, blurRadius, &dirtyRect, nullptr, useHardwareAccel); } + mContext = mOwnedContext.get(); if (mContext) { // we don't need to blur if skipRect is equal to rect diff --git a/layout/painting/nsCSSRendering.h b/layout/painting/nsCSSRendering.h index 74cf22445536..6d71761c55c8 100644 --- a/layout/painting/nsCSSRendering.h +++ b/layout/painting/nsCSSRendering.h @@ -942,7 +942,8 @@ class nsContextBoxBlur { bool aConstrainSpreadRadius = true); gfxAlphaBoxBlur mAlphaBoxBlur; - RefPtr mContext; + mozilla::UniquePtr mOwnedContext; + gfxContext* mContext; // may be either mOwnedContext or mDestinationContext gfxContext* mDestinationCtx; /* This is true if the blur already has it's content transformed diff --git a/layout/painting/nsCSSRenderingGradients.cpp b/layout/painting/nsCSSRenderingGradients.cpp index 2b8a8e84b061..8892321f276c 100644 --- a/layout/painting/nsCSSRenderingGradients.cpp +++ b/layout/painting/nsCSSRenderingGradients.cpp @@ -1155,7 +1155,7 @@ bool nsCSSGradientRenderer::TryPaintTilesWithExtendMode( return false; } - RefPtr tileContext = gfxContext::CreateOrNull(tileTarget); + UniquePtr tileContext = gfxContext::CreateOrNull(tileTarget); tileContext->SetPattern(aGradientPattern); tileContext->Paint(); diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 7ada63823913..1f6119a7ee6d 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -315,14 +315,14 @@ static bool GenerateAndPushTextMask(nsIFrame* aFrame, gfxContext* aContext, if (!maskDT || !maskDT->IsValid()) { return false; } - RefPtr maskCtx = + UniquePtr maskCtx = gfxContext::CreatePreservingTransformOrNull(maskDT); MOZ_ASSERT(maskCtx); maskCtx->Multiply(Matrix::Translation(bounds.TopLeft().ToUnknownPoint())); // Shade text shape into mask A8 surface. nsLayoutUtils::PaintFrame( - maskCtx, aFrame, nsRect(nsPoint(0, 0), aFrame->GetSize()), + maskCtx.get(), aFrame, nsRect(nsPoint(0, 0), aFrame->GetSize()), NS_RGB(255, 255, 255), nsDisplayListBuilderMode::GenerateGlyph); // Push the generated mask into aContext, so that the caller can pop and @@ -5066,9 +5066,9 @@ void nsDisplayBlendMode::Paint(nsDisplayListBuilder* aBuilder, return; } - RefPtr ctx = gfxContext::CreatePreservingTransformOrNull(temp); + UniquePtr ctx = gfxContext::CreatePreservingTransformOrNull(temp); - GetChildren()->Paint(aBuilder, ctx, + GetChildren()->Paint(aBuilder, ctx.get(), mFrame->PresContext()->AppUnitsPerDevPixel()); // Draw the temporary DT to the real destination, applying the blend mode, but @@ -6869,7 +6869,7 @@ void nsDisplayTransform::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx, untransformedDT->SetTransform( Matrix::Translation(-Point(pixelBounds.X(), pixelBounds.Y()))); - RefPtr groupTarget = + UniquePtr groupTarget = gfxContext::CreatePreservingTransformOrNull(untransformedDT); if (aPolygon) { @@ -6878,7 +6878,7 @@ void nsDisplayTransform::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx, aCtx->GetDrawTarget()->PushClip(path); } - GetChildren()->Paint(aBuilder, groupTarget, + GetChildren()->Paint(aBuilder, groupTarget.get(), mFrame->PresContext()->AppUnitsPerDevPixel()); if (aPolygon) { @@ -7543,8 +7543,8 @@ bool nsDisplayText::CreateWebRenderCommands( bounds = bounds.Intersect(visible); } - RefPtr textDrawer = aBuilder.GetTextContext( - aResources, aSc, aManager, this, bounds, deviceOffset); + gfxContext* textDrawer = aBuilder.GetTextContext(aResources, aSc, aManager, + this, bounds, deviceOffset); aBuilder.StartGroup(this); diff --git a/layout/painting/nsImageRenderer.cpp b/layout/painting/nsImageRenderer.cpp index 7ff27c193785..134e3e4017ca 100644 --- a/layout/painting/nsImageRenderer.cpp +++ b/layout/painting/nsImageRenderer.cpp @@ -474,7 +474,8 @@ ImgDrawResult nsImageRenderer::Draw(nsPresContext* aPresContext, SamplingFilter samplingFilter = nsLayoutUtils::GetSamplingFilterForFrame(mForFrame); ImgDrawResult result = ImgDrawResult::SUCCESS; - RefPtr ctx = &aRenderingContext; + gfxContext* ctx = &aRenderingContext; + UniquePtr tempCtx; IntRect tmpDTRect; if (ctx->CurrentOp() != CompositionOp::OP_OVER || @@ -493,7 +494,8 @@ ImgDrawResult nsImageRenderer::Draw(nsPresContext* aPresContext, } tempDT->SetTransform(ctx->GetDrawTarget()->GetTransform() * Matrix::Translation(-tmpDTRect.TopLeft())); - ctx = gfxContext::CreatePreservingTransformOrNull(tempDT); + tempCtx = gfxContext::CreatePreservingTransformOrNull(tempDT); + ctx = tempCtx.get(); if (!ctx) { gfxDevCrash(LogReason::InvalidContext) << "ImageRenderer::Draw problem " << gfx::hexa(tempDT); diff --git a/layout/printing/PrintTranslator.cpp b/layout/printing/PrintTranslator.cpp index 6179411d0908..b3d5609a08b2 100644 --- a/layout/printing/PrintTranslator.cpp +++ b/layout/printing/PrintTranslator.cpp @@ -20,7 +20,7 @@ namespace layout { PrintTranslator::PrintTranslator(nsDeviceContext* aDeviceContext) : mDeviceContext(aDeviceContext) { - RefPtr context = + UniquePtr context = mDeviceContext->CreateReferenceRenderingContext(); mBaseDT = context->GetDrawTarget(); } @@ -71,7 +71,7 @@ bool PrintTranslator::TranslateRecording(PRFileDescStream& aRecording) { already_AddRefed PrintTranslator::CreateDrawTarget( ReferencePtr aRefPtr, const gfx::IntSize& aSize, gfx::SurfaceFormat aFormat) { - RefPtr context = mDeviceContext->CreateRenderingContext(); + UniquePtr context = mDeviceContext->CreateRenderingContext(); if (!context) { NS_WARNING("Failed to create rendering context for print."); return nullptr; diff --git a/layout/svg/FilterInstance.cpp b/layout/svg/FilterInstance.cpp index 6d23070ef916..2accdefd5904 100644 --- a/layout/svg/FilterInstance.cpp +++ b/layout/svg/FilterInstance.cpp @@ -636,17 +636,18 @@ void FilterInstance::BuildSourcePaint(SourceInfo* aSource, return; } - RefPtr ctx = gfxContext::CreateOrNull(offscreenDT); + UniquePtr ctx = gfxContext::CreateOrNull(offscreenDT); MOZ_ASSERT(ctx); // already checked the draw target above - gfxContextAutoSaveRestore saver(ctx); + gfxContextAutoSaveRestore saver(ctx.get()); ctx->SetMatrixDouble(mPaintTransform * gfxMatrix::Translation(-neededRect.TopLeft())); GeneralPattern pattern; if (aSource == &mFillPaint) { - SVGUtils::MakeFillPatternFor(mTargetFrame, ctx, &pattern, aImgParams); + SVGUtils::MakeFillPatternFor(mTargetFrame, ctx.get(), &pattern, aImgParams); } else if (aSource == &mStrokePaint) { - SVGUtils::MakeStrokePatternFor(mTargetFrame, ctx, &pattern, aImgParams); + SVGUtils::MakeStrokePatternFor(mTargetFrame, ctx.get(), &pattern, + aImgParams); } if (pattern.GetPattern()) { @@ -707,7 +708,7 @@ void FilterInstance::BuildSourceImage(DrawTarget* aDest, // space to device space and back again). However, that would make the // code more complex while being hard to get right without introducing // subtle bugs, and in practice it probably makes no real difference.) - RefPtr ctx = gfxContext::CreateOrNull(offscreenDT); + UniquePtr ctx = gfxContext::CreateOrNull(offscreenDT); MOZ_ASSERT(ctx); // already checked the draw target above gfxMatrix devPxToCssPxTM = SVGUtils::GetCSSPxToDevPxMatrix(mTargetFrame); DebugOnly invertible = devPxToCssPxTM.Invert(); diff --git a/layout/svg/SVGClipPathFrame.cpp b/layout/svg/SVGClipPathFrame.cpp index dc35761dfa98..2e7b4f29cb0c 100644 --- a/layout/svg/SVGClipPathFrame.cpp +++ b/layout/svg/SVGClipPathFrame.cpp @@ -232,7 +232,7 @@ already_AddRefed SVGClipPathFrame::GetClipMask( return nullptr; } - RefPtr maskContext = + UniquePtr maskContext = gfxContext::CreatePreservingTransformOrNull(maskDT); if (!maskContext) { gfxCriticalError() << "SVGClipPath context problem " << gfx::hexa(maskDT); diff --git a/layout/svg/SVGForeignObjectFrame.cpp b/layout/svg/SVGForeignObjectFrame.cpp index c850ad09f932..1d385fa2c5fe 100644 --- a/layout/svg/SVGForeignObjectFrame.cpp +++ b/layout/svg/SVGForeignObjectFrame.cpp @@ -464,13 +464,13 @@ void SVGForeignObjectFrame::DoReflow() { } // initiate a synchronous reflow here and now: - RefPtr renderingContext = + UniquePtr renderingContext = presContext->PresShell()->CreateReferenceRenderingContext(); mInReflow = true; WritingMode wm = kid->GetWritingMode(); - ReflowInput reflowInput(presContext, kid, renderingContext, + ReflowInput reflowInput(presContext, kid, renderingContext.get(), LogicalSize(wm, ISize(wm), NS_UNCONSTRAINEDSIZE)); ReflowOutput desiredSize(reflowInput); nsReflowStatus status; diff --git a/layout/svg/SVGIntegrationUtils.cpp b/layout/svg/SVGIntegrationUtils.cpp index f7b81dc17960..47f9d63ee4e2 100644 --- a/layout/svg/SVGIntegrationUtils.cpp +++ b/layout/svg/SVGIntegrationUtils.cpp @@ -466,7 +466,7 @@ static bool PaintMaskSurface(const PaintFramesParams& aParams, gfxPoint devPixelOffsetToUserSpace = nsLayoutUtils::PointToGfxPoint( aOffsetToUserSpace, presContext->AppUnitsPerDevPixel()); - RefPtr maskContext = + UniquePtr maskContext = gfxContext::CreatePreservingTransformOrNull(aMaskDT); MOZ_ASSERT(maskContext); @@ -498,7 +498,7 @@ static bool PaintMaskSurface(const PaintFramesParams& aParams, aMaskDT->SetTransform(tmp); } } else if (svgReset->mMask.mLayers[i].mImage.IsResolved()) { - gfxContextMatrixAutoSaveRestore matRestore(maskContext); + gfxContextMatrixAutoSaveRestore matRestore(maskContext.get()); maskContext->Multiply(gfxMatrix::Translation(-devPixelOffsetToUserSpace)); nsCSSRendering::PaintBGParams params = diff --git a/layout/svg/SVGMaskFrame.cpp b/layout/svg/SVGMaskFrame.cpp index de192823d5f2..b949faf1c584 100644 --- a/layout/svg/SVGMaskFrame.cpp +++ b/layout/svg/SVGMaskFrame.cpp @@ -78,7 +78,7 @@ already_AddRefed SVGMaskFrame::GetMaskForMaskedFrame( return nullptr; } - RefPtr tmpCtx = + UniquePtr tmpCtx = gfxContext::CreatePreservingTransformOrNull(maskDT); MOZ_ASSERT(tmpCtx); // already checked the draw target above diff --git a/layout/svg/SVGPatternFrame.cpp b/layout/svg/SVGPatternFrame.cpp index 67d531866b6f..1dbe88ec1f79 100644 --- a/layout/svg/SVGPatternFrame.cpp +++ b/layout/svg/SVGPatternFrame.cpp @@ -338,7 +338,7 @@ already_AddRefed SVGPatternFrame::PaintPattern( } dt->ClearRect(Rect(0, 0, surfaceSize.width, surfaceSize.height)); - RefPtr ctx = gfxContext::CreateOrNull(dt); + UniquePtr ctx = gfxContext::CreateOrNull(dt); MOZ_ASSERT(ctx); // already checked the draw target above if (aGraphicOpacity != 1.0f) { diff --git a/layout/svg/SVGTextFrame.cpp b/layout/svg/SVGTextFrame.cpp index caa66de13dd8..e858b502a4d6 100644 --- a/layout/svg/SVGTextFrame.cpp +++ b/layout/svg/SVGTextFrame.cpp @@ -5124,7 +5124,7 @@ void SVGTextFrame::DoReflow() { return; } - RefPtr renderingContext = + UniquePtr renderingContext = presContext->PresShell()->CreateReferenceRenderingContext(); if (UpdateFontSizeScaleFactor()) { @@ -5133,9 +5133,9 @@ void SVGTextFrame::DoReflow() { kid->MarkIntrinsicISizesDirty(); } - nscoord inlineSize = kid->GetPrefISize(renderingContext); + nscoord inlineSize = kid->GetPrefISize(renderingContext.get()); WritingMode wm = kid->GetWritingMode(); - ReflowInput reflowInput(presContext, kid, renderingContext, + ReflowInput reflowInput(presContext, kid, renderingContext.get(), LogicalSize(wm, inlineSize, NS_UNCONSTRAINEDSIZE)); ReflowOutput desiredSize(reflowInput); nsReflowStatus status; diff --git a/layout/svg/SVGUtils.cpp b/layout/svg/SVGUtils.cpp index 774b95b59451..c5db39c617b2 100644 --- a/layout/svg/SVGUtils.cpp +++ b/layout/svg/SVGUtils.cpp @@ -508,7 +508,7 @@ class MixModeBlender { mTargetOffset = drawRect.TopLeft(); - return mTargetCtx; + return mTargetCtx.get(); } void BlendToTarget() { @@ -564,7 +564,7 @@ class MixModeBlender { nsIFrame* mFrame; gfxContext* mSourceCtx; - RefPtr mTargetCtx; + UniquePtr mTargetCtx; IntPoint mTargetOffset; }; diff --git a/layout/xul/nsSplitterFrame.cpp b/layout/xul/nsSplitterFrame.cpp index 9874b8a8005e..0a2ee336f131 100644 --- a/layout/xul/nsSplitterFrame.cpp +++ b/layout/xul/nsSplitterFrame.cpp @@ -546,9 +546,9 @@ nsresult nsSplitterFrameInner::MouseDown(Event* aMouseEvent) { // get our index nsPresContext* outerPresContext = mOuter->PresContext(); - RefPtr rc = + UniquePtr rc = outerPresContext->PresShell()->CreateReferenceRenderingContext(); - nsBoxLayoutState state(outerPresContext, rc); + nsBoxLayoutState state(outerPresContext, rc.get()); mDidDrag = false; diff --git a/layout/xul/nsTextBoxFrame.cpp b/layout/xul/nsTextBoxFrame.cpp index 288c13cfa245..a7424bc99c35 100644 --- a/layout/xul/nsTextBoxFrame.cpp +++ b/layout/xul/nsTextBoxFrame.cpp @@ -302,10 +302,10 @@ bool nsDisplayXULTextBox::CreateWebRenderCommands( RefPtr textDrawer = new mozilla::layout::TextDrawTarget(aBuilder, aResources, aSc, aManager, this, bounds); - RefPtr captureCtx = + UniquePtr captureCtx = gfxContext::CreateOrNull(textDrawer, deviceOffset); - Paint(aDisplayListBuilder, captureCtx); + Paint(aDisplayListBuilder, captureCtx.get()); textDrawer->TerminateShadows(); return textDrawer->Finish(); @@ -469,7 +469,7 @@ void nsTextBoxFrame::DrawText(gfxContext& aRenderingContext, } } - RefPtr refContext = + UniquePtr refContext = PresShell()->CreateReferenceRenderingContext(); DrawTarget* refDrawTarget = refContext->GetDrawTarget(); diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index f20d39b2636c..0bf2fe93ae09 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -213,14 +213,15 @@ nscoord nsTreeBodyFrame::CalcMaxRowWidth() { nscoord rowWidth; nsTreeColumn* col; - RefPtr rc = PresShell()->CreateReferenceRenderingContext(); + UniquePtr rc = PresShell()->CreateReferenceRenderingContext(); for (int32_t row = 0; row < mRowCount; ++row) { rowWidth = 0; for (col = mColumns->GetFirstColumn(); col; col = col->GetNext()) { nscoord desiredWidth, currentWidth; - nsresult rv = GetCellWidth(row, col, rc, desiredWidth, currentWidth); + nsresult rv = + GetCellWidth(row, col, rc.get(), desiredWidth, currentWidth); if (NS_FAILED(rv)) { MOZ_ASSERT_UNREACHABLE("invalid column"); continue; @@ -1004,7 +1005,7 @@ nsresult nsTreeBodyFrame::GetCoordsForCellItem(int32_t aRow, nsTreeColumn* aCol, // interfere with our computations. AdjustForBorderPadding(cellContext, cellRect); - RefPtr rc = + UniquePtr rc = presContext->PresShell()->CreateReferenceRenderingContext(); // Now we'll start making our way across the cell, starting at the edge of @@ -1263,7 +1264,7 @@ nsCSSAnonBoxPseudoStaticAtom* nsTreeBodyFrame::GetItemWithinCellAt( bool isRTL = StyleVisibility()->mDirection == StyleDirection::Rtl; nsPresContext* presContext = PresContext(); - RefPtr rc = + UniquePtr rc = presContext->PresShell()->CreateReferenceRenderingContext(); if (aColumn->IsPrimary()) { @@ -1504,9 +1505,9 @@ nsresult nsTreeBodyFrame::IsCellCropped(int32_t aRow, nsTreeColumn* aCol, if (!aCol) return NS_ERROR_INVALID_ARG; - RefPtr rc = PresShell()->CreateReferenceRenderingContext(); + UniquePtr rc = PresShell()->CreateReferenceRenderingContext(); - rv = GetCellWidth(aRow, aCol, rc, desiredSize, currentSize); + rv = GetCellWidth(aRow, aCol, rc.get(), desiredSize, currentSize); NS_ENSURE_SUCCESS(rv, rv); *_retval = desiredSize > currentSize; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 06ccb9eed4fa..7de57342a2fe 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1316,7 +1316,7 @@ bool nsChildView::PaintWindow(LayoutDeviceIntRegion aRegion) { bool nsChildView::PaintWindowInDrawTarget(gfx::DrawTarget* aDT, const LayoutDeviceIntRegion& aRegion, const gfx::IntSize& aSurfaceSize) { - RefPtr targetContext = gfxContext::CreateOrNull(aDT); + UniquePtr targetContext = gfxContext::CreateOrNull(aDT); MOZ_ASSERT(targetContext); // Set up the clip region and clear existing contents in the backing surface. @@ -1330,7 +1330,7 @@ bool nsChildView::PaintWindowInDrawTarget(gfx::DrawTarget* aDT, nsAutoRetainCocoaObject kungFuDeathGrip(mView); if (GetWindowRenderer()->GetBackendType() == LayersBackend::LAYERS_NONE) { - nsBaseWidget::AutoLayerManagerSetup setupLayerManager(this, targetContext, + nsBaseWidget::AutoLayerManagerSetup setupLayerManager(this, targetContext.get(), BufferMode::BUFFER_NONE); return PaintWindow(aRegion); } diff --git a/widget/cocoa/nsCocoaUtils.mm b/widget/cocoa/nsCocoaUtils.mm index 0b7e01461abe..1854dfbf15d9 100644 --- a/widget/cocoa/nsCocoaUtils.mm +++ b/widget/cocoa/nsCocoaUtils.mm @@ -494,7 +494,7 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer* aImage, ui return NS_ERROR_FAILURE; } - RefPtr context = gfxContext::CreateOrNull(drawTarget); + UniquePtr context = gfxContext::CreateOrNull(drawTarget); MOZ_ASSERT(context); SVGImageContext svgContext; @@ -502,7 +502,7 @@ nsresult nsCocoaUtils::CreateNSImageFromImageContainer(imgIContainer* aImage, ui SVGImageContext::MaybeStoreContextPaint(svgContext, *aPresContext, *aComputedStyle, aImage); } mozilla::image::ImgDrawResult res = - aImage->Draw(context, scaledSize, ImageRegion::Create(scaledSize), aWhichFrame, + aImage->Draw(context.get(), scaledSize, ImageRegion::Create(scaledSize), aWhichFrame, SamplingFilter::POINT, svgContext, imgIContainer::FLAG_SYNC_DECODE, 1.0); if (res != mozilla::image::ImgDrawResult::SUCCESS) { diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index f75736f142c9..7b804619a395 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -3852,7 +3852,7 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) { if (!dt || !dt->IsValid()) { return FALSE; } - RefPtr ctx; + UniquePtr ctx; IntRect boundsRect = region.GetBounds().ToUnknownRect(); IntPoint offset(0, 0); if (dt->GetSize() == boundsRect.Size()) { @@ -3908,7 +3908,7 @@ gboolean nsWindow::OnExposeEvent(cairo_t* cr) { // reused SHM image. See bug 1258086. dt->ClearRect(Rect(boundsRect)); } - AutoLayerManagerSetup setupLayerManager(this, ctx, layerBuffering); + AutoLayerManagerSetup setupLayerManager(this, ctx.get(), layerBuffering); painted = listener->PaintWindow(this, region); // Re-get the listener since the will paint notification might have diff --git a/widget/nsBaseDragService.cpp b/widget/nsBaseDragService.cpp index f1b492865e22..2c90803496c1 100644 --- a/widget/nsBaseDragService.cpp +++ b/widget/nsBaseDragService.cpp @@ -940,11 +940,11 @@ nsresult nsBaseDragService::DrawDragForImage( destSize, SurfaceFormat::B8G8R8A8); if (!dt || !dt->IsValid()) return NS_ERROR_FAILURE; - RefPtr ctx = gfxContext::CreateOrNull(dt); + UniquePtr ctx = gfxContext::CreateOrNull(dt); if (!ctx) return NS_ERROR_FAILURE; ImgDrawResult res = imgContainer->Draw( - ctx, destSize, ImageRegion::Create(destSize), + ctx.get(), destSize, ImageRegion::Create(destSize), imgIContainer::FRAME_CURRENT, SamplingFilter::GOOD, SVGImageContext(), imgIContainer::FLAG_SYNC_DECODE, 1.0); if (res == ImgDrawResult::BAD_IMAGE || res == ImgDrawResult::BAD_ARGS || diff --git a/widget/uikit/nsWindow.mm b/widget/uikit/nsWindow.mm index ffb867c5cffa..e50972ce8bce 100644 --- a/widget/uikit/nsWindow.mm +++ b/widget/uikit/nsWindow.mm @@ -317,7 +317,7 @@ class nsAutoRetainUIKitObject { // Create Cairo objects. RefPtr targetSurface; - RefPtr targetContext; + UniquePtrPtr targetContext; if (gfxPlatform::GetPlatform()->SupportsAzureContentForType(gfx::BackendType::CAIRO)) { // This is dead code unless you mess with prefs, but keep it around for // debugging. diff --git a/widget/windows/nsNativeThemeWin.cpp b/widget/windows/nsNativeThemeWin.cpp index 1ec9fe6e9ba1..5ac186d84658 100644 --- a/widget/windows/nsNativeThemeWin.cpp +++ b/widget/windows/nsNativeThemeWin.cpp @@ -1427,12 +1427,12 @@ nsNativeThemeWin::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame, return NS_OK; } - RefPtr ctx = aContext; - gfxContextMatrixAutoSaveRestore save(ctx); + gfxContextMatrixAutoSaveRestore save(aContext); double themeScale = GetThemeDpiScaleFactor(aFrame); if (themeScale != 1.0) { - ctx->SetMatrix(ctx->CurrentMatrix().PreScale(themeScale, themeScale)); + aContext->SetMatrix( + aContext->CurrentMatrix().PreScale(themeScale, themeScale)); } gfxFloat p2a = gfxFloat(aFrame->PresContext()->AppUnitsPerDevPixel()); @@ -1446,7 +1446,7 @@ nsNativeThemeWin::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame, dr.Scale(1.0 / (p2a * themeScale)); gfxWindowsNativeDrawing nativeDrawing( - ctx, dr, GetWidgetNativeDrawingFlags(aAppearance)); + aContext, dr, GetWidgetNativeDrawingFlags(aAppearance)); RENDER_AGAIN: @@ -3109,10 +3109,8 @@ nsresult nsNativeThemeWin::ClassicDrawWidgetBackground( tr.Scale(1.0 / p2a); dr.Scale(1.0 / p2a); - RefPtr ctx = aContext; - gfxWindowsNativeDrawing nativeDrawing( - ctx, dr, GetWidgetNativeDrawingFlags(aAppearance)); + aContext, dr, GetWidgetNativeDrawingFlags(aAppearance)); RENDER_AGAIN: diff --git a/widget/windows/nsWindowGfx.cpp b/widget/windows/nsWindowGfx.cpp index 395095f365d4..c2a96331334e 100644 --- a/widget/windows/nsWindowGfx.cpp +++ b/widget/windows/nsWindowGfx.cpp @@ -307,11 +307,11 @@ bool nsWindow::OnPaint(HDC aDC, uint32_t aNestingLevel) { break; } - RefPtr thebesContext = gfxContext::CreateOrNull(dt); + UniquePtr thebesContext = gfxContext::CreateOrNull(dt); MOZ_ASSERT(thebesContext); // already checked draw target above { - AutoLayerManagerSetup setupLayerManager(this, thebesContext, + AutoLayerManagerSetup setupLayerManager(this, thebesContext.get(), doubleBuffering); result = listener->PaintWindow(this, region); }