gfx/2d/PathRecording.h

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

mercurial