зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1280324, part 1 - Add functionality to the PrintTarget sub-classes to return reference DrawTargets. r=edwin
This commit is contained in:
Родитель
4e5a3c052b
Коммит
81c7af4165
|
@ -75,6 +75,36 @@ PrintTarget::MakeDrawTarget(const IntSize& aSize,
|
|||
return dt.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DrawTarget>
|
||||
PrintTarget::GetReferenceDrawTarget()
|
||||
{
|
||||
if (!mRefDT) {
|
||||
IntSize size(1, 1);
|
||||
|
||||
cairo_surface_t* surface =
|
||||
cairo_surface_create_similar(mCairoSurface,
|
||||
cairo_surface_get_content(mCairoSurface),
|
||||
size.width, size.height);
|
||||
|
||||
if (cairo_surface_status(surface)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DrawTarget> dt =
|
||||
Factory::CreateDrawTargetForCairoSurface(surface, size);
|
||||
|
||||
// The DT addrefs the surface, so we need drop our own reference to it:
|
||||
cairo_surface_destroy(surface);
|
||||
|
||||
if (!dt || !dt->IsValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mRefDT = dt.forget();
|
||||
}
|
||||
return do_AddRef(mRefDT);
|
||||
}
|
||||
|
||||
already_AddRefed<DrawTarget>
|
||||
PrintTarget::CreateRecordingDrawTarget(DrawEventRecorder* aRecorder,
|
||||
DrawTarget* aDrawTarget)
|
||||
|
|
|
@ -111,6 +111,14 @@ public:
|
|||
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.
|
||||
*/
|
||||
virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget();
|
||||
|
||||
protected:
|
||||
|
||||
// Only created via subclass's constructors
|
||||
|
@ -124,6 +132,7 @@ protected:
|
|||
DrawTarget* aDrawTarget);
|
||||
|
||||
cairo_surface_t* mCairoSurface;
|
||||
RefPtr<DrawTarget> mRefDT; // reference DT
|
||||
IntSize mSize;
|
||||
bool mIsFinished;
|
||||
};
|
||||
|
|
|
@ -52,6 +52,20 @@ PrintTargetThebes::MakeDrawTarget(const IntSize& aSize,
|
|||
return dt.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DrawTarget>
|
||||
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());
|
||||
}
|
||||
return do_AddRef(mRefDT);
|
||||
}
|
||||
|
||||
nsresult
|
||||
PrintTargetThebes::BeginPrinting(const nsAString& aTitle,
|
||||
const nsAString& aPrintToFileName)
|
||||
|
|
|
@ -41,6 +41,8 @@ public:
|
|||
MakeDrawTarget(const IntSize& aSize,
|
||||
DrawEventRecorder* aRecorder = nullptr) override;
|
||||
|
||||
virtual already_AddRefed<DrawTarget> GetReferenceDrawTarget() final;
|
||||
|
||||
private:
|
||||
|
||||
// Only created via CreateOrNull
|
||||
|
|
Загрузка…
Ссылка в новой задаче