gfx/2d/PathRecording.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "PathRecording.h"
michael@0 7 #include "DrawEventRecorder.h"
michael@0 8
michael@0 9 namespace mozilla {
michael@0 10 namespace gfx {
michael@0 11
michael@0 12 using namespace std;
michael@0 13
michael@0 14 void
michael@0 15 PathBuilderRecording::MoveTo(const Point &aPoint)
michael@0 16 {
michael@0 17 PathOp op;
michael@0 18 op.mType = PathOp::OP_MOVETO;
michael@0 19 op.mP1 = aPoint;
michael@0 20 mPathOps.push_back(op);
michael@0 21 mPathBuilder->MoveTo(aPoint);
michael@0 22 }
michael@0 23
michael@0 24 void
michael@0 25 PathBuilderRecording::LineTo(const Point &aPoint)
michael@0 26 {
michael@0 27 PathOp op;
michael@0 28 op.mType = PathOp::OP_LINETO;
michael@0 29 op.mP1 = aPoint;
michael@0 30 mPathOps.push_back(op);
michael@0 31 mPathBuilder->LineTo(aPoint);
michael@0 32 }
michael@0 33
michael@0 34 void
michael@0 35 PathBuilderRecording::BezierTo(const Point &aCP1, const Point &aCP2, const Point &aCP3)
michael@0 36 {
michael@0 37 PathOp op;
michael@0 38 op.mType = PathOp::OP_BEZIERTO;
michael@0 39 op.mP1 = aCP1;
michael@0 40 op.mP2 = aCP2;
michael@0 41 op.mP3 = aCP3;
michael@0 42 mPathOps.push_back(op);
michael@0 43 mPathBuilder->BezierTo(aCP1, aCP2, aCP3);
michael@0 44 }
michael@0 45
michael@0 46 void
michael@0 47 PathBuilderRecording::QuadraticBezierTo(const Point &aCP1, const Point &aCP2)
michael@0 48 {
michael@0 49 PathOp op;
michael@0 50 op.mType = PathOp::OP_QUADRATICBEZIERTO;
michael@0 51 op.mP1 = aCP1;
michael@0 52 op.mP2 = aCP2;
michael@0 53 mPathOps.push_back(op);
michael@0 54 mPathBuilder->QuadraticBezierTo(aCP1, aCP2);
michael@0 55 }
michael@0 56
michael@0 57 void
michael@0 58 PathBuilderRecording::Close()
michael@0 59 {
michael@0 60 PathOp op;
michael@0 61 op.mType = PathOp::OP_CLOSE;
michael@0 62 mPathOps.push_back(op);
michael@0 63 mPathBuilder->Close();
michael@0 64 }
michael@0 65
michael@0 66 Point
michael@0 67 PathBuilderRecording::CurrentPoint() const
michael@0 68 {
michael@0 69 return mPathBuilder->CurrentPoint();
michael@0 70 }
michael@0 71
michael@0 72 TemporaryRef<Path>
michael@0 73 PathBuilderRecording::Finish()
michael@0 74 {
michael@0 75 RefPtr<Path> path = mPathBuilder->Finish();
michael@0 76 return new PathRecording(path, mPathOps, mFillRule);
michael@0 77 }
michael@0 78
michael@0 79 PathRecording::~PathRecording()
michael@0 80 {
michael@0 81 for (size_t i = 0; i < mStoredRecorders.size(); i++) {
michael@0 82 mStoredRecorders[i]->RemoveStoredPath(this);
michael@0 83 mStoredRecorders[i]->RecordEvent(RecordedPathDestruction(this));
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 TemporaryRef<PathBuilder>
michael@0 88 PathRecording::CopyToBuilder(FillRule aFillRule) const
michael@0 89 {
michael@0 90 RefPtr<PathBuilder> pathBuilder = mPath->CopyToBuilder(aFillRule);
michael@0 91 RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(pathBuilder, aFillRule);
michael@0 92 recording->mPathOps = mPathOps;
michael@0 93 return recording;
michael@0 94 }
michael@0 95
michael@0 96 TemporaryRef<PathBuilder>
michael@0 97 PathRecording::TransformedCopyToBuilder(const Matrix &aTransform, FillRule aFillRule) const
michael@0 98 {
michael@0 99 RefPtr<PathBuilder> pathBuilder = mPath->TransformedCopyToBuilder(aTransform, aFillRule);
michael@0 100 RefPtr<PathBuilderRecording> recording = new PathBuilderRecording(pathBuilder, aFillRule);
michael@0 101 typedef std::vector<PathOp> pathOpVec;
michael@0 102 for (pathOpVec::const_iterator iter = mPathOps.begin(); iter != mPathOps.end(); iter++) {
michael@0 103 PathOp newPathOp;
michael@0 104 newPathOp.mType = iter->mType;
michael@0 105 if (sPointCount[newPathOp.mType] >= 1) {
michael@0 106 newPathOp.mP1 = aTransform * iter->mP1;
michael@0 107 }
michael@0 108 if (sPointCount[newPathOp.mType] >= 2) {
michael@0 109 newPathOp.mP2 = aTransform * iter->mP2;
michael@0 110 }
michael@0 111 if (sPointCount[newPathOp.mType] >= 3) {
michael@0 112 newPathOp.mP3 = aTransform * iter->mP3;
michael@0 113 }
michael@0 114 recording->mPathOps.push_back(newPathOp);
michael@0 115 }
michael@0 116 return recording;
michael@0 117 }
michael@0 118
michael@0 119 }
michael@0 120 }

mercurial