Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/2d/PathRecording.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_PATHRECORDING_H_
8
#define MOZILLA_GFX_PATHRECORDING_H_
9
10
#include "2D.h"
11
#include <vector>
12
#include <ostream>
13
14
#include "PathHelpers.h"
15
16
namespace mozilla {
17
namespace gfx {
18
19
struct PathOp
20
{
21
  enum OpType {
22
    OP_MOVETO = 0,
23
    OP_LINETO,
24
    OP_BEZIERTO,
25
    OP_QUADRATICBEZIERTO,
26
    OP_CLOSE
27
  };
28
29
  OpType mType;
30
  Point mP1;
31
  Point mP2;
32
  Point mP3;
33
};
34
35
const int32_t sPointCount[] = { 1, 1, 3, 2, 0, 0 };
36
37
class PathRecording;
38
class DrawEventRecorderPrivate;
39
40
class PathBuilderRecording : public PathBuilder
41
{
42
public:
43
  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilderRecording, override)
44
45
  PathBuilderRecording(PathBuilder *aBuilder, FillRule aFillRule)
46
    : mPathBuilder(aBuilder), mFillRule(aFillRule)
47
0
  {
48
0
  }
49
50
  /* Move the current point in the path, any figure currently being drawn will
51
   * be considered closed during fill operations, however when stroking the
52
   * closing line segment will not be drawn.
53
   */
54
  virtual void MoveTo(const Point &aPoint) override;
55
  /* Add a linesegment to the current figure */
56
  virtual void LineTo(const Point &aPoint) override;
57
  /* Add a cubic bezier curve to the current figure */
58
  virtual void BezierTo(const Point &aCP1,
59
                        const Point &aCP2,
60
                        const Point &aCP3) override;
61
  /* Add a quadratic bezier curve to the current figure */
62
  virtual void QuadraticBezierTo(const Point &aCP1,
63
                                 const Point &aCP2) override;
64
  /* Close the current figure, this will essentially generate a line segment
65
   * from the current point to the starting point for the current figure
66
   */
67
  virtual void Close() override;
68
69
  /* Add an arc to the current figure */
70
  virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
71
0
                   float aEndAngle, bool aAntiClockwise) override {
72
0
    ArcToBezier(this, aOrigin, Size(aRadius, aRadius), aStartAngle, aEndAngle,
73
0
                aAntiClockwise);
74
0
  }
75
76
  /* Point the current subpath is at - or where the next subpath will start
77
   * if there is no active subpath.
78
   */
79
  virtual Point CurrentPoint() const override;
80
81
  virtual already_AddRefed<Path> Finish() override;
82
83
0
  virtual BackendType GetBackendType() const override { return BackendType::RECORDING; }
84
85
private:
86
  friend class PathRecording;
87
88
  RefPtr<PathBuilder> mPathBuilder;
89
  FillRule mFillRule;
90
  std::vector<PathOp> mPathOps;
91
};
92
93
class PathRecording : public Path
94
{
95
public:
96
  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathRecording, override)
97
98
  PathRecording(Path *aPath, const std::vector<PathOp> aOps, FillRule aFillRule)
99
    : mPath(aPath), mPathOps(aOps), mFillRule(aFillRule)
100
0
  {
101
0
  }
102
103
  ~PathRecording();
104
105
0
  virtual BackendType GetBackendType() const override { return BackendType::RECORDING; }
106
  virtual already_AddRefed<PathBuilder> CopyToBuilder(FillRule aFillRule) const override;
107
  virtual already_AddRefed<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform,
108
                                                             FillRule aFillRule) const override;
109
  virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const override
110
0
  { return mPath->ContainsPoint(aPoint, aTransform); }
111
  virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
112
                                   const Point &aPoint,
113
                                   const Matrix &aTransform) const override
114
0
  { return mPath->StrokeContainsPoint(aStrokeOptions, aPoint, aTransform); }
115
116
  virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const override
117
0
  { return mPath->GetBounds(aTransform); }
118
119
  virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions,
120
                                const Matrix &aTransform = Matrix()) const override
121
0
  { return mPath->GetStrokedBounds(aStrokeOptions, aTransform); }
122
123
0
  virtual void StreamToSink(PathSink *aSink) const override { mPath->StreamToSink(aSink); }
124
125
0
  virtual FillRule GetFillRule() const override { return mFillRule; }
126
127
  void StorePath(std::ostream &aStream) const;
128
  static void ReadPathToBuilder(std::istream &aStream, PathBuilder *aBuilder);
129
130
private:
131
  friend class DrawTargetWrapAndRecord;
132
  friend class DrawTargetRecording;
133
  friend class RecordedPathCreation;
134
135
  RefPtr<Path> mPath;
136
  std::vector<PathOp> mPathOps;
137
  FillRule mFillRule;
138
139
  // Event recorders that have this path in their event stream.
140
  std::vector<RefPtr<DrawEventRecorderPrivate>> mStoredRecorders;
141
};
142
143
} // namespace gfx
144
} // namespace mozilla
145
146
#endif /* MOZILLA_GFX_PATHRECORDING_H_ */