Bug 1317295 - Record PrintTarget::GetReferenceDrawTarget DrawTargets. r=edwin, a=jcristau
--- 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;
};