Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/2d/DrawTargetDual.h
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
#ifndef MOZILLA_GFX_DRAWTARGETDUAL_H_
8
#define MOZILLA_GFX_DRAWTARGETDUAL_H_
9
     
10
#include <vector>
11
#include <sstream>
12
13
#include "SourceSurfaceDual.h"
14
     
15
#include "2D.h"
16
#include "Filters.h"
17
     
18
namespace mozilla {
19
namespace gfx {
20
     
21
#define FORWARD_FUNCTION(funcName) \
22
0
  virtual void funcName() override { mA->funcName(); mB->funcName(); }
Unexecuted instantiation: mozilla::gfx::DrawTargetDual::Flush()
Unexecuted instantiation: mozilla::gfx::DrawTargetDual::PopClip()
Unexecuted instantiation: mozilla::gfx::DrawTargetDual::PopLayer()
23
#define FORWARD_FUNCTION1(funcName, var1Type, var1Name) \
24
0
  virtual void funcName(var1Type var1Name) override { mA->funcName(var1Name); mB->funcName(var1Name); }
Unexecuted instantiation: mozilla::gfx::DrawTargetDual::PushClip(mozilla::gfx::Path const*)
Unexecuted instantiation: mozilla::gfx::DrawTargetDual::PushClipRect(mozilla::gfx::RectTyped<mozilla::gfx::UnknownUnits, float> const&)
25
26
/* This is a special type of DrawTarget. It duplicates all drawing calls
27
 * accross two drawtargets. An exception to this is when a snapshot of another
28
 * dual DrawTarget is used as the source for any surface data. In this case
29
 * the snapshot of the first source DrawTarget is used as a source for the call
30
 * to the first destination DrawTarget (mA) and the snapshot of the second
31
 * source DrawTarget is used at the source for the second destination
32
 * DrawTarget (mB). This class facilitates black-background/white-background
33
 * drawing for per-component alpha extraction for backends which do not support
34
 * native component alpha.
35
 */
36
class DrawTargetDual : public DrawTarget
37
{
38
public:
39
  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetDual, override)
40
  DrawTargetDual(DrawTarget *aA, DrawTarget *aB)
41
    : mA(aA)
42
    , mB(aB)
43
0
  { 
44
0
    mFormat = aA->GetFormat();
45
0
  }
46
     
47
0
  virtual DrawTargetType GetType() const override { return mA->GetType(); }
48
0
  virtual BackendType GetBackendType() const override { return mA->GetBackendType(); }
49
0
  virtual already_AddRefed<SourceSurface> Snapshot() override {
50
0
    return MakeAndAddRef<SourceSurfaceDual>(mA, mB);
51
0
  }
52
0
  virtual IntSize GetSize() const override { return mA->GetSize(); }
53
54
  virtual void DetachAllSnapshots() override;
55
56
  FORWARD_FUNCTION(Flush)
57
  FORWARD_FUNCTION1(PushClip, const Path *, aPath)
58
  FORWARD_FUNCTION1(PushClipRect, const Rect &, aRect)
59
  FORWARD_FUNCTION(PopClip)
60
  FORWARD_FUNCTION(PopLayer)
61
62
0
  virtual void SetTransform(const Matrix &aTransform) override {
63
0
    mTransform = aTransform;
64
0
    mA->SetTransform(aTransform);
65
0
    mB->SetTransform(aTransform);
66
0
  }
67
68
  virtual void DrawSurface(SourceSurface *aSurface, const Rect &aDest, const Rect & aSource,
69
                           const DrawSurfaceOptions &aSurfOptions, const DrawOptions &aOptions) override;
70
71
  virtual void DrawFilter(FilterNode *aNode,
72
                          const Rect &aSourceRect,
73
                          const Point &aDestPoint,
74
                          const DrawOptions &aOptions = DrawOptions()) override
75
0
  {
76
0
    mA->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions);
77
0
    mB->DrawFilter(aNode, aSourceRect, aDestPoint, aOptions);
78
0
  }
79
80
  virtual void MaskSurface(const Pattern &aSource,
81
                           SourceSurface *aMask,
82
                           Point aOffset,
83
                           const DrawOptions &aOptions = DrawOptions()) override;
84
85
  virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, const Point &aDest,
86
                                     const Color &aColor, const Point &aOffset,
87
                                     Float aSigma, CompositionOp aOp) override;
88
89
  virtual void ClearRect(const Rect &aRect) override;
90
91
  virtual void CopySurface(SourceSurface *aSurface, const IntRect &aSourceRect,
92
                           const IntPoint &aDestination) override;
93
94
  virtual void FillRect(const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions) override;
95
96
  virtual void StrokeRect(const Rect &aRect, const Pattern &aPattern,
97
                          const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) override;
98
99
  virtual void StrokeLine(const Point &aStart, const Point &aEnd, const Pattern &aPattern,
100
                          const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) override;
101
102
  virtual void Stroke(const Path *aPath, const Pattern &aPattern,
103
                      const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) override;
104
105
  virtual void Fill(const Path *aPath, const Pattern &aPattern, const DrawOptions &aOptions) override;
106
107
  virtual void FillGlyphs(ScaledFont *aScaledFont, const GlyphBuffer &aBuffer,
108
                          const Pattern &aPattern, const DrawOptions &aOptions) override;
109
  
110
  virtual void Mask(const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions) override;
111
112
  virtual void PushLayer(bool aOpaque, Float aOpacity,
113
                         SourceSurface* aMask,
114
                         const Matrix& aMaskTransform,
115
                         const IntRect& aBounds = IntRect(),
116
                         bool aCopyBackground = false) override;
117
118
  virtual bool Unrotate(IntPoint aRotation) override
119
0
  {
120
0
    return mA->Unrotate(aRotation) &&
121
0
           mB->Unrotate(aRotation);
122
0
  }
123
124
  virtual already_AddRefed<SourceSurface>
125
    CreateSourceSurfaceFromData(unsigned char *aData,
126
                                const IntSize &aSize,
127
                                int32_t aStride,
128
                                SurfaceFormat aFormat) const override
129
0
  {
130
0
    return mA->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat);
131
0
  }
132
     
133
  virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override
134
0
  {
135
0
    return mA->OptimizeSourceSurface(aSurface);
136
0
  }
137
     
138
  virtual already_AddRefed<SourceSurface>
139
    CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override
140
0
  {
141
0
    return mA->CreateSourceSurfaceFromNativeSurface(aSurface);
142
0
  }
143
     
144
  virtual already_AddRefed<DrawTarget>
145
    CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override;
146
     
147
  virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override
148
0
  {
149
0
    return mA->CreatePathBuilder(aFillRule);
150
0
  }
151
     
152
  virtual already_AddRefed<GradientStops>
153
    CreateGradientStops(GradientStop *aStops,
154
                        uint32_t aNumStops,
155
                        ExtendMode aExtendMode = ExtendMode::CLAMP) const override
156
0
  {
157
0
    return mA->CreateGradientStops(aStops, aNumStops, aExtendMode);
158
0
  }
159
160
  virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override
161
0
  {
162
0
    return mA->CreateFilter(aType);
163
0
  }
164
165
  virtual void *GetNativeSurface(NativeSurfaceType aType) override
166
0
  {
167
0
    return nullptr;
168
0
  }
169
170
  virtual bool IsDualDrawTarget() const override
171
0
  {
172
0
    return true;
173
0
  }
174
175
0
  virtual bool IsCurrentGroupOpaque() override { return mA->IsCurrentGroupOpaque(); }
176
     
177
private:
178
  RefPtr<DrawTarget> mA;
179
  RefPtr<DrawTarget> mB;
180
};
181
     
182
} // namespace gfx
183
} // namespace mozilla
184
     
185
#endif /* MOZILLA_GFX_DRAWTARGETDUAL_H_ */