Bug 1317295 - Record PrintTarget::GetReferenceDrawTarget DrawTargets. r=edwin, a=jcristau
authorJonathan Watt <jwatt@jwatt.org>
Tue, 15 Nov 2016 23:01:41 +0000
changeset 352617 1ceec185789fca53a2eee3dba0da59ce34ff601c
parent 352616 fb302a466f46b7798eb403756586fc51b7d2cd3e
child 352618 00d4e15490f311616d5c6eb9299ff4201e97a218
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedwin, jcristau
bugs1317295
milestone52.0a2
Bug 1317295 - Record PrintTarget::GetReferenceDrawTarget DrawTargets. r=edwin, a=jcristau
gfx/src/nsDeviceContext.cpp
gfx/thebes/PrintTarget.cpp
gfx/thebes/PrintTarget.h
gfx/thebes/PrintTargetThebes.cpp
gfx/thebes/PrintTargetThebes.h
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -361,17 +361,17 @@ nsDeviceContext::CreateRenderingContextC
 #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;
     if (aWantReferenceContext) {
-      dt = printingTarget->GetReferenceDrawTarget();
+      dt = printingTarget->GetReferenceDrawTarget(recorder);
     } 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 "
--- a/gfx/thebes/PrintTarget.cpp
+++ b/gfx/thebes/PrintTarget.cpp
@@ -79,17 +79,17 @@ PrintTarget::MakeDrawTarget(const IntSiz
       return nullptr;
     }
   }
 
   return dt.forget();
 }
 
 already_AddRefed<DrawTarget>
-PrintTarget::GetReferenceDrawTarget()
+PrintTarget::GetReferenceDrawTarget(DrawEventRecorder* aRecorder)
 {
   if (!mRefDT) {
     IntSize size(1, 1);
 
     cairo_surface_t* surface =
       cairo_surface_create_similar(mCairoSurface,
                                    cairo_surface_get_content(mCairoSurface),
                                    size.width, size.height);
@@ -103,16 +103,23 @@ PrintTarget::GetReferenceDrawTarget()
 
     // The DT addrefs the surface, so we need drop our own reference to it:
     cairo_surface_destroy(surface);
 
     if (!dt || !dt->IsValid()) {
       return nullptr;
     }
 
+    if (aRecorder) {
+      dt = CreateRecordingDrawTarget(aRecorder, dt);
+      if (!dt || !dt->IsValid()) {
+        return nullptr;
+      }
+    }
+
     mRefDT = dt.forget();
   }
   return do_AddRef(mRefDT);
 }
 
 already_AddRefed<DrawTarget>
 PrintTarget::CreateRecordingDrawTarget(DrawEventRecorder* aRecorder,
                                        DrawTarget* aDrawTarget)
--- a/gfx/thebes/PrintTarget.h
+++ b/gfx/thebes/PrintTarget.h
@@ -126,17 +126,17 @@ public:
                  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.
    */
-  virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget();
+  virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget(DrawEventRecorder* aRecorder);
 
 protected:
 
   // Only created via subclass's constructors
   explicit PrintTarget(cairo_surface_t* aCairoSurface, const IntSize& aSize);
 
   // Protected because we're refcounted
   virtual ~PrintTarget();
--- a/gfx/thebes/PrintTargetThebes.cpp
+++ b/gfx/thebes/PrintTargetThebes.cpp
@@ -52,24 +52,30 @@ PrintTargetThebes::MakeDrawTarget(const 
       return nullptr;
     }
   }
 
   return dt.forget();
 }
 
 already_AddRefed<DrawTarget>
-PrintTargetThebes::GetReferenceDrawTarget()
+PrintTargetThebes::GetReferenceDrawTarget(DrawEventRecorder* aRecorder)
 {
   if (!mRefDT) {
     RefPtr<gfx::DrawTarget> dt =
       gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(mGfxSurface, mSize);
     if (!dt || !dt->IsValid()) {
       return nullptr;
     }
+    if (aRecorder) {
+      dt = CreateRecordingDrawTarget(aRecorder, dt);
+      if (!dt || !dt->IsValid()) {
+        return nullptr;
+      }
+    }
     mRefDT = dt->CreateSimilarDrawTarget(IntSize(1,1), dt->GetFormat());
   }
   return do_AddRef(mRefDT);
 }
 
 nsresult
 PrintTargetThebes::BeginPrinting(const nsAString& aTitle,
                                  const nsAString& aPrintToFileName)
--- a/gfx/thebes/PrintTargetThebes.h
+++ b/gfx/thebes/PrintTargetThebes.h
@@ -36,17 +36,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() final;
+  virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget(DrawEventRecorder* aRecorder) final;
 
 private:
 
   // Only created via CreateOrNull
   explicit PrintTargetThebes(gfxASurface* aSurface);
 
   RefPtr<gfxASurface> mGfxSurface;
 };