Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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/. */
6 #include "PathRecording.h"
7 #include "DrawEventRecorder.h"
9 namespace mozilla {
10 namespace gfx {
12 using namespace std;
14 void
15 PathBuilderRecording::MoveTo(const Point &aPoint)
16 {
17 PathOp op;
18 op.mType = PathOp::OP_MOVETO;
19 op.mP1 = aPoint;
20 mPathOps.push_back(op);
21 mPathBuilder->MoveTo(aPoint);
22 }
24 void
25 PathBuilderRecording::LineTo(const Point &aPoint)
26 {
27 PathOp op;
28 op.mType = PathOp::OP_LINETO;
29 op.mP1 = aPoint;
30 mPathOps.push_back(op);
31 mPathBuilder->LineTo(aPoint);
32 }
34 void
35 PathBuilderRecording::BezierTo(const Point &aCP1, const Point &aCP2, const Point &aCP3)
36 {
37 PathOp op;
38 op.mType = PathOp::OP_BEZIERTO;
39 op.mP1 = aCP1;
40 op.mP2 = aCP2;
41 op.mP3 = aCP3;
42 mPathOps.push_back(op);
43 mPathBuilder->BezierTo(aCP1, aCP2, aCP3);
44 }
46 void
47 PathBuilderRecording::QuadraticBezierTo(const Point &aCP1, const Point &aCP2)
48 {
49 PathOp op;
50 op.mType = PathOp::OP_QUADRATICBEZIERTO;
51 op.mP1 = aCP1;
52 op.mP2 = aCP2;
53 mPathOps.push_back(op);
54 mPathBuilder->QuadraticBezierTo(aCP1, aCP2);
55 }
57 void
58 PathBuilderRecording::Close()
59 {
60 PathOp op;
61 op.mType = PathOp::OP_CLOSE;
62 mPathOps.push_back(op);
63 mPathBuilder->Close();
64 }
66 Point
67 PathBuilderRecording::CurrentPoint() const
68 {
69 return mPathBuilder->CurrentPoint();
70 }
72 TemporaryRef<Path>
73 PathBuilderRecording::Finish()
74 {
75 RefPtr<Path> path = mPathBuilder->Finish();
76 return new PathRecording(path, mPathOps, mFillRule);
77 }
79 PathRecording::~PathRecording()
80 {
81 for (size_t i = 0; i < mStoredRecorders.size(); i++) {
82 mStoredRecorders[i]->RemoveStoredPath(this);
83 mStoredRecorders[i]->RecordEvent(RecordedPathDestruction(this));
84 }
85 }
87 TemporaryRef<PathBuilder>
88 PathRecording::CopyToBuilder(FillRule aFillRule) const
89 {
90 RefPtr<PathBuilder> pathBuilder = mPath->CopyToBuilder(aFillRule);
91 RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(pathBuilder, aFillRule);
92 recording->mPathOps = mPathOps;
93 return recording;
94 }
96 TemporaryRef<PathBuilder>
97 PathRecording::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const
98 {
99 RefPtr<PathBuilder> pathBuilder = mPath->TransformedCopyToBuilder(aTransform, aFillRule);
100 RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(pathBuilder, aFillRule);
101 typedef std::vector<PathOp> pathOpVec;
102 for (pathOpVec::const_iterator iter = mPathOps.begin(); iter != mPathOps.end(); iter++) {
103 PathOp newPathOp;
104 newPathOp.mType = iter->mType;
105 if (sPointCount[newPathOp.mType] >= 1) {
106 newPathOp.mP1 = aTransform * iter->mP1;
107 }
108 if (sPointCount[newPathOp.mType] >= 2) {
109 newPathOp.mP2 = aTransform * iter->mP2;
110 }
111 if (sPointCount[newPathOp.mType] >= 3) {
112 newPathOp.mP3 = aTransform * iter->mP3;
113 }
114 recording->mPathOps.push_back(newPathOp);
115 }
116 return recording;
117 }
119 }
120 }