diff --git a/gfx/src/nsDeviceContext.cpp b/gfx/src/nsDeviceContext.cpp index 7496b59e4a6..e5f23be1771 100644 --- a/gfx/src/nsDeviceContext.cpp +++ b/gfx/src/nsDeviceContext.cpp @@ -442,59 +442,16 @@ nsDeviceContext::Init(nsIWidget *aWidget) return NS_OK; } -nsresult -nsDeviceContext::CreateRenderingContext(nsIWidget *aWidget, - nsRenderingContext *&aContext) -{ - nsresult rv; - - aContext = nsnull; - nsRefPtr pContext; - rv = CreateRenderingContextInstance(*getter_AddRefs(pContext)); - if (NS_SUCCEEDED(rv)) { - nsRefPtr surface(aWidget->GetThebesSurface()); - if (surface) { - pContext->Init(this, surface); - aContext = pContext; - NS_ADDREF(aContext); - } else { - rv = NS_ERROR_FAILURE; - } - } - - return rv; -} - nsresult nsDeviceContext::CreateRenderingContext(nsRenderingContext *&aContext) { - nsresult rv = NS_OK; + NS_ABORT_IF_FALSE(mPrintingSurface, "only call for printing dcs"); - aContext = nsnull; - nsRefPtr pContext; - rv = CreateRenderingContextInstance(*getter_AddRefs(pContext)); - if (NS_SUCCEEDED(rv)) { - if (mPrintingSurface) { - pContext->Init(this, mPrintingSurface); - pContext->Scale(mPrintingScale, mPrintingScale); - aContext = pContext; - NS_ADDREF(aContext); - } else { - rv = NS_ERROR_FAILURE; - } - } + nsRefPtr pContext = new nsRenderingContext(); - return rv; -} - -nsresult -nsDeviceContext::CreateRenderingContextInstance(nsRenderingContext *&aContext) -{ - nsRefPtr renderingContext = new nsRenderingContext(); - if (!renderingContext) - return NS_ERROR_OUT_OF_MEMORY; - - aContext = renderingContext; + pContext->Init(this, mPrintingSurface); + pContext->Scale(mPrintingScale, mPrintingScale); + aContext = pContext; NS_ADDREF(aContext); return NS_OK; diff --git a/gfx/src/nsDeviceContext.h b/gfx/src/nsDeviceContext.h index 2fd68e92bf4..eab44bbeee1 100644 --- a/gfx/src/nsDeviceContext.h +++ b/gfx/src/nsDeviceContext.h @@ -97,28 +97,13 @@ public: nsresult InitForPrinting(nsIDeviceContextSpec *aDevSpec); /** - * Create a rendering context and initialize it from an nsIWidget - * @param aWidget widget to initialize context from - * @param aContext out parameter for new rendering context - * @return error status - */ - nsresult CreateRenderingContext(nsIWidget *aWidget, - nsRenderingContext *&aContext); - - /** - * Create a rendering context and initialize it. + * Create a rendering context and initialize it. Only call this + * method on device contexts that were initialized for printing. * @param aContext out parameter for new rendering context * @return error status */ nsresult CreateRenderingContext(nsRenderingContext *&aContext); - /** - * Create an uninitalised rendering context. - * @param aContext out parameter for new rendering context - * @return error status - */ - nsresult CreateRenderingContextInstance(nsRenderingContext *&aContext); - /** * Gets the number of app units in one CSS pixel; this number is global, * not unique to each device context. diff --git a/layout/base/FrameLayerBuilder.cpp b/layout/base/FrameLayerBuilder.cpp index 288fbaa290d..2d6d80caa21 100644 --- a/layout/base/FrameLayerBuilder.cpp +++ b/layout/base/FrameLayerBuilder.cpp @@ -1892,11 +1892,7 @@ FrameLayerBuilder::DrawThebesLayer(ThebesLayer* aLayer, } } - nsRefPtr rc; - nsresult rv = - presContext->DeviceContext()->CreateRenderingContextInstance(*getter_AddRefs(rc)); - if (NS_FAILED(rv)) - return; + nsRefPtr rc = new nsRenderingContext(); rc->Init(presContext->DeviceContext(), aContext); Clip currentClip; diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index f560f1e65a9..3e13675abb7 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -1197,15 +1197,13 @@ nsCSSRendering::PaintBoxShadowOuter(nsPresContext* aPresContext, // Draw the widget shape gfxContextMatrixAutoSaveRestore save(shadowContext); - nsDeviceContext* devCtx = aPresContext->DeviceContext(); - nsRefPtr wrapperCtx; - devCtx->CreateRenderingContextInstance(*getter_AddRefs(wrapperCtx)); - wrapperCtx->Init(devCtx, shadowContext); - wrapperCtx->Translate(nsPoint(shadowItem->mXOffset, shadowItem->mYOffset)); + nsRefPtr wrapperCtx = new nsRenderingContext(); + wrapperCtx->Init(aPresContext->DeviceContext(), shadowContext); + wrapperCtx->Translate(nsPoint(shadowItem->mXOffset, + shadowItem->mYOffset)); nsRect nativeRect; nativeRect.IntersectRect(frameRect, aDirtyRect); - aPresContext->GetTheme()->DrawWidgetBackground(wrapperCtx, aForFrame, styleDisplay->mAppearance, aFrameArea, nativeRect); } else { diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 71b53e3fc0a..465ff7879c6 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -3761,10 +3761,8 @@ PresShell::GetReferenceRenderingContext() nsDeviceContext* devCtx = mPresContext->DeviceContext(); nsRefPtr rc; if (mPresContext->IsScreen()) { - devCtx->CreateRenderingContextInstance(*getter_AddRefs(rc)); - if (rc) { - rc->Init(devCtx, gfxPlatform::GetPlatform()->ScreenReferenceSurface()); - } + rc = new nsRenderingContext(); + rc->Init(devCtx, gfxPlatform::GetPlatform()->ScreenReferenceSurface()); } else { devCtx->CreateRenderingContext(*getter_AddRefs(rc)); } @@ -5283,8 +5281,7 @@ PresShell::RenderDocument(const nsRect& aRect, PRUint32 aFlags, AutoSaveRestoreRenderingState _(this); - nsRefPtr rc; - devCtx->CreateRenderingContextInstance(*getter_AddRefs(rc)); + nsRefPtr rc = new nsRenderingContext(); rc->Init(devCtx, aThebesContext); PRBool wouldFlushRetainedLayers = PR_FALSE; @@ -5608,8 +5605,7 @@ PresShell::PaintRangePaintInfo(nsTArray >* aItems, context.Rectangle(gfxRect(0, 0, pixelArea.width, pixelArea.height)); context.Fill(); - nsRefPtr rc; - deviceContext->CreateRenderingContextInstance(*getter_AddRefs(rc)); + nsRefPtr rc = new nsRenderingContext(); rc->Init(deviceContext, surface); if (aRegion) { diff --git a/layout/inspector/src/inFlasher.cpp b/layout/inspector/src/inFlasher.cpp index ca1b3f4209a..9305e694834 100644 --- a/layout/inspector/src/inFlasher.cpp +++ b/layout/inspector/src/inFlasher.cpp @@ -142,7 +142,7 @@ inFlasher::RepaintElement(nsIDOMElement* aElement) return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP inFlasher::DrawElementOutline(nsIDOMElement* aElement) { NS_ENSURE_ARG_POINTER(aElement); @@ -159,20 +159,19 @@ inFlasher::DrawElementOutline(nsIDOMElement* aElement) nsPoint offset; nsIWidget* widget = frame->GetNearestWidget(offset); if (widget) { - nsRefPtr rcontext; - frame->PresContext()->DeviceContext()-> - CreateRenderingContext(widget, *getter_AddRefs(rcontext)); - if (rcontext) { - nsRect rect(offset, frame->GetSize()); - if (mInvert) { - rcontext->InvertRect(rect); - } + nsRefPtr rcontext = new nsRenderingContext(); + rcontext->Init(frame->PresContext()->DeviceContext(), + widget->GetThebesSurface()); - PRBool isLastFrame = frame->GetNextContinuation() == nsnull; - DrawOutline(rect.x, rect.y, rect.width, rect.height, rcontext, - isFirstFrame, isLastFrame); - isFirstFrame = PR_FALSE; + nsRect rect(offset, frame->GetSize()); + if (mInvert) { + rcontext->InvertRect(rect); } + + PRBool isLastFrame = frame->GetNextContinuation() == nsnull; + DrawOutline(rect.x, rect.y, rect.width, rect.height, rcontext, + isFirstFrame, isLastFrame); + isFirstFrame = PR_FALSE; } frame = frame->GetNextContinuation(); } diff --git a/layout/svg/base/src/nsSVGUtils.cpp b/layout/svg/base/src/nsSVGUtils.cpp index 36a56b468df..d0e221ae506 100644 --- a/layout/svg/base/src/nsSVGUtils.cpp +++ b/layout/svg/base/src/nsSVGUtils.cpp @@ -1465,11 +1465,9 @@ nsRenderingContext* nsSVGRenderState::GetRenderingContext(nsIFrame *aFrame) { if (!mRenderingContext) { - nsDeviceContext* devCtx = aFrame->PresContext()->DeviceContext(); - devCtx->CreateRenderingContextInstance(*getter_AddRefs(mRenderingContext)); - if (!mRenderingContext) - return nsnull; - mRenderingContext->Init(devCtx, mGfxContext); + mRenderingContext = new nsRenderingContext(); + mRenderingContext->Init(aFrame->PresContext()->DeviceContext(), + mGfxContext); } return mRenderingContext; } diff --git a/layout/xul/base/src/nsTextBoxFrame.cpp b/layout/xul/base/src/nsTextBoxFrame.cpp index 965033c91fe..4b62be4d3c5 100644 --- a/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/layout/xul/base/src/nsTextBoxFrame.cpp @@ -621,20 +621,17 @@ void nsTextBoxFrame::PaintOneShadow(gfxContext* aCtx, shadowColor = aForegroundColor; // Conjure an nsRenderingContext from a gfxContext for DrawText - nsRefPtr renderingContext = nsnull; - nsDeviceContext* devCtx = PresContext()->DeviceContext(); - devCtx->CreateRenderingContextInstance(*getter_AddRefs(renderingContext)); - if (!renderingContext) - return; - renderingContext->Init(devCtx, shadowContext); + nsRefPtr renderingContext = new nsRenderingContext(); + renderingContext->Init(PresContext()->DeviceContext(), shadowContext); aCtx->Save(); aCtx->NewPath(); aCtx->SetColor(gfxRGBA(shadowColor)); - // Draw the text onto our alpha-only surface to capture the alpha values. - // Remember that the box blur context has a device offset on it, so we don't need to - // translate any coordinates to fit on the surface. + // Draw the text onto our alpha-only surface to capture the alpha + // values. Remember that the box blur context has a device offset + // on it, so we don't need to translate any coordinates to fit on + // the surface. DrawText(*renderingContext, shadowRect, &shadowColor); contextBoxBlur.DoPaint(); aCtx->Restore();