Bug 996326: Make nsDeviceContext::CreateRenderingContext() return its result directly, instead of using outparam. r=roc
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 14 Apr 2014 20:15:01 -0700
changeset 196936 81ce5041d5d944ca9c0464cd8703d2e80df64476
parent 196935 6cc06a35f253203d7986d07f3188415eef4aa5bc
child 196937 b79772297b2e4465643ffc7bc8d9f06c9ed9d45b
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs996326
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 996326: Make nsDeviceContext::CreateRenderingContext() return its result directly, instead of using outparam. r=roc
gfx/src/nsDeviceContext.cpp
gfx/src/nsDeviceContext.h
layout/base/nsPresShell.cpp
layout/generic/nsSimplePageSequenceFrame.cpp
layout/printing/nsPrintEngine.cpp
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -372,18 +372,18 @@ nsDeviceContext::Init(nsIWidget *aWidget
     if (mScreenManager)
         return NS_OK;
 
     mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
 
     return NS_OK;
 }
 
-nsresult
-nsDeviceContext::CreateRenderingContext(nsRenderingContext *&aContext)
+already_AddRefed<nsRenderingContext>
+nsDeviceContext::CreateRenderingContext()
 {
     nsRefPtr<gfxASurface> printingSurface = mPrintingSurface;
 #ifdef XP_MACOSX
     // CreateRenderingContext() can be called (on reflow) after EndPage()
     // but before BeginPage().  On OS X (and only there) mPrintingSurface
     // will in this case be null, because OS X printing surfaces are
     // per-page, and therefore only truly valid between calls to BeginPage()
     // and EndPage().  But we can get away with fudging things here, if need
@@ -395,20 +395,18 @@ nsDeviceContext::CreateRenderingContext(
     nsRefPtr<nsRenderingContext> pContext = new nsRenderingContext();
 
     RefPtr<gfx::DrawTarget> dt =
       gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(printingSurface,
                                                              gfx::IntSize(mWidth, mHeight));
 
     pContext->Init(this, dt);
     pContext->Scale(mPrintingScale, mPrintingScale);
-    aContext = pContext;
-    NS_ADDREF(aContext);
 
-    return NS_OK;
+    return pContext.forget();
 }
 
 nsresult
 nsDeviceContext::GetDepth(uint32_t& aDepth)
 {
     if (mDepth == 0) {
         nsCOMPtr<nsIScreen> primaryScreen;
         mScreenManager->GetPrimaryScreen(getter_AddRefs(primaryScreen));
--- a/gfx/src/nsDeviceContext.h
+++ b/gfx/src/nsDeviceContext.h
@@ -52,20 +52,20 @@ public:
      * @param aDevSpec the specification of the printing device
      * @return error status
      */
     nsresult InitForPrinting(nsIDeviceContextSpec *aDevSpec);
 
     /**
      * 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
+     *
+     * @return the new rendering context (guaranteed to be non-null)
      */
-    nsresult CreateRenderingContext(nsRenderingContext *&aContext);
+    already_AddRefed<nsRenderingContext> CreateRenderingContext();
 
     /**
      * Gets the number of app units in one CSS pixel; this number is global,
      * not unique to each device context.
      */
     static int32_t AppUnitsPerCSSPixel() { return mozilla::AppUnitsPerCSSPixel(); }
 
     /**
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -2902,17 +2902,17 @@ already_AddRefed<nsRenderingContext>
 PresShell::GetReferenceRenderingContext()
 {
   nsDeviceContext* devCtx = mPresContext->DeviceContext();
   nsRefPtr<nsRenderingContext> rc;
   if (mPresContext->IsScreen()) {
     rc = new nsRenderingContext();
     rc->Init(devCtx, gfxPlatform::GetPlatform()->ScreenReferenceSurface());
   } else {
-    devCtx->CreateRenderingContext(*getter_AddRefs(rc));
+    rc = devCtx->CreateRenderingContext();
   }
   return rc.forget();
 }
 
 nsresult
 PresShell::GoToAnchor(const nsAString& aAnchorName, bool aScroll)
 {
   if (!mDocument) {
--- a/layout/generic/nsSimplePageSequenceFrame.cpp
+++ b/layout/generic/nsSimplePageSequenceFrame.cpp
@@ -586,19 +586,18 @@ nsSimplePageSequenceFrame::PrePrintNextP
       nsDeviceContext *dc = PresContext()->DeviceContext();
       PR_PL(("\n"));
       PR_PL(("***************** BeginPage *****************\n"));
       rv = dc->BeginPage();
       NS_ENSURE_SUCCESS(rv, rv);
 
       mCalledBeginPage = true;
       
-      nsRefPtr<nsRenderingContext> renderingContext;
-      dc->CreateRenderingContext(*getter_AddRefs(renderingContext));
-      NS_ENSURE_TRUE(renderingContext, NS_ERROR_OUT_OF_MEMORY);
+      nsRefPtr<nsRenderingContext> renderingContext =
+        dc->CreateRenderingContext();
 
       nsRefPtr<gfxASurface> renderingSurface =
           renderingContext->ThebesContext()->CurrentSurface();
       NS_ENSURE_TRUE(renderingSurface, NS_ERROR_OUT_OF_MEMORY);
 
       for (int32_t i = mCurrentCanvasList.Length() - 1; i >= 0 ; i--) {
         HTMLCanvasElement* canvas = mCurrentCanvasList[i];
         nsIntSize size = canvas->GetSize();
@@ -717,19 +716,18 @@ nsSimplePageSequenceFrame::PrintNextPage
           NS_ENSURE_SUCCESS(rv, rv);
         } else {
           mCalledBeginPage = false;
         }
       }
 
       PR_PL(("SeqFr::PrintNextPage -> %p PageNo: %d", pf, mPageNum));
 
-      nsRefPtr<nsRenderingContext> renderingContext;
-      dc->CreateRenderingContext(*getter_AddRefs(renderingContext));
-      NS_ENSURE_TRUE(renderingContext, NS_ERROR_OUT_OF_MEMORY);
+      nsRefPtr<nsRenderingContext> renderingContext =
+        dc->CreateRenderingContext();
 
       nsRect drawingRect(nsPoint(0, 0), currentPage->GetSize());
       nsRegion drawingRegion(drawingRect);
       nsLayoutUtils::PaintFrame(renderingContext, currentPage,
                                 drawingRegion, NS_RGBA(0,0,0,0),
                                 nsLayoutUtils::PAINT_SYNC_DECODE_IMAGES);
 
       if (mSelectionHeight >= 0 && selectionY < mSelectionHeight) {
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -2260,18 +2260,18 @@ nsPrintEngine::ReflowPrintObject(nsPrint
       // Dump all the frames and view to a a file
       FILE * fd = fopen(filename, "w");
       if (fd) {
         nsIFrame *theRootFrame =
           aPO->mPresShell->FrameManager()->GetRootFrame();
         fprintf(fd, "Title: %s\n", docStr.get());
         fprintf(fd, "URL:   %s\n", urlStr.get());
         fprintf(fd, "--------------- Frames ----------------\n");
-        nsRefPtr<nsRenderingContext> renderingContext;
-        mPrt->mPrintDocDC->CreateRenderingContext(*getter_AddRefs(renderingContext));
+        nsRefPtr<nsRenderingContext> renderingContext =
+          mPrt->mPrintDocDC->CreateRenderingContext();
         RootFrameList(aPO->mPresContext, fd, 0);
         //DumpFrames(fd, aPO->mPresContext, renderingContext, theRootFrame, 0);
         fprintf(fd, "---------------------------------------\n\n");
         fprintf(fd, "--------------- Views From Root Frame----------------\n");
         nsView* v = theRootFrame->GetView();
         if (v) {
           v->List(fd);
         } else {
@@ -2500,18 +2500,18 @@ nsPrintEngine::DoPrint(nsPrintObject * a
       GetDisplayTitleAndURL(aPO, docTitleStr, docURLStr, eDocTitleDefBlank);
 
       if (nsIPrintSettings::kRangeSelection == printRangeType) {
         CloneSelection(aPO->mDocument->GetOriginalDocument(), aPO->mDocument);
 
         poPresContext->SetIsRenderingOnlySelection(true);
         // temporarily creating rendering context
         // which is needed to find the selection frames
-        nsRefPtr<nsRenderingContext> rc;
-        mPrt->mPrintDC->CreateRenderingContext(*getter_AddRefs(rc));
+        nsRefPtr<nsRenderingContext> rc =
+          mPrt->mPrintDC->CreateRenderingContext();
 
         // find the starting and ending page numbers
         // via the selection
         nsIFrame* startFrame;
         nsIFrame* endFrame;
         int32_t   startPageNum;
         int32_t   endPageNum;
         nsRect    startRect;
@@ -3806,18 +3806,18 @@ void DumpLayoutData(char*              a
   char filename[256];
   sprintf(filename, "print_dump_layout_%d.txt", gDumpLOFileNameCnt++);
   FILE * fd = aFD?aFD:fopen(filename, "w");
   if (fd) {
     fprintf(fd, "Title: %s\n", aTitleStr?aTitleStr:"");
     fprintf(fd, "URL:   %s\n", aURLStr?aURLStr:"");
     fprintf(fd, "--------------- Frames ----------------\n");
     fprintf(fd, "--------------- Frames ----------------\n");
-    nsRefPtr<nsRenderingContext> renderingContext;
-    aDC->CreateRenderingContext(*getter_AddRefs(renderingContext));
+    nsRefPtr<nsRenderingContext> renderingContext =
+      aDC->CreateRenderingContext();
     RootFrameList(aPresContext, fd, 0);
     //DumpFrames(fd, aPresContext, renderingContext, aRootFrame, 0);
     fprintf(fd, "---------------------------------------\n\n");
     fprintf(fd, "--------------- Views From Root Frame----------------\n");
     nsView* v = aRootFrame->GetView();
     if (v) {
       v->List(fd);
     } else {