Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/thebes/PrintTargetThebes.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/. */
5
6
#include "PrintTargetThebes.h"
7
8
#include "gfxASurface.h"
9
#include "gfxPlatform.h"
10
#include "mozilla/gfx/Logging.h"
11
12
namespace mozilla {
13
namespace gfx {
14
15
/* static */ already_AddRefed<PrintTargetThebes>
16
PrintTargetThebes::CreateOrNull(gfxASurface* aSurface)
17
0
{
18
0
  MOZ_ASSERT(aSurface);
19
0
20
0
  if (!aSurface || aSurface->CairoStatus()) {
21
0
    return nullptr;
22
0
  }
23
0
24
0
  RefPtr<PrintTargetThebes> target = new PrintTargetThebes(aSurface);
25
0
26
0
  return target.forget();
27
0
}
28
29
PrintTargetThebes::PrintTargetThebes(gfxASurface* aSurface)
30
  : PrintTarget(nullptr, aSurface->GetSize())
31
  , mGfxSurface(aSurface)
32
0
{
33
0
}
34
35
already_AddRefed<DrawTarget>
36
PrintTargetThebes::MakeDrawTarget(const IntSize& aSize,
37
                                  DrawEventRecorder* aRecorder)
38
0
{
39
0
  // This should not be called outside of BeginPage()/EndPage() calls since
40
0
  // some backends can only provide a valid DrawTarget at that time.
41
0
  MOZ_ASSERT(mHasActivePage, "We can't guarantee a valid DrawTarget");
42
0
43
0
  RefPtr<gfx::DrawTarget> dt =
44
0
    gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(mGfxSurface, aSize);
45
0
  if (!dt || !dt->IsValid()) {
46
0
    return nullptr;
47
0
  }
48
0
49
0
  if (aRecorder) {
50
0
    dt = CreateWrapAndRecordDrawTarget(aRecorder, dt);
51
0
    if (!dt || !dt->IsValid()) {
52
0
      return nullptr;
53
0
    }
54
0
  }
55
0
56
0
  return dt.forget();
57
0
}
58
59
already_AddRefed<DrawTarget>
60
PrintTargetThebes::GetReferenceDrawTarget()
61
0
{
62
0
  if (!mRefDT) {
63
0
    RefPtr<gfx::DrawTarget> dt =
64
0
      gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(mGfxSurface, mSize);
65
0
    if (!dt || !dt->IsValid()) {
66
0
      return nullptr;
67
0
    }
68
0
    mRefDT = dt->CreateSimilarDrawTarget(IntSize(1,1), dt->GetFormat());
69
0
  }
70
0
71
0
  return do_AddRef(mRefDT);
72
0
}
73
74
nsresult
75
PrintTargetThebes::BeginPrinting(const nsAString& aTitle,
76
                                 const nsAString& aPrintToFileName,
77
                                 int32_t aStartPage,
78
                                 int32_t aEndPage)
79
0
{
80
0
  return mGfxSurface->BeginPrinting(aTitle, aPrintToFileName);
81
0
}
82
83
nsresult
84
PrintTargetThebes::EndPrinting()
85
0
{
86
0
  return mGfxSurface->EndPrinting();
87
0
}
88
89
nsresult
90
PrintTargetThebes::AbortPrinting()
91
0
{
92
#ifdef DEBUG
93
  mHasActivePage = false;
94
#endif
95
  return mGfxSurface->AbortPrinting();
96
0
}
97
98
nsresult
99
PrintTargetThebes::BeginPage()
100
0
{
101
#ifdef DEBUG
102
  mHasActivePage = true;
103
#endif
104
  return mGfxSurface->BeginPage();
105
0
}
106
107
nsresult
108
PrintTargetThebes::EndPage()
109
0
{
110
#ifdef DEBUG
111
  mHasActivePage = false;
112
#endif
113
  return mGfxSurface->EndPage();
114
0
}
115
116
void
117
PrintTargetThebes::Finish()
118
0
{
119
0
  return mGfxSurface->Finish();
120
0
}
121
122
} // namespace gfx
123
} // namespace mozilla