Bug 1435286 - Stop recording draw events for reference DrawTargets returned from PrintTarget. r=bobowen
authorJonathan Watt <jwatt@jwatt.org>
Thu, 18 Jan 2018 12:45:18 +0000
changeset 402305 2ec583a00c078700add6a3615f6b6af12756695c
parent 402304 f63842f2fce7a5378df739c66da10a1053dc59de
child 402306 9e42baec7ea6e7a10f4f47e9ed070be60ba9a65d
push id33377
push usernerli@mozilla.com
push dateSat, 03 Feb 2018 09:53:15 +0000
treeherdermozilla-central@92b6195a9367 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1435286
milestone60.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 1435286 - Stop recording draw events for reference DrawTargets returned from PrintTarget. r=bobowen MozReview-Commit-ID: 1cE71hBCGx5
gfx/src/nsDeviceContext.cpp
gfx/thebes/PrintTarget.cpp
gfx/thebes/PrintTarget.h
gfx/thebes/PrintTargetCG.h
gfx/thebes/PrintTargetCG.mm
gfx/thebes/PrintTargetEMF.cpp
gfx/thebes/PrintTargetEMF.h
gfx/thebes/PrintTargetSkPDF.cpp
gfx/thebes/PrintTargetSkPDF.h
gfx/thebes/PrintTargetThebes.cpp
gfx/thebes/PrintTargetThebes.h
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -377,24 +377,23 @@ nsDeviceContext::CreateReferenceRenderin
 }
 
 already_AddRefed<gfxContext>
 nsDeviceContext::CreateRenderingContextCommon(bool aWantReferenceContext)
 {
     MOZ_ASSERT(IsPrinterContext());
     MOZ_ASSERT(mWidth > 0 && mHeight > 0);
 
-    // 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;
     if (aWantReferenceContext) {
-      dt = mPrintTarget->GetReferenceDrawTarget(recorder);
+      dt = mPrintTarget->GetReferenceDrawTarget();
     } else {
+      // This will be null if e10s is disabled or print.print_via_parent=false.
+      RefPtr<DrawEventRecorder> recorder;
+      mDeviceContextSpec->GetDrawEventRecorder(getter_AddRefs(recorder));
       dt = mPrintTarget->MakeDrawTarget(gfx::IntSize(mWidth, mHeight), recorder);
     }
 
     if (!dt || !dt->IsValid()) {
       gfxCriticalNote
         << "Failed to create draw target in device context sized "
         << mWidth << "x" << mHeight << " and pointer "
         << hexa(mPrintTarget);
--- a/gfx/thebes/PrintTarget.cpp
+++ b/gfx/thebes/PrintTarget.cpp
@@ -27,17 +27,16 @@ namespace mozilla {
 namespace gfx {
 
 PrintTarget::PrintTarget(cairo_surface_t* aCairoSurface, const IntSize& aSize)
   : mCairoSurface(aCairoSurface)
   , mSize(aSize)
   , mIsFinished(false)
 #ifdef DEBUG
   , mHasActivePage(false)
-  , mRecorder(nullptr)
 #endif
 
 {
 #if 0
   // aCairoSurface is null when our PrintTargetThebes subclass's ctor calls us.
   // Once PrintTargetThebes is removed, enable this assertion.
   MOZ_ASSERT(aCairoSurface && !cairo_surface_status(aCairoSurface),
              "CreateOrNull factory methods should not call us without a "
@@ -94,17 +93,17 @@ PrintTarget::MakeDrawTarget(const IntSiz
       return nullptr;
     }
   }
 
   return dt.forget();
 }
 
 already_AddRefed<DrawTarget>
-PrintTarget::GetReferenceDrawTarget(DrawEventRecorder* aRecorder)
+PrintTarget::GetReferenceDrawTarget()
 {
   if (!mRefDT) {
     const IntSize size(1, 1);
 
     cairo_surface_t* similar;
     switch (cairo_surface_get_type(mCairoSurface)) {
 #ifdef CAIRO_HAS_WIN32_SURFACE
     case CAIRO_SURFACE_TYPE_WIN32:
@@ -138,37 +137,16 @@ PrintTarget::GetReferenceDrawTarget(Draw
     cairo_surface_destroy(similar);
 
     if (!dt || !dt->IsValid()) {
       return nullptr;
     }
     mRefDT = dt.forget();
   }
 
-  if (aRecorder) {
-    if (!mRecordingRefDT) {
-      RefPtr<DrawTarget> dt = CreateWrapAndRecordDrawTarget(aRecorder, mRefDT);
-      if (!dt || !dt->IsValid()) {
-        return nullptr;
-      }
-      mRecordingRefDT = dt.forget();
-#ifdef DEBUG
-      mRecorder = aRecorder;
-#endif
-    }
-#ifdef DEBUG
-    else {
-      MOZ_ASSERT(aRecorder == mRecorder,
-                 "Caching mRecordingRefDT assumes the aRecorder is an invariant");
-    }
-#endif
-
-    return do_AddRef(mRecordingRefDT);
-  }
-
   return do_AddRef(mRefDT);
 }
 
 /* static */
 void
 PrintTarget::AdjustPrintJobNameForIPP(const nsAString& aJobName,
                                       nsCString& aAdjustedJobName)
 {
--- a/gfx/thebes/PrintTarget.h
+++ b/gfx/thebes/PrintTarget.h
@@ -129,20 +129,19 @@ public:
    */
   virtual already_AddRefed<DrawTarget>
   MakeDrawTarget(const IntSize& aSize,
                  DrawEventRecorder* aRecorder = nullptr);
 
   /**
    * Returns a reference DrawTarget. Unlike MakeDrawTarget, this method is not
    * restricted to being called between BeginPage()/EndPage() calls, and the
-   * returned DrawTarget it is still valid to use after EndPage() has been
-   * called.
+   * returned DrawTarget is still valid to use after EndPage() has been called.
    */
-  virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget(DrawEventRecorder* aRecorder);
+  virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget();
 
   /**
    * If IsSyncPagePrinting returns true, then a user can assume the content of
    * a page was already printed after EndPage().
    * If IsSyncPagePrinting returns false, then a user should register a
    * callback function using RegisterPageDoneCallback to receive page print
    * done notifications.
    */
@@ -165,28 +164,20 @@ protected:
 
   static already_AddRefed<DrawTarget>
   CreateWrapAndRecordDrawTarget(DrawEventRecorder* aRecorder,
                                 DrawTarget* aDrawTarget);
 
   cairo_surface_t* mCairoSurface;
   RefPtr<DrawTarget> mRefDT; // reference DT
 
-  // Early on during printing we expect to be called without a recorder in
-  // order to gather metrics for reflow.  However, in a content process, once
-  // we go on to paint we then expect to be called with a recorder.  Hence why
-  // we have this separate recording reference DrawTarget (which wraps mRefDT).
-  RefPtr<DrawTarget> mRecordingRefDT;
-
   IntSize mSize;
   bool mIsFinished;
 #ifdef DEBUG
   bool mHasActivePage;
-  // owned by mRecordingRefDT, so kept alive for our entire lifetime if set:
-  DrawEventRecorder* mRecorder;
 #endif
 
   PageDoneCallback mPageDoneCallback;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
--- a/gfx/thebes/PrintTargetCG.h
+++ b/gfx/thebes/PrintTargetCG.h
@@ -29,17 +29,17 @@ public:
                                  int32_t aStartPage,
                                  int32_t aEndPage) final override;
   virtual nsresult EndPrinting() final override;
   virtual nsresult AbortPrinting() final override;
   virtual nsresult BeginPage() final override;
   virtual nsresult EndPage() final override;
 
   virtual already_AddRefed<DrawTarget>
-  GetReferenceDrawTarget(DrawEventRecorder* aRecorder) final override;
+  GetReferenceDrawTarget() final override;
 
 private:
   PrintTargetCG(PMPrintSession aPrintSession,
                 PMPageFormat aPageFormat,
                 PMPrintSettings aPrintSettings,
                 const IntSize& aSize);
   ~PrintTargetCG();
 
--- a/gfx/thebes/PrintTargetCG.mm
+++ b/gfx/thebes/PrintTargetCG.mm
@@ -60,17 +60,17 @@ PrintTargetCG::CreateOrNull(PMPrintSessi
 
 static size_t
 PutBytesNull(void* info, const void* buffer, size_t count)
 {
   return count;
 }
 
 already_AddRefed<DrawTarget>
-PrintTargetCG::GetReferenceDrawTarget(DrawEventRecorder* aRecorder)
+PrintTargetCG::GetReferenceDrawTarget()
 {
   if (!mRefDT) {
     const IntSize size(1, 1);
 
     CGDataConsumerCallbacks callbacks = {PutBytesNull, nullptr};
     CGDataConsumerRef consumer = CGDataConsumerCreate(nullptr, &callbacks);
     CGContextRef pdfContext = CGPDFContextCreate(consumer, nullptr, nullptr);
     CGDataConsumerRelease(consumer);
@@ -92,37 +92,16 @@ PrintTargetCG::GetReferenceDrawTarget(Dr
     cairo_surface_destroy(similar);
 
     if (!dt || !dt->IsValid()) {
       return nullptr;
     }
     mRefDT = dt.forget();
   }
 
-  if (aRecorder) {
-    if (!mRecordingRefDT) {
-      RefPtr<DrawTarget> dt = CreateWrapAndRecordDrawTarget(aRecorder, mRefDT);
-      if (!dt || !dt->IsValid()) {
-        return nullptr;
-      }
-      mRecordingRefDT = dt.forget();
-#ifdef DEBUG
-      mRecorder = aRecorder;
-#endif
-    }
-#ifdef DEBUG
-    else {
-      MOZ_ASSERT(aRecorder == mRecorder,
-                 "Caching mRecordingRefDT assumes the aRecorder is an invariant");
-    }
-#endif
-
-    return do_AddRef(mRecordingRefDT);
-  }
-
   return do_AddRef(mRefDT);
 }
 
 nsresult
 PrintTargetCG::BeginPrinting(const nsAString& aTitle,
                              const nsAString& aPrintToFileName,
                              int32_t aStartPage,
                              int32_t aEndPage)
--- a/gfx/thebes/PrintTargetEMF.cpp
+++ b/gfx/thebes/PrintTargetEMF.cpp
@@ -153,25 +153,25 @@ already_AddRefed<DrawTarget>
 PrintTargetEMF::MakeDrawTarget(const IntSize& aSize,
                                DrawEventRecorder* aRecorder)
 {
   MOZ_ASSERT(!mChannelBroken);
   return mTargetForCurrentPage->MakeDrawTarget(aSize, aRecorder);
 }
 
 already_AddRefed<DrawTarget>
-PrintTargetEMF::GetReferenceDrawTarget(DrawEventRecorder* aRecorder)
+PrintTargetEMF::GetReferenceDrawTarget()
 {
   if (!mRefTarget) {
     auto dummy = MakeUnique<SkNullWStream>();
     mRefTarget = PrintTargetSkPDF::CreateOrNull(Move(dummy), mSize);
   }
 
   if (!mRefDT) {
-    mRefDT = mRefTarget->GetReferenceDrawTarget(aRecorder);
+    mRefDT = mRefTarget->GetReferenceDrawTarget();
   }
 
   return mRefDT.forget();
 }
 
 void
 PrintTargetEMF::ConvertToEMFDone(const nsresult& aResult,
                                  mozilla::ipc::Shmem&& aEMF)
--- a/gfx/thebes/PrintTargetEMF.h
+++ b/gfx/thebes/PrintTargetEMF.h
@@ -47,17 +47,17 @@ public:
   nsresult BeginPage() final override;
   nsresult EndPage() final override;
 
   already_AddRefed<DrawTarget>
   MakeDrawTarget(const IntSize& aSize,
                  DrawEventRecorder* aRecorder = nullptr) final override;
 
   already_AddRefed<DrawTarget>
-  GetReferenceDrawTarget(DrawEventRecorder* aRecorder) final override;
+  GetReferenceDrawTarget() final override;
 
   void ConvertToEMFDone(const nsresult& aResult, mozilla::ipc::Shmem&& aEMF);
   bool IsSyncPagePrinting() const final { return false; }
   void ChannelIsBroken() { mChannelBroken = true; }
 
 private:
   PrintTargetEMF(HDC aDC, const IntSize& aSize);
   ~PrintTargetEMF() override;
--- a/gfx/thebes/PrintTargetSkPDF.cpp
+++ b/gfx/thebes/PrintTargetSkPDF.cpp
@@ -117,17 +117,17 @@ PrintTargetSkPDF::MakeDrawTarget(const I
   if (!mPageDT) {
     mPageCanvas = nullptr;
     return nullptr;
   }
   return do_AddRef(mPageDT);
 }
 
 already_AddRefed<DrawTarget>
-PrintTargetSkPDF::GetReferenceDrawTarget(DrawEventRecorder* aRecorder)
+PrintTargetSkPDF::GetReferenceDrawTarget()
 {
   if (!mRefDT) {
     SkDocument::PDFMetadata metadata;
     // SkDocument stores a non-owning raw pointer to aStream
     mRefPDFDoc = SkDocument::MakePDF(&mRefOStream,
                                      SK_ScalarDefaultRasterDPI,
                                      metadata, nullptr, true);
     if (!mRefPDFDoc) {
@@ -140,34 +140,13 @@ PrintTargetSkPDF::GetReferenceDrawTarget
     RefPtr<DrawTarget> dt =
       Factory::CreateDrawTargetWithSkCanvas(mRefCanvas);
     if (!dt) {
       return nullptr;
     }
     mRefDT = dt.forget();
   }
 
-  if (aRecorder) {
-    if (!mRecordingRefDT) {
-      RefPtr<DrawTarget> dt = CreateWrapAndRecordDrawTarget(aRecorder, mRefDT);
-      if (!dt || !dt->IsValid()) {
-        return nullptr;
-      }
-      mRecordingRefDT = dt.forget();
-#ifdef DEBUG
-      mRecorder = aRecorder;
-#endif
-    }
-#ifdef DEBUG
-    else {
-      MOZ_ASSERT(aRecorder == mRecorder,
-                 "Caching mRecordingRefDT assumes the aRecorder is an invariant");
-    }
-#endif
-
-    return do_AddRef(mRecordingRefDT);
-  }
-
   return do_AddRef(mRefDT);
 }
 
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/thebes/PrintTargetSkPDF.h
+++ b/gfx/thebes/PrintTargetSkPDF.h
@@ -39,17 +39,17 @@ public:
   virtual nsresult BeginPage() override;
   virtual nsresult EndPage() override;
 
   virtual already_AddRefed<DrawTarget>
   MakeDrawTarget(const IntSize& aSize,
                  DrawEventRecorder* aRecorder = nullptr) final override;
 
   virtual already_AddRefed<DrawTarget>
-  GetReferenceDrawTarget(DrawEventRecorder* aRecorder) override final;
+  GetReferenceDrawTarget() override final;
 
 private:
   PrintTargetSkPDF(const IntSize& aSize,
                    UniquePtr<SkWStream> aStream);
   virtual ~PrintTargetSkPDF();
 
   // Do not hand out references to this object.  It holds a non-owning
   // reference to mOStreame, so must not outlive mOStream.
--- a/gfx/thebes/PrintTargetThebes.cpp
+++ b/gfx/thebes/PrintTargetThebes.cpp
@@ -52,48 +52,27 @@ PrintTargetThebes::MakeDrawTarget(const 
       return nullptr;
     }
   }
 
   return dt.forget();
 }
 
 already_AddRefed<DrawTarget>
-PrintTargetThebes::GetReferenceDrawTarget(DrawEventRecorder* aRecorder)
+PrintTargetThebes::GetReferenceDrawTarget()
 {
   if (!mRefDT) {
     RefPtr<gfx::DrawTarget> dt =
       gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(mGfxSurface, mSize);
     if (!dt || !dt->IsValid()) {
       return nullptr;
     }
     mRefDT = dt->CreateSimilarDrawTarget(IntSize(1,1), dt->GetFormat());
   }
 
-  if (aRecorder) {
-    if (!mRecordingRefDT) {
-      RefPtr<DrawTarget> dt = CreateWrapAndRecordDrawTarget(aRecorder, mRefDT);
-      if (!dt || !dt->IsValid()) {
-        return nullptr;
-      }
-      mRecordingRefDT = dt.forget();
-#ifdef DEBUG
-      mRecorder = aRecorder;
-#endif
-    }
-#ifdef DEBUG
-    else {
-      MOZ_ASSERT(aRecorder == mRecorder,
-                 "Caching mRecordingRefDT assumes the aRecorder is an invariant");
-    }
-#endif
-
-    return do_AddRef(mRecordingRefDT);
-  }
-
   return do_AddRef(mRefDT);
 }
 
 nsresult
 PrintTargetThebes::BeginPrinting(const nsAString& aTitle,
                                  const nsAString& aPrintToFileName,
                                  int32_t aStartPage,
                                  int32_t aEndPage)
--- a/gfx/thebes/PrintTargetThebes.h
+++ b/gfx/thebes/PrintTargetThebes.h
@@ -38,17 +38,17 @@ public:
   virtual nsresult BeginPage() override;
   virtual nsresult EndPage() override;
   virtual void Finish() override;
 
   virtual already_AddRefed<DrawTarget>
   MakeDrawTarget(const IntSize& aSize,
                  DrawEventRecorder* aRecorder = nullptr) override;
 
-  virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget(DrawEventRecorder* aRecorder) final override;
+  virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget() final override;
 
 private:
 
   // Only created via CreateOrNull
   explicit PrintTargetThebes(gfxASurface* aSurface);
 
   RefPtr<gfxASurface> mGfxSurface;
 };