Bug 1280324, part 2 - Add a CreateReferenceRenderingContext method to nsDeviceContext. r=edwin
authorJonathan Watt <jwatt@jwatt.org>
Thu, 27 Oct 2016 19:24:12 +0100
changeset 346890 620893e272d615af3192524b9ca959890f9a2c24
parent 346889 bcb5f7b49427929996c0b8425cb9220f0c07e7bc
child 346891 20f8aeb59ada4e5165ea585c490c62c0e5d4f2f3
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin
bugs1280324
milestone52.0a1
Bug 1280324, part 2 - Add a CreateReferenceRenderingContext method to nsDeviceContext. r=edwin
gfx/src/nsDeviceContext.cpp
gfx/src/nsDeviceContext.h
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -327,16 +327,28 @@ nsDeviceContext::Init(nsIWidget *aWidget
 
     return rv;
 }
 
 // XXX This is only for printing. We should make that obvious in the name.
 already_AddRefed<gfxContext>
 nsDeviceContext::CreateRenderingContext()
 {
+  return CreateRenderingContextCommon(/* not a reference context */ false);
+}
+
+already_AddRefed<gfxContext>
+nsDeviceContext::CreateReferenceRenderingContext()
+{
+  return CreateRenderingContextCommon(/* a reference context */ true);
+}
+
+already_AddRefed<gfxContext>
+nsDeviceContext::CreateRenderingContextCommon(bool aWantReferenceContext)
+{
     MOZ_ASSERT(IsPrinterContext());
     MOZ_ASSERT(mWidth > 0 && mHeight > 0);
 
     RefPtr<PrintTarget> printingTarget = mPrintTarget;
 #ifdef XP_MACOSX
     // CreateRenderingContext() can be called (on reflow) after EndPage()
     // but before BeginPage().  On OS X (and only there) mPrintTarget
     // will in this case be null, because OS X printing surfaces are
@@ -347,18 +359,23 @@ nsDeviceContext::CreateRenderingContext(
       printingTarget = mCachedPrintTarget;
     }
 #endif
 
     // This will usually be null, depending on the pref print.print_via_parent.
     RefPtr<DrawEventRecorder> recorder;
     mDeviceContextSpec->GetDrawEventRecorder(getter_AddRefs(recorder));
 
-    RefPtr<gfx::DrawTarget> dt =
-      printingTarget->MakeDrawTarget(gfx::IntSize(mWidth, mHeight), recorder);
+    RefPtr<gfx::DrawTarget> dt;
+    if (aWantReferenceContext) {
+      dt = printingTarget->GetReferenceDrawTarget();
+    } else {
+      dt = printingTarget->MakeDrawTarget(gfx::IntSize(mWidth, mHeight), recorder);
+    }
+
     if (!dt || !dt->IsValid()) {
       gfxCriticalNote
         << "Failed to create draw target in device context sized "
         << mWidth << "x" << mHeight << " and pointers "
         << hexa(mPrintTarget) << " and " << hexa(printingTarget);
       return nullptr;
     }
 
--- a/gfx/src/nsDeviceContext.h
+++ b/gfx/src/nsDeviceContext.h
@@ -66,16 +66,24 @@ public:
      * Create a rendering context and initialize it.  Only call this
      * method on device contexts that were initialized for printing.
      *
      * @return the new rendering context (guaranteed to be non-null)
      */
     already_AddRefed<gfxContext> CreateRenderingContext();
 
     /**
+     * Create a reference rendering context and initialize it.  Only call this
+     * method on device contexts that were initialized for printing.
+     *
+     * @return the new rendering context.
+     */
+    already_AddRefed<gfxContext> CreateReferenceRenderingContext();
+
+    /**
      * 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(); }
 
     /**
      * Gets the number of app units in one device pixel; this number
      * is usually a factor of AppUnitsPerCSSPixel(), although that is
@@ -257,16 +265,23 @@ public:
     bool IsPrinterContext();
 
     mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale();
 
 private:
     // Private destructor, to discourage deletion outside of Release():
     ~nsDeviceContext();
 
+    /**
+     * Implementation shared by CreateRenderingContext and
+     * CreateReferenceRenderingContext.
+     */
+    already_AddRefed<gfxContext>
+    CreateRenderingContextCommon(bool aWantReferenceContext);
+
     void SetDPI(double* aScale = nullptr);
     void ComputeClientRectUsingScreen(nsRect *outRect);
     void ComputeFullAreaUsingScreen(nsRect *outRect);
     void FindScreen(nsIScreen **outScreen);
 
     // Return false if the surface is not right
     bool CalcPrintingSize();
     void UpdateAppUnitsForFullZoom();