Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / thebes / PrintTargetThebes.cpp
blob466ad7b11912ec5f9e41be7c5a78b6171afd1b55
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "PrintTargetThebes.h"
8 #include "gfxASurface.h"
9 #include "gfxPlatform.h"
10 #include "mozilla/gfx/Logging.h"
12 namespace mozilla::gfx {
14 /* static */
15 already_AddRefed<PrintTargetThebes> PrintTargetThebes::CreateOrNull(
16 gfxASurface* aSurface) {
17 MOZ_ASSERT(aSurface);
19 if (!aSurface || aSurface->CairoStatus()) {
20 return nullptr;
23 RefPtr<PrintTargetThebes> target = new PrintTargetThebes(aSurface);
25 return target.forget();
28 PrintTargetThebes::PrintTargetThebes(gfxASurface* aSurface)
29 : PrintTarget(nullptr, aSurface->GetSize()), mGfxSurface(aSurface) {}
31 already_AddRefed<DrawTarget> PrintTargetThebes::MakeDrawTarget(
32 const IntSize& aSize, DrawEventRecorder* aRecorder) {
33 // This should not be called outside of BeginPage()/EndPage() calls since
34 // some backends can only provide a valid DrawTarget at that time.
35 MOZ_ASSERT(mHasActivePage, "We can't guarantee a valid DrawTarget");
37 RefPtr<gfx::DrawTarget> dt =
38 gfxPlatform::CreateDrawTargetForSurface(mGfxSurface, aSize);
39 if (!dt || !dt->IsValid()) {
40 return nullptr;
43 if (aRecorder) {
44 dt = CreateRecordingDrawTarget(aRecorder, dt);
45 if (!dt || !dt->IsValid()) {
46 return nullptr;
50 return dt.forget();
53 already_AddRefed<DrawTarget> PrintTargetThebes::GetReferenceDrawTarget() {
54 if (!mRefDT) {
55 RefPtr<gfx::DrawTarget> dt =
56 gfxPlatform::CreateDrawTargetForSurface(mGfxSurface, mSize);
57 if (!dt || !dt->IsValid()) {
58 return nullptr;
60 mRefDT = dt->CreateSimilarDrawTarget(IntSize(1, 1), dt->GetFormat());
63 return do_AddRef(mRefDT);
66 nsresult PrintTargetThebes::BeginPrinting(const nsAString& aTitle,
67 const nsAString& aPrintToFileName,
68 int32_t aStartPage,
69 int32_t aEndPage) {
70 return mGfxSurface->BeginPrinting(aTitle, aPrintToFileName);
73 nsresult PrintTargetThebes::EndPrinting() { return mGfxSurface->EndPrinting(); }
75 nsresult PrintTargetThebes::AbortPrinting() {
76 #ifdef DEBUG
77 mHasActivePage = false;
78 #endif
79 return mGfxSurface->AbortPrinting();
82 nsresult PrintTargetThebes::BeginPage(const IntSize& aSizeInPoints) {
83 #ifdef DEBUG
84 mHasActivePage = true;
85 #endif
86 return mGfxSurface->BeginPage();
89 nsresult PrintTargetThebes::EndPage() {
90 #ifdef DEBUG
91 mHasActivePage = false;
92 #endif
93 return mGfxSurface->EndPage();
96 void PrintTargetThebes::Finish() { return mGfxSurface->Finish(); }
98 } // namespace mozilla::gfx