2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2016-06-16 19:26:59 +03:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "PrintTargetThebes.h"
|
|
|
|
|
|
|
|
#include "gfxASurface.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "mozilla/gfx/Logging.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<PrintTargetThebes> PrintTargetThebes::CreateOrNull(
|
|
|
|
gfxASurface* aSurface) {
|
2016-06-16 19:26:59 +03:00
|
|
|
MOZ_ASSERT(aSurface);
|
|
|
|
|
|
|
|
if (!aSurface || aSurface->CairoStatus()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<PrintTargetThebes> target = new PrintTargetThebes(aSurface);
|
|
|
|
|
|
|
|
return target.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintTargetThebes::PrintTargetThebes(gfxASurface* aSurface)
|
|
|
|
: PrintTarget(nullptr, aSurface->GetSize()), mGfxSurface(aSurface) {}
|
|
|
|
|
|
|
|
already_AddRefed<DrawTarget> PrintTargetThebes::MakeDrawTarget(
|
|
|
|
const IntSize& aSize, DrawEventRecorder* aRecorder) {
|
2016-10-27 21:25:02 +03:00
|
|
|
// This should not be called outside of BeginPage()/EndPage() calls since
|
|
|
|
// some backends can only provide a valid DrawTarget at that time.
|
|
|
|
MOZ_ASSERT(mHasActivePage, "We can't guarantee a valid DrawTarget");
|
|
|
|
|
2016-06-16 19:26:59 +03:00
|
|
|
RefPtr<gfx::DrawTarget> dt =
|
2019-06-05 15:46:19 +03:00
|
|
|
gfxPlatform::CreateDrawTargetForSurface(mGfxSurface, aSize);
|
2016-06-16 19:26:59 +03:00
|
|
|
if (!dt || !dt->IsValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-06-16 19:28:50 +03:00
|
|
|
if (aRecorder) {
|
2017-06-12 23:52:29 +03:00
|
|
|
dt = CreateWrapAndRecordDrawTarget(aRecorder, dt);
|
2016-06-16 19:28:50 +03:00
|
|
|
if (!dt || !dt->IsValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 19:26:59 +03:00
|
|
|
return dt.forget();
|
|
|
|
}
|
|
|
|
|
2018-01-18 15:45:18 +03:00
|
|
|
already_AddRefed<DrawTarget> PrintTargetThebes::GetReferenceDrawTarget() {
|
2016-10-27 21:24:12 +03:00
|
|
|
if (!mRefDT) {
|
|
|
|
RefPtr<gfx::DrawTarget> dt =
|
2019-06-05 15:46:19 +03:00
|
|
|
gfxPlatform::CreateDrawTargetForSurface(mGfxSurface, mSize);
|
2016-10-27 21:24:12 +03:00
|
|
|
if (!dt || !dt->IsValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-03-21 12:36:08 +03:00
|
|
|
mRefDT = dt->CreateSimilarDrawTarget(IntSize(1, 1), dt->GetFormat());
|
|
|
|
}
|
|
|
|
|
2016-10-27 21:24:12 +03:00
|
|
|
return do_AddRef(mRefDT);
|
|
|
|
}
|
|
|
|
|
2016-06-16 19:26:59 +03:00
|
|
|
nsresult PrintTargetThebes::BeginPrinting(const nsAString& aTitle,
|
2016-11-29 10:54:30 +03:00
|
|
|
const nsAString& aPrintToFileName,
|
|
|
|
int32_t aStartPage,
|
|
|
|
int32_t aEndPage) {
|
2016-06-16 19:26:59 +03:00
|
|
|
return mGfxSurface->BeginPrinting(aTitle, aPrintToFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PrintTargetThebes::EndPrinting() { return mGfxSurface->EndPrinting(); }
|
|
|
|
|
|
|
|
nsresult PrintTargetThebes::AbortPrinting() {
|
2016-11-02 15:41:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
mHasActivePage = false;
|
|
|
|
#endif
|
2016-06-16 19:26:59 +03:00
|
|
|
return mGfxSurface->AbortPrinting();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PrintTargetThebes::BeginPage() {
|
2016-11-02 15:41:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
mHasActivePage = true;
|
|
|
|
#endif
|
2016-06-16 19:26:59 +03:00
|
|
|
return mGfxSurface->BeginPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PrintTargetThebes::EndPage() {
|
2016-11-02 15:41:19 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
mHasActivePage = false;
|
|
|
|
#endif
|
2016-06-16 19:26:59 +03:00
|
|
|
return mGfxSurface->EndPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintTargetThebes::Finish() { return mGfxSurface->Finish(); }
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|