Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/2d/DrawTargetOffset.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "DrawTargetOffset.h"
8
#include "Logging.h"
9
#include "PathHelpers.h"
10
11
using namespace std;
12
13
namespace mozilla {
14
namespace gfx {
15
16
DrawTargetOffset::DrawTargetOffset()
17
0
{
18
0
}
19
20
bool
21
DrawTargetOffset::Init(DrawTarget *aDrawTarget, IntPoint aOrigin)
22
0
{
23
0
  mDrawTarget = aDrawTarget;
24
0
  mOrigin = aOrigin;
25
0
  mDrawTarget->SetTransform(Matrix::Translation(-mOrigin.x,
26
0
                                                -mOrigin.y));
27
0
  mFormat = mDrawTarget->GetFormat();
28
0
  SetPermitSubpixelAA(IsOpaque(mFormat));
29
0
  return true;
30
0
}
31
32
already_AddRefed<SourceSurface>
33
DrawTargetOffset::Snapshot()
34
0
{
35
0
  return mDrawTarget->Snapshot();
36
0
}
37
38
void
39
DrawTargetOffset::DetachAllSnapshots()
40
0
{}
41
42
// Skip the mClippedOut check since this is only used for Flush() which
43
// should happen even if we're clipped.
44
#define OFFSET_COMMAND(command) \
45
  void \
46
  DrawTargetOffset::command() \
47
0
  { \
48
0
    mDrawTarget->command(); \
49
0
  }
50
#define OFFSET_COMMAND1(command, type1) \
51
  void \
52
  DrawTargetOffset::command(type1 arg1) \
53
0
  { \
54
0
    mDrawTarget->command(arg1); \
55
0
  }
56
#define OFFSET_COMMAND3(command, type1, type2, type3) \
57
  void \
58
  DrawTargetOffset::command(type1 arg1, type2 arg2, type3 arg3) \
59
0
  { \
60
0
    mDrawTarget->command(arg1, arg2, arg3); \
61
0
  }
62
#define OFFSET_COMMAND4(command, type1, type2, type3, type4) \
63
  void \
64
  DrawTargetOffset::command(type1 arg1, type2 arg2, type3 arg3, type4 arg4) \
65
0
  { \
66
0
    mDrawTarget->command(arg1, arg2, arg3, arg4); \
67
0
  }
Unexecuted instantiation: mozilla::gfx::DrawTargetOffset::MaskSurface(mozilla::gfx::Pattern const&, mozilla::gfx::SourceSurface*, mozilla::gfx::PointTyped<mozilla::gfx::UnknownUnits, float>, mozilla::gfx::DrawOptions const&)
Unexecuted instantiation: mozilla::gfx::DrawTargetOffset::FillGlyphs(mozilla::gfx::ScaledFont*, mozilla::gfx::GlyphBuffer const&, mozilla::gfx::Pattern const&, mozilla::gfx::DrawOptions const&)
68
#define OFFSET_COMMAND5(command, type1, type2, type3, type4, type5) \
69
  void \
70
  DrawTargetOffset::command(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) \
71
  { \
72
    mDrawTarget->command(arg1, arg2, arg3, arg4, arg5); \
73
  }
74
75
OFFSET_COMMAND(Flush)
76
OFFSET_COMMAND1(ClearRect, const Rect&)
77
OFFSET_COMMAND4(MaskSurface, const Pattern&, SourceSurface*, Point, const DrawOptions&)
78
OFFSET_COMMAND4(FillGlyphs, ScaledFont*, const GlyphBuffer&, const Pattern&, const DrawOptions&)
79
OFFSET_COMMAND3(Mask, const Pattern&, const Pattern&, const DrawOptions&)
80
81
void
82
DrawTargetOffset::DrawFilter(FilterNode* aNode, const Rect& aSourceRect, const Point& aDestPoint, const DrawOptions& aOptions)
83
0
{
84
0
  auto clone = mTransform;
85
0
  bool invertible = clone.Invert();
86
0
  auto src = aSourceRect;
87
0
  if (invertible) {
88
0
    // Try to reduce the source rect so that it's not much bigger
89
0
    // than the draw target. The result is not minimal. Examples
90
0
    // are left as an exercise for the reader.
91
0
    auto destRect = Rect(mOrigin.x,
92
0
                         mOrigin.y,
93
0
                         mDrawTarget->GetSize().width,
94
0
                         mDrawTarget->GetSize().height);
95
0
    auto dtBounds = clone.TransformBounds(destRect);
96
0
    src = aSourceRect.Intersect(dtBounds);
97
0
  }
98
0
  auto shift = src.TopLeft() - aSourceRect.TopLeft();
99
0
  mDrawTarget->DrawFilter(aNode, src, aDestPoint + shift, aOptions);
100
0
}
101
102
void
103
DrawTargetOffset::PushClip(const Path* aPath)
104
0
{
105
0
  mDrawTarget->PushClip(aPath);
106
0
}
107
108
void
109
DrawTargetOffset::PushClipRect(const Rect& aRect)
110
0
{
111
0
  mDrawTarget->PushClipRect(aRect);
112
0
}
113
114
void
115
DrawTargetOffset::PopClip()
116
0
{
117
0
  mDrawTarget->PopClip();
118
0
}
119
120
void
121
DrawTargetOffset::CopySurface(SourceSurface *aSurface,
122
                             const IntRect &aSourceRect,
123
                             const IntPoint &aDestination)
124
0
{
125
0
  IntPoint tileOrigin = mOrigin;
126
0
  // CopySurface ignores the transform, account for that here.
127
0
  mDrawTarget->CopySurface(aSurface, aSourceRect, aDestination - tileOrigin);
128
0
}
129
130
void
131
DrawTargetOffset::SetTransform(const Matrix& aTransform)
132
0
{
133
0
  Matrix mat = aTransform;
134
0
  mat.PostTranslate(Float(-mOrigin.x), Float(-mOrigin.y));
135
0
  mDrawTarget->SetTransform(mat);
136
0
137
0
  DrawTarget::SetTransform(aTransform);
138
0
}
139
140
void
141
DrawTargetOffset::SetPermitSubpixelAA(bool aPermitSubpixelAA)
142
0
{
143
0
  mDrawTarget->SetPermitSubpixelAA(aPermitSubpixelAA);
144
0
}
145
146
void
147
DrawTargetOffset::DrawSurface(SourceSurface* aSurface, const Rect& aDest, const Rect& aSource, const DrawSurfaceOptions& aSurfaceOptions, const DrawOptions& aDrawOptions)
148
0
{
149
0
  mDrawTarget->DrawSurface(aSurface, aDest, aSource, aSurfaceOptions, aDrawOptions);
150
0
}
151
152
void
153
DrawTargetOffset::FillRect(const Rect& aRect, const Pattern& aPattern, const DrawOptions& aDrawOptions)
154
0
{
155
0
  mDrawTarget->FillRect(aRect, aPattern, aDrawOptions);
156
0
}
157
158
void
159
DrawTargetOffset::Stroke(const Path* aPath, const Pattern& aPattern, const StrokeOptions& aStrokeOptions, const DrawOptions& aDrawOptions)
160
0
{
161
0
  mDrawTarget->Stroke(aPath, aPattern, aStrokeOptions, aDrawOptions);
162
0
}
163
164
void
165
DrawTargetOffset::StrokeRect(const Rect& aRect, const Pattern& aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions& aDrawOptions)
166
0
{
167
0
  mDrawTarget->StrokeRect(aRect, aPattern, aStrokeOptions, aDrawOptions);
168
0
}
169
170
void
171
DrawTargetOffset::StrokeLine(const Point& aStart, const Point& aEnd, const Pattern& aPattern, const StrokeOptions &aStrokeOptions, const DrawOptions& aDrawOptions)
172
0
{
173
0
  mDrawTarget->StrokeLine(aStart, aEnd, aPattern, aStrokeOptions, aDrawOptions);
174
0
}
175
176
void
177
DrawTargetOffset::Fill(const Path* aPath, const Pattern& aPattern, const DrawOptions& aDrawOptions)
178
0
{
179
0
  mDrawTarget->Fill(aPath, aPattern, aDrawOptions);
180
0
}
181
182
void
183
DrawTargetOffset::PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask,
184
                           const Matrix& aMaskTransform, const IntRect& aBounds,
185
                           bool aCopyBackground)
186
0
{
187
0
  IntRect bounds = aBounds;
188
0
  bounds.MoveBy(mOrigin);
189
0
  mDrawTarget->PushLayer(aOpaque, aOpacity, aMask, aMaskTransform, bounds, aCopyBackground);
190
0
}
191
192
void
193
DrawTargetOffset::PushLayerWithBlend(bool aOpaque, Float aOpacity,
194
                                    SourceSurface* aMask,
195
                                    const Matrix& aMaskTransform,
196
                                    const IntRect& aBounds,
197
                                    bool aCopyBackground,
198
                                    CompositionOp aOp)
199
0
{
200
0
  IntRect bounds = aBounds;
201
0
  bounds.MoveBy(mOrigin);
202
0
  mDrawTarget->PushLayerWithBlend(aOpaque, aOpacity, aMask, aMaskTransform, bounds, aCopyBackground, aOp);
203
0
}
204
205
void
206
DrawTargetOffset::PopLayer()
207
0
{
208
0
  mDrawTarget->PopLayer();
209
0
}
210
211
} // namespace gfx
212
} // namespace mozilla