/src/mozilla-central/gfx/2d/PathRecording.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 "PathRecording.h" |
8 | | #include "DrawEventRecorder.h" |
9 | | #include "RecordedEventImpl.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace gfx { |
13 | | |
14 | | using namespace std; |
15 | | |
16 | | void |
17 | | PathBuilderRecording::MoveTo(const Point &aPoint) |
18 | 0 | { |
19 | 0 | PathOp op; |
20 | 0 | op.mType = PathOp::OP_MOVETO; |
21 | 0 | op.mP1 = aPoint; |
22 | 0 | mPathOps.push_back(op); |
23 | 0 | mPathBuilder->MoveTo(aPoint); |
24 | 0 | } |
25 | | |
26 | | void |
27 | | PathBuilderRecording::LineTo(const Point &aPoint) |
28 | 0 | { |
29 | 0 | PathOp op; |
30 | 0 | op.mType = PathOp::OP_LINETO; |
31 | 0 | op.mP1 = aPoint; |
32 | 0 | mPathOps.push_back(op); |
33 | 0 | mPathBuilder->LineTo(aPoint); |
34 | 0 | } |
35 | | |
36 | | void |
37 | | PathBuilderRecording::BezierTo(const Point &aCP1, const Point &aCP2, const Point &aCP3) |
38 | 0 | { |
39 | 0 | PathOp op; |
40 | 0 | op.mType = PathOp::OP_BEZIERTO; |
41 | 0 | op.mP1 = aCP1; |
42 | 0 | op.mP2 = aCP2; |
43 | 0 | op.mP3 = aCP3; |
44 | 0 | mPathOps.push_back(op); |
45 | 0 | mPathBuilder->BezierTo(aCP1, aCP2, aCP3); |
46 | 0 | } |
47 | | |
48 | | void |
49 | | PathBuilderRecording::QuadraticBezierTo(const Point &aCP1, const Point &aCP2) |
50 | 0 | { |
51 | 0 | PathOp op; |
52 | 0 | op.mType = PathOp::OP_QUADRATICBEZIERTO; |
53 | 0 | op.mP1 = aCP1; |
54 | 0 | op.mP2 = aCP2; |
55 | 0 | mPathOps.push_back(op); |
56 | 0 | mPathBuilder->QuadraticBezierTo(aCP1, aCP2); |
57 | 0 | } |
58 | | |
59 | | void |
60 | | PathBuilderRecording::Close() |
61 | 0 | { |
62 | 0 | PathOp op; |
63 | 0 | op.mType = PathOp::OP_CLOSE; |
64 | 0 | mPathOps.push_back(op); |
65 | 0 | mPathBuilder->Close(); |
66 | 0 | } |
67 | | |
68 | | Point |
69 | | PathBuilderRecording::CurrentPoint() const |
70 | 0 | { |
71 | 0 | return mPathBuilder->CurrentPoint(); |
72 | 0 | } |
73 | | |
74 | | already_AddRefed<Path> |
75 | | PathBuilderRecording::Finish() |
76 | 0 | { |
77 | 0 | RefPtr<Path> path = mPathBuilder->Finish(); |
78 | 0 | return MakeAndAddRef<PathRecording>(path, mPathOps, mFillRule); |
79 | 0 | } |
80 | | |
81 | | PathRecording::~PathRecording() |
82 | 0 | { |
83 | 0 | for (size_t i = 0; i < mStoredRecorders.size(); i++) { |
84 | 0 | mStoredRecorders[i]->RemoveStoredObject(this); |
85 | 0 | mStoredRecorders[i]->RecordEvent(RecordedPathDestruction(this)); |
86 | 0 | } |
87 | 0 | } |
88 | | |
89 | | already_AddRefed<PathBuilder> |
90 | | PathRecording::CopyToBuilder(FillRule aFillRule) const |
91 | 0 | { |
92 | 0 | RefPtr<PathBuilder> pathBuilder = mPath->CopyToBuilder(aFillRule); |
93 | 0 | RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(pathBuilder, aFillRule); |
94 | 0 | recording->mPathOps = mPathOps; |
95 | 0 | return recording.forget(); |
96 | 0 | } |
97 | | |
98 | | already_AddRefed<PathBuilder> |
99 | | PathRecording::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const |
100 | 0 | { |
101 | 0 | RefPtr<PathBuilder> pathBuilder = mPath->TransformedCopyToBuilder(aTransform, aFillRule); |
102 | 0 | RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(pathBuilder, aFillRule); |
103 | 0 | typedef std::vector<PathOp> pathOpVec; |
104 | 0 | for (pathOpVec::const_iterator iter = mPathOps.begin(); iter != mPathOps.end(); iter++) { |
105 | 0 | PathOp newPathOp; |
106 | 0 | newPathOp.mType = iter->mType; |
107 | 0 | if (sPointCount[newPathOp.mType] >= 1) { |
108 | 0 | newPathOp.mP1 = aTransform.TransformPoint(iter->mP1); |
109 | 0 | } |
110 | 0 | if (sPointCount[newPathOp.mType] >= 2) { |
111 | 0 | newPathOp.mP2 = aTransform.TransformPoint(iter->mP2); |
112 | 0 | } |
113 | 0 | if (sPointCount[newPathOp.mType] >= 3) { |
114 | 0 | newPathOp.mP3 = aTransform.TransformPoint(iter->mP3); |
115 | 0 | } |
116 | 0 | recording->mPathOps.push_back(newPathOp); |
117 | 0 | } |
118 | 0 | return recording.forget(); |
119 | 0 | } |
120 | | |
121 | | } // namespace gfx |
122 | | } // namespace mozilla |